summaryrefslogtreecommitdiff
path: root/js/src/jit-test/lib/bytecode-cache.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/lib/bytecode-cache.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloaduxp-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jit-test/lib/bytecode-cache.js')
-rw-r--r--js/src/jit-test/lib/bytecode-cache.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/js/src/jit-test/lib/bytecode-cache.js b/js/src/jit-test/lib/bytecode-cache.js
new file mode 100644
index 0000000000..d6b713d6dc
--- /dev/null
+++ b/js/src/jit-test/lib/bytecode-cache.js
@@ -0,0 +1,52 @@
+
+function evalWithCache(code, ctx) {
+ ctx = ctx || {};
+ ctx = Object.create(ctx, {
+ fileName: { value: "evalWithCacheCode.js" },
+ lineNumber: { value: 0 }
+ });
+ code = code instanceof Object ? code : cacheEntry(code);
+
+ // We create a new global ...
+ if (!("global" in ctx))
+ ctx.global = newGlobal({ cloneSingletons: true });
+
+ if (!("isRunOnce" in ctx))
+ ctx.isRunOnce = true;
+
+ // Fetch the verification function from the evaluation context. This function
+ // is used to assert the state of the script/function after each run of the
+ // evaluate function.
+ var checkAfter = ctx.checkAfter || function(ctx) {};
+
+ // The generation counter is used to represent environment variations which
+ // might cause the program to run differently, and thus to have a different
+ // set of functions executed.
+ ctx.global.generation = 0;
+ var res1 = evaluate(code, Object.create(ctx, {saveBytecode: { value: true } }));
+ checkAfter(ctx);
+
+ ctx.global.generation = 1;
+ var res2 = evaluate(code, Object.create(ctx, {loadBytecode: { value: true }, saveBytecode: { value: true } }));
+ checkAfter(ctx);
+
+ ctx.global.generation = 2;
+ var res3 = evaluate(code, Object.create(ctx, {loadBytecode: { value: true } }));
+ checkAfter(ctx);
+
+ ctx.global.generation = 3;
+ var res0 = evaluate(code, ctx);
+ checkAfter(ctx);
+
+ if (ctx.assertEqResult) {
+ assertEq(res0, res1);
+ assertEq(res0, res2);
+ assertEq(res0, res3);
+ }
+
+ if (ctx.checkFrozen) {
+ assertEq(Object.isFrozen(res0), Object.isFrozen(res1));
+ assertEq(Object.isFrozen(res0), Object.isFrozen(res2));
+ assertEq(Object.isFrozen(res0), Object.isFrozen(res3));
+ }
+}