summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/xpcshell/test_objectgrips-25.js
blob: f80572bb19524f06cc6b5455955bb329af7a6831 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Test object with private properties (preview + enumPrivateProperties)

"use strict";

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

function evalCode(debuggee) {
  debuggee.eval(
    function stopMe(obj) {
      debugger;
    }.toString()
  );
  debuggee.eval(`
    class MyClass {
      constructor(name, password) {
        this.name = name;
        this.#password = password;
      }

      #password;
      #salt = "sEcr3t";
      #getSaltedPassword() {
        return this.#password + this.#salt;
      }
    }

    stopMe(new MyClass("Susie", "p4$$w0rD"));
  `);
}

add_task(
  threadFrontTest(async ({ threadFront, debuggee }) => {
    const packet = await executeOnNextTickAndWaitForPause(
      () => evalCode(debuggee),
      threadFront
    );

    const [grip] = packet.frame.arguments;

    let { privateProperties } = grip.preview;
    strictEqual(
      privateProperties.length,
      2,
      "There is 2 private properties in the grip preview"
    );
    let [password, salt] = privateProperties;

    strictEqual(
      password.name,
      "#password",
      "Got expected name for #password private property in preview"
    );
    deepEqual(
      password.descriptor,
      {
        configurable: true,
        enumerable: false,
        writable: true,
        value: "p4$$w0rD",
      },
      "Got expected property descriptor for #password in preview"
    );

    strictEqual(
      salt.name,
      "#salt",
      "Got expected name for #salt private property in preview"
    );
    deepEqual(
      salt.descriptor,
      {
        configurable: true,
        enumerable: false,
        writable: true,
        value: "sEcr3t",
      },
      "Got expected property descriptor for #salt in preview"
    );

    const objClient = threadFront.pauseGrip(grip);
    const iterator = await objClient.enumPrivateProperties();
    ({ privateProperties } = await iterator.slice(0, iterator.count));

    strictEqual(
      privateProperties.length,
      2,
      "enumPrivateProperties returned 2 private properties."
    );
    [password, salt] = privateProperties;

    strictEqual(
      password.name,
      "#password",
      "Got expected name for #password private property via enumPrivateProperties"
    );
    deepEqual(
      password.descriptor,
      {
        configurable: true,
        enumerable: false,
        writable: true,
        value: "p4$$w0rD",
      },
      "Got expected property descriptor for #password via enumPrivateProperties"
    );

    strictEqual(
      salt.name,
      "#salt",
      "Got expected name for #salt private property via enumPrivateProperties"
    );
    deepEqual(
      salt.descriptor,
      {
        configurable: true,
        enumerable: false,
        writable: true,
        value: "sEcr3t",
      },
      "Got expected property descriptor for #salt via enumPrivateProperties"
    );

    await threadFront.resume();
  })
);