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