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