Debian Codegraph @

js/src/jit-test/tests/debug/Object-setProperty-01.js

raw
1 // tests calling script functions via Debugger.Object.prototype.setProperty
2 "use strict";
3
4 var global = newGlobal({newCompartment: true});
5 var dbg = new Debugger(global);
6 dbg.onDebuggerStatement = onDebuggerStatement;
7
8 global.eval(`
9 const sym = Symbol("a symbol key");
10
11 const arr = [];
12 const obj = {
13 set stringNormal(value) {
14 this._stringNormal = value;
15 },
16 set stringAbrupt(value) {
17 throw value;
18 },
19
20 set objectNormal(value) {
21 this._objectNormal = value;
22 },
23 set objectAbrupt(value) {
24 throw value;
25 },
26
27 set context(value) {
28 this._context = this;
29 },
30
31 set 1234(value) {
32 this._1234 = value;
33 },
34
35 set [sym](value) {
36 this._sym = value;
37 },
38
39 get getterOnly() {},
40 readOnly: "",
41
42 stringProp: "",
43 objProp: {},
44 };
45 Object.defineProperty(obj, "readOnly", { writable: false });
46
47 const objChild = Object.create(obj);
48 const proxyChild = new Proxy(obj, {});
49
50 const testObj = { };
51 const testChildObj = { };
52 const testProxyObj = { };
53
54 debugger;
55 `);
56
57 function onDebuggerStatement(frame) {
58 const { environment } = frame;
59 const sym = environment.getVariable("sym");
60 const arr = environment.getVariable("arr");
61 const obj = environment.getVariable("obj");
62 const objChild = environment.getVariable("objChild");
63 const proxyChild = environment.getVariable("proxyChild");
64
65 assertEq(arr.setProperty(1, "index 1").return, true);
66 assertEq(arr.getProperty(1).return, "index 1");
67 assertEq(arr.getProperty("1").return, "index 1");
68 assertEq(arr.getProperty(0).return, undefined);
69 assertEq(arr.getProperty("length").return, 2);
70
71 assertEq(arr.setProperty("2", "index 2").return, true);
72 assertEq(arr.getProperty(2).return, "index 2");
73 assertEq(arr.getProperty("2").return, "index 2");
74 assertEq(arr.getProperty(0).return, undefined);
75 assertEq(arr.getProperty("length").return, 3);
76
77 const testObj = environment.getVariable("testObj");
78 assertEq(obj.setProperty("undefined", 123).return, true);
79 assertEq(obj.getProperty("undefined").return, 123);
80 assertEq(obj.setProperty().return, true);
81 assertEq(obj.getProperty("undefined").return, undefined);
82
83 assertEq(obj.setProperty("missing", 42).return, true);
84 assertEq(obj.getProperty("missing").return, 42);
85
86 assertEq(obj.setProperty("stringNormal", "a normal value").return, true);
87 assertEq(obj.getProperty("_stringNormal").return, "a normal value");
88 assertEq(obj.setProperty("stringAbrupt", "an abrupt value").throw, "an abrupt value");
89
90 assertEq(obj.setProperty("objectNormal", testObj).return, true);
91 assertEq(obj.getProperty("_objectNormal").return, testObj);
92 assertEq(obj.setProperty("objectAbrupt", testObj).throw, testObj);
93
94 assertEq(obj.setProperty("context", "a value").return, true);
95 assertEq(obj.getProperty("_context").return, obj);
96
97 assertEq(obj.setProperty(1234, "number value").return, true);
98 assertEq(obj.getProperty("_1234").return, "number value");
99
100 assertEq(obj.setProperty(sym, "symbol value").return, true);
101 assertEq(obj.getProperty("_sym").return, "symbol value");
102
103 assertEq(obj.setProperty("getterOnly", "a value").return, false);
104 assertEq(obj.setProperty("readOnly", "a value").return, false);
105
106 assertEq(obj.setProperty("stringProp", "a normal value").return, true);
107 assertEq(obj.getProperty("stringProp").return, "a normal value");
108
109 assertEq(obj.setProperty("objectProp", testObj).return, true);
110 assertEq(obj.getProperty("objectProp").return, testObj);
111
112 const testChildObj = environment.getVariable("testChildObj");
113 assertEq(objChild.setProperty("undefined", 123).return, true);
114 assertEq(objChild.getProperty("undefined").return, 123);
115 assertEq(objChild.setProperty().return, true);
116 assertEq(objChild.getProperty("undefined").return, undefined);
117
118 assertEq(objChild.setProperty("missing", 42).return, true);
119 assertEq(objChild.getProperty("missing").return, 42);
120
121 assertEq(objChild.setProperty("stringNormal", "a normal child value").return, true);
122 assertEq(objChild.getProperty("_stringNormal").return, "a normal child value");
123
124 assertEq(objChild.setProperty("stringAbrupt", "an abrupt child value").throw, "an abrupt child value");
125
126 assertEq(objChild.setProperty("objectNormal", testChildObj).return, true);
127 assertEq(objChild.getProperty("_objectNormal").return, testChildObj);
128
129 assertEq(objChild.setProperty("objectAbrupt", testChildObj).throw, testChildObj);
130
131 assertEq(objChild.setProperty("context", "a value").return, true);
132 assertEq(objChild.getProperty("_context").return, objChild);
133
134 assertEq(objChild.setProperty(1234, "number value").return, true);
135 assertEq(objChild.getProperty("_1234").return, "number value");
136
137 assertEq(objChild.setProperty(sym, "symbol value").return, true);
138 assertEq(objChild.getProperty("_sym").return, "symbol value");
139
140 assertEq(objChild.setProperty("getterOnly", "a value").return, false);
141 assertEq(objChild.setProperty("readOnly", "a value").return, false);
142
143 assertEq(objChild.setProperty("stringProp", "a normal child value").return, true);
144 assertEq(objChild.getProperty("stringProp").return, "a normal child value");
145
146 assertEq(objChild.setProperty("objectProp", testChildObj).return, true);
147 assertEq(objChild.getProperty("objectProp").return, testChildObj);
148
149 const testProxyObj = environment.getVariable("testProxyObj");
150 assertEq(proxyChild.setProperty("undefined", 123).return, true);
151 assertEq(proxyChild.getProperty("undefined").return, 123);
152 assertEq(proxyChild.setProperty().return, true);
153 assertEq(proxyChild.getProperty("undefined").return, undefined);
154
155 assertEq(proxyChild.setProperty("missing", 42).return, true);
156 assertEq(proxyChild.getProperty("missing").return, 42);
157
158 assertEq(proxyChild.setProperty("stringNormal", "a normal child value").return, true);
159 assertEq(proxyChild.getProperty("_stringNormal").return, "a normal child value");
160
161 assertEq(proxyChild.setProperty("stringAbrupt", "an abrupt child value").throw, "an abrupt child value");
162
163 assertEq(proxyChild.setProperty("objectNormal", testProxyObj).return, true);
164 assertEq(proxyChild.getProperty("_objectNormal").return, testProxyObj);
165
166 assertEq(proxyChild.setProperty("objectAbrupt", testProxyObj).throw, testProxyObj);
167
168 assertEq(proxyChild.setProperty("context", "a value").return, true);
169 assertEq(proxyChild.getProperty("_context").return, proxyChild);
170
171 assertEq(proxyChild.setProperty(1234, "number value").return, true);
172 assertEq(proxyChild.getProperty("_1234").return, "number value");
173
174 assertEq(proxyChild.setProperty(sym, "symbol value").return, true);
175 assertEq(proxyChild.getProperty("_sym").return, "symbol value");
176
177 assertEq(proxyChild.setProperty("getterOnly", "a value").return, false);
178 assertEq(proxyChild.setProperty("readOnly", "a value").return, false);
179
180 assertEq(proxyChild.setProperty("stringProp", "a normal child value").return, true);
181 assertEq(proxyChild.getProperty("stringProp").return, "a normal child value");
182
183 assertEq(proxyChild.setProperty("objectProp", testProxyObj).return, true);
184 assertEq(proxyChild.getProperty("objectProp").return, testProxyObj);
185 };