summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/unit/test_objectgrips-12.js
blob: 32d4d47e01f8ba3f83a60280da4cb2562654e390 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Test getDisplayString.

Cu.import("resource://testing-common/PromiseTestUtils.jsm", this);

var gDebuggee;
var gClient;
var gThreadClient;

function run_test()
{
  initTestDebuggerServer();
  gDebuggee = addTestGlobal("test-grips");
  gDebuggee.eval(function stopMe(arg1) {
    debugger;
  }.toString());

  gClient = new DebuggerClient(DebuggerServer.connectPipe());
  gClient.connect().then(function () {
    attachTestTabAndResume(gClient, "test-grips", function (aResponse, aTabClient, aThreadClient) {
      gThreadClient = aThreadClient;
      test_display_string();
    });
  });
  do_test_pending();
}

function test_display_string()
{
  const testCases = [
    {
      input: "new Boolean(true)",
      output: "true"
    },
    {
      input: "new Number(5)",
      output: "5"
    },
    {
      input: "new String('foo')",
      output: "foo"
    },
    {
      input: "new Map()",
      output: "[object Map]"
    },
    {
      input: "[,,,,,,,]",
      output: ",,,,,,"
    },
    {
      input: "[1, 2, 3]",
      output: "1,2,3"
    },
    {
      input: "[undefined, null, true, 'foo', 5]",
      output: ",,true,foo,5"
    },
    {
      input: "[{},{}]",
      output: "[object Object],[object Object]"
    },
    {
      input: "(" + function () {
        const arr = [1];
        arr.push(arr);
        return arr;
      } + ")()",
      output: "1,"
    },
    {
      input: "{}",
      output: "[object Object]"
    },
    {
      input: "Object.create(null)",
      output: "[object Object]"
    },
    {
      input: "new Error('foo')",
      output: "Error: foo"
    },
    {
      input: "new SyntaxError()",
      output: "SyntaxError"
    },
    {
      input: "new ReferenceError('')",
      output: "ReferenceError"
    },
    {
      input: "(" + function () {
        const err = new Error("bar");
        err.name = "foo";
        return err;
      } + ")()",
      output: "foo: bar"
    },
    {
      input: "() => {}",
      output: "() => {}"
    },
    {
      input: "function (foo, bar) {}",
      output: "function (foo, bar) {}"
    },
    {
      input: "function foo(bar) {}",
      output: "function foo(bar) {}"
    },
    {
      input: "Array",
      output: Array + ""
    },
    {
      input: "/foo[bar]/g",
      output: "/foo[bar]/g"
    },
    {
      input: "new Proxy({}, {})",
      output: "[object Object]"
    },
    {
      input: "Promise.resolve(5)",
      output: "Promise (fulfilled: 5)"
    },
    {
      // This rejection is left uncaught, see expectUncaughtRejection below.
      input: "Promise.reject(new Error())",
      output: "Promise (rejected: Error)"
    },
    {
      input: "new Promise(function () {})",
      output: "Promise (pending)"
    }
  ];

  PromiseTestUtils.expectUncaughtRejection(/Error/);

  gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    const args = aPacket.frame.arguments;

    (function loop() {
      const objClient = gThreadClient.pauseGrip(args.pop());
      objClient.getDisplayString(function ({ displayString }) {
        do_check_eq(displayString, testCases.pop().output);
        if (args.length) {
          loop();
        } else {
          gThreadClient.resume(function () {
            finishClient(gClient);
          });
        }
      });
    })();
  });

  const inputs = testCases.map(({ input }) => input).join(",");
  gDebuggee.eval("stopMe(" + inputs + ")");
}