tor-browser

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

test_framebindings-04.js (2318B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /* strict mode code may not contain 'with' statements */
      5 /* eslint-disable strict */
      6 
      7 /**
      8 * Check the environment bindings of a  |with| within a |with|.
      9 */
     10 
     11 add_task(
     12  threadFrontTest(async ({ threadFront, debuggee }) => {
     13    const packet = await executeOnNextTickAndWaitForPause(
     14      () => evalCode(debuggee),
     15      threadFront
     16    );
     17 
     18    const env = await packet.frame.getEnvironment();
     19    Assert.notEqual(env, undefined);
     20 
     21    const objClient = threadFront.pauseGrip(env.object);
     22    let response = await objClient.getPrototypeAndProperties();
     23    Assert.equal(response.ownProperties.one.value, 1);
     24    Assert.equal(response.ownProperties.two.value, 2);
     25    Assert.equal(response.ownProperties.foo, undefined);
     26 
     27    let parentEnv = env.parent;
     28    Assert.notEqual(parentEnv, undefined);
     29 
     30    const parentClient = threadFront.pauseGrip(parentEnv.object);
     31    response = await parentClient.getPrototypeAndProperties();
     32    Assert.equal(response.ownProperties.PI.value, Math.PI);
     33    Assert.equal(response.ownProperties.cos.value.getGrip().type, "object");
     34    Assert.equal(response.ownProperties.cos.value.getGrip().class, "Function");
     35    Assert.ok(!!response.ownProperties.cos.value.actorID);
     36 
     37    parentEnv = parentEnv.parent;
     38    Assert.notEqual(parentEnv, undefined);
     39 
     40    const bindings = parentEnv.bindings;
     41    const args = bindings.arguments;
     42    const vars = bindings.variables;
     43    Assert.equal(args.length, 1);
     44    Assert.equal(args[0].number.value, 10);
     45    Assert.equal(vars.r.value, 10);
     46    Assert.equal(vars.a.value, Math.PI * 100);
     47    Assert.equal(vars.arguments.value.class, "Arguments");
     48    Assert.ok(!!vars.arguments.value.actor);
     49    Assert.equal(vars.foo.value, 2 * Math.PI);
     50 
     51    await threadFront.resume();
     52  })
     53 );
     54 
     55 function evalCode(debuggee) {
     56  /* eslint-disable */
     57  debuggee.eval(
     58    "(" +
     59      function () {
     60        function stopMe(number) {
     61          var a,
     62            obj = { one: 1, two: 2 };
     63          var r = number;
     64          with (Math) {
     65            a = PI * r * r;
     66            with (obj) {
     67              var foo = two * PI;
     68              debugger;
     69            }
     70          }
     71        }
     72        stopMe(10);
     73      } +
     74      ")()"
     75  );
     76  /* eslint-enable */
     77 }