summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/etc/generate-nosuchproperty-tests.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/jit-test/etc/generate-nosuchproperty-tests.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jit-test/etc/generate-nosuchproperty-tests.js')
-rw-r--r--js/src/jit-test/etc/generate-nosuchproperty-tests.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/js/src/jit-test/etc/generate-nosuchproperty-tests.js b/js/src/jit-test/etc/generate-nosuchproperty-tests.js
new file mode 100644
index 000000000..7eaec2ae6
--- /dev/null
+++ b/js/src/jit-test/etc/generate-nosuchproperty-tests.js
@@ -0,0 +1,78 @@
+
+// This code generates the test cases jit-test/tests/baseline/no-such-property-getprop.js
+//
+// In particular, it generates the testChain_<N>_<I>() and runChain_<N>_<I>() functions
+// at the tail of the file.
+
+var TEST_CASE_FUNCS = [];
+function runChain_NNNN_DDDD(obj) {
+ var sum = 0;
+ for (var i = 0; i < 100; i++)
+ sum += obj.foo;
+ return sum;
+}
+function testChain_NNNN_DDDD() {
+ var obj = createTower(NNNN);
+ assertEq(runChain_NNNN_DDDD(obj), NaN);
+ updateChain(obj, DDDD, 'foo', 9);
+ assertEq(runChain_NNNN_DDDD(obj), 900);
+}
+function generateTestCase(n, d) {
+ var runFuncName = "runChain_" + n + "_" + d;
+ var testFuncName = "testChain_" + n + "_" + d;
+ TEST_CASE_FUNCS.push(testFuncName);
+
+ print("//// Test chain of length " + n + " with late-property-addition at depth " + d);
+ print(uneval(runChain_NNNN_DDDD).replace(/NNNN/g, ''+n).replace(/DDDD/g, ''+d));
+ print(uneval(testChain_NNNN_DDDD).replace(/NNNN/g, ''+n).replace(/DDDD/g, ''+d));
+ print("");
+}
+
+// Helper function to create an object with a proto-chain of length N.
+function createTower(n) {
+ var result = Object.create(null);
+ for (var i = 0; i < n; i++)
+ result = Object.create(result);
+ return result;
+}
+
+function updateChain(obj, depth, prop, value) {
+ // Walk down the proto chain |depth| iterations and set |prop| to |value|.
+ var cur = obj;
+ for (var i = 0; i < depth; i++)
+ cur = Object.getPrototypeOf(cur);
+
+ var desc = {value:value, writable:true, configurable:true, enumerable:true};
+ Object.defineProperty(cur, prop, desc);
+}
+
+print("/////////////////////////////////////////");
+print("// This is a generated file!");
+print("// See jit-tests/etc/generate-nosuchproperty-tests.js for the code");
+print("// that generated this code!");
+print("/////////////////////////////////////////");
+print("");
+print("/////////////////////////////////////////");
+print("// PRELUDE //");
+print("/////////////////////////////////////////");
+print("");
+print(createTower);
+print(updateChain);
+print("");
+print("/////////////////////////////////////////");
+print("// TEST CASES //");
+print("/////////////////////////////////////////");
+print("");
+for (var n = 0; n <= 10; n++) {
+ for (var d = 0; d <= n; d++) {
+ generateTestCase(n, d);
+ }
+}
+
+print("");
+print("/////////////////////////////////////////");
+print("// RUNNER //");
+print("/////////////////////////////////////////");
+print("");
+for (var i = 0; i < TEST_CASE_FUNCS.length; i++)
+ print(TEST_CASE_FUNCS[i] + "();");