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