|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Check the environment bindongs of a |with| within a |with|. |
|
6 */ |
|
7 |
|
8 var gDebuggee; |
|
9 var gClient; |
|
10 var gThreadClient; |
|
11 |
|
12 function run_test() |
|
13 { |
|
14 initTestDebuggerServer(); |
|
15 gDebuggee = addTestGlobal("test-stack"); |
|
16 gClient = new DebuggerClient(DebuggerServer.connectPipe()); |
|
17 gClient.connect(function() { |
|
18 attachTestTabAndResume(gClient, "test-stack", function(aResponse, aTabClient, aThreadClient) { |
|
19 gThreadClient = aThreadClient; |
|
20 test_pause_frame(); |
|
21 }); |
|
22 }); |
|
23 do_test_pending(); |
|
24 } |
|
25 |
|
26 function test_pause_frame() |
|
27 { |
|
28 gThreadClient.addOneTimeListener("paused", function(aEvent, aPacket) { |
|
29 let env = aPacket.frame.environment; |
|
30 do_check_neq(env, undefined); |
|
31 |
|
32 let objClient = gThreadClient.pauseGrip(env.object); |
|
33 objClient.getPrototypeAndProperties(function(aResponse) { |
|
34 do_check_eq(aResponse.ownProperties.one.value, 1); |
|
35 do_check_eq(aResponse.ownProperties.two.value, 2); |
|
36 do_check_eq(aResponse.ownProperties.foo, undefined); |
|
37 |
|
38 let parentEnv = env.parent; |
|
39 do_check_neq(parentEnv, undefined); |
|
40 |
|
41 let parentClient = gThreadClient.pauseGrip(parentEnv.object); |
|
42 parentClient.getPrototypeAndProperties(function(aResponse) { |
|
43 do_check_eq(aResponse.ownProperties.PI.value, Math.PI); |
|
44 do_check_eq(aResponse.ownProperties.cos.value.type, "object"); |
|
45 do_check_eq(aResponse.ownProperties.cos.value.class, "Function"); |
|
46 do_check_true(!!aResponse.ownProperties.cos.value.actor); |
|
47 |
|
48 parentEnv = parentEnv.parent; |
|
49 do_check_neq(parentEnv, undefined); |
|
50 |
|
51 let bindings = parentEnv.bindings; |
|
52 let args = bindings.arguments; |
|
53 let vars = bindings.variables; |
|
54 do_check_eq(args.length, 1); |
|
55 do_check_eq(args[0].aNumber.value, 10); |
|
56 do_check_eq(vars.r.value, 10); |
|
57 do_check_eq(vars.a.value, Math.PI * 100); |
|
58 do_check_eq(vars.arguments.value.class, "Arguments"); |
|
59 do_check_true(!!vars.arguments.value.actor); |
|
60 do_check_eq(vars.foo.value, 2 * Math.PI); |
|
61 |
|
62 gThreadClient.resume(function() { |
|
63 finishClient(gClient); |
|
64 }); |
|
65 }); |
|
66 }); |
|
67 |
|
68 }); |
|
69 |
|
70 gDebuggee.eval("(" + function() { |
|
71 function stopMe(aNumber) { |
|
72 var a, obj = { one: 1, two: 2 }; |
|
73 var r = aNumber; |
|
74 with (Math) { |
|
75 a = PI * r * r; |
|
76 with (obj) { |
|
77 var foo = two * PI; |
|
78 debugger; |
|
79 } |
|
80 } |
|
81 }; |
|
82 stopMe(10); |
|
83 } + ")()"); |
|
84 } |