summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Object-setProperty-01.js
blob: cde5f68e541bbe84e0c18980a4e28f53412f2662 (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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// tests calling script functions via Debugger.Object.prototype.setProperty
"use strict";

var global = newGlobal({newCompartment: true});
var dbg = new Debugger(global);
dbg.onDebuggerStatement = onDebuggerStatement;

global.eval(`
const sym = Symbol("a symbol key");

const arr = [];
const obj = {
    set stringNormal(value) {
        this._stringNormal = value;
    },
    set stringAbrupt(value) {
        throw value;
    },

    set objectNormal(value) {
        this._objectNormal = value;
    },
    set objectAbrupt(value) {
        throw value;
    },

    set context(value) {
        this._context = this;
    },

    set 1234(value) {
        this._1234 = value;
    },

    set [sym](value) {
        this._sym = value;
    },

    get getterOnly() {},
    readOnly: "",

    stringProp: "",
    objProp: {},
};
Object.defineProperty(obj, "readOnly", { writable: false });

const objChild = Object.create(obj);
const proxyChild = new Proxy(obj, {});

const testObj = { };
const testChildObj = { };
const testProxyObj = { };

debugger;
`);

function onDebuggerStatement(frame) {
    const { environment } = frame;
    const sym = environment.getVariable("sym");
    const arr = environment.getVariable("arr");
    const obj = environment.getVariable("obj");
    const objChild = environment.getVariable("objChild");
    const proxyChild = environment.getVariable("proxyChild");

    assertEq(arr.setProperty(1, "index 1").return, true);
    assertEq(arr.getProperty(1).return, "index 1");
    assertEq(arr.getProperty("1").return, "index 1");
    assertEq(arr.getProperty(0).return, undefined);
    assertEq(arr.getProperty("length").return, 2);

    assertEq(arr.setProperty("2", "index 2").return, true);
    assertEq(arr.getProperty(2).return, "index 2");
    assertEq(arr.getProperty("2").return, "index 2");
    assertEq(arr.getProperty(0).return, undefined);
    assertEq(arr.getProperty("length").return, 3);

    const testObj = environment.getVariable("testObj");
    assertEq(obj.setProperty("undefined", 123).return, true);
    assertEq(obj.getProperty("undefined").return, 123);
    assertEq(obj.setProperty().return, true);
    assertEq(obj.getProperty("undefined").return, undefined);

    assertEq(obj.setProperty("missing", 42).return, true);
    assertEq(obj.getProperty("missing").return, 42);

    assertEq(obj.setProperty("stringNormal", "a normal value").return, true);
    assertEq(obj.getProperty("_stringNormal").return, "a normal value");
    assertEq(obj.setProperty("stringAbrupt", "an abrupt value").throw, "an abrupt value");

    assertEq(obj.setProperty("objectNormal", testObj).return, true);
    assertEq(obj.getProperty("_objectNormal").return, testObj);
    assertEq(obj.setProperty("objectAbrupt", testObj).throw, testObj);

    assertEq(obj.setProperty("context", "a value").return, true);
    assertEq(obj.getProperty("_context").return, obj);

    assertEq(obj.setProperty(1234, "number value").return, true);
    assertEq(obj.getProperty("_1234").return, "number value");

    assertEq(obj.setProperty(sym, "symbol value").return, true);
    assertEq(obj.getProperty("_sym").return, "symbol value");

    assertEq(obj.setProperty("getterOnly", "a value").return, false);
    assertEq(obj.setProperty("readOnly", "a value").return, false);

    assertEq(obj.setProperty("stringProp", "a normal value").return, true);
    assertEq(obj.getProperty("stringProp").return, "a normal value");

    assertEq(obj.setProperty("objectProp", testObj).return, true);
    assertEq(obj.getProperty("objectProp").return, testObj);

    const testChildObj = environment.getVariable("testChildObj");
    assertEq(objChild.setProperty("undefined", 123).return, true);
    assertEq(objChild.getProperty("undefined").return, 123);
    assertEq(objChild.setProperty().return, true);
    assertEq(objChild.getProperty("undefined").return, undefined);

    assertEq(objChild.setProperty("missing", 42).return, true);
    assertEq(objChild.getProperty("missing").return, 42);

    assertEq(objChild.setProperty("stringNormal", "a normal child value").return, true);
    assertEq(objChild.getProperty("_stringNormal").return, "a normal child value");

    assertEq(objChild.setProperty("stringAbrupt", "an abrupt child value").throw, "an abrupt child value");

    assertEq(objChild.setProperty("objectNormal", testChildObj).return, true);
    assertEq(objChild.getProperty("_objectNormal").return, testChildObj);

    assertEq(objChild.setProperty("objectAbrupt", testChildObj).throw, testChildObj);

    assertEq(objChild.setProperty("context", "a value").return, true);
    assertEq(objChild.getProperty("_context").return, objChild);

    assertEq(objChild.setProperty(1234, "number value").return, true);
    assertEq(objChild.getProperty("_1234").return, "number value");

    assertEq(objChild.setProperty(sym, "symbol value").return, true);
    assertEq(objChild.getProperty("_sym").return, "symbol value");

    assertEq(objChild.setProperty("getterOnly", "a value").return, false);
    assertEq(objChild.setProperty("readOnly", "a value").return, false);

    assertEq(objChild.setProperty("stringProp", "a normal child value").return, true);
    assertEq(objChild.getProperty("stringProp").return, "a normal child value");

    assertEq(objChild.setProperty("objectProp", testChildObj).return, true);
    assertEq(objChild.getProperty("objectProp").return, testChildObj);

    const testProxyObj = environment.getVariable("testProxyObj");
    assertEq(proxyChild.setProperty("undefined", 123).return, true);
    assertEq(proxyChild.getProperty("undefined").return, 123);
    assertEq(proxyChild.setProperty().return, true);
    assertEq(proxyChild.getProperty("undefined").return, undefined);

    assertEq(proxyChild.setProperty("missing", 42).return, true);
    assertEq(proxyChild.getProperty("missing").return, 42);

    assertEq(proxyChild.setProperty("stringNormal", "a normal child value").return, true);
    assertEq(proxyChild.getProperty("_stringNormal").return, "a normal child value");

    assertEq(proxyChild.setProperty("stringAbrupt", "an abrupt child value").throw, "an abrupt child value");

    assertEq(proxyChild.setProperty("objectNormal", testProxyObj).return, true);
    assertEq(proxyChild.getProperty("_objectNormal").return, testProxyObj);

    assertEq(proxyChild.setProperty("objectAbrupt", testProxyObj).throw, testProxyObj);

    assertEq(proxyChild.setProperty("context", "a value").return, true);
    assertEq(proxyChild.getProperty("_context").return, proxyChild);

    assertEq(proxyChild.setProperty(1234, "number value").return, true);
    assertEq(proxyChild.getProperty("_1234").return, "number value");

    assertEq(proxyChild.setProperty(sym, "symbol value").return, true);
    assertEq(proxyChild.getProperty("_sym").return, "symbol value");

    assertEq(proxyChild.setProperty("getterOnly", "a value").return, false);
    assertEq(proxyChild.setProperty("readOnly", "a value").return, false);

    assertEq(proxyChild.setProperty("stringProp", "a normal child value").return, true);
    assertEq(proxyChild.getProperty("stringProp").return, "a normal child value");

    assertEq(proxyChild.setProperty("objectProp", testProxyObj).return, true);
    assertEq(proxyChild.getProperty("objectProp").return, testProxyObj);
};