envChain_object-executeInGlobalWithBindings-shadow-only-eval.js (3508B)
1 // Verify the environment chain for Debugger.Object described in 2 // js/src/vm/EnvironmentObject.h. 3 4 // WithEnvironmentObject shouldn't be created if if all bindings are shadowed, 5 // even if the script has direct eval. 6 7 const g = newGlobal({newCompartment: true}); 8 const dbg = new Debugger(); 9 const gw = dbg.addDebuggee(g); 10 11 const bindings = { 12 bindings_prop_var: 61, 13 bindings_prop_lexical: 71, 14 bindings_prop_lexical2: 71, 15 }; 16 17 const {envs, vars} = JSON.parse(gw.executeInGlobalWithBindings(` 18 eval(''); 19 var bindings_prop_var = 60; 20 let bindings_prop_lexical = 70; 21 let bindings_prop_lexical2; 22 bindings_prop_lexical2 = 70; 23 24 const vars = { 25 bindings_prop_var, 26 bindings_prop_lexical, 27 bindings_prop_lexical2, 28 }; 29 30 const envs = []; 31 let env = getInnerMostEnvironmentObject(); 32 while (env) { 33 envs.push({ 34 type: getEnvironmentObjectType(env) || "*global*", 35 36 bindings_prop_var: !!Object.getOwnPropertyDescriptor(env, "bindings_prop_var"), 37 bindings_prop_var_value: Object.getOwnPropertyDescriptor(env, "bindings_prop_var")?.value, 38 bindings_prop_lexical: !!Object.getOwnPropertyDescriptor(env, "bindings_prop_lexical"), 39 bindings_prop_lexical_value: Object.getOwnPropertyDescriptor(env, "bindings_prop_lexical")?.value, 40 bindings_prop_lexical2: !!Object.getOwnPropertyDescriptor(env, "bindings_prop_lexical2"), 41 bindings_prop_lexical2_value: Object.getOwnPropertyDescriptor(env, "bindings_prop_lexical2")?.value, 42 }); 43 44 env = getEnclosingEnvironmentObject(env); 45 } 46 JSON.stringify({envs, vars}); 47 `, bindings).return); 48 49 assertEq(vars.bindings_prop_var, 60, 50 "qualified var should read the value set by the declaration"); 51 assertEq(vars.bindings_prop_lexical, 70, 52 "lexical should read the value set by the declaration"); 53 assertEq(vars.bindings_prop_lexical2, 70, 54 "lexical should read the value set by the assignment"); 55 56 assertEq(bindings.bindings_prop_var, 61, 57 "the original bindings property must not be overwritten for var"); 58 assertEq(bindings.bindings_prop_lexical, 71, 59 "the original bindings property must not be overwritten for lexical"); 60 assertEq(bindings.bindings_prop_lexical2, 71, 61 "the original bindings property must not be overwritten for lexical"); 62 63 assertEq(envs.length, 2, 64 "WithEnvironmentObject shouldn't be created if if all bindings are " + 65 "shadowed, even if the script has direct eval"); 66 67 let i = 0, env; 68 69 env = envs[i]; i++; 70 assertEq(env.type, "GlobalLexicalEnvironmentObject"); 71 assertEq(env.bindings_prop_var, false); 72 assertEq(env.bindings_prop_lexical, true, 73 "lexical must live in the GlobalLexicalEnvironmentObject even if it conflicts with the bindings object property"); 74 assertEq(env.bindings_prop_lexical_value, 70); 75 assertEq(env.bindings_prop_lexical2, true, 76 "lexical must live in the GlobalLexicalEnvironmentObject even if it conflicts with the bindings object property"); 77 assertEq(env.bindings_prop_lexical2_value, 70, 78 "lexical value must be set by the assignment even if it conflicts with the bindings object property"); 79 80 env = envs[i]; i++; 81 assertEq(env.type, "*global*"); 82 83 assertEq(env.bindings_prop_var, true, 84 "qualified var binding must be created in the global even if it conflicts with the bindings object property"); 85 assertEq(env.bindings_prop_var_value, 60, 86 "qualified var value must be set even if it conflicts with the bindings object property"); 87 assertEq(env.bindings_prop_lexical, false); 88 assertEq(env.bindings_prop_lexical2, false);