Debian Codegraph @

js/src/tests/test262/built-ins/Proxy/defineProperty/trap-is-missing-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-defineownproperty-p-desc
6 description: >
7 If "defineProperty" trap is null or undefined, [[DefineOwnProperty]] call
8 is properly forwarded to [[ProxyTarget]] (which is also a Proxy object).
9 info: |
10 [[DefineOwnProperty]] (P, Desc)
11
12 [...]
13 5. Let target be O.[[ProxyTarget]].
14 6. Let trap be ? GetMethod(handler, "defineProperty").
15 7. If trap is undefined, then
16 a. Return ? target.[[DefineOwnProperty]](P, Desc).
17 features: [Proxy, Reflect]
18 ---*/
19
20 var string = new String("str");
21 var stringTarget = new Proxy(string, {});
22 var stringProxy = new Proxy(stringTarget, {});
23
24 assert(Reflect.defineProperty(stringProxy, "4", {value: 4}));
25 assert.sameValue(string[4], 4);
26
27 assert.throws(TypeError, function() {
28 Object.defineProperty(stringProxy, "0", {
29 value: "x",
30 });
31 });
32
33 Object.preventExtensions(string);
34 assert(!Reflect.defineProperty(stringProxy, "foo", {value: 5}));
35
36
37 var func = function() {};
38 var funcTarget = new Proxy(func, {});
39 var funcProxy = new Proxy(funcTarget, {});
40
41 Object.defineProperty(funcProxy, "name", {value: "foo"});
42 assert.sameValue(func.name, "foo");
43
44 assert.throws(TypeError, function() {
45 Object.defineProperty(funcProxy, "prototype", {
46 set: function(_value) {},
47 });
48 });
49
50 reportCompare(0, 0);