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/tests/debug/envChain_object-executeInGlobalWithBindings-shadow-only.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.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/tests/debug/envChain_object-executeInGlobalWithBindings-shadow-only.js')
-rw-r--r-- | js/src/jit-test/tests/debug/envChain_object-executeInGlobalWithBindings-shadow-only.js | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/debug/envChain_object-executeInGlobalWithBindings-shadow-only.js b/js/src/jit-test/tests/debug/envChain_object-executeInGlobalWithBindings-shadow-only.js new file mode 100644 index 0000000000..5291396bb1 --- /dev/null +++ b/js/src/jit-test/tests/debug/envChain_object-executeInGlobalWithBindings-shadow-only.js @@ -0,0 +1,86 @@ +// Verify the environment chain for Debugger.Object described in +// js/src/vm/EnvironmentObject.h. + +// WithEnvironmentObject shouldn't be created if all bindings are shadowed. + +const g = newGlobal({newCompartment: true}); +const dbg = new Debugger(); +const gw = dbg.addDebuggee(g); + +const bindings = { + bindings_prop_var: 61, + bindings_prop_lexical: 71, + bindings_prop_lexical2: 71, +}; + +const {envs, vars} = JSON.parse(gw.executeInGlobalWithBindings(` +var bindings_prop_var = 60; +let bindings_prop_lexical = 70; +let bindings_prop_lexical2; +bindings_prop_lexical2 = 70; + +const vars = { + bindings_prop_var, + bindings_prop_lexical, + bindings_prop_lexical2, +}; + +const envs = []; +let env = getInnerMostEnvironmentObject(); +while (env) { + envs.push({ + type: getEnvironmentObjectType(env) || "*global*", + + bindings_prop_var: !!Object.getOwnPropertyDescriptor(env, "bindings_prop_var"), + bindings_prop_var_value: Object.getOwnPropertyDescriptor(env, "bindings_prop_var")?.value, + bindings_prop_lexical: !!Object.getOwnPropertyDescriptor(env, "bindings_prop_lexical"), + bindings_prop_lexical_value: Object.getOwnPropertyDescriptor(env, "bindings_prop_lexical")?.value, + bindings_prop_lexical2: !!Object.getOwnPropertyDescriptor(env, "bindings_prop_lexical2"), + bindings_prop_lexical2_value: Object.getOwnPropertyDescriptor(env, "bindings_prop_lexical2")?.value, + }); + + env = getEnclosingEnvironmentObject(env); +} +JSON.stringify({envs, vars}); +`, bindings).return); + +assertEq(vars.bindings_prop_var, 60, + "qualified var should read the value set by the declaration"); +assertEq(vars.bindings_prop_lexical, 70, + "lexical should read the value set by the declaration"); +assertEq(vars.bindings_prop_lexical2, 70, + "lexical should read the value set by the assignment"); + +assertEq(bindings.bindings_prop_var, 61, + "the original bindings property must not be overwritten for var"); +assertEq(bindings.bindings_prop_lexical, 71, + "the original bindings property must not be overwritten for lexical"); +assertEq(bindings.bindings_prop_lexical2, 71, + "the original bindings property must not be overwritten for lexical"); + +assertEq(envs.length, 2, + "WithEnvironmentObject shouldn't be created if all bindings are " + + "shadowed"); + +let i = 0, env; + +env = envs[i]; i++; +assertEq(env.type, "GlobalLexicalEnvironmentObject"); +assertEq(env.bindings_prop_var, false); +assertEq(env.bindings_prop_lexical, true, + "lexical must live in the GlobalLexicalEnvironmentObject even if it conflicts with the bindings object property"); +assertEq(env.bindings_prop_lexical_value, 70); +assertEq(env.bindings_prop_lexical2, true, + "lexical must live in the GlobalLexicalEnvironmentObject even if it conflicts with the bindings object property"); +assertEq(env.bindings_prop_lexical2_value, 70, + "lexical value must be set by the assignment even if it conflicts with the bindings object property"); + +env = envs[i]; i++; +assertEq(env.type, "*global*"); + +assertEq(env.bindings_prop_var, true, + "qualified var binding must be created in the global even if it conflicts with the bindings object property"); +assertEq(env.bindings_prop_var_value, 60, + "qualified var value must be set even if it conflicts with the bindings object property"); +assertEq(env.bindings_prop_lexical, false); +assertEq(env.bindings_prop_lexical2, false); |