1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 // Verify the environment chain for subscripts described in
8 // js/src/vm/EnvironmentObject.h.
10 add_task(async function() {
12 Services.scriptloader.loadSubScript(`data:,
18 const funcs = Cu.getJSTestingFunctions();
20 let env = funcs.getInnerMostEnvironmentObject();
23 type: funcs.getEnvironmentObjectType(env) || "*global*",
24 qualified: !!Object.getOwnPropertyDescriptor(env, "qualified"),
25 unqualified: !!Object.getOwnPropertyDescriptor(env, "unqualified"),
26 lexical: !!Object.getOwnPropertyDescriptor(env, "lexical"),
27 prop: !!Object.getOwnPropertyDescriptor(env, "prop"),
30 env = funcs.getEnclosingEnvironmentObject(env);
36 const envs = target.ENVS;
38 Assert.equal(envs.length, 4);
43 Assert.equal(env.type, "NonSyntacticLexicalEnvironmentObject");
44 Assert.equal(env.qualified, false);
45 Assert.equal(env.unqualified, false);
46 Assert.equal(env.lexical, true, "lexical must live in the NSLEO");
47 Assert.equal(env.prop, false);
50 Assert.equal(env.type, "WithEnvironmentObject");
51 Assert.equal(env.qualified, true, "qualified var must live in the with env");
52 Assert.equal(env.unqualified, false);
53 Assert.equal(env.lexical, false);
54 Assert.equal(env.prop, true, "this property must live in the with env");
57 Assert.equal(env.type, "GlobalLexicalEnvironmentObject");
58 Assert.equal(env.qualified, false);
59 Assert.equal(env.unqualified, false);
60 Assert.equal(env.lexical, false);
61 Assert.equal(env.prop, false);
64 Assert.equal(env.type, "*global*");
65 Assert.equal(env.qualified, false);
66 Assert.equal(env.unqualified, true, "unqualified var must live in the global");
67 Assert.equal(env.lexical, false);
68 Assert.equal(env.prop, false);
70 Assert.equal(target.qualified, 10, "qualified var must be reflected to the target object");
71 Assert.equal(target.prop, 40, "this property must be reflected to the target object");