Title: [201053] trunk
Revision
201053
Author
[email protected]
Date
2016-05-17 15:52:47 -0700 (Tue, 17 May 2016)

Log Message

REGRESSION(r192855): Math.random() always produces the same first 7 decimal points the first two invocations
https://bugs.webkit.org/show_bug.cgi?id=157805
<rdar://problem/26327851>

Patch by Joseph Pecoraro <[email protected]> on 2016-05-17
Reviewed by Geoffrey Garen.

Source/WTF:

* wtf/WeakRandom.h:
(WTF::WeakRandom::setSeed):
Advance once to randomize the 32bit seed across the 128bit state
and avoid re-using 64bits of state in the second advance.

LayoutTests:

* js/dom/math-random-initial-values-expected.txt: Added.
* js/dom/math-random-initial-values.html: Added.
* js/resources/math-random-initial-values-iframe.html: Added.
Test that less then 5% of the time, early Math.random invocations
produce very similiar values. Before this change we were failing
100%, but after we see similiar values mostly around 0-3%.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (201052 => 201053)


--- trunk/LayoutTests/ChangeLog	2016-05-17 22:39:00 UTC (rev 201052)
+++ trunk/LayoutTests/ChangeLog	2016-05-17 22:52:47 UTC (rev 201053)
@@ -1,3 +1,18 @@
+2016-05-17  Joseph Pecoraro  <[email protected]>
+
+        REGRESSION(r192855): Math.random() always produces the same first 7 decimal points the first two invocations
+        https://bugs.webkit.org/show_bug.cgi?id=157805
+        <rdar://problem/26327851>
+
+        Reviewed by Geoffrey Garen.
+
+        * js/dom/math-random-initial-values-expected.txt: Added.
+        * js/dom/math-random-initial-values.html: Added.
+        * js/resources/math-random-initial-values-iframe.html: Added.
+        Test that less then 5% of the time, early Math.random invocations
+        produce very similiar values. Before this change we were failing
+        100%, but after we see similiar values mostly around 0-3%.
+
 2016-05-17  Keith Miller  <[email protected]>
 
         Rollout r200426 since it causes PLT regressions.

Added: trunk/LayoutTests/js/dom/math-random-initial-values-expected.txt (0 => 201053)


--- trunk/LayoutTests/js/dom/math-random-initial-values-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/js/dom/math-random-initial-values-expected.txt	2016-05-17 22:52:47 UTC (rev 201053)
@@ -0,0 +1,10 @@
+This tests early Math.random values are not consistently nearly identical.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS framesWithSimiliarEarlyRandomValues <= 5 is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/js/dom/math-random-initial-values.html (0 => 201053)


--- trunk/LayoutTests/js/dom/math-random-initial-values.html	                        (rev 0)
+++ trunk/LayoutTests/js/dom/math-random-initial-values.html	2016-05-17 22:52:47 UTC (rev 201053)
@@ -0,0 +1,44 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+window.jsTestIsAsync = true;
+
+description("This tests early Math.random values are not consistently nearly identical.");
+
+var seen = 0;
+var expected = 100;
+var framesWithSimiliarEarlyRandomValues = 0;
+var lastRandom1 = 0;
+
+window.addEventListener("message", function(event) {
+    if (event.data.similiar)
+        framesWithSimiliarEarlyRandomValues++;
+
+    if (event.data.random1 === lastRandom1)
+        testFailed("Random number should be different between frames");
+    lastRandom1 = event.data.random1;
+
+    if (++seen === expected) {
+        shouldBeTrue("framesWithSimiliarEarlyRandomValues <= 5");
+        if (framesWithSimiliarEarlyRandomValues > 5)
+            debug("framesWithSimiliarEarlyRandomValues: " + framesWithSimiliarEarlyRandomValues);
+        finishJSTest();
+    }
+});
+
+function createFrame() {
+    var iframe = document.createElement("iframe");
+    iframe.src = ""
+    document.body.appendChild(iframe);
+}
+
+for (var i = 0; i < expected; ++i)
+    createFrame();
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/js/resources/math-random-initial-values-iframe.html (0 => 201053)


--- trunk/LayoutTests/js/resources/math-random-initial-values-iframe.html	                        (rev 0)
+++ trunk/LayoutTests/js/resources/math-random-initial-values-iframe.html	2016-05-17 22:52:47 UTC (rev 201053)
@@ -0,0 +1,6 @@
+<script>
+var random1 = Math.random();
+var random2 = Math.random();
+var similiar = Math.floor(random1 * 1000) === Math.floor(random2 * 1000);
+window.top.postMessage({similiar, random1, random2}, "*");
+</script>

Modified: trunk/Source/WTF/ChangeLog (201052 => 201053)


--- trunk/Source/WTF/ChangeLog	2016-05-17 22:39:00 UTC (rev 201052)
+++ trunk/Source/WTF/ChangeLog	2016-05-17 22:52:47 UTC (rev 201053)
@@ -1,3 +1,16 @@
+2016-05-17  Joseph Pecoraro  <[email protected]>
+
+        REGRESSION(r192855): Math.random() always produces the same first 7 decimal points the first two invocations
+        https://bugs.webkit.org/show_bug.cgi?id=157805
+        <rdar://problem/26327851>
+
+        Reviewed by Geoffrey Garen.
+
+        * wtf/WeakRandom.h:
+        (WTF::WeakRandom::setSeed):
+        Advance once to randomize the 32bit seed across the 128bit state
+        and avoid re-using 64bits of state in the second advance.
+
 2016-05-17  Dean Jackson  <[email protected]>
 
         Remove ES6_GENERATORS flag

Modified: trunk/Source/WTF/wtf/WeakRandom.h (201052 => 201053)


--- trunk/Source/WTF/wtf/WeakRandom.h	2016-05-17 22:39:00 UTC (rev 201052)
+++ trunk/Source/WTF/wtf/WeakRandom.h	2016-05-17 22:52:47 UTC (rev 201053)
@@ -56,6 +56,7 @@
 
         m_low = seed;
         m_high = seed;
+        advance();
     }
 
     unsigned seed() const { return m_seed; }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to