test_envChain_subscript.js (1781B)
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/. */ 4 5 "use strict"; 6 7 // Verify the environment chain for subscripts described in 8 // js/src/vm/EnvironmentObject.h. 9 10 add_task(async function() { 11 const target = {}; 12 Services.scriptloader.loadSubScript("resource://test/file_envChain_subscript.js", target); 13 14 const envs = target.ENVS; 15 16 Assert.equal(envs.length, 4); 17 18 let i = 0, env; 19 20 env = envs[i]; i++; 21 Assert.equal(env.type, "NonSyntacticLexicalEnvironmentObject"); 22 Assert.equal(env.qualified, false); 23 Assert.equal(env.unqualified, false); 24 Assert.equal(env.lexical, true, "lexical must live in the NSLEO"); 25 Assert.equal(env.prop, false); 26 27 env = envs[i]; i++; 28 Assert.equal(env.type, "WithEnvironmentObject"); 29 Assert.equal(env.qualified, true, "qualified var must live in the with env"); 30 Assert.equal(env.unqualified, false); 31 Assert.equal(env.lexical, false); 32 Assert.equal(env.prop, true, "this property must live in the with env"); 33 34 env = envs[i]; i++; 35 Assert.equal(env.type, "GlobalLexicalEnvironmentObject"); 36 Assert.equal(env.qualified, false); 37 Assert.equal(env.unqualified, false); 38 Assert.equal(env.lexical, false); 39 Assert.equal(env.prop, false); 40 41 env = envs[i]; i++; 42 Assert.equal(env.type, "*global*"); 43 Assert.equal(env.qualified, false); 44 Assert.equal(env.unqualified, true, "unqualified var must live in the global"); 45 Assert.equal(env.lexical, false); 46 Assert.equal(env.prop, false); 47 48 Assert.equal(target.qualified, 10, "qualified var must be reflected to the target object"); 49 Assert.equal(target.prop, 40, "this property must be reflected to the target object"); 50 });