summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/xpcshell/test_objectgrips-16.js
blob: 785c3bc36dddabc62e17e14ff6b29db880d8eb35 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
/* eslint-disable no-shadow, max-nested-callbacks */

"use strict";

Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
registerCleanupFunction(() => {
  Services.prefs.clearUserPref("security.allow_eval_with_system_principal");
});

add_task(
  threadFrontTest(async ({ threadFront, debuggee }) => {
    const packet = await executeOnNextTickAndWaitForPause(
      eval_code,
      threadFront
    );
    const [grip] = packet.frame.arguments;

    // Checks grip.preview properties.
    check_preview(grip);

    const objClient = threadFront.pauseGrip(grip);
    const response = await objClient.getPrototypeAndProperties();
    // Checks the result of getPrototypeAndProperties.
    check_prototype_and_properties(response);

    await threadFront.resume();

    function eval_code() {
      debuggee.eval(
        function stopMe(arg1) {
          debugger;
        }.toString()
      );
      debuggee.eval(`
        stopMe({
          [Symbol()]: "first unnamed symbol",
          [Symbol()]: "second unnamed symbol",
          [Symbol("named")] : "named symbol",
          [Symbol.iterator] : function* () {
            yield 1;
            yield 2;
          },
          x: 10,
        });
      `);
    }

    function check_preview(grip) {
      Assert.equal(grip.class, "Object");

      const { preview } = grip;
      Assert.equal(preview.ownProperties.x.configurable, true);
      Assert.equal(preview.ownProperties.x.enumerable, true);
      Assert.equal(preview.ownProperties.x.writable, true);
      Assert.equal(preview.ownProperties.x.value, 10);

      const [
        firstUnnamedSymbol,
        secondUnnamedSymbol,
        namedSymbol,
        iteratorSymbol,
      ] = preview.ownSymbols;

      Assert.equal(firstUnnamedSymbol.name, undefined);
      Assert.equal(firstUnnamedSymbol.type, "symbol");
      Assert.equal(firstUnnamedSymbol.descriptor.configurable, true);
      Assert.equal(firstUnnamedSymbol.descriptor.enumerable, true);
      Assert.equal(firstUnnamedSymbol.descriptor.writable, true);
      Assert.equal(firstUnnamedSymbol.descriptor.value, "first unnamed symbol");

      Assert.equal(secondUnnamedSymbol.name, undefined);
      Assert.equal(secondUnnamedSymbol.type, "symbol");
      Assert.equal(secondUnnamedSymbol.descriptor.configurable, true);
      Assert.equal(secondUnnamedSymbol.descriptor.enumerable, true);
      Assert.equal(secondUnnamedSymbol.descriptor.writable, true);
      Assert.equal(
        secondUnnamedSymbol.descriptor.value,
        "second unnamed symbol"
      );

      Assert.equal(namedSymbol.name, "named");
      Assert.equal(namedSymbol.type, "symbol");
      Assert.equal(namedSymbol.descriptor.configurable, true);
      Assert.equal(namedSymbol.descriptor.enumerable, true);
      Assert.equal(namedSymbol.descriptor.writable, true);
      Assert.equal(namedSymbol.descriptor.value, "named symbol");

      Assert.equal(iteratorSymbol.name, "Symbol.iterator");
      Assert.equal(iteratorSymbol.type, "symbol");
      Assert.equal(iteratorSymbol.descriptor.configurable, true);
      Assert.equal(iteratorSymbol.descriptor.enumerable, true);
      Assert.equal(iteratorSymbol.descriptor.writable, true);
      Assert.equal(iteratorSymbol.descriptor.value.class, "Function");
    }

    function check_prototype_and_properties(response) {
      Assert.equal(response.ownProperties.x.configurable, true);
      Assert.equal(response.ownProperties.x.enumerable, true);
      Assert.equal(response.ownProperties.x.writable, true);
      Assert.equal(response.ownProperties.x.value, 10);

      const [
        firstUnnamedSymbol,
        secondUnnamedSymbol,
        namedSymbol,
        iteratorSymbol,
      ] = response.ownSymbols;

      Assert.equal(firstUnnamedSymbol.name, "Symbol()");
      Assert.equal(firstUnnamedSymbol.descriptor.configurable, true);
      Assert.equal(firstUnnamedSymbol.descriptor.enumerable, true);
      Assert.equal(firstUnnamedSymbol.descriptor.writable, true);
      Assert.equal(firstUnnamedSymbol.descriptor.value, "first unnamed symbol");

      Assert.equal(secondUnnamedSymbol.name, "Symbol()");
      Assert.equal(secondUnnamedSymbol.descriptor.configurable, true);
      Assert.equal(secondUnnamedSymbol.descriptor.enumerable, true);
      Assert.equal(secondUnnamedSymbol.descriptor.writable, true);
      Assert.equal(
        secondUnnamedSymbol.descriptor.value,
        "second unnamed symbol"
      );

      Assert.equal(namedSymbol.name, "Symbol(named)");
      Assert.equal(namedSymbol.descriptor.configurable, true);
      Assert.equal(namedSymbol.descriptor.enumerable, true);
      Assert.equal(namedSymbol.descriptor.writable, true);
      Assert.equal(namedSymbol.descriptor.value, "named symbol");

      Assert.equal(iteratorSymbol.name, "Symbol(Symbol.iterator)");
      Assert.equal(iteratorSymbol.descriptor.configurable, true);
      Assert.equal(iteratorSymbol.descriptor.enumerable, true);
      Assert.equal(iteratorSymbol.descriptor.writable, true);
      Assert.equal(iteratorSymbol.descriptor.value.class, "Function");
    }
  })
);