| 1 |
// Verify the environment chain for Debugger.Object described in |
| 2 |
// js/src/vm/EnvironmentObject.h. |
| 3 |
|
| 4 |
// WithEnvironmentObject shouldn't be created if all bindings are shadowed. |
| 5 |
|
| 6 |
const g = newGlobal({newCompartment: true}); |
| 7 |
const dbg = new Debugger(); |
| 8 |
const gw = dbg.addDebuggee(g); |
| 9 |
|
| 10 |
const bindings = { |
| 11 |
bindings_prop_var: 61, |
| 12 |
bindings_prop_lexical: 71, |
| 13 |
bindings_prop_lexical2: 71, |
| 14 |
}; |
| 15 |
|
| 16 |
const {envs, vars} = JSON.parse(gw.executeInGlobalWithBindings(` |
| 17 |
var bindings_prop_var = 60; |
| 18 |
let bindings_prop_lexical = 70; |
| 19 |
let bindings_prop_lexical2; |
| 20 |
bindings_prop_lexical2 = 70; |
| 21 |
|
| 22 |
const vars = { |
| 23 |
bindings_prop_var, |
| 24 |
bindings_prop_lexical, |
| 25 |
bindings_prop_lexical2, |
| 26 |
}; |
| 27 |
|
| 28 |
const envs = []; |
| 29 |
let env = getInnerMostEnvironmentObject(); |
| 30 |
while (env) { |
| 31 |
envs.push({ |
| 32 |
type: getEnvironmentObjectType(env) || "*global*", |
| 33 |
|
| 34 |
bindings_prop_var: !!Object.getOwnPropertyDescriptor(env, "bindings_prop_var"), |
| 35 |
bindings_prop_var_value: Object.getOwnPropertyDescriptor(env, "bindings_prop_var")?.value, |
| 36 |
bindings_prop_lexical: !!Object.getOwnPropertyDescriptor(env, "bindings_prop_lexical"), |
| 37 |
bindings_prop_lexical_value: Object.getOwnPropertyDescriptor(env, "bindings_prop_lexical")?.value, |
| 38 |
bindings_prop_lexical2: !!Object.getOwnPropertyDescriptor(env, "bindings_prop_lexical2"), |
| 39 |
bindings_prop_lexical2_value: Object.getOwnPropertyDescriptor(env, "bindings_prop_lexical2")?.value, |
| 40 |
}); |
| 41 |
|
| 42 |
env = getEnclosingEnvironmentObject(env); |
| 43 |
} |
| 44 |
JSON.stringify({envs, vars}); |
| 45 |
`, bindings).return); |
| 46 |
|
| 47 |
assertEq(vars.bindings_prop_var, 60, |
| 48 |
"qualified var should read the value set by the declaration"); |
| 49 |
assertEq(vars.bindings_prop_lexical, 70, |
| 50 |
"lexical should read the value set by the declaration"); |
| 51 |
assertEq(vars.bindings_prop_lexical2, 70, |
| 52 |
"lexical should read the value set by the assignment"); |
| 53 |
|
| 54 |
assertEq(bindings.bindings_prop_var, 61, |
| 55 |
"the original bindings property must not be overwritten for var"); |
| 56 |
assertEq(bindings.bindings_prop_lexical, 71, |
| 57 |
"the original bindings property must not be overwritten for lexical"); |
| 58 |
assertEq(bindings.bindings_prop_lexical2, 71, |
| 59 |
"the original bindings property must not be overwritten for lexical"); |
| 60 |
|
| 61 |
assertEq(envs.length, 2, |
| 62 |
"WithEnvironmentObject shouldn't be created if all bindings are " + |
| 63 |
"shadowed"); |
| 64 |
|
| 65 |
let i = 0, env; |
| 66 |
|
| 67 |
env = envs[i]; i++; |
| 68 |
assertEq(env.type, "GlobalLexicalEnvironmentObject"); |
| 69 |
assertEq(env.bindings_prop_var, false); |
| 70 |
assertEq(env.bindings_prop_lexical, true, |
| 71 |
"lexical must live in the GlobalLexicalEnvironmentObject even if it conflicts with the bindings object property"); |
| 72 |
assertEq(env.bindings_prop_lexical_value, 70); |
| 73 |
assertEq(env.bindings_prop_lexical2, true, |
| 74 |
"lexical must live in the GlobalLexicalEnvironmentObject even if it conflicts with the bindings object property"); |
| 75 |
assertEq(env.bindings_prop_lexical2_value, 70, |
| 76 |
"lexical value must be set by the assignment even if it conflicts with the bindings object property"); |
| 77 |
|
| 78 |
env = envs[i]; i++; |
| 79 |
assertEq(env.type, "*global*"); |
| 80 |
|
| 81 |
assertEq(env.bindings_prop_var, true, |
| 82 |
"qualified var binding must be created in the global even if it conflicts with the bindings object property"); |
| 83 |
assertEq(env.bindings_prop_var_value, 60, |
| 84 |
"qualified var value must be set even if it conflicts with the bindings object property"); |
| 85 |
assertEq(env.bindings_prop_lexical, false); |
| 86 |
assertEq(env.bindings_prop_lexical2, false); |