Create correctness tests for binary snippet operators.
https://bugs.webkit.org/show_bug.cgi?id=151465

Reviewed by Geoffrey Garen.

Implement a common infrastructure for generating and running tests on binary
operators.  Also re-implemented the op_add, op_sub, and op_mul tests to be based
on this new infrastructure.

* tests/stress/op_add.js:
* tests/stress/op_mul.js:
* tests/stress/op_sub.js:
- These were reimplemented using binary-op-test.js.

* tests/stress/op_div.js: Added.
* tests/stress/op_mod.js: Added.

* tests/stress/op_bitand.js: Added.
* tests/stress/op_bitor.js: Added.
* tests/stress/op_bitxor.js: Added.

* tests/stress/op_lshift.js: Added.
* tests/stress/op_rshift.js: Added.
* tests/stress/op_urshift.js: Added.

* tests/stress/resources/binary-op-test.js: Added.
- Common code for generating and running tests.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@192664 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/tests/stress/op_add.js b/Source/JavaScriptCore/tests/stress/op_add.js
index 143f9d3..6b613fb 100644
--- a/Source/JavaScriptCore/tests/stress/op_add.js
+++ b/Source/JavaScriptCore/tests/stress/op_add.js
@@ -1,363 +1,63 @@
 //@ runFTLNoCJIT
 
-// This test module aims to test the addition operator by comparing its runtime
-// behavior (using the different tiers) with expected values computed at initialization
-// time using the LLINT / bytecode generator.
-//
-// It works by generating test scenarios from permutations of value pairs to exercise
-// the addition operator. It computes the expected results by evaluating an expression
-// to add the values in an initialization pass. The scenarios are later applied to
-// a set of test functions of the forms:
-//
-//     variable + variable
-//     constant + variable
-//     variable + constant
-//
-// See generateScenarios() and initializeTestCases() for details on how the test
-// cases are generated.
-//
 // If all goes well, this test module will terminate silently. If not, it will print
-// errors.
+// errors. See binary-op-test.js for debugging options if needed.
 
-var verbose = false;
-var abortOnFirstFail = false;
+load("./resources/binary-op-test.js");
+
+//============================================================================
+// Test configuration data:
+
+var opName = "add";
+var op = "+";
 
 var o1 = {
     valueOf: function() { return 10; }
 };
 
-var set1 = [
+var posInfinity = 1 / 0;
+var negInfinity = -1 / 0;
+
+var values = [
     'o1',
     'null',
     'undefined',
-    'NaN',
-    '"abc"',
-];
-
-var set2 = [
-    '10',
-    '-10',
-    '2147483647',
-    '-2147483647',
-    '4294967296',
-    '-4294967296',
-    '100.2',
-    '-100.2',
     'true',
     'false',
+
+    'NaN',
+    'posInfinity',
+    'negInfinity',
+    '100.2', // Some random small double value.
+    '-100.2',
+    '54294967296.2923', // Some random large double value.
+    '-54294967296.2923',
+
+    '0',
+    '-0',
+    '1',
+    '-1',
+    '0x3fff',
+    '-0x3fff',
+    '0x7fff',
+    '-0x7fff',
+    '0x10000',
+    '-0x10000',
+    '0x7ffffff',
+    '-0x7ffffff',
+    '0x100000000',
+    '-0x100000000',
+
+    '"abc"',
+    '"0"',
+    '"-0"',
+    '"1"',
+    '"-1"',
 ];
 
-// Assemble the values that we'll be testing with:
-var values = [];
-for (var i = 0; i < set1.length; i++)
-    values.push(set1[i]);
-for (var i = 0; i < set2.length; i++)
-    values.push(set2[i]);
-for (var i = 0; i < set2.length; i++)
-    values.push('"' + set2[i] + '"');
+tests = [];
+generateBinaryTests(tests, opName, op, "VarVar", values, values);
+generateBinaryTests(tests, opName, op, "VarConst", values, values);
+generateBinaryTests(tests, opName, op, "ConstVar", values, values);
 
-function generateScenarios(xvalues, yvalues) {
-    var scenarios = [];
-    for (var i = 0; i < xvalues.length; i++) {
-        for (var j = 0; j < yvalues.length; j++) {
-            var xStr = xvalues[i];
-            var yStr = yvalues[j];
-            var x = eval(xStr);
-            var y = eval(yStr);
-            var name = "(" + xStr + " + " + yStr + ")";
-            var expected = eval("" + xStr + " + " + yStr);
-            var scenario = { name: name, x: x, y: y, expected: expected };
-
-            scenarios.push(scenario);
-        }
-    }
-    return scenarios;
-}
-
-function printScenarios(scenarios) {
-    for (var i = 0; i < scenarios.length; i++) {
-        var scenario = scenarios[i];
-        print("scenario[" + i + "]: { name: " + scenario.name + ", x: " + scenario.x, ", y: " + scenario.y + ", expected: " + scenario.expected + " }");
-    }
-}
-
-var testCases = [
-    {
-        name: "add",
-        func: function(x, y) { return x + y; },
-        xvalues: values,
-        yvalues: values
-    },
-    {
-        name: "addI32V",
-        func: function(x, y) { return 10 + y; },
-        xvalues: [ '10' ],
-        yvalues: values
-    },
-    {
-        name: "addVI32",
-        func: function(x, y) { return x + 10; },
-        xvalues: values,
-        yvalues: [ '10' ]
-    },
-    {
-        name: "addI32oV",
-        func: function(x, y) { return 2147483647 + y; },
-        xvalues: [ '2147483647' ],
-        yvalues: values
-    },
-    {
-        name: "addVI32o",
-        func: function(x, y) { return x + 2147483647; },
-        xvalues: values,
-        yvalues: [ '2147483647' ]
-    },
-    {
-        name: "addI32onV",
-        func: function(x, y) { return -2147483647 + y; },
-        xvalues: [ '-2147483647' ],
-        yvalues: values
-    },
-    {
-        name: "addVI32on",
-        func: function(x, y) { return x + (-2147483647); },
-        xvalues: values,
-        yvalues: [ '-2147483647' ]
-    },
-    {
-        name: "addI52V",
-        func: function(x, y) { return 4294967296 + y; },
-        xvalues: [ '4294967296' ],
-        yvalues: values
-    },
-    {
-        name: "addVI52",
-        func: function(x, y) { return x + 4294967296; },
-        xvalues: values,
-        yvalues: [ '4294967296' ]
-    },
-    {
-        name: "addI52nV",
-        func: function(x, y) { return -4294967296 + y; },
-        xvalues: [ '-4294967296' ],
-        yvalues: values
-    },
-    {
-        name: "addVI52n",
-        func: function(x, y) { return x + (-4294967296); },
-        xvalues: values,
-        yvalues: [ '-4294967296' ]
-    },
-    {
-        name: "addDV",
-        func: function(x, y) { return 100.2 + y; },
-        xvalues: [ '100.2' ],
-        yvalues: values
-    },
-    {
-        name: "addVD",
-        func: function(x, y) { return x + 100.2; },
-        xvalues: values,
-        yvalues: [ '100.2' ]
-    },
-    {
-        name: "addBV",
-        func: function(x, y) { return true + y; },
-        xvalues: [ 'true' ],
-        yvalues: values
-    },
-    {
-        name: "addVB",
-        func: function(x, y) { return x + true; },
-        xvalues: values,
-        yvalues: [ 'true' ]
-    },
-    {
-        name: "addSi32V",
-        func: function(x, y) { return "10" + y; },
-        xvalues: [ '"10"' ],
-        yvalues: values
-    },
-    {
-        name: "addVSi32",
-        func: function(x, y) { return x + "10"; },
-        xvalues: values,
-        yvalues: [ '"10"' ]
-    },
-
-    {
-        name: "addSi32oV",
-        func: function(x, y) { return "2147483647" + y; },
-        xvalues: [ '"2147483647"' ],
-        yvalues: values
-    },
-    {
-        name: "addVSi32o",
-        func: function(x, y) { return x + "2147483647"; },
-        xvalues: values,
-        yvalues: [ '"2147483647"' ]
-    },
-    {
-        name: "addSi32onV",
-        func: function(x, y) { return "-2147483647" + y; },
-        xvalues: [ '"-2147483647"' ],
-        yvalues: values
-    },
-    {
-        name: "addVSi32on",
-        func: function(x, y) { return x + "-2147483647"; },
-        xvalues: values,
-        yvalues: [ '"-2147483647"' ]
-    },
-    {
-        name: "addSi52V",
-        func: function(x, y) { return "4294967296" + y; },
-        xvalues: [ '"4294967296"' ],
-        yvalues: values
-    },
-    {
-        name: "addVSi52",
-        func: function(x, y) { return x + "4294967296"; },
-        xvalues: values,
-        yvalues: [ '"4294967296"' ]
-    },
-    {
-        name: "addSi52nV",
-        func: function(x, y) { return "-4294967296" + y; },
-        xvalues: [ '"-4294967296"' ],
-        yvalues: values
-    },
-    {
-        name: "addVSi52n",
-        func: function(x, y) { return x + "-4294967296"; },
-        xvalues: values,
-        yvalues: [ '"-4294967296"' ]
-    },
-    {
-        name: "addSdV",
-        func: function(x, y) { return "100.2" + y; },
-        xvalues: [ '"100.2"' ],
-        yvalues: values
-    },
-    {
-        name: "addVSd",
-        func: function(x, y) { return x + "100.2"; },
-        xvalues: values,
-        yvalues: [ '"100.2"' ]
-    },
-    {
-        name: "addSbV",
-        func: function(x, y) { return "true" + y; },
-        xvalues: [ '"true"' ],
-        yvalues: values
-    },
-    {
-        name: "addVSb",
-        func: function(x, y) { return x + "true"; },
-        xvalues: values,
-        yvalues: [ '"true"' ]
-    },
-
-    {
-        name: "addSV",
-        func: function(x, y) { return "abc" + y; },
-        xvalues: [ '"abc"' ],
-        yvalues: values
-    },
-    {
-        name: "addVS",
-        func: function(x, y) { return x + "abc"; },
-        xvalues: values,
-        yvalues: [ '"abc"' ]
-    },
-    {
-        name: "addNV",
-        func: function(x, y) { return null + y; },
-        xvalues: [ 'null' ],
-        yvalues: values
-    },
-    {
-        name: "addVN",
-        func: function(x, y) { return x + null; },
-        xvalues: values,
-        yvalues: [ 'null' ]
-    },
-    {
-        name: "addOV",
-        func: function(x, y) { return o1 + y; },
-        xvalues: [ 'o1' ],
-        yvalues: values
-    },
-    {
-        name: "addVO",
-        func: function(x, y) { return x + o1; },
-        xvalues: values,
-        yvalues: [ 'o1' ]
-    },
-    {
-        name: "addNaNV",
-        func: function(x, y) { return NaN + y; },
-        xvalues: [ 'NaN' ],
-        yvalues: values
-    },
-    {
-        name: "addVNaN",
-        func: function(x, y) { return x + NaN; },
-        xvalues: values,
-        yvalues: [ 'NaN' ]
-    },
-];
-
-function initializeTestCases() {
-    for (var test of testCases) {
-        noInline(test.func);
-        test.scenarios = generateScenarios(test.xvalues, test.yvalues);
-    }
-}
-initializeTestCases();
-
-var errorReport = "";
-
-function stringifyIfNeeded(x) {
-    if (typeof x == "string")
-        return '"' + x + '"';
-    return x;
-}
-
-function runTest(test) {
-    var failedScenario = [];
-    var scenarios = test.scenarios;
-    var testFunc = test.func;
-    try {
-        for (var i = 0; i < 10000; i++) {
-            for (var scenarioID = 0; scenarioID < scenarios.length; scenarioID++) {
-                var scenario = scenarios[scenarioID];
-                if (verbose)
-                    print("Testing " + test.name + ":" + scenario.name + " on iteration " + i + ": expecting " + stringifyIfNeeded(scenario.expected)); 
-
-                var result = testFunc(scenario.x, scenario.y);
-                if (result == scenario.expected)
-                    continue;
-                if (Number.isNaN(result) && Number.isNaN(scenario.expected))
-                    continue;
-                if (!failedScenario[scenarioID]) {
-                    errorReport += "FAIL: " + test.name + ":" + scenario.name + " started failing on iteration " + i
-                        + ": expected " + stringifyIfNeeded(scenario.expected) + ", actual " + stringifyIfNeeded(result) + "\n";
-                    if (abortOnFirstFail)
-                        throw errorReport;
-                    failedScenario[scenarioID] = scenario;
-                }
-            }
-        }
-    } catch(e) {
-        if (abortOnFirstFail)
-            throw e; // Negate the catch by re-throwing.
-        errorReport += "Unexpected exception: " + e + "\n";
-    }
-}
-
-for (var test of testCases)
-    runTest(test);
-
-if (errorReport !== "")
-    throw "Error: bad result:\n" + errorReport;
+run();
diff --git a/Source/JavaScriptCore/tests/stress/op_bitand.js b/Source/JavaScriptCore/tests/stress/op_bitand.js
new file mode 100644
index 0000000..d511a2a
--- /dev/null
+++ b/Source/JavaScriptCore/tests/stress/op_bitand.js
@@ -0,0 +1,69 @@
+//@ runFTLNoCJIT
+
+// If all goes well, this test module will terminate silently. If not, it will print
+// errors. See binary-op-test.js for debugging options if needed.
+
+load("./resources/binary-op-test.js");
+
+//============================================================================
+// Test configuration data:
+
+var opName = "bitand";
+var op = "&";
+
+var o1 = {
+    valueOf: function() { return 10; }
+};
+
+var posInfinity = 1 / 0;
+var negInfinity = -1 / 0;
+
+var values = [
+    'o1',
+    'null',
+    'undefined',
+    'true',
+    'false',
+
+    'NaN',
+    'posInfinity',
+    'negInfinity',
+    '100.2', // Some random small double value.
+    '-100.2',
+    '54294967296.2923', // Some random large double value.
+    '-54294967296.2923',
+
+    '0',
+    '-0',
+    '1',
+    '-1',
+    '0x3fff',
+    '-0x3fff',
+    '0x7fff',
+    '-0x7fff',
+    '0x10000',
+    '-0x10000',
+    '0x7ffffff',
+    '-0x7ffffff',
+    '0xa5a5a5a5',
+    '0x100000000',
+    '-0x100000000',
+
+    '"abc"',
+    '"0"',
+    '"-0"',
+    '"1"',
+    '"-1"',
+    '"0x7ffffff"',
+    '"-0x7ffffff"',
+    '"0xa5a5a5a5"',
+    '"0x100000000"',
+    '"-0x100000000"',
+];
+
+tests = [];
+generateBinaryTests(tests, opName, op, "VarVar", values, values);
+generateBinaryTests(tests, opName, op, "VarConst", values, values);
+generateBinaryTests(tests, opName, op, "ConstVar", values, values);
+
+run();
diff --git a/Source/JavaScriptCore/tests/stress/op_bitor.js b/Source/JavaScriptCore/tests/stress/op_bitor.js
new file mode 100644
index 0000000..594c14b
--- /dev/null
+++ b/Source/JavaScriptCore/tests/stress/op_bitor.js
@@ -0,0 +1,69 @@
+//@ runFTLNoCJIT
+
+// If all goes well, this test module will terminate silently. If not, it will print
+// errors. See binary-op-test.js for debugging options if needed.
+
+load("./resources/binary-op-test.js");
+
+//============================================================================
+// Test configuration data:
+
+var opName = "bitor";
+var op = "|";
+
+var o1 = {
+    valueOf: function() { return 10; }
+};
+
+var posInfinity = 1 / 0;
+var negInfinity = -1 / 0;
+
+var values = [
+    'o1',
+    'null',
+    'undefined',
+    'true',
+    'false',
+
+    'NaN',
+    'posInfinity',
+    'negInfinity',
+    '100.2', // Some random small double value.
+    '-100.2',
+    '54294967296.2923', // Some random large double value.
+    '-54294967296.2923',
+
+    '0',
+    '-0',
+    '1',
+    '-1',
+    '0x3fff',
+    '-0x3fff',
+    '0x7fff',
+    '-0x7fff',
+    '0x10000',
+    '-0x10000',
+    '0x7ffffff',
+    '-0x7ffffff',
+    '0xa5a5a5a5',
+    '0x100000000',
+    '-0x100000000',
+
+    '"abc"',
+    '"0"',
+    '"-0"',
+    '"1"',
+    '"-1"',
+    '"0x7ffffff"',
+    '"-0x7ffffff"',
+    '"0xa5a5a5a5"',
+    '"0x100000000"',
+    '"-0x100000000"',
+];
+
+tests = [];
+generateBinaryTests(tests, opName, op, "VarVar", values, values);
+generateBinaryTests(tests, opName, op, "VarConst", values, values);
+generateBinaryTests(tests, opName, op, "ConstVar", values, values);
+
+run();
diff --git a/Source/JavaScriptCore/tests/stress/op_bitxor.js b/Source/JavaScriptCore/tests/stress/op_bitxor.js
new file mode 100644
index 0000000..4d15904
--- /dev/null
+++ b/Source/JavaScriptCore/tests/stress/op_bitxor.js
@@ -0,0 +1,69 @@
+//@ runFTLNoCJIT
+
+// If all goes well, this test module will terminate silently. If not, it will print
+// errors. See binary-op-test.js for debugging options if needed.
+
+load("./resources/binary-op-test.js");
+
+//============================================================================
+// Test configuration data:
+
+var opName = "bitxor";
+var op = "^";
+
+var o1 = {
+    valueOf: function() { return 10; }
+};
+
+var posInfinity = 1 / 0;
+var negInfinity = -1 / 0;
+
+var values = [
+    'o1',
+    'null',
+    'undefined',
+    'true',
+    'false',
+
+    'NaN',
+    'posInfinity',
+    'negInfinity',
+    '100.2', // Some random small double value.
+    '-100.2',
+    '54294967296.2923', // Some random large double value.
+    '-54294967296.2923',
+
+    '0',
+    '-0',
+    '1',
+    '-1',
+    '0x3fff',
+    '-0x3fff',
+    '0x7fff',
+    '-0x7fff',
+    '0x10000',
+    '-0x10000',
+    '0x7ffffff',
+    '-0x7ffffff',
+    '0xa5a5a5a5',
+    '0x100000000',
+    '-0x100000000',
+
+    '"abc"',
+    '"0"',
+    '"-0"',
+    '"1"',
+    '"-1"',
+    '"0x7ffffff"',
+    '"-0x7ffffff"',
+    '"0xa5a5a5a5"',
+    '"0x100000000"',
+    '"-0x100000000"',
+];
+
+tests = [];
+generateBinaryTests(tests, opName, op, "VarVar", values, values);
+generateBinaryTests(tests, opName, op, "VarConst", values, values);
+generateBinaryTests(tests, opName, op, "ConstVar", values, values);
+
+run();
diff --git a/Source/JavaScriptCore/tests/stress/op_div.js b/Source/JavaScriptCore/tests/stress/op_div.js
new file mode 100644
index 0000000..7c0ec11
--- /dev/null
+++ b/Source/JavaScriptCore/tests/stress/op_div.js
@@ -0,0 +1,73 @@
+//@ runFTLNoCJIT
+
+// If all goes well, this test module will terminate silently. If not, it will print
+// errors. See binary-op-test.js for debugging options if needed.
+
+load("./resources/binary-op-test.js");
+
+//============================================================================
+// Test configuration data:
+
+var opName = "div";
+var op = "/";
+
+var o1 = {
+    valueOf: function() { return 10; }
+};
+
+var posInfinity = 1 / 0;
+var negInfinity = -1 / 0;
+
+var values = [
+    'o1',
+    'null',
+    'undefined',
+    'true',
+    'false',
+
+    'NaN',
+    'posInfinity',
+    'negInfinity',
+    '100.2', // Some random small double value.
+    '-100.2',
+    '54294967296.2923', // Some random large double value.
+    '-54294967296.2923',
+
+    '0',
+    '-0',
+    '1',
+    '-1',
+    '0x3fff',
+    '-0x3fff',
+    '0x7fff',
+    '-0x7fff',
+    '0x10000',
+    '-0x10000',
+    '0x7ffffff',
+    '-0x7ffffff',
+    '0x100000000',
+    '-0x100000000',
+
+    '"abc"',
+    '"0"',
+    '"-0"',
+    '"1"',
+    '"-1"',
+    '"0x3fff"',
+    '"-0x3fff"',
+    '"0x7fff"',
+    '"-0x7fff"',
+    '"0x10000"',
+    '"-0x10000"',
+    '"0x7ffffff"',
+    '"-0x7ffffff"',
+    '"0x100000000"',
+    '"-0x100000000"',
+];
+
+tests = [];
+generateBinaryTests(tests, opName, op, "VarVar", values, values);
+generateBinaryTests(tests, opName, op, "VarConst", values, values);
+generateBinaryTests(tests, opName, op, "ConstVar", values, values);
+
+run();
diff --git a/Source/JavaScriptCore/tests/stress/op_lshift.js b/Source/JavaScriptCore/tests/stress/op_lshift.js
new file mode 100644
index 0000000..9218aef
--- /dev/null
+++ b/Source/JavaScriptCore/tests/stress/op_lshift.js
@@ -0,0 +1,77 @@
+//@ runFTLNoCJIT
+
+// If all goes well, this test module will terminate silently. If not, it will print
+// errors. See binary-op-test.js for debugging options if needed.
+
+load("./resources/binary-op-test.js");
+
+//============================================================================
+// Test configuration data:
+
+var opName = "lshift";
+var op = "<<";
+
+var o1 = {
+    valueOf: function() { return 10; }
+};
+
+var posInfinity = 1 / 0;
+var negInfinity = -1 / 0;
+
+var values = [
+    'o1',
+    'null',
+    'undefined',
+    'true',
+    'false',
+
+    'NaN',
+    'posInfinity',
+    'negInfinity',
+    '100.2', // Some random small double value.
+    '-100.2',
+    '54294967296.2923', // Some random large double value.
+    '-54294967296.2923',
+
+    '0',
+    '-0',
+    '1',
+    '-1',
+    '5',
+    '-5',
+    '31',
+    '-31',
+    '32',
+    '-32',
+    '0x3fff',
+    '-0x3fff',
+    '0x7fff',
+    '-0x7fff',
+    '0x10000',
+    '-0x10000',
+    '0x7ffffff',
+    '-0x7ffffff',
+    '0x100000000',
+    '-0x100000000',
+
+    '"abc"',
+    '"0"',
+    '"-0"',
+    '"1"',
+    '"-1"',
+    '"5"',
+    '"-5"',
+    '"31"',
+    '"-31"',
+    '"32"',
+    '"-32"',
+    '"0x3fff"',
+    '"-0x3fff"',
+];
+
+tests = [];
+generateBinaryTests(tests, opName, op, "VarVar", values, values);
+generateBinaryTests(tests, opName, op, "VarConst", values, values);
+generateBinaryTests(tests, opName, op, "ConstVar", values, values);
+
+run();
diff --git a/Source/JavaScriptCore/tests/stress/op_mod.js b/Source/JavaScriptCore/tests/stress/op_mod.js
new file mode 100644
index 0000000..666ac71
--- /dev/null
+++ b/Source/JavaScriptCore/tests/stress/op_mod.js
@@ -0,0 +1,73 @@
+//@ runFTLNoCJIT
+
+// If all goes well, this test module will terminate silently. If not, it will print
+// errors. See binary-op-test.js for debugging options if needed.
+
+load("./resources/binary-op-test.js");
+
+//============================================================================
+// Test configuration data:
+
+var opName = "mod";
+var op = "%";
+
+var o1 = {
+    valueOf: function() { return 10; }
+};
+
+var posInfinity = 1 / 0;
+var negInfinity = -1 / 0;
+
+var values = [
+    'o1',
+    'null',
+    'undefined',
+    'true',
+    'false',
+
+    'NaN',
+    'posInfinity',
+    'negInfinity',
+    '100.2', // Some random small double value.
+    '-100.2',
+    '54294967296.2923', // Some random large double value.
+    '-54294967296.2923',
+
+    '0',
+    '-0',
+    '1',
+    '-1',
+    '0x3fff',
+    '-0x3fff',
+    '0x7fff',
+    '-0x7fff',
+    '0x10000',
+    '-0x10000',
+    '0x7ffffff',
+    '-0x7ffffff',
+    '0x100000000',
+    '-0x100000000',
+
+    '"abc"',
+    '"0"',
+    '"-0"',
+    '"1"',
+    '"-1"',
+    '"0x3fff"',
+    '"-0x3fff"',
+    '"0x7fff"',
+    '"-0x7fff"',
+    '"0x10000"',
+    '"-0x10000"',
+    '"0x7ffffff"',
+    '"-0x7ffffff"',
+    '"0x100000000"',
+    '"-0x100000000"',
+];
+
+tests = [];
+generateBinaryTests(tests, opName, op, "VarVar", values, values);
+generateBinaryTests(tests, opName, op, "VarConst", values, values);
+generateBinaryTests(tests, opName, op, "ConstVar", values, values);
+
+run();
diff --git a/Source/JavaScriptCore/tests/stress/op_mul.js b/Source/JavaScriptCore/tests/stress/op_mul.js
index 1569ad8..562a74a 100644
--- a/Source/JavaScriptCore/tests/stress/op_mul.js
+++ b/Source/JavaScriptCore/tests/stress/op_mul.js
@@ -1,26 +1,15 @@
 //@ runFTLNoCJIT
 
-// This test module aims to test the multiplication operator by comparing its runtime
-// behavior (using the different tiers) with expected values computed at initialization
-// time using the LLINT / bytecode generator.
-//
-// It works by generating test scenarios from permutations of value pairs to exercise
-// the multiplication operator. It computes the expected results by evaluating an
-// expression to multiply the values in an initialization pass. The scenarios are later
-// applied to a set of test functions of the forms:
-//
-//     variable * variable
-//     constant * variable
-//     variable * constant
-//
-// See generateScenarios() and initializeTestCases() for details on how the test
-// cases are generated.
-//
 // If all goes well, this test module will terminate silently. If not, it will print
-// errors.
+// errors. See binary-op-test.js for debugging options if needed.
 
-var verbose = false;
-var abortOnFirstFail = false;
+load("./resources/binary-op-test.js");
+
+//============================================================================
+// Test configuration data:
+
+var opName = "mul";
+var op = "*";
 
 var o1 = {
     valueOf: function() { return 10; }
@@ -29,17 +18,21 @@
 var posInfinity = 1 / 0;
 var negInfinity = -1 / 0;
 
-var set1 = [
+var values = [
     'o1',
     'null',
     'undefined',
+    'true',
+    'false',
+
     'NaN',
     'posInfinity',
     'negInfinity',
-    '"abc"',
-];
+    '100.2', // Some random small double value.
+    '-100.2',
+    '54294967296.2923', // Some random large double value.
+    '-54294967296.2923',
 
-var set2 = [
     '0',
     '-0',
     '1',
@@ -50,337 +43,31 @@
     '-0x7fff',
     '0x10000',
     '-0x10000',
-    '2147483647',
-    '-2147483647',
-    '4294967296',
-    '-4294967296',
-    '100.2',
-    '-100.2',
-    'true',
-    'false',
+    '0x7ffffff',
+    '-0x7ffffff',
+    '0x100000000',
+    '-0x100000000',
+
+    '"abc"',
+    '"0"',
+    '"-0"',
+    '"1"',
+    '"-1"',
+    '"0x3fff"',
+    '"-0x3fff"',
+    '"0x7fff"',
+    '"-0x7fff"',
+    '"0x10000"',
+    '"-0x10000"',
+    '"0x7ffffff"',
+    '"-0x7ffffff"',
+    '"0x100000000"',
+    '"-0x100000000"',
 ];
 
-// Assemble the values that we'll be testing with:
-var values = [];
-for (var i = 0; i < set1.length; i++)
-    values.push(set1[i]);
-for (var i = 0; i < set2.length; i++)
-    values.push(set2[i]);
-for (var i = 0; i < set2.length; i++)
-    values.push('"' + set2[i] + '"');
+tests = [];
+generateBinaryTests(tests, opName, op, "VarVar", values, values);
+generateBinaryTests(tests, opName, op, "VarConst", values, values);
+generateBinaryTests(tests, opName, op, "ConstVar", values, values);
 
-function generateScenarios(xvalues, yvalues) {
-    var scenarios = [];
-    for (var i = 0; i < xvalues.length; i++) {
-        for (var j = 0; j < yvalues.length; j++) {
-            var xStr = xvalues[i];
-            var yStr = yvalues[j];
-            var x = eval(xStr);
-            var y = eval(yStr);
-            var name = "(" + xStr + " * " + yStr + ")";
-            var expected = eval("" + xStr + " * " + yStr);
-            var scenario = { name: name, x: x, y: y, expected: expected };
-
-            scenarios.push(scenario);
-        }
-    }
-    return scenarios;
-}
-
-function printScenarios(scenarios) {
-    for (var i = 0; i < scenarios.length; i++) {
-        var scenario = scenarios[i];
-        print("scenario[" + i + "]: { name: " + scenario.name + ", x: " + scenario.x, ", y: " + scenario.y + ", expected: " + scenario.expected + " }");
-    }
-}
-
-var testCases = [
-    {
-        name: "mul",
-        func: function(x, y) { return x * y; },
-        xvalues: values,
-        yvalues: values
-    },
-    {
-        name: "mulI32V",
-        func: function(x, y) { return 1 * y; },
-        xvalues: [ '1' ],
-        yvalues: values
-    },
-    {
-        name: "mulVI32",
-        func: function(x, y) { return x * 1; },
-        xvalues: values,
-        yvalues: [ '1' ]
-    },
-    {
-        name: "mulI32oV",
-        func: function(x, y) { return 2147483647 * y; },
-        xvalues: [ '2147483647' ],
-        yvalues: values
-    },
-    {
-        name: "mulVI32o",
-        func: function(x, y) { return x * 2147483647; },
-        xvalues: values,
-        yvalues: [ '2147483647' ]
-    },
-    {
-        name: "mulI32onV",
-        func: function(x, y) { return -2147483647 * y; },
-        xvalues: [ '-2147483647' ],
-        yvalues: values
-    },
-    {
-        name: "mulVI32on",
-        func: function(x, y) { return x * (-2147483647); },
-        xvalues: values,
-        yvalues: [ '-2147483647' ]
-    },
-    {
-        name: "mulI52V",
-        func: function(x, y) { return 4294967296 * y; },
-        xvalues: [ '4294967296' ],
-        yvalues: values
-    },
-    {
-        name: "mulVI52",
-        func: function(x, y) { return x * 4294967296; },
-        xvalues: values,
-        yvalues: [ '4294967296' ]
-    },
-    {
-        name: "mulI52nV",
-        func: function(x, y) { return -4294967296 * y; },
-        xvalues: [ '-4294967296' ],
-        yvalues: values
-    },
-    {
-        name: "mulVI52n",
-        func: function(x, y) { return x * (-4294967296); },
-        xvalues: values,
-        yvalues: [ '-4294967296' ]
-    },
-    {
-        name: "mulDV",
-        func: function(x, y) { return 100.2 * y; },
-        xvalues: [ '100.2' ],
-        yvalues: values
-    },
-    {
-        name: "mulVD",
-        func: function(x, y) { return x * 100.2; },
-        xvalues: values,
-        yvalues: [ '100.2' ]
-    },
-    {
-        name: "mulBV",
-        func: function(x, y) { return true * y; },
-        xvalues: [ 'true' ],
-        yvalues: values
-    },
-    {
-        name: "mulVB",
-        func: function(x, y) { return x * true; },
-        xvalues: values,
-        yvalues: [ 'true' ]
-    },
-    {
-        name: "mulSi32V",
-        func: function(x, y) { return "10" * y; },
-        xvalues: [ '"10"' ],
-        yvalues: values
-    },
-    {
-        name: "mulVSi32",
-        func: function(x, y) { return x * "10"; },
-        xvalues: values,
-        yvalues: [ '"10"' ]
-    },
-
-    {
-        name: "mulSi32oV",
-        func: function(x, y) { return "2147483647" * y; },
-        xvalues: [ '"2147483647"' ],
-        yvalues: values
-    },
-    {
-        name: "mulVSi32o",
-        func: function(x, y) { return x * "2147483647"; },
-        xvalues: values,
-        yvalues: [ '"2147483647"' ]
-    },
-    {
-        name: "mulSi32onV",
-        func: function(x, y) { return "-2147483647" * y; },
-        xvalues: [ '"-2147483647"' ],
-        yvalues: values
-    },
-    {
-        name: "mulVSi32on",
-        func: function(x, y) { return x * "-2147483647"; },
-        xvalues: values,
-        yvalues: [ '"-2147483647"' ]
-    },
-    {
-        name: "mulSi52V",
-        func: function(x, y) { return "4294967296" * y; },
-        xvalues: [ '"4294967296"' ],
-        yvalues: values
-    },
-    {
-        name: "mulVSi52",
-        func: function(x, y) { return x * "4294967296"; },
-        xvalues: values,
-        yvalues: [ '"4294967296"' ]
-    },
-    {
-        name: "mulSi52nV",
-        func: function(x, y) { return "-4294967296" * y; },
-        xvalues: [ '"-4294967296"' ],
-        yvalues: values
-    },
-    {
-        name: "mulVSi52n",
-        func: function(x, y) { return x * "-4294967296"; },
-        xvalues: values,
-        yvalues: [ '"-4294967296"' ]
-    },
-    {
-        name: "mulSdV",
-        func: function(x, y) { return "100.2" * y; },
-        xvalues: [ '"100.2"' ],
-        yvalues: values
-    },
-    {
-        name: "mulVSd",
-        func: function(x, y) { return x * "100.2"; },
-        xvalues: values,
-        yvalues: [ '"100.2"' ]
-    },
-    {
-        name: "mulSbV",
-        func: function(x, y) { return "true" * y; },
-        xvalues: [ '"true"' ],
-        yvalues: values
-    },
-    {
-        name: "mulVSb",
-        func: function(x, y) { return x * "true"; },
-        xvalues: values,
-        yvalues: [ '"true"' ]
-    },
-
-    {
-        name: "mulSV",
-        func: function(x, y) { return "abc" * y; },
-        xvalues: [ '"abc"' ],
-        yvalues: values
-    },
-    {
-        name: "mulVS",
-        func: function(x, y) { return x * "abc"; },
-        xvalues: values,
-        yvalues: [ '"abc"' ]
-    },
-    {
-        name: "mulNV",
-        func: function(x, y) { return null * y; },
-        xvalues: [ 'null' ],
-        yvalues: values
-    },
-    {
-        name: "mulVN",
-        func: function(x, y) { return x * null; },
-        xvalues: values,
-        yvalues: [ 'null' ]
-    },
-    {
-        name: "mulOV",
-        func: function(x, y) { return o1 * y; },
-        xvalues: [ 'o1' ],
-        yvalues: values
-    },
-    {
-        name: "mulVO",
-        func: function(x, y) { return x * o1; },
-        xvalues: values,
-        yvalues: [ 'o1' ]
-    },
-    {
-        name: "mulNaNV",
-        func: function(x, y) { return NaN * y; },
-        xvalues: [ 'NaN' ],
-        yvalues: values
-    },
-    {
-        name: "mulVNaN",
-        func: function(x, y) { return x * NaN; },
-        xvalues: values,
-        yvalues: [ 'NaN' ]
-    },
-];
-
-function initializeTestCases() {
-    for (var test of testCases) {
-        noInline(test.func);
-        test.scenarios = generateScenarios(test.xvalues, test.yvalues);
-    }
-}
-initializeTestCases();
-
-var errorReport = "";
-
-function stringifyIfNeeded(x) {
-    if (typeof x == "string")
-        return '"' + x + '"';
-    return x;
-}
-
-function isIdentical(x, y) {
-    if (x == y) {
-        if (x)
-            return true;
-        // Distinguish between 0 and negative 0.
-        if (1 / x == 1 / y)
-            return true;
-    } else if (Number.isNaN(x) && Number.isNaN(y))
-        return true;
-    return false;
-}
-
-function runTest(test) {
-    var failedScenario = [];
-    var scenarios = test.scenarios;
-    var testFunc = test.func;
-    try {
-        for (var i = 0; i < 10000; i++) {
-            for (var scenarioID = 0; scenarioID < scenarios.length; scenarioID++) {
-                var scenario = scenarios[scenarioID];
-                if (verbose)
-                    print("Testing " + test.name + ":" + scenario.name + " on iteration " + i + ": expecting " + stringifyIfNeeded(scenario.expected)); 
-
-                var result = testFunc(scenario.x, scenario.y);
-                if (isIdentical(result, scenario.expected))
-                    continue;
-                if (!failedScenario[scenarioID]) {
-                    errorReport += "FAIL: " + test.name + ":" + scenario.name + " started failing on iteration " + i
-                        + ": expected " + stringifyIfNeeded(scenario.expected) + ", actual " + stringifyIfNeeded(result) + "\n";
-                    if (abortOnFirstFail)
-                        throw errorReport;
-                    failedScenario[scenarioID] = scenario;
-                }
-            }
-        }
-    } catch(e) {
-        if (abortOnFirstFail)
-            throw e; // Negate the catch by re-throwing.
-        errorReport += "Unexpected exception: " + e + "\n";
-    }
-}
-
-for (var test of testCases)
-    runTest(test);
-
-if (errorReport !== "")
-    throw "Error: bad result:\n" + errorReport;
+run();
diff --git a/Source/JavaScriptCore/tests/stress/op_rshift.js b/Source/JavaScriptCore/tests/stress/op_rshift.js
new file mode 100644
index 0000000..a6ea9aa
--- /dev/null
+++ b/Source/JavaScriptCore/tests/stress/op_rshift.js
@@ -0,0 +1,77 @@
+//@ runFTLNoCJIT
+
+// If all goes well, this test module will terminate silently. If not, it will print
+// errors. See binary-op-test.js for debugging options if needed.
+
+load("./resources/binary-op-test.js");
+
+//============================================================================
+// Test configuration data:
+
+var opName = "rshift";
+var op = ">>";
+
+var o1 = {
+    valueOf: function() { return 10; }
+};
+
+var posInfinity = 1 / 0;
+var negInfinity = -1 / 0;
+
+var values = [
+    'o1',
+    'null',
+    'undefined',
+    'true',
+    'false',
+
+    'NaN',
+    'posInfinity',
+    'negInfinity',
+    '100.2', // Some random small double value.
+    '-100.2',
+    '54294967296.2923', // Some random large double value.
+    '-54294967296.2923',
+
+    '0',
+    '-0',
+    '1',
+    '-1',
+    '5',
+    '-5',
+    '31',
+    '-31',
+    '32',
+    '-32',
+    '0x3fff',
+    '-0x3fff',
+    '0x7fff',
+    '-0x7fff',
+    '0x10000',
+    '-0x10000',
+    '0x7ffffff',
+    '-0x7ffffff',
+    '0x100000000',
+    '-0x100000000',
+
+    '"abc"',
+    '"0"',
+    '"-0"',
+    '"1"',
+    '"-1"',
+    '"5"',
+    '"-5"',
+    '"31"',
+    '"-31"',
+    '"32"',
+    '"-32"',
+    '"0x3fff"',
+    '"-0x3fff"',
+];
+
+tests = [];
+generateBinaryTests(tests, opName, op, "VarVar", values, values);
+generateBinaryTests(tests, opName, op, "VarConst", values, values);
+generateBinaryTests(tests, opName, op, "ConstVar", values, values);
+
+run();
diff --git a/Source/JavaScriptCore/tests/stress/op_sub.js b/Source/JavaScriptCore/tests/stress/op_sub.js
index 3e60d74..cbcc41c 100644
--- a/Source/JavaScriptCore/tests/stress/op_sub.js
+++ b/Source/JavaScriptCore/tests/stress/op_sub.js
@@ -1,308 +1,73 @@
 //@ runFTLNoCJIT
 
-// This test module aims to test the subtraction operator by comparing its runtime
-// behavior (using the different tiers) with expected values computed at initialization
-// time using the LLINT / bytecode generator.
-//
-// It works by generating test scenarios from permutations of value pairs to exercise
-// the subtraction operator. It computes the expected results by evaluating an expression
-// to subtract the values in an initialization pass. The scenarios are later applied to
-// a set of test functions of the forms:
-//
-//     variable - variable
-//     constant - variable
-//     variable - constant
-//
-// See generateScenarios() and initializeTestCases() for details on how the test
-// cases are generated.
-//
 // If all goes well, this test module will terminate silently. If not, it will print
-// errors.
+// errors. See binary-op-test.js for debugging options if needed.
 
-var verbose = false;
-var abortOnFirstFail = false;
+load("./resources/binary-op-test.js");
+
+//============================================================================
+// Test configuration data:
+
+var opName = "sub";
+var op = "-";
 
 var o1 = {
     valueOf: function() { return 10; }
 };
 
-var set1 = [
+var posInfinity = 1 / 0;
+var negInfinity = -1 / 0;
+
+var values = [
     'o1',
     'null',
     'undefined',
-    'NaN',
-    '"abc"',
-];
-
-var set2 = [
-    '10',
-    '-10',
-    '2147483647',
-    '-2147483647',
-    '4294967296',
-    '-4294967296',
-    '100.2',
-    '-100.2',
     'true',
     'false',
+
+    'NaN',
+    'posInfinity',
+    'negInfinity',
+    '100.2', // Some random small double value.
+    '-100.2',
+    '54294967296.2923', // Some random large double value.
+    '-54294967296.2923',
+
+    '0',
+    '-0',
+    '1',
+    '-1',
+    '0x3fff',
+    '-0x3fff',
+    '0x7fff',
+    '-0x7fff',
+    '0x10000',
+    '-0x10000',
+    '0x7ffffff',
+    '-0x7ffffff',
+    '0x100000000',
+    '-0x100000000',
+
+    '"abc"',
+    '"0"',
+    '"-0"',
+    '"1"',
+    '"-1"',
+    '"0x3fff"',
+    '"-0x3fff"',
+    '"0x7fff"',
+    '"-0x7fff"',
+    '"0x10000"',
+    '"-0x10000"',
+    '"0x7ffffff"',
+    '"-0x7ffffff"',
+    '"0x100000000"',
+    '"-0x100000000"',
 ];
 
-// Assemble the values that we'll be testing with:
-var values = [];
-for (var i = 0; i < set1.length; i++)
-    values.push(set1[i]);
-for (var i = 0; i < set2.length; i++)
-    values.push(set2[i]);
-for (var i = 0; i < set2.length; i++)
-    values.push('"' + set2[i] + '"');
+tests = [];
+generateBinaryTests(tests, opName, op, "VarVar", values, values);
+generateBinaryTests(tests, opName, op, "VarConst", values, values);
+generateBinaryTests(tests, opName, op, "ConstVar", values, values);
 
-function generateScenarios(xvalues, yvalues) {
-    var scenarios = [];
-    for (var i = 0; i < xvalues.length; i++) {
-        for (var j = 0; j < yvalues.length; j++) {
-            var xStr = xvalues[i];
-            var yStr = yvalues[j];
-            var x = eval(xStr);
-            var y = eval(yStr);
-            var name = "(" + xStr + " - " + yStr + ")";
-            var expected = eval("" + xStr + " - " + yStr);
-            var scenario = { name: name, x: x, y: y, expected: expected };
-
-            scenarios.push(scenario);
-        }
-    }
-    return scenarios;
-}
-
-function printScenarios(scenarios) {
-    for (var i = 0; i < scenarios.length; i++) {
-        var scenario = scenarios[i];
-        print("scenario[" + i + "]: { name: " + scenario.name + ", x: " + scenario.x, ", y: " + scenario.y + ", expected: " + scenario.expected + " }");
-    }
-}
-
-var testCases = [
-    {
-        name: "sub",
-        func: function(x, y) { return x - y; },
-        xvalues: values,
-        yvalues: values
-    },
-    {
-        name: "subI32V",
-        func: function(x, y) { return 10 - y; },
-        xvalues: [ '10' ],
-        yvalues: values
-    },
-    {
-        name: "subVI32",
-        func: function(x, y) { return x - 10; },
-        xvalues: values,
-        yvalues: [ '10' ]
-    },
-    {
-        name: "subI32oV",
-        func: function(x, y) { return -2147483647 - y; },
-        xvalues: [ '-2147483647' ],
-        yvalues: values
-    },
-    {
-        name: "subVI32o",
-        func: function(x, y) { return x - 2147483647; },
-        xvalues: values,
-        yvalues: [ '2147483647' ]
-    },
-    {
-        name: "subI52V",
-        func: function(x, y) { return 4294967296 - y; },
-        xvalues: [ '4294967296' ],
-        yvalues: values
-    },
-    {
-        name: "subVI52",
-        func: function(x, y) { return x - 4294967296; },
-        xvalues: values,
-        yvalues: [ '4294967296' ]
-    },
-    {
-        name: "subDV",
-        func: function(x, y) { return 100.2 - y; },
-        xvalues: [ '100.2' ],
-        yvalues: values
-    },
-    {
-        name: "subVD",
-        func: function(x, y) { return x - 100.2; },
-        xvalues: values,
-        yvalues: [ '100.2' ]
-    },
-    {
-        name: "subBV",
-        func: function(x, y) { return true - y; },
-        xvalues: [ 'true' ],
-        yvalues: values
-    },
-    {
-        name: "subVB",
-        func: function(x, y) { return x - true; },
-        xvalues: values,
-        yvalues: [ 'true' ]
-    },
-    {
-        name: "subSi32V",
-        func: function(x, y) { return "10" - y; },
-        xvalues: [ '"10"' ],
-        yvalues: values
-    },
-    {
-        name: "subVSi32",
-        func: function(x, y) { return x - "10"; },
-        xvalues: values,
-        yvalues: [ '"10"' ]
-    },
-
-    {
-        name: "subSi32oV",
-        func: function(x, y) { return "-2147483647" - y; },
-        xvalues: [ '"-2147483647"' ],
-        yvalues: values
-    },
-    {
-        name: "subVSi32o",
-        func: function(x, y) { return x - "2147483647"; },
-        xvalues: values,
-        yvalues: [ '"2147483647"' ]
-    },
-    {
-        name: "subSi52V",
-        func: function(x, y) { return "4294967296" - y; },
-        xvalues: [ '"4294967296"' ],
-        yvalues: values
-    },
-    {
-        name: "subVSi52",
-        func: function(x, y) { return x - "4294967296"; },
-        xvalues: values,
-        yvalues: [ '"4294967296"' ]
-    },
-    {
-        name: "subSdV",
-        func: function(x, y) { return "100.2" - y; },
-        xvalues: [ '"100.2"' ],
-        yvalues: values
-    },
-    {
-        name: "subVSd",
-        func: function(x, y) { return x - "100.2"; },
-        xvalues: values,
-        yvalues: [ '"100.2"' ]
-    },
-    {
-        name: "subSbV",
-        func: function(x, y) { return "true" - y; },
-        xvalues: [ '"true"' ],
-        yvalues: values
-    },
-    {
-        name: "subVSb",
-        func: function(x, y) { return x - "true"; },
-        xvalues: values,
-        yvalues: [ '"true"' ]
-    },
-
-    {
-        name: "subSV",
-        func: function(x, y) { return "abc" - y; },
-        xvalues: [ '"abc"' ],
-        yvalues: values
-    },
-    {
-        name: "subVS",
-        func: function(x, y) { return x - "abc"; },
-        xvalues: values,
-        yvalues: [ '"abc"' ]
-    },
-    {
-        name: "subNV",
-        func: function(x, y) { return null - y; },
-        xvalues: [ 'null' ],
-        yvalues: values
-    },
-    {
-        name: "subVN",
-        func: function(x, y) { return x - null; },
-        xvalues: values,
-        yvalues: [ 'null' ]
-    },
-    {
-        name: "subOV",
-        func: function(x, y) { return o1 - y; },
-        xvalues: [ 'o1' ],
-        yvalues: values
-    },
-    {
-        name: "subVO",
-        func: function(x, y) { return x - o1; },
-        xvalues: values,
-        yvalues: [ 'o1' ]
-    },
-    {
-        name: "subNaNV",
-        func: function(x, y) { return NaN - y; },
-        xvalues: [ 'NaN' ],
-        yvalues: values
-    },
-    {
-        name: "subVNaN",
-        func: function(x, y) { return x - NaN; },
-        xvalues: values,
-        yvalues: [ 'NaN' ]
-    },
-];
-
-function initializeTestCases() {
-    for (var test of testCases) {
-        noInline(test.func);
-        test.scenarios = generateScenarios(test.xvalues, test.yvalues);
-    }
-}
-initializeTestCases();
-
-var errorReport = "";
-
-function runTest(test) {
-    var failedScenario = [];
-    var scenarios = test.scenarios;
-    var testFunc = test.func;
-    try {
-        for (var i = 0; i < 10000; i++) {
-            for (var scenarioID = 0; scenarioID < scenarios.length; scenarioID++) {
-                var scenario = scenarios[scenarioID];
-                if (verbose)
-                    print("Testing " + test.name + ":" + scenario.name + " on iteration " + i + ": expecting " + scenario.expected); 
-
-                var result = testFunc(scenario.x, scenario.y);
-                if (result == scenario.expected)
-                    continue;
-                if (Number.isNaN(result) && Number.isNaN(scenario.expected))
-                    continue;
-                if (!failedScenario[scenarioID]) {
-                    errorReport += "FAIL: " + test.name + ":" + scenario.name + " started failing on iteration " + i + ": expected " + scenario.expected + ", actual " + result + "\n";
-                    if (abortOnFirstFail)
-                        throw errorReport;
-                    failedScenario[scenarioID] = scenario;
-                }
-            }
-        }
-    } catch(e) {
-        if (abortOnFirstFail)
-            throw e; // Negate the catch by re-throwing.
-        errorReport += "Unexpected exception: " + e + "\n";
-    }
-}
-
-for (var test of testCases)
-    runTest(test);
-
-if (errorReport !== "")
-    throw "Error: bad result:\n" + errorReport;
+run();
diff --git a/Source/JavaScriptCore/tests/stress/op_urshift.js b/Source/JavaScriptCore/tests/stress/op_urshift.js
new file mode 100644
index 0000000..17d1acb
--- /dev/null
+++ b/Source/JavaScriptCore/tests/stress/op_urshift.js
@@ -0,0 +1,77 @@
+//@ runFTLNoCJIT
+
+// If all goes well, this test module will terminate silently. If not, it will print
+// errors. See binary-op-test.js for debugging options if needed.
+
+load("./resources/binary-op-test.js");
+
+//============================================================================
+// Test configuration data:
+
+var opName = "urshift";
+var op = ">>>";
+
+var o1 = {
+    valueOf: function() { return 10; }
+};
+
+var posInfinity = 1 / 0;
+var negInfinity = -1 / 0;
+
+var values = [
+    'o1',
+    'null',
+    'undefined',
+    'true',
+    'false',
+
+    'NaN',
+    'posInfinity',
+    'negInfinity',
+    '100.2', // Some random small double value.
+    '-100.2',
+    '54294967296.2923', // Some random large double value.
+    '-54294967296.2923',
+
+    '0',
+    '-0',
+    '1',
+    '-1',
+    '5',
+    '-5',
+    '31',
+    '-31',
+    '32',
+    '-32',
+    '0x3fff',
+    '-0x3fff',
+    '0x7fff',
+    '-0x7fff',
+    '0x10000',
+    '-0x10000',
+    '0x7ffffff',
+    '-0x7ffffff',
+    '0x100000000',
+    '-0x100000000',
+
+    '"abc"',
+    '"0"',
+    '"-0"',
+    '"1"',
+    '"-1"',
+    '"5"',
+    '"-5"',
+    '"31"',
+    '"-31"',
+    '"32"',
+    '"-32"',
+    '"0x3fff"',
+    '"-0x3fff"',
+];
+
+tests = [];
+generateBinaryTests(tests, opName, op, "VarVar", values, values);
+generateBinaryTests(tests, opName, op, "VarConst", values, values);
+generateBinaryTests(tests, opName, op, "ConstVar", values, values);
+
+run();
diff --git a/Source/JavaScriptCore/tests/stress/resources/binary-op-test.js b/Source/JavaScriptCore/tests/stress/resources/binary-op-test.js
new file mode 100644
index 0000000..956045c
--- /dev/null
+++ b/Source/JavaScriptCore/tests/stress/resources/binary-op-test.js
@@ -0,0 +1,131 @@
+// This test module provides infrastructure for generating and running tests on a binary
+// operator.
+//
+// It works by generating test functions to exercise the specified operator using
+// from permutations of operand value pairs. For each test, it computes the expected
+// result by exercising the test function once (using the LLINT) at test generation time.
+// The test runner later compares the result produced by the function (as it tiers up)
+// against the expected result.
+//
+// The generated tests can exercise the operator using the following operand types.
+//     variable * variable
+//     constant * variable
+//     variable * constant
+//
+// If all goes well, this test module will terminate silently. If not, it will print
+// errors.
+
+//============================================================================
+// Debugging options:
+
+var verbose = false;
+var abortOnFirstFail = false;
+var testFilterStr = undefined; // Define a filter string to filter tests to run.
+
+var verboseTestGeneration = false;
+
+//============================================================================
+// Test generation:
+
+function stringifyIfNeeded(x) {
+    if (typeof x == "string")
+        return '"' + x + '"';
+    return x;
+}
+
+// operandTypes are "VarVar", "VarConst", and "ConstVar".
+function generateBinaryTests(tests, opName, op, operandTypes, leftValues, rightValues) {
+    var funcName = opName + operandTypes;
+    for (var i = 0; i < leftValues.length; i++) {
+        for (var j = 0; j < rightValues.length; j++) {
+            var test = { };
+            xStr = leftValues[i];
+            yStr = rightValues[j];
+            test.x = eval(xStr);
+            test.y = eval(yStr);
+
+            if (operandTypes == "VarVar") {
+                test.signature = funcName + "(x, y) { return x " + op + " y }";
+                test.name = test.signature + " with x:" + xStr + ", y:" + yStr;
+            } else if (operandTypes == "VarConst") {
+                test.signature = funcName + "(x, _) { return x " + op + " " + yStr + " }";
+                test.name = test.signature + " with x:" + xStr;
+            } else if (operandTypes == "ConstVar") {
+                test.signature = funcName + "(_, y) { return " + xStr + " " + op + " y }";
+                test.name = test.signature + " with y:" + yStr;
+            }
+
+            test.func = eval("(function " + test.signature + ")");
+            noInline(test.func);
+
+            test.expectedResult = test.func(test.x, test.y);
+            test.name += ", expected:" + stringifyIfNeeded(test.expectedResult);
+
+            tests.push(test);
+            if (verboseTestGeneration)
+                print("Generated " + test.name);
+        }
+    }
+}
+
+//============================================================================
+// Test running and reporting:
+
+var errorReport = "";
+
+function isIdentical(x, y) {
+    if (typeof x != typeof y)
+        return false;
+    if (x == y) {
+        if (x)
+            return true;
+        // Distinguish between 0 and negative 0.
+        if (1 / x == 1 / y)
+            return true;
+    } else if (Number.isNaN(x) && Number.isNaN(y))
+        return true;
+    return false;
+}
+
+function runTest(test) {
+    if (testFilterStr && !test.name.includes(testFilterStr))
+        return;
+
+    var firstFailed = -1;
+    try {
+        if (verbose)
+            print(test.name);
+        for (var i = 0; i < 10000; i++) {
+            var result = test.func(test.x, test.y);
+            if (isIdentical(result, test.expectedResult))
+                continue;
+            if (firstFailed < 0) {
+                errorReport += "FAILED: " + test.name + " started failing on iteration " + i
+                    + ": actual " + stringifyIfNeeded(result) + "\n";
+                if (abortOnFirstFail)
+                    throw errorReport;
+                firstFailed = i;
+            }
+        }
+    } catch(e) {
+        if (abortOnFirstFail)
+            throw e; // Negate the catch by re-throwing.
+        errorReport += "FAILED: Unexpected exception: " + e + "\n";
+    }
+}
+
+function run() {
+    if (verbose)
+        print("Start testing");
+
+    for (var test of tests)
+        runTest(test);
+    // for (var i = 0; i < tests.length; i++)
+    //     runTest(tests[i]);
+
+    if (errorReport !== "")
+        throw "Found failures:\n" + errorReport;
+
+    if (verbose)
+        print("Done testing");
+}