|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Test that ObjectClient.prototype.getDefinitionSite and the "definitionSite" |
|
5 // request work properly. |
|
6 |
|
7 var gDebuggee; |
|
8 var gClient; |
|
9 var gThreadClient; |
|
10 |
|
11 function run_test() |
|
12 { |
|
13 initTestDebuggerServer(); |
|
14 gDebuggee = addTestGlobal("test-grips"); |
|
15 gDebuggee.eval(function stopMe() { |
|
16 debugger; |
|
17 }.toString()); |
|
18 |
|
19 gClient = new DebuggerClient(DebuggerServer.connectPipe()); |
|
20 gClient.connect(function() { |
|
21 attachTestTabAndResume(gClient, "test-grips", function(aResponse, aTabClient, aThreadClient) { |
|
22 gThreadClient = aThreadClient; |
|
23 add_pause_listener(); |
|
24 }); |
|
25 }); |
|
26 do_test_pending(); |
|
27 } |
|
28 |
|
29 function add_pause_listener() |
|
30 { |
|
31 gThreadClient.addOneTimeListener("paused", function(aEvent, aPacket) { |
|
32 const [funcGrip, objGrip] = aPacket.frame.arguments; |
|
33 const func = gThreadClient.pauseGrip(funcGrip); |
|
34 const obj = gThreadClient.pauseGrip(objGrip); |
|
35 test_definition_site(func, obj); |
|
36 }); |
|
37 |
|
38 eval_code(); |
|
39 } |
|
40 |
|
41 function eval_code() { |
|
42 gDebuggee.eval([ |
|
43 "this.line0 = Error().lineNumber;", |
|
44 "function f() {}", |
|
45 "stopMe(f, {});" |
|
46 ].join("\n")); |
|
47 } |
|
48 |
|
49 function test_definition_site(func, obj) { |
|
50 func.getDefinitionSite(({ error, url, line, column }) => { |
|
51 do_check_true(!error); |
|
52 do_check_eq(url, getFilePath("test_objectgrips-13.js")); |
|
53 do_check_eq(line, gDebuggee.line0 + 1); |
|
54 do_check_eq(column, 0); |
|
55 |
|
56 test_bad_definition_site(obj); |
|
57 }); |
|
58 } |
|
59 |
|
60 function test_bad_definition_site(obj) { |
|
61 try { |
|
62 obj._client.request("definitionSite", () => do_check_true(false)); |
|
63 } catch (e) { |
|
64 gThreadClient.resume(() => finishClient(gClient)); |
|
65 } |
|
66 } |