tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

envChain_object-executeInGlobalWithBindings-no-use-eval.js (1955B)


      1 // Verify the environment chain for Debugger.Object described in
      2 // js/src/vm/EnvironmentObject.h.
      3 
      4 // WithEnvironmentObject should be created if the script has direct eval,
      5 // even if no binding is used outside of 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: 61,
     13 };
     14 
     15 const envs = JSON.parse(gw.executeInGlobalWithBindings(`
     16 eval('');
     17 var qualified = 10;
     18 unqualified = 20;
     19 let lexical = 30;
     20 this.prop = 40;
     21 
     22 const envs = [];
     23 let env = getInnerMostEnvironmentObject();
     24 while (env) {
     25  envs.push({
     26    type: getEnvironmentObjectType(env) || "*global*",
     27    qualified: !!Object.getOwnPropertyDescriptor(env, "qualified"),
     28    unqualified: !!Object.getOwnPropertyDescriptor(env, "unqualified"),
     29    lexical: !!Object.getOwnPropertyDescriptor(env, "lexical"),
     30    prop: !!Object.getOwnPropertyDescriptor(env, "prop"),
     31  });
     32 
     33  env = getEnclosingEnvironmentObject(env);
     34 }
     35 JSON.stringify(envs);
     36 `, bindings).return);
     37 
     38 assertEq(envs.length, 3,
     39         "WithEnvironmentObject should be created if the script has direct " +
     40         "eval, even if no binding is used outside of direct eval");
     41 
     42 let i = 0, env;
     43 
     44 env = envs[i]; i++;
     45 assertEq(env.type, "WithEnvironmentObject");
     46 assertEq(env.qualified, false);
     47 assertEq(env.unqualified, false);
     48 assertEq(env.lexical, false);
     49 assertEq(env.prop, false);
     50 
     51 env = envs[i]; i++;
     52 assertEq(env.type, "GlobalLexicalEnvironmentObject");
     53 assertEq(env.qualified, false);
     54 assertEq(env.unqualified, false);
     55 assertEq(env.lexical, true, "lexical must live in the GlobalLexicalEnvironmentObject");
     56 assertEq(env.prop, false);
     57 
     58 env = envs[i]; i++;
     59 assertEq(env.type, "*global*");
     60 assertEq(env.qualified, true, "qualified var must live in the global");
     61 assertEq(env.unqualified, true, "unqualified name must live in the global");
     62 assertEq(env.lexical, false);
     63 assertEq(env.prop, true, "this property must live in the global");