Debian Codegraph @

js/src/tests/test262/built-ins/Proxy/defineProperty/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-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 includes: [propertyHelper.js]
19 ---*/
20
21 var plainObject = Object.create(null);
22 Object.defineProperty(plainObject, "foo", {
23 configurable: false,
24 });
25
26 var plainObjectTarget = new Proxy(plainObject, {});
27 var plainObjectProxy = new Proxy(plainObjectTarget, {
28 defineProperty: null,
29 });
30
31 assert.throws(TypeError, function() {
32 Object.defineProperty(plainObjectProxy, "foo", {
33 configurable: true,
34 });
35 });
36
37 Object.defineProperty(plainObjectProxy, "bar", {
38 get: function() {
39 return 2;
40 },
41 });
42 assert.sameValue(plainObject.bar, 2);
43
44
45 var regExp = /(?:)/g;
46 var regExpTarget = new Proxy(regExp, {});
47 var regExpProxy = new Proxy(regExpTarget, {
48 defineProperty: null,
49 });
50
51 assert(
52 Reflect.defineProperty(regExpProxy, "lastIndex", {
53 writable: false,
54 })
55 );
56
57 verifyNotWritable(regExp, "lastIndex");
58
59 reportCompare(0, 0);