diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/jit-test/lib/bytecode-cache.js | |
parent | Initial commit. (diff) | |
download | firefox-e51783d008170d9ab27d25da98ca3a38b0a41b67.tar.xz firefox-e51783d008170d9ab27d25da98ca3a38b0a41b67.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/lib/bytecode-cache.js')
-rw-r--r-- | js/src/jit-test/lib/bytecode-cache.js | 55 |
1 files changed, 55 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..1f8f58643a --- /dev/null +++ b/js/src/jit-test/lib/bytecode-cache.js @@ -0,0 +1,55 @@ + +function evalWithCache(code, ctx) { + ctx = ctx || {}; + ctx = Object.create(ctx, { + fileName: { value: "evalWithCacheCode.js" }, + lineNumber: { value: 0 } + }); + code = code instanceof Object ? code : cacheEntry(code); + + var incremental = ctx.incremental || false; + + // We create a new global ... + if (!("global" in ctx)) + ctx.global = newGlobal({newCompartment: ctx.newCompartment}); + + var ctx_save = Object.create(ctx, { + saveIncrementalBytecode: { value: 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, ctx_save); + checkAfter(ctx); + + ctx.global.generation = 1; + var res2 = evaluate(code, Object.create(ctx_save, {loadBytecode: { 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)); + } +} |