UNPKG

30.6 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _realm = require("../realm.js");
9
10var _index = require("./index.js");
11
12var _invariant = _interopRequireDefault(require("../invariant.js"));
13
14var _abstract = require("../methods/abstract.js");
15
16var _get = require("../methods/get.js");
17
18var _is = require("../methods/is.js");
19
20var _singletons = require("../singletons.js");
21
22var _call = require("../methods/call.js");
23
24function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
26function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
28function FindPropertyKey(realm, keys, key) {
29 for (let i = 0; i < keys.length; ++i) {
30 if ((0, _abstract.SamePropertyKey)(realm, key, keys[i])) {
31 return i;
32 }
33 }
34
35 return -1;
36}
37
38class ProxyValue extends _index.ObjectValue {
39 constructor(realm) {
40 super(realm);
41 }
42
43 getTrackedPropertyNames() {
44 return ProxyValue.trackedPropertyNames;
45 }
46
47 isSimpleObject() {
48 return false;
49 }
50
51 usesOrdinaryObjectInternalPrototypeMethods() {
52 return false;
53 } // ECMA262 9.5.1
54
55
56 $GetPrototypeOf() {
57 let realm = this.$Realm; // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
58
59 let handler = this.$ProxyHandler; // 2. If handler is null, throw a TypeError exception.
60
61 if (handler instanceof _index.NullValue) {
62 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
63 } // 3. Assert: Type(handler) is Object.
64
65
66 (0, _invariant.default)(handler instanceof _index.ObjectValue, "expected an object"); // 4. Let target be the value of the [[ProxyTarget]] internal slot of O.
67
68 let target = this.$ProxyTarget;
69 (0, _invariant.default)(target instanceof _index.ObjectValue); // 5. Let trap be ? GetMethod(handler, "getPrototypeOf").
70
71 let trap = (0, _get.GetMethod)(realm, handler, "getPrototypeOf"); // 6. If trap is undefined, then
72
73 if (trap instanceof _index.UndefinedValue) {
74 // a. Return ? target.[[GetPrototypeOf]]().
75 return target.$GetPrototypeOf();
76 } // 7. Let handlerProto be ? Call(trap, handler, « target »).
77
78
79 let handlerProto = (0, _call.Call)(realm, trap, handler, [target]); // 8. If Type(handlerProto) is neither Object nor Null, throw a TypeError exception.
80
81 if (!(handlerProto instanceof _index.ObjectValue) && !(handlerProto instanceof _index.NullValue)) {
82 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
83 } // 9. Let extensibleTarget be ? IsExtensible(target).
84
85
86 let extensibleTarget = (0, _is.IsExtensible)(realm, target); // 10. If extensibleTarget is true, return handlerProto.
87
88 if (extensibleTarget) return handlerProto; // 11. Let targetProto be ? target.[[GetPrototypeOf]]().
89
90 let targetProto = target.$GetPrototypeOf(); // 12. If SameValue(handlerProto, targetProto) is false, throw a TypeError exception.
91
92 if (!(0, _abstract.SameValuePartial)(realm, handlerProto, targetProto)) {
93 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
94 } // 13. Return handlerProto.
95
96
97 return handlerProto;
98 } // ECMA262 9.5.2
99
100
101 $SetPrototypeOf(V) {
102 let realm = this.$Realm; // 1. Assert: Either Type(V) is Object or Type(V) is Null.
103
104 (0, _invariant.default)(V instanceof _index.ObjectValue || V instanceof _index.NullValue, "expected object or null"); // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
105
106 let handler = this.$ProxyHandler; // 3. If handler is null, throw a TypeError exception.
107
108 if (handler instanceof _index.NullValue) {
109 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
110 } // 4. Assert: Type(handler) is Object.
111
112
113 (0, _invariant.default)(handler instanceof _index.ObjectValue, "expected object"); // 5. Let target be the value of the [[ProxyTarget]] internal slot of O.
114
115 let target = this.$ProxyTarget;
116 (0, _invariant.default)(target instanceof _index.ObjectValue); // 6. Let trap be ? GetMethod(handler, "setPrototypeOf").
117
118 let trap = (0, _get.GetMethod)(realm, handler, "setPrototypeOf"); // 7. If trap is undefined, then
119
120 if (trap instanceof _index.UndefinedValue) {
121 // a. Return ? target.[[SetPrototypeOf]](V).
122 return target.$SetPrototypeOf(V);
123 } // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « target, V »)).
124
125
126 let booleanTrapResult = _singletons.To.ToBooleanPartial(realm, (0, _call.Call)(realm, trap, handler, [target, V])); // 9. If booleanTrapResult is false, return false.
127
128
129 if (!booleanTrapResult) return false; // 10. Let extensibleTarget be ? IsExtensible(target).
130
131 let extensibleTarget = (0, _is.IsExtensible)(realm, target); // 11. If extensibleTarget is true, return true.
132
133 if (extensibleTarget) return true; // 12. Let targetProto be ? target.[[GetPrototypeOf]]().
134
135 let targetProto = target.$GetPrototypeOf(); // 13. If SameValue(V, targetProto) is false, throw a TypeError exception.
136
137 if (!(0, _abstract.SameValuePartial)(realm, V, targetProto)) {
138 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
139 } // 14. Return true.
140
141
142 return true;
143 } // ECMA262 9.5.3
144
145
146 $IsExtensible() {
147 let realm = this.$Realm; // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
148
149 let handler = this.$ProxyHandler; // 2. If handler is null, throw a TypeError exception.
150
151 if (handler instanceof _index.NullValue) {
152 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
153 } // 3. Assert: Type(handler) is Object.
154
155
156 (0, _invariant.default)(handler instanceof _index.ObjectValue, "expected object"); // 4. Let target be the value of the [[ProxyTarget]] internal slot of O.
157
158 let target = this.$ProxyTarget; // 5. Let trap be ? GetMethod(handler, "isExtensible").
159
160 let trap = (0, _get.GetMethod)(realm, handler, "isExtensible"); // 6. If trap is undefined, then
161
162 if (trap instanceof _index.UndefinedValue) {
163 // a. Return ? target.[[IsExtensible]]().
164 (0, _invariant.default)(target instanceof _index.ObjectValue);
165 return target.$IsExtensible();
166 } // 7. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « target »)).
167
168
169 let booleanTrapResult = _singletons.To.ToBooleanPartial(realm, (0, _call.Call)(realm, trap, handler, [target])); // 8. Let targetResult be ? target.[[IsExtensible]]().
170
171
172 (0, _invariant.default)(target instanceof _index.ObjectValue);
173 let targetResult = target.$IsExtensible(); // 9. If SameValue(booleanTrapResult, targetResult) is false, throw a TypeError exception.
174
175 if (booleanTrapResult !== targetResult) {
176 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
177 } // 10. Return booleanTrapResult.
178
179
180 return booleanTrapResult;
181 } // ECMA262 9.5.4
182
183
184 $PreventExtensions() {
185 let realm = this.$Realm; // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
186
187 let handler = this.$ProxyHandler; // 2. If handler is null, throw a TypeError exception.
188
189 if (handler instanceof _index.NullValue) {
190 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
191 } // 3. Assert: Type(handler) is Object.
192
193
194 (0, _invariant.default)(handler instanceof _index.ObjectValue, "expected object"); // 4. Let target be the value of the [[ProxyTarget]] internal slot of O.
195
196 let target = this.$ProxyTarget; // 5. Let trap be ? GetMethod(handler, "preventExtensions").
197
198 let trap = (0, _get.GetMethod)(realm, handler, "preventExtensions"); // 6. If trap is undefined, then
199
200 if (trap instanceof _index.UndefinedValue) {
201 // a. Return ? target.[[PreventExtensions]]().
202 (0, _invariant.default)(target instanceof _index.ObjectValue);
203 return target.$PreventExtensions();
204 } // 7. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « target »)).
205
206
207 let booleanTrapResult = _singletons.To.ToBooleanPartial(realm, (0, _call.Call)(realm, trap, handler, [target])); // 8. If booleanTrapResult is true, then
208
209
210 if (booleanTrapResult) {
211 // a. Let targetIsExtensible be ? target.[[IsExtensible]]().
212 (0, _invariant.default)(target instanceof _index.ObjectValue);
213 let targetIsExtensible = target.$IsExtensible(); // b. If targetIsExtensible is true, throw a TypeError exception.
214
215 if (targetIsExtensible) {
216 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
217 }
218 } // 9. Return booleanTrapResult.
219
220
221 return booleanTrapResult;
222 } // ECMA262 9.5.5
223
224
225 $GetOwnProperty(P) {
226 let realm = this.$Realm; // 1. Assert: IsPropertyKey(P) is true.
227
228 (0, _invariant.default)((0, _is.IsPropertyKey)(realm, P), "expected property key"); // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
229
230 let handler = this.$ProxyHandler; // 3. If handler is null, throw a TypeError exception.
231
232 if (handler instanceof _index.NullValue) {
233 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
234 } // 4. Assert: Type(handler) is Object.
235
236
237 (0, _invariant.default)(handler instanceof _index.ObjectValue, "expected object"); // 5. Let target be the value of the [[ProxyTarget]] internal slot of O.
238
239 let target = this.$ProxyTarget;
240 (0, _invariant.default)(target instanceof _index.ObjectValue); // 6. Let trap be ? GetMethod(handler, "getOwnPropertyDescriptor").
241
242 let trap = (0, _get.GetMethod)(realm, handler, "getOwnPropertyDescriptor"); // 7. If trap is undefined, then
243
244 if (trap instanceof _index.UndefinedValue) {
245 // a. Return ? target.[[GetOwnProperty]](P).
246 return target.$GetOwnProperty(P);
247 } // 8. Let trapResultObj be ? Call(trap, handler, « target, P »).
248
249
250 let trapResultObj = (0, _call.Call)(realm, trap, handler, [target, typeof P === "string" ? new _index.StringValue(realm, P) : P]); // 9. If Type(trapResultObj) is neither Object nor Undefined, throw a TypeError exception.
251
252 if (!(trapResultObj instanceof _index.ObjectValue) && !(trapResultObj instanceof _index.UndefinedValue)) {
253 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
254 } // 10. Let targetDesc be ? target.[[GetOwnProperty]](P).
255
256
257 let targetDesc = target.$GetOwnProperty(P); // 11. If trapResultObj is undefined, then
258
259 if (trapResultObj instanceof _index.UndefinedValue) {
260 // a. If targetDesc is undefined, return undefined.
261 if (!targetDesc) return undefined;
262
263 _singletons.Properties.ThrowIfMightHaveBeenDeleted(targetDesc.value); // b. If targetDesc.[[Configurable]] is false, throw a TypeError exception.
264
265
266 if (!targetDesc.configurable) {
267 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
268 } // c. Let extensibleTarget be ? IsExtensible(target).
269
270
271 let extensibleTarget = (0, _is.IsExtensible)(realm, target); // d. Assert: Type(extensibleTarget) is Boolean.
272
273 (0, _invariant.default)(typeof extensibleTarget === "boolean", "expected boolean"); // e. If extensibleTarget is false, throw a TypeError exception.
274
275 if (!extensibleTarget) {
276 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
277 } // f. Return undefined.
278
279
280 return undefined;
281 } // 12. Let extensibleTarget be ? IsExtensible(target).
282
283
284 let extensibleTarget = (0, _is.IsExtensible)(realm, target); // 13. Let resultDesc be ? ToPropertyDescriptor(trapResultObj).
285
286 let resultDesc = _singletons.To.ToPropertyDescriptor(realm, trapResultObj); // 14. Call CompletePropertyDescriptor(resultDesc).
287
288
289 _singletons.Properties.CompletePropertyDescriptor(realm, resultDesc); // 15. Let valid be IsCompatiblePropertyDescriptor(extensibleTarget, resultDesc, targetDesc).
290
291
292 let valid = _singletons.Properties.IsCompatiblePropertyDescriptor(realm, extensibleTarget, resultDesc, targetDesc); // 16. If valid is false, throw a TypeError exception.
293
294
295 if (!valid) {
296 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
297 } // 17. If resultDesc.[[Configurable]] is false, then
298
299
300 if (!resultDesc.configurable) {
301 // a. If targetDesc is undefined or targetDesc.[[Configurable]] is true, then
302 if (!targetDesc || targetDesc.configurable) {
303 // i. Throw a TypeError exception.
304 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
305 }
306 } // 18. Return resultDesc.
307
308
309 return resultDesc;
310 } // ECMA262 9.5.6
311
312
313 $DefineOwnProperty(P, Desc) {
314 let realm = this.$Realm; // 1. Assert: IsPropertyKey(P) is true.
315
316 (0, _invariant.default)((0, _is.IsPropertyKey)(realm, P), "expected property key"); // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
317
318 let handler = this.$ProxyHandler; // 3. If handler is null, throw a TypeError exception.
319
320 if (handler instanceof _index.NullValue) {
321 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
322 } // 4. Assert: Type(handler) is Object.
323
324
325 (0, _invariant.default)(handler instanceof _index.ObjectValue, "expected object"); // 5. Let target be the value of the [[ProxyTarget]] internal slot of O.
326
327 let target = this.$ProxyTarget;
328 (0, _invariant.default)(target instanceof _index.ObjectValue); // 6. Let trap be ? GetMethod(handler, "defineProperty").
329
330 let trap = (0, _get.GetMethod)(realm, handler, "defineProperty"); // 7. If trap is undefined, then
331
332 if (trap instanceof _index.UndefinedValue) {
333 // a. Return ? target.[[DefineOwnProperty]](P, Desc).
334 return target.$DefineOwnProperty(P, Desc);
335 } // 8. Let descObj be FromPropertyDescriptor(Desc).
336
337
338 let descObj = _singletons.Properties.FromPropertyDescriptor(realm, Desc); // 9. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « target, P, descObj »)).
339
340
341 let booleanTrapResult = _singletons.To.ToBooleanPartial(realm, (0, _call.Call)(realm, trap, handler, [target, typeof P === "string" ? new _index.StringValue(realm, P) : P, descObj])); // 10. If booleanTrapResult is false, return false.
342
343
344 if (!booleanTrapResult) return false; // 11. Let targetDesc be ? target.[[GetOwnProperty]](P).
345
346 let targetDesc = target.$GetOwnProperty(P); // 12. Let extensibleTarget be ? IsExtensible(target).
347
348 let extensibleTarget = (0, _is.IsExtensible)(realm, target); // 13. If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is false, then
349
350 let settingConfigFalse;
351
352 if ("configurable" in Desc && !Desc.configurable) {
353 // a. Let settingConfigFalse be true.
354 settingConfigFalse = true;
355 } else {
356 // 14. Else let settingConfigFalse be false.
357 settingConfigFalse = false;
358 } // 15. If targetDesc is undefined, then
359
360
361 if (!targetDesc) {
362 // a. If extensibleTarget is false, throw a TypeError exception.
363 if (!extensibleTarget) {
364 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
365 } // b. If settingConfigFalse is true, throw a TypeError exception.
366
367
368 if (settingConfigFalse) {
369 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
370 }
371 } else {
372 // 16. Else targetDesc is not undefined,
373 _singletons.Properties.ThrowIfMightHaveBeenDeleted(targetDesc.value); // a. If IsCompatiblePropertyDescriptor(extensibleTarget, Desc, targetDesc) is false, throw a TypeError exception.
374
375
376 if (!_singletons.Properties.IsCompatiblePropertyDescriptor(realm, extensibleTarget, Desc, targetDesc)) {
377 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
378 } // b. If settingConfigFalse is true and targetDesc.[[Configurable]] is true, throw a TypeError exception.
379
380
381 if (settingConfigFalse && targetDesc.configurable) {
382 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
383 }
384 } // 17. Return true.
385
386
387 return true;
388 } // ECMA262 9.5.7
389
390
391 $HasProperty(P) {
392 let realm = this.$Realm; // 1. Assert: IsPropertyKey(P) is true.
393
394 (0, _invariant.default)((0, _is.IsPropertyKey)(realm, P), "expected property key"); // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
395
396 let handler = this.$ProxyHandler; // 3. If handler is null, throw a TypeError exception.
397
398 if (handler instanceof _index.NullValue) {
399 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
400 } // 4. Assert: Type(handler) is Object.
401
402
403 (0, _invariant.default)(handler instanceof _index.ObjectValue, "expected object"); // 5. Let target be the value of the [[ProxyTarget]] internal slot of O.
404
405 let target = this.$ProxyTarget;
406 (0, _invariant.default)(target instanceof _index.ObjectValue); // 6. Let trap be ? GetMethod(handler, "has").
407
408 let trap = (0, _get.GetMethod)(realm, handler, "has"); // 7. If trap is undefined, then
409
410 if (trap instanceof _index.UndefinedValue) {
411 // a. Return ? target.[[HasProperty]](P).
412 return target.$HasProperty(P);
413 } // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « target, P »)).
414
415
416 let booleanTrapResult = _singletons.To.ToBooleanPartial(realm, (0, _call.Call)(realm, trap, handler, [target, typeof P === "string" ? new _index.StringValue(realm, P) : P])); // 9. If booleanTrapResult is false, then
417
418
419 if (!booleanTrapResult) {
420 // a. Let targetDesc be ? target.[[GetOwnProperty]](P).
421 let targetDesc = target.$GetOwnProperty(P); // b. If targetDesc is not undefined, then
422
423 if (targetDesc) {
424 _singletons.Properties.ThrowIfMightHaveBeenDeleted(targetDesc.value); // i. If targetDesc.[[Configurable]] is false, throw a TypeError exception.
425
426
427 if (!targetDesc.configurable) {
428 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
429 } // ii. Let extensibleTarget be ? IsExtensible(target).
430
431
432 let extensibleTarget = (0, _is.IsExtensible)(realm, target); // iii. If extensibleTarget is false, throw a TypeError exception.
433
434 if (!extensibleTarget) {
435 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
436 }
437 }
438 } // 10. Return booleanTrapResult.
439
440
441 return booleanTrapResult;
442 } // ECMA262 9.5.8
443
444
445 $Get(P, Receiver) {
446 let realm = this.$Realm; // 1. Assert: IsPropertyKey(P) is true.
447
448 (0, _invariant.default)((0, _is.IsPropertyKey)(realm, P), "expected property key"); // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
449
450 let handler = this.$ProxyHandler; // 3. If handler is null, throw a TypeError exception.
451
452 if (handler instanceof _index.NullValue) {
453 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
454 } // 4. Assert: Type(handler) is Object.
455
456
457 (0, _invariant.default)(handler instanceof _index.ObjectValue, "expected object"); // 5. Let target be the value of the [[ProxyTarget]] internal slot of O.
458
459 let target = this.$ProxyTarget;
460 (0, _invariant.default)(target instanceof _index.ObjectValue); // 6. Let trap be ? GetMethod(handler, "get").
461
462 let trap = (0, _get.GetMethod)(realm, handler, "get"); // 7. If trap is undefined, then
463
464 if (trap instanceof _index.UndefinedValue) {
465 // a. Return ? target.[[Get]](P, Receiver).
466 return target.$Get(P, Receiver);
467 } // 8. Let trapResult be ? Call(trap, handler, « target, P, Receiver »).
468
469
470 let trapResult = (0, _call.Call)(realm, trap, handler, [target, typeof P === "string" ? new _index.StringValue(realm, P) : P, Receiver]); // 9. Let targetDesc be ? target.[[GetOwnProperty]](P).
471
472 let targetDesc = target.$GetOwnProperty(P); // 10. If targetDesc is not undefined, then
473
474 if (targetDesc) {
475 _singletons.Properties.ThrowIfMightHaveBeenDeleted(targetDesc.value); // a. If IsDataDescriptor(targetDesc) is true and targetDesc.[[Configurable]] is false and targetDesc.[[Writable]] is false, then
476
477
478 if ((0, _is.IsDataDescriptor)(realm, targetDesc) && targetDesc.configurable === false && targetDesc.writable === false) {
479 // i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a TypeError exception.
480 let targetValue = targetDesc.value || realm.intrinsics.undefined;
481 (0, _invariant.default)(targetValue instanceof _index.Value);
482
483 if (!(0, _abstract.SameValuePartial)(realm, trapResult, targetValue)) {
484 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
485 }
486 } // b. If IsAccessorDescriptor(targetDesc) is true and targetDesc.[[Configurable]] is false and targetDesc.[[Get]] is undefined, then
487
488
489 if ((0, _is.IsAccessorDescriptor)(realm, targetDesc) && targetDesc.configurable === false && (!targetDesc.get || targetDesc.get instanceof _index.UndefinedValue)) {
490 // i. If trapResult is not undefined, throw a TypeError exception.
491 if (!(trapResult instanceof _index.UndefinedValue)) {
492 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
493 }
494 }
495 } // 11. Return trapResult.
496
497
498 return trapResult;
499 } // ECMA262 9.5.9
500
501
502 $Set(P, V, Receiver) {
503 let realm = this.$Realm; // 1. Assert: IsPropertyKey(P) is true.
504
505 (0, _invariant.default)((0, _is.IsPropertyKey)(realm, P), "expected property key"); // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
506
507 let handler = this.$ProxyHandler; // 3. If handler is null, throw a TypeError exception.
508
509 if (handler instanceof _index.NullValue) {
510 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
511 } // 4. Assert: Type(handler) is Object.
512
513
514 (0, _invariant.default)(handler instanceof _index.ObjectValue, "expected object"); // 5. Let target be the value of the [[ProxyTarget]] internal slot of O.
515
516 let target = this.$ProxyTarget; // 6. Let trap be ? GetMethod(handler, "set").
517
518 let trap = (0, _get.GetMethod)(realm, handler, "set"); // 7. If trap is undefined, then
519
520 if (trap instanceof _index.UndefinedValue) {
521 // a. Return ? target.[[Set]](P, V, Receiver).
522 (0, _invariant.default)(target instanceof _index.ObjectValue);
523 return target.$Set(P, V, Receiver);
524 } // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « target, P, V, Receiver »)).
525
526
527 let booleanTrapResult = _singletons.To.ToBooleanPartial(realm, (0, _call.Call)(realm, trap, handler, [target, typeof P === "string" ? new _index.StringValue(realm, P) : P, V, Receiver])); // 9. If booleanTrapResult is false, return false.
528
529
530 if (!booleanTrapResult) return false; // 10. Let targetDesc be ? target.[[GetOwnProperty]](P).
531
532 (0, _invariant.default)(target instanceof _index.ObjectValue);
533 let targetDesc = target.$GetOwnProperty(P); // 11. If targetDesc is not undefined, then
534
535 if (targetDesc) {
536 _singletons.Properties.ThrowIfMightHaveBeenDeleted(targetDesc.value); // a. If IsDataDescriptor(targetDesc) is true and targetDesc.[[Configurable]] is false and targetDesc.[[Writable]] is false, then
537
538
539 if ((0, _is.IsDataDescriptor)(realm, targetDesc) && !targetDesc.configurable && !targetDesc.writable) {
540 // i. If SameValue(V, targetDesc.[[Value]]) is false, throw a TypeError exception.
541 let targetValue = targetDesc.value || realm.intrinsics.undefined;
542 (0, _invariant.default)(targetValue instanceof _index.Value);
543
544 if (!(0, _abstract.SameValuePartial)(realm, V, targetValue)) {
545 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
546 }
547 } // b. If IsAccessorDescriptor(targetDesc) is true and targetDesc.[[Configurable]] is false, then
548
549
550 if ((0, _is.IsAccessorDescriptor)(realm, targetDesc) && !targetDesc.configurable) {
551 // i. If targetDesc.[[Set]] is undefined, throw a TypeError exception.
552 if (!targetDesc.set || targetDesc.set instanceof _index.UndefinedValue) {
553 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
554 }
555 }
556 } // 12. Return true.
557
558
559 return true;
560 } // ECMA262 9.5.10
561
562
563 $Delete(P) {
564 let realm = this.$Realm; // 1. Assert: IsPropertyKey(P) is true.
565
566 (0, _invariant.default)((0, _is.IsPropertyKey)(realm, P), "expected property key"); // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
567
568 let handler = this.$ProxyHandler; // 3. If handler is null, throw a TypeError exception.
569
570 if (handler instanceof _index.NullValue) {
571 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
572 } // 4. Assert: Type(handler) is Object.
573
574
575 (0, _invariant.default)(handler instanceof _index.ObjectValue, "expected object"); // 5. Let target be the value of the [[ProxyTarget]] internal slot of O.
576
577 let target = this.$ProxyTarget; // 6. Let trap be ? GetMethod(handler, "deleteProperty").
578
579 let trap = (0, _get.GetMethod)(realm, handler, "deleteProperty"); // 7. If trap is undefined, then
580
581 if (trap instanceof _index.UndefinedValue) {
582 // a. Return ? target.[[Delete]](P).
583 (0, _invariant.default)(target instanceof _index.ObjectValue);
584 return target.$Delete(P);
585 } // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « target, P »)).
586
587
588 let booleanTrapResult = _singletons.To.ToBooleanPartial(realm, (0, _call.Call)(realm, trap, handler, [target, typeof P === "string" ? new _index.StringValue(realm, P) : P])); // 9. If booleanTrapResult is false, return false.
589
590
591 if (!booleanTrapResult) return false; // 10. Let targetDesc be ? target.[[GetOwnProperty]](P).
592
593 (0, _invariant.default)(target instanceof _index.ObjectValue);
594 let targetDesc = target.$GetOwnProperty(P); // 11. If targetDesc is undefined, return true.
595
596 if (!targetDesc) return true;
597
598 _singletons.Properties.ThrowIfMightHaveBeenDeleted(targetDesc.value); // 12. If targetDesc.[[Configurable]] is false, throw a TypeError exception.
599
600
601 if (!targetDesc.configurable) {
602 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
603 } // 13. Return true.
604
605
606 return true;
607 } // ECMA262 9.5.11
608
609
610 $OwnPropertyKeys() {
611 let realm = this.$Realm; // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
612
613 let handler = this.$ProxyHandler; // 2. If handler is null, throw a TypeError exception.
614
615 if (handler instanceof _index.NullValue) {
616 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
617 } // 3. Assert: Type(handler) is Object.
618
619
620 (0, _invariant.default)(handler instanceof _index.ObjectValue, "expected object"); // 4. Let target be the value of the [[ProxyTarget]] internal slot of O.
621
622 let target = this.$ProxyTarget;
623 (0, _invariant.default)(target instanceof _index.ObjectValue); // 5. Let trap be ? GetMethod(handler, "ownKeys").
624
625 let trap = (0, _get.GetMethod)(realm, handler, "ownKeys"); // 6. If trap is undefined, then
626
627 if (trap instanceof _index.UndefinedValue) {
628 // a. Return ? target.[[OwnPropertyKeys]]().
629 return target.$OwnPropertyKeys();
630 } // 7. Let trapResultArray be ? Call(trap, handler, « target »).
631
632
633 let trapResultArray = (0, _call.Call)(realm, trap, handler, [target]); // 8. Let trapResult be ? CreateListFromArrayLike(trapResultArray, « String, Symbol »).
634
635 let trapResult = _singletons.Create.CreateListFromArrayLike(realm, trapResultArray, ["String", "Symbol"]); // 9. Let extensibleTarget be ? IsExtensible(target).
636
637
638 let extensibleTarget = (0, _is.IsExtensible)(realm, target); // 10. Let targetKeys be ? target.[[OwnPropertyKeys]]().
639
640 let targetKeys = target.$OwnPropertyKeys(); // 11. Assert: targetKeys is a List containing only String and Symbol values.
641
642 for (let key of targetKeys) {
643 (0, _invariant.default)(key instanceof _index.SymbolValue || key instanceof _index.StringValue, "expected string or symbol");
644 } // 12. Let targetConfigurableKeys be a new empty List.
645
646
647 let targetConfigurableKeys = []; // 13. Let targetNonconfigurableKeys be a new empty List.
648
649 let targetNonconfigurableKeys = []; // 14. Repeat, for each element key of targetKeys,
650
651 for (let key of targetKeys) {
652 // a. Let desc be ? target.[[GetOwnProperty]](key).
653 let desc = target.$GetOwnProperty(key);
654 if (desc) _singletons.Properties.ThrowIfMightHaveBeenDeleted(desc.value); // b. If desc is not undefined and desc.[[Configurable]] is false, then
655
656 if (desc && desc.configurable === false) {
657 // i. Append key as an element of targetNonconfigurableKeys.
658 targetNonconfigurableKeys.push(key);
659 } else {
660 // c. Else,
661 // i. Append key as an element of targetConfigurableKeys.
662 targetConfigurableKeys.push(key);
663 }
664 } // 15. If extensibleTarget is true and targetNonconfigurableKeys is empty, then
665
666
667 if (extensibleTarget && !targetNonconfigurableKeys.length) {
668 // a. Return trapResult.
669 return trapResult;
670 } // 16. Let uncheckedResultKeys be a new List which is a copy of trapResult.
671
672
673 let uncheckedResultKeys = trapResult.slice(); // 17. Repeat, for each key that is an element of targetNonconfigurableKeys,
674
675 for (let key of targetNonconfigurableKeys) {
676 // a. If key is not an element of uncheckedResultKeys, throw a TypeError exception.
677 let index = FindPropertyKey(realm, uncheckedResultKeys, key);
678
679 if (index < 0) {
680 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "key is not an element of uncheckedResultKeys");
681 } // b. Remove key from uncheckedResultKeys.
682
683
684 uncheckedResultKeys.splice(index, 1);
685 } // 18. If extensibleTarget is true, return trapResult.
686
687
688 if (extensibleTarget) return trapResult; // 19. Repeat, for each key that is an element of targetConfigurableKeys,
689
690 for (let key of targetConfigurableKeys) {
691 // a. If key is not an element of uncheckedResultKeys, throw a TypeError exception.
692 let index = FindPropertyKey(realm, uncheckedResultKeys, key);
693
694 if (index < 0) {
695 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "key is not an element of uncheckedResultKeys");
696 } // b. Remove key from uncheckedResultKeys.
697
698
699 uncheckedResultKeys.splice(index, 1);
700 } // 20. If uncheckedResultKeys is not empty, throw a TypeError exception.
701
702
703 if (uncheckedResultKeys.length) {
704 throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
705 } // 21. Return trapResult.
706
707
708 return trapResult;
709 }
710
711}
712
713exports.default = ProxyValue;
714
715_defineProperty(ProxyValue, "trackedPropertyNames", _index.ObjectValue.trackedPropertyNames.concat(["$ProxyTarget", "$ProxyHandler"]));
716//# sourceMappingURL=ProxyValue.js.map
\No newline at end of file