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