|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Test getDisplayString. |
|
5 |
|
6 var gDebuggee; |
|
7 var gClient; |
|
8 var gThreadClient; |
|
9 |
|
10 function run_test() |
|
11 { |
|
12 initTestDebuggerServer(); |
|
13 gDebuggee = addTestGlobal("test-grips"); |
|
14 gDebuggee.eval(function stopMe(arg1) { |
|
15 debugger; |
|
16 }.toString()); |
|
17 |
|
18 gClient = new DebuggerClient(DebuggerServer.connectPipe()); |
|
19 gClient.connect(function() { |
|
20 attachTestTabAndResume(gClient, "test-grips", function(aResponse, aTabClient, aThreadClient) { |
|
21 gThreadClient = aThreadClient; |
|
22 test_display_string(); |
|
23 }); |
|
24 }); |
|
25 do_test_pending(); |
|
26 } |
|
27 |
|
28 function test_display_string() |
|
29 { |
|
30 const testCases = [ |
|
31 { |
|
32 input: "new Boolean(true)", |
|
33 output: "true" |
|
34 }, |
|
35 { |
|
36 input: "new Number(5)", |
|
37 output: "5" |
|
38 }, |
|
39 { |
|
40 input: "new String('foo')", |
|
41 output: "foo" |
|
42 }, |
|
43 { |
|
44 input: "new Map()", |
|
45 output: "[object Map]" |
|
46 }, |
|
47 { |
|
48 input: "[,,,,,,,]", |
|
49 output: ",,,,,," |
|
50 }, |
|
51 { |
|
52 input: "[1, 2, 3]", |
|
53 output: "1,2,3" |
|
54 }, |
|
55 { |
|
56 input: "[undefined, null, true, 'foo', 5]", |
|
57 output: ",,true,foo,5" |
|
58 }, |
|
59 { |
|
60 input: "[{},{}]", |
|
61 output: "[object Object],[object Object]" |
|
62 }, |
|
63 { |
|
64 input: "(" + function() { |
|
65 const arr = [1]; |
|
66 arr.push(arr); |
|
67 return arr; |
|
68 } + ")()", |
|
69 output: "1," |
|
70 }, |
|
71 { |
|
72 input: "{}", |
|
73 output: "[object Object]" |
|
74 }, |
|
75 { |
|
76 input: "Object.create(null)", |
|
77 output: "[object Object]" |
|
78 }, |
|
79 { |
|
80 input: "new Error('foo')", |
|
81 output: "Error: foo" |
|
82 }, |
|
83 { |
|
84 input: "new SyntaxError()", |
|
85 output: "SyntaxError" |
|
86 }, |
|
87 { |
|
88 input: "new ReferenceError('')", |
|
89 output: "ReferenceError" |
|
90 }, |
|
91 { |
|
92 input: "(" + function() { |
|
93 const err = new Error("bar"); |
|
94 err.name = "foo"; |
|
95 return err; |
|
96 } + ")()", |
|
97 output: "foo: bar" |
|
98 }, |
|
99 { |
|
100 input: "() => {}", |
|
101 output: "() => {}" |
|
102 }, |
|
103 { |
|
104 input: "function (foo, bar) {}", |
|
105 output: "function (foo, bar) {}" |
|
106 }, |
|
107 { |
|
108 input: "function foo(bar) {}", |
|
109 output: "function foo(bar) {}" |
|
110 }, |
|
111 { |
|
112 input: "Array", |
|
113 output: Array + "" |
|
114 }, |
|
115 { |
|
116 input: "/foo[bar]/g", |
|
117 output: "/foo[bar]/g" |
|
118 }, |
|
119 { |
|
120 input: "new Proxy({}, {})", |
|
121 output: "[object Object]" |
|
122 } |
|
123 ]; |
|
124 |
|
125 gThreadClient.addOneTimeListener("paused", function(aEvent, aPacket) { |
|
126 const args = aPacket.frame.arguments; |
|
127 |
|
128 (function loop() { |
|
129 const objClient = gThreadClient.pauseGrip(args.pop()); |
|
130 objClient.getDisplayString(function({ displayString }) { |
|
131 do_check_eq(displayString, testCases.pop().output); |
|
132 if (args.length) { |
|
133 loop(); |
|
134 } else { |
|
135 gThreadClient.resume(function() { |
|
136 finishClient(gClient); |
|
137 }); |
|
138 } |
|
139 }); |
|
140 })(); |
|
141 }); |
|
142 |
|
143 const inputs = testCases.map(({ input }) => input).join(","); |
|
144 gDebuggee.eval("stopMe(" + inputs + ")"); |
|
145 } |