| 1 |
// Verify the environment chain for Debugger.Object described in |
| 2 |
// js/src/vm/EnvironmentObject.h. |
| 3 |
|
| 4 |
// Passing empty bindings shouldn't create WithEnvironmentObject. |
| 5 |
|
| 6 |
const g = newGlobal({newCompartment: true}); |
| 7 |
const dbg = new Debugger(); |
| 8 |
const gw = dbg.addDebuggee(g); |
| 9 |
|
| 10 |
const bindings = {}; |
| 11 |
|
| 12 |
const envs = JSON.parse(gw.executeInGlobalWithBindings(` |
| 13 |
var qualified = 10; |
| 14 |
unqualified = 20; |
| 15 |
let lexical = 30; |
| 16 |
this.prop = 40; |
| 17 |
|
| 18 |
const envs = []; |
| 19 |
let env = getInnerMostEnvironmentObject(); |
| 20 |
while (env) { |
| 21 |
envs.push({ |
| 22 |
type: getEnvironmentObjectType(env) || "*global*", |
| 23 |
qualified: !!Object.getOwnPropertyDescriptor(env, "qualified"), |
| 24 |
unqualified: !!Object.getOwnPropertyDescriptor(env, "unqualified"), |
| 25 |
lexical: !!Object.getOwnPropertyDescriptor(env, "lexical"), |
| 26 |
prop: !!Object.getOwnPropertyDescriptor(env, "prop"), |
| 27 |
}); |
| 28 |
|
| 29 |
env = getEnclosingEnvironmentObject(env); |
| 30 |
} |
| 31 |
JSON.stringify(envs); |
| 32 |
`, bindings).return); |
| 33 |
|
| 34 |
assertEq(envs.length, 2, |
| 35 |
"WithEnvironmentObject shouldn't be created if there's no binding"); |
| 36 |
|
| 37 |
let i = 0, env; |
| 38 |
|
| 39 |
env = envs[i]; i++; |
| 40 |
assertEq(env.type, "GlobalLexicalEnvironmentObject"); |
| 41 |
assertEq(env.qualified, false); |
| 42 |
assertEq(env.unqualified, false); |
| 43 |
assertEq(env.lexical, true, "lexical must live in the GlobalLexicalEnvironmentObject"); |
| 44 |
assertEq(env.prop, false); |
| 45 |
|
| 46 |
env = envs[i]; i++; |
| 47 |
assertEq(env.type, "*global*"); |
| 48 |
assertEq(env.qualified, true, "qualified var must live in the global"); |
| 49 |
assertEq(env.unqualified, true, "unqualified name must live in the global"); |
| 50 |
assertEq(env.lexical, false); |
| 51 |
assertEq(env.prop, true, "this property must live in the global"); |