|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Test that self-hosted functions aren't traced and don't add depth. |
|
6 */ |
|
7 |
|
8 var gDebuggee; |
|
9 var gClient; |
|
10 var gTraceClient; |
|
11 |
|
12 function run_test() |
|
13 { |
|
14 initTestTracerServer(); |
|
15 gDebuggee = addTestGlobal("test-tracer-actor"); |
|
16 gClient = new DebuggerClient(DebuggerServer.connectPipe()); |
|
17 gClient.connect(function() { |
|
18 attachTestTab(gClient, "test-tracer-actor", function(aResponse, aTabClient) { |
|
19 gClient.attachTracer(aResponse.traceActor, function(aResponse, aTraceClient) { |
|
20 gTraceClient = aTraceClient; |
|
21 test_frame_depths(); |
|
22 }); |
|
23 }); |
|
24 }); |
|
25 do_test_pending(); |
|
26 } |
|
27 |
|
28 function test_frame_depths() |
|
29 { |
|
30 const tracesStopped = promise.defer(); |
|
31 gClient.addListener("traces", (aEvent, { traces }) => { |
|
32 for (let t of traces) { |
|
33 check_trace(t); |
|
34 } |
|
35 tracesStopped.resolve(); |
|
36 }); |
|
37 |
|
38 start_trace() |
|
39 .then(eval_code) |
|
40 .then(() => tracesStopped.promise) |
|
41 .then(stop_trace) |
|
42 .then(function() { |
|
43 finishClient(gClient); |
|
44 }).then(null, error => { |
|
45 do_check_true(false, "Should not get an error, got: " + DevToolsUtils.safeErrorString(error)); |
|
46 }); |
|
47 } |
|
48 |
|
49 function start_trace() |
|
50 { |
|
51 let deferred = promise.defer(); |
|
52 gTraceClient.startTrace(["depth", "name", "location"], null, function() { deferred.resolve(); }); |
|
53 return deferred.promise; |
|
54 } |
|
55 |
|
56 function eval_code() |
|
57 { |
|
58 gDebuggee.eval("(" + function iife() { |
|
59 [1].forEach(function noop() {}); |
|
60 for (let x of [1]) {} |
|
61 } + ")()"); |
|
62 } |
|
63 |
|
64 function stop_trace() |
|
65 { |
|
66 let deferred = promise.defer(); |
|
67 gTraceClient.stopTrace(null, function() { deferred.resolve(); }); |
|
68 return deferred.promise; |
|
69 } |
|
70 |
|
71 function check_trace({ sequence, depth, name, location }) |
|
72 { |
|
73 if (location) { |
|
74 do_check_true(location.url !== "self-hosted"); |
|
75 } |
|
76 |
|
77 switch(sequence) { |
|
78 case 0: |
|
79 do_check_eq(name, "(eval)"); |
|
80 case 5: |
|
81 do_check_eq(depth, 0); |
|
82 break; |
|
83 |
|
84 case 1: |
|
85 do_check_eq(name, "iife"); |
|
86 case 4: |
|
87 do_check_eq(depth, 1); |
|
88 break; |
|
89 |
|
90 case 2: |
|
91 do_check_eq(name, "noop"); |
|
92 case 3: |
|
93 do_check_eq(depth, 2); |
|
94 break; |
|
95 |
|
96 default: |
|
97 // Should have covered all sequences. |
|
98 do_check_true(false); |
|
99 } |
|
100 } |