Debian Codegraph @

js/src/tests/test262/built-ins/Proxy/set/trap-is-null-target-is-proxy.js

raw
1 // Copyright (C) 2020 Alexey Shvayka. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-proxy-object-internal-methods-and-internal-slots-set-p-v-receiver
6 description: >
7 If "set" trap is null or undefined, [[Set]] call is properly
8 forwarded to [[ProxyTarget]] (which is also a Proxy object).
9 info: |
10 [[Set]] ( P, V, Receiver )
11
12 [...]
13 5. Let target be O.[[ProxyTarget]].
14 6. Let trap be ? GetMethod(handler, "set").
15 7. If trap is undefined, then
16 a. Return ? target.[[Set]](P, V, Receiver).
17 features: [Proxy, Reflect]
18 includes: [compareArray.js]
19 ---*/
20
21 var array = [1, 2, 3];
22 var arrayTarget = new Proxy(array, {});
23 var arrayProxy = new Proxy(arrayTarget, {
24 set: null,
25 });
26
27 arrayProxy.length = 0;
28 assert.compareArray(array, []);
29
30 Object.preventExtensions(array);
31
32 assert(!Reflect.set(arrayProxy, "foo", 2));
33 assert.throws(TypeError, function() {
34 "use strict";
35 arrayProxy[0] = 3;
36 });
37
38
39 var string = new String("str");
40 var stringTarget = new Proxy(string, {});
41 var stringProxy = new Proxy(stringTarget, {
42 set: null,
43 });
44
45 stringProxy[4] = 1;
46 assert.sameValue(string[4], 1);
47
48 assert(!Reflect.set(stringProxy, "0", "s"));
49 assert(!Reflect.set(stringProxy, "length", 3));
50
51 reportCompare(0, 0);