michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Test getDisplayString. michael@0: michael@0: var gDebuggee; michael@0: var gClient; michael@0: var gThreadClient; michael@0: michael@0: function run_test() michael@0: { michael@0: initTestDebuggerServer(); michael@0: gDebuggee = addTestGlobal("test-grips"); michael@0: gDebuggee.eval(function stopMe(arg1) { michael@0: debugger; michael@0: }.toString()); michael@0: michael@0: gClient = new DebuggerClient(DebuggerServer.connectPipe()); michael@0: gClient.connect(function() { michael@0: attachTestTabAndResume(gClient, "test-grips", function(aResponse, aTabClient, aThreadClient) { michael@0: gThreadClient = aThreadClient; michael@0: test_display_string(); michael@0: }); michael@0: }); michael@0: do_test_pending(); michael@0: } michael@0: michael@0: function test_display_string() michael@0: { michael@0: const testCases = [ michael@0: { michael@0: input: "new Boolean(true)", michael@0: output: "true" michael@0: }, michael@0: { michael@0: input: "new Number(5)", michael@0: output: "5" michael@0: }, michael@0: { michael@0: input: "new String('foo')", michael@0: output: "foo" michael@0: }, michael@0: { michael@0: input: "new Map()", michael@0: output: "[object Map]" michael@0: }, michael@0: { michael@0: input: "[,,,,,,,]", michael@0: output: ",,,,,," michael@0: }, michael@0: { michael@0: input: "[1, 2, 3]", michael@0: output: "1,2,3" michael@0: }, michael@0: { michael@0: input: "[undefined, null, true, 'foo', 5]", michael@0: output: ",,true,foo,5" michael@0: }, michael@0: { michael@0: input: "[{},{}]", michael@0: output: "[object Object],[object Object]" michael@0: }, michael@0: { michael@0: input: "(" + function() { michael@0: const arr = [1]; michael@0: arr.push(arr); michael@0: return arr; michael@0: } + ")()", michael@0: output: "1," michael@0: }, michael@0: { michael@0: input: "{}", michael@0: output: "[object Object]" michael@0: }, michael@0: { michael@0: input: "Object.create(null)", michael@0: output: "[object Object]" michael@0: }, michael@0: { michael@0: input: "new Error('foo')", michael@0: output: "Error: foo" michael@0: }, michael@0: { michael@0: input: "new SyntaxError()", michael@0: output: "SyntaxError" michael@0: }, michael@0: { michael@0: input: "new ReferenceError('')", michael@0: output: "ReferenceError" michael@0: }, michael@0: { michael@0: input: "(" + function() { michael@0: const err = new Error("bar"); michael@0: err.name = "foo"; michael@0: return err; michael@0: } + ")()", michael@0: output: "foo: bar" michael@0: }, michael@0: { michael@0: input: "() => {}", michael@0: output: "() => {}" michael@0: }, michael@0: { michael@0: input: "function (foo, bar) {}", michael@0: output: "function (foo, bar) {}" michael@0: }, michael@0: { michael@0: input: "function foo(bar) {}", michael@0: output: "function foo(bar) {}" michael@0: }, michael@0: { michael@0: input: "Array", michael@0: output: Array + "" michael@0: }, michael@0: { michael@0: input: "/foo[bar]/g", michael@0: output: "/foo[bar]/g" michael@0: }, michael@0: { michael@0: input: "new Proxy({}, {})", michael@0: output: "[object Object]" michael@0: } michael@0: ]; michael@0: michael@0: gThreadClient.addOneTimeListener("paused", function(aEvent, aPacket) { michael@0: const args = aPacket.frame.arguments; michael@0: michael@0: (function loop() { michael@0: const objClient = gThreadClient.pauseGrip(args.pop()); michael@0: objClient.getDisplayString(function({ displayString }) { michael@0: do_check_eq(displayString, testCases.pop().output); michael@0: if (args.length) { michael@0: loop(); michael@0: } else { michael@0: gThreadClient.resume(function() { michael@0: finishClient(gClient); michael@0: }); michael@0: } michael@0: }); michael@0: })(); michael@0: }); michael@0: michael@0: const inputs = testCases.map(({ input }) => input).join(","); michael@0: gDebuggee.eval("stopMe(" + inputs + ")"); michael@0: }