toolkit/devtools/server/tests/unit/test_framebindings-04.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/devtools/server/tests/unit/test_framebindings-04.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Check the environment bindongs of a  |with| within a |with|.
     1.9 + */
    1.10 +
    1.11 +var gDebuggee;
    1.12 +var gClient;
    1.13 +var gThreadClient;
    1.14 +
    1.15 +function run_test()
    1.16 +{
    1.17 +  initTestDebuggerServer();
    1.18 +  gDebuggee = addTestGlobal("test-stack");
    1.19 +  gClient = new DebuggerClient(DebuggerServer.connectPipe());
    1.20 +  gClient.connect(function() {
    1.21 +    attachTestTabAndResume(gClient, "test-stack", function(aResponse, aTabClient, aThreadClient) {
    1.22 +      gThreadClient = aThreadClient;
    1.23 +      test_pause_frame();
    1.24 +    });
    1.25 +  });
    1.26 +  do_test_pending();
    1.27 +}
    1.28 +
    1.29 +function test_pause_frame()
    1.30 +{
    1.31 +  gThreadClient.addOneTimeListener("paused", function(aEvent, aPacket) {
    1.32 +    let env = aPacket.frame.environment;
    1.33 +    do_check_neq(env, undefined);
    1.34 +
    1.35 +    let objClient = gThreadClient.pauseGrip(env.object);
    1.36 +    objClient.getPrototypeAndProperties(function(aResponse) {
    1.37 +      do_check_eq(aResponse.ownProperties.one.value, 1);
    1.38 +      do_check_eq(aResponse.ownProperties.two.value, 2);
    1.39 +      do_check_eq(aResponse.ownProperties.foo, undefined);
    1.40 +
    1.41 +      let parentEnv = env.parent;
    1.42 +      do_check_neq(parentEnv, undefined);
    1.43 +
    1.44 +      let parentClient = gThreadClient.pauseGrip(parentEnv.object);
    1.45 +      parentClient.getPrototypeAndProperties(function(aResponse) {
    1.46 +        do_check_eq(aResponse.ownProperties.PI.value, Math.PI);
    1.47 +        do_check_eq(aResponse.ownProperties.cos.value.type, "object");
    1.48 +        do_check_eq(aResponse.ownProperties.cos.value.class, "Function");
    1.49 +        do_check_true(!!aResponse.ownProperties.cos.value.actor);
    1.50 +
    1.51 +        parentEnv = parentEnv.parent;
    1.52 +        do_check_neq(parentEnv, undefined);
    1.53 +
    1.54 +        let bindings = parentEnv.bindings;
    1.55 +        let args = bindings.arguments;
    1.56 +        let vars = bindings.variables;
    1.57 +        do_check_eq(args.length, 1);
    1.58 +        do_check_eq(args[0].aNumber.value, 10);
    1.59 +        do_check_eq(vars.r.value, 10);
    1.60 +        do_check_eq(vars.a.value, Math.PI * 100);
    1.61 +        do_check_eq(vars.arguments.value.class, "Arguments");
    1.62 +        do_check_true(!!vars.arguments.value.actor);
    1.63 +        do_check_eq(vars.foo.value, 2 * Math.PI);
    1.64 +
    1.65 +        gThreadClient.resume(function() {
    1.66 +          finishClient(gClient);
    1.67 +        });
    1.68 +      });
    1.69 +    });
    1.70 +
    1.71 +  });
    1.72 +
    1.73 +  gDebuggee.eval("(" + function() {
    1.74 +    function stopMe(aNumber) {
    1.75 +      var a, obj = { one: 1, two: 2 };
    1.76 +      var r = aNumber;
    1.77 +      with (Math) {
    1.78 +        a = PI * r * r;
    1.79 +        with (obj) {
    1.80 +          var foo = two * PI;
    1.81 +          debugger;
    1.82 +        }
    1.83 +      }
    1.84 +    };
    1.85 +    stopMe(10);
    1.86 +  } + ")()");
    1.87 +}

mercurial