| 1 |
// Verify the environment chain for Debugger.Object described in |
| 2 |
// js/src/vm/EnvironmentObject.h. |
| 3 |
|
| 4 |
const g = newGlobal({newCompartment: true}); |
| 5 |
const dbg = new Debugger(); |
| 6 |
const gw = dbg.addDebuggee(g); |
| 7 |
|
| 8 |
const bindings = { |
| 9 |
bindings_prop: 50, |
| 10 |
|
| 11 |
bindings_prop_var: 61, |
| 12 |
bindings_prop_lexical: 71, |
| 13 |
bindings_prop_lexical2: 71, |
| 14 |
bindings_prop_unqualified: 81, |
| 15 |
}; |
| 16 |
|
| 17 |
const {envs, vars} = JSON.parse(gw.executeInGlobalWithBindings(` |
| 18 |
var qualified = 10; |
| 19 |
unqualified = 20; |
| 20 |
let lexical = 30; |
| 21 |
this.prop = 40; |
| 22 |
|
| 23 |
var bindings_prop_var = 60; |
| 24 |
let bindings_prop_lexical = 70; |
| 25 |
let bindings_prop_lexical2; |
| 26 |
bindings_prop_lexical2 = 70; |
| 27 |
bindings_prop_unqualified = 80; |
| 28 |
|
| 29 |
const vars = { |
| 30 |
bindings_prop_var, |
| 31 |
bindings_prop_lexical, |
| 32 |
bindings_prop_lexical2, |
| 33 |
bindings_prop_unqualified, |
| 34 |
}; |
| 35 |
|
| 36 |
const envs = []; |
| 37 |
let env = getInnerMostEnvironmentObject(); |
| 38 |
while (env) { |
| 39 |
envs.push({ |
| 40 |
type: getEnvironmentObjectType(env) || "*global*", |
| 41 |
qualified: !!Object.getOwnPropertyDescriptor(env, "qualified"), |
| 42 |
unqualified: !!Object.getOwnPropertyDescriptor(env, "unqualified"), |
| 43 |
lexical: !!Object.getOwnPropertyDescriptor(env, "lexical"), |
| 44 |
prop: !!Object.getOwnPropertyDescriptor(env, "prop"), |
| 45 |
bindings_prop: !!Object.getOwnPropertyDescriptor(env, "bindings_prop"), |
| 46 |
|
| 47 |
bindings_prop_var: !!Object.getOwnPropertyDescriptor(env, "bindings_prop_var"), |
| 48 |
bindings_prop_var_value: Object.getOwnPropertyDescriptor(env, "bindings_prop_var")?.value, |
| 49 |
bindings_prop_lexical: !!Object.getOwnPropertyDescriptor(env, "bindings_prop_lexical"), |
| 50 |
bindings_prop_lexical_value: Object.getOwnPropertyDescriptor(env, "bindings_prop_lexical")?.value, |
| 51 |
bindings_prop_lexical2: !!Object.getOwnPropertyDescriptor(env, "bindings_prop_lexical2"), |
| 52 |
bindings_prop_lexical2_value: Object.getOwnPropertyDescriptor(env, "bindings_prop_lexical2")?.value, |
| 53 |
bindings_prop_unqualified: !!Object.getOwnPropertyDescriptor(env, "bindings_prop_unqualified"), |
| 54 |
bindings_prop_unqualified_value: Object.getOwnPropertyDescriptor(env, "bindings_prop_unqualified")?.value, |
| 55 |
}); |
| 56 |
|
| 57 |
env = getEnclosingEnvironmentObject(env); |
| 58 |
} |
| 59 |
JSON.stringify({envs, vars}); |
| 60 |
`, bindings, { |
| 61 |
useInnerBindings: true, |
| 62 |
}).return); |
| 63 |
|
| 64 |
assertEq(vars.bindings_prop_var, 60, |
| 65 |
"qualified var should read the value set by the declaration"); |
| 66 |
assertEq(vars.bindings_prop_lexical, 71, |
| 67 |
"lexical is shadowed by extra bindings"); |
| 68 |
assertEq(vars.bindings_prop_lexical2, 70, |
| 69 |
"lexical is shadowed by extra bindings"); |
| 70 |
assertEq(vars.bindings_prop_unqualified, 80, |
| 71 |
"unqualified name is shadowed by extra bindings"); |
| 72 |
|
| 73 |
assertEq(bindings.bindings_prop_var, 61, |
| 74 |
"the original bindings property must not be overwritten for var"); |
| 75 |
assertEq(bindings.bindings_prop_lexical, 71, |
| 76 |
"the original bindings property must not be overwritten for lexical"); |
| 77 |
assertEq(bindings.bindings_prop_lexical2, 71, |
| 78 |
"the original bindings property must not be overwritten for lexical"); |
| 79 |
assertEq(bindings.bindings_prop_unqualified, 81, |
| 80 |
"the original bindings property must not be overwritten for unqualified"); |
| 81 |
|
| 82 |
assertEq(envs.length, 3); |
| 83 |
|
| 84 |
let i = 0, env; |
| 85 |
|
| 86 |
env = envs[i]; i++; |
| 87 |
assertEq(env.type, "WithEnvironmentObject"); |
| 88 |
assertEq(env.qualified, false); |
| 89 |
assertEq(env.unqualified, false); |
| 90 |
assertEq(env.lexical, false); |
| 91 |
assertEq(env.prop, false); |
| 92 |
assertEq(env.bindings_prop, true, "bindings property must live in the with env for bindings"); |
| 93 |
|
| 94 |
assertEq(env.bindings_prop_var, true, |
| 95 |
"bindings property must live in the with env for bindings"); |
| 96 |
assertEq(env.bindings_prop_lexical, true, |
| 97 |
"bindings property must live in the with env for bindings"); |
| 98 |
assertEq(env.bindings_prop_lexical2, true, |
| 99 |
"bindings property must live in the with env for bindings"); |
| 100 |
assertEq(env.bindings_prop_unqualified, true, |
| 101 |
"bindings property must live in the with env for bindings"); |
| 102 |
assertEq(env.bindings_prop_unqualified_value, 80, |
| 103 |
"bindings property must be overwritten for unqualified"); |
| 104 |
|
| 105 |
env = envs[i]; i++; |
| 106 |
assertEq(env.type, "GlobalLexicalEnvironmentObject"); |
| 107 |
assertEq(env.qualified, false); |
| 108 |
assertEq(env.unqualified, false); |
| 109 |
assertEq(env.lexical, true, "lexical must live in the GlobalLexicalEnvironmentObject"); |
| 110 |
assertEq(env.prop, false); |
| 111 |
assertEq(env.bindings_prop, false); |
| 112 |
|
| 113 |
assertEq(env.bindings_prop_var, false); |
| 114 |
assertEq(env.bindings_prop_lexical, true, |
| 115 |
"lexical must live in the GlobalLexicalEnvironmentObject even if it conflicts with the bindings object property"); |
| 116 |
assertEq(env.bindings_prop_lexical_value, 70); |
| 117 |
assertEq(env.bindings_prop_lexical2, true, |
| 118 |
"lexical must live in the GlobalLexicalEnvironmentObject even if it conflicts with the bindings object property"); |
| 119 |
assertEq(env.bindings_prop_lexical2_value, undefined, |
| 120 |
"lexical must be shadowed"); |
| 121 |
assertEq(env.bindings_prop_unqualified, false); |
| 122 |
|
| 123 |
env = envs[i]; i++; |
| 124 |
assertEq(env.type, "*global*"); |
| 125 |
assertEq(env.qualified, true, "qualified var must live in the global"); |
| 126 |
assertEq(env.unqualified, true, "unqualified name must live in the global"); |
| 127 |
assertEq(env.lexical, false); |
| 128 |
assertEq(env.prop, true, "this property must live in the global"); |
| 129 |
assertEq(env.bindings_prop, false); |
| 130 |
|
| 131 |
assertEq(env.bindings_prop_var, true, |
| 132 |
"qualified var binding must be created in the global even if it conflicts with the bindings object property"); |
| 133 |
assertEq(env.bindings_prop_var_value, undefined, |
| 134 |
"qualified var must be shadowed"); |
| 135 |
assertEq(env.bindings_prop_lexical, false); |
| 136 |
assertEq(env.bindings_prop_lexical2, false); |
| 137 |
assertEq(env.bindings_prop_unqualified, false); |