diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor')
23 files changed, 787 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/browser.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/browser.js diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/call-parameters.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/call-parameters.js new file mode 100644 index 0000000000..e2de3003d0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/call-parameters.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Trap is called with hander context and parameters are target and P +info: | + [[GetOwnProperty]] (P) + + ... + 9. Let trapResultObj be Call(trap, handler, «target, P»). + ... +features: [Proxy] +---*/ + +var _target, _handler, _prop; +var target = { + attr: 1 +}; +var handler = { + getOwnPropertyDescriptor: function(t, prop) { + _target = t; + _handler = this; + _prop = prop; + + return Object.getOwnPropertyDescriptor(t, prop); + } +}; +var p = new Proxy(target, handler); + +Object.getOwnPropertyDescriptor(p, "attr"); + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); +assert.sameValue(_prop, "attr"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/null-handler.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/null-handler.js new file mode 100644 index 0000000000..85161e2289 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/null-handler.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if handler is null. +features: [Proxy] +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p.proxy); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-target-is-not-extensible.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-target-is-not-extensible.js new file mode 100644 index 0000000000..8e18c836ce --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-target-is-not-extensible.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if trap result is undefined and target is not + extensible +info: | + [[GetOwnProperty]] (P) + + ... + 14. If trapResultObj is undefined, then + ... + e. If ToBoolean(extensibleTarget) is false, throw a TypeError exception. + ... +features: [Proxy] +---*/ + +var target = { + foo: 1 +}; + +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + return; + } +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "foo"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-targetdesc-is-not-configurable.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-targetdesc-is-not-configurable.js new file mode 100644 index 0000000000..42d6655c65 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-targetdesc-is-not-configurable.js @@ -0,0 +1,36 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if trap result is undefined and target property + descriptor is not configurable +info: | + [[GetOwnProperty]] (P) + + ... + 14. If trapResultObj is undefined, then + ... + b. If targetDesc.[[Configurable]] is false, throw a TypeError exception. + ... +features: [Proxy] +---*/ + +var target = {}; +Object.defineProperty(target, "foo", { + configurable: false, + enumerable: false, + value: 1 +}); + +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + return; + } +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "foo"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-targetdesc-is-undefined.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-targetdesc-is-undefined.js new file mode 100644 index 0000000000..babd3624c7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined-targetdesc-is-undefined.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if trap result is undefined and target property + descriptor is undefined. +info: | + [[GetOwnProperty]] (P) + + ... + 14. If trapResultObj is undefined, then + a. If targetDesc is undefined, return undefined. + ... +features: [Proxy] +---*/ + +var t = {}; +var trapped; +var p = new Proxy(t, { + getOwnPropertyDescriptor: function(target, prop) { + trapped = true; + return; + } +}); + +assert.sameValue( + Object.getOwnPropertyDescriptor(p, "attr"), + undefined +); + +assert(trapped); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined.js new file mode 100644 index 0000000000..4029362b98 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-is-undefined.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Return undefined if trap result is undefined and target is extensible and + the target property descriptor is configurable. +info: | + [[GetOwnProperty]] (P) + + ... + 14. If trapResultObj is undefined, then + ... + f. Return undefined. + ... +features: [Proxy] +---*/ + +var target = { + attr: 1 +}; + +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + return; + } +}); + +assert.sameValue(Object.getOwnPropertyDescriptor(p, "attr"), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-type-is-not-object-nor-undefined-realm.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-type-is-not-object-nor-undefined-realm.js new file mode 100644 index 0000000000..ad53efeab7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-type-is-not-object-nor-undefined-realm.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-getownproperty-p +description: > + Error when trap result is neither Object nor undefined (honoring the Realm of + the current execution context) +info: | + [...] + 9. If Type(trapResultObj) is neither Object nor Undefined, throw a TypeError + exception. +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; + +var p = new OProxy({}, { + getOwnPropertyDescriptor: function() { + return null; + } +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, 'x'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-type-is-not-object-nor-undefined.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-type-is-not-object-nor-undefined.js new file mode 100644 index 0000000000..5d93892e5f --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/result-type-is-not-object-nor-undefined.js @@ -0,0 +1,45 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if trap result is neither Object nor Undefined +info: | + [[GetOwnProperty]] (P) + + ... + 11. If Type(trapResultObj) is neither Object nor Undefined, throw a + TypeError exception. + ... +features: [Proxy, Symbol] +---*/ + +var target = { + number: 1, + symbol: Symbol(), + string: '', + boolean: true +}; +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + return t[prop]; + } +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "number"); +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "string"); +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "symbol"); +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "boolean"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-invalid-descriptor.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-invalid-descriptor.js new file mode 100644 index 0000000000..f8a20d2d33 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-invalid-descriptor.js @@ -0,0 +1,36 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if trap result and target property descriptors + are not compatible. +info: | + [[GetOwnProperty]] (P) + + ... + 20. Let valid be IsCompatiblePropertyDescriptor (extensibleTarget, + resultDesc, targetDesc). + 21. If valid is false, throw a TypeError exception. +features: [Proxy] +---*/ + +var target = {}; + +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + var foo = { + bar: 1 + }; + + return Object.getOwnPropertyDescriptor(foo, "bar"); + } +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "bar"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-not-configurable-not-writable-targetdesc-is-writable.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-not-configurable-not-writable-targetdesc-is-writable.js new file mode 100644 index 0000000000..bc4537b651 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-not-configurable-not-writable-targetdesc-is-writable.js @@ -0,0 +1,42 @@ +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-getownproperty-p +description: > + Throws a TypeError exception if resultDesc is both non-configurable and + non-writable, while targetDesc is writable. +info: | + [[GetOwnProperty]] (P) + + ... + 17. If resultDesc.[[Configurable]] is false, then + ... + b. If resultDesc has a [[Writable]] field and resultDesc.[[Writable]] is + false, then + i. If targetDesc.[[Writable]] is true, throw a TypeError exception. + ... +features: [Proxy, proxy-missing-checks] +---*/ + +var trapCalls = 0; +var p = new Proxy({}, { + getOwnPropertyDescriptor: function(t, prop) { + Object.defineProperty(t, prop, { + configurable: false, + writable: true, + }); + + trapCalls++; + return { + configurable: false, + writable: false, + }; + }, +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "prop"); +}); +assert.sameValue(trapCalls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-not-configurable-targetdesc-is-configurable.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-not-configurable-targetdesc-is-configurable.js new file mode 100644 index 0000000000..50d8bdc080 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-not-configurable-targetdesc-is-configurable.js @@ -0,0 +1,42 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if trap result is not configurable but target + property descriptor is configurable. +info: | + [[GetOwnProperty]] (P) + + ... + 22. If resultDesc.[[Configurable]] is false, then + a. If targetDesc is undefined or targetDesc.[[Configurable]] is true, + then + i. Throw a TypeError exception. + ... +features: [Proxy] +---*/ + +var target = { + bar: 1 +}; + +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + var foo = {}; + + Object.defineProperty(foo, "bar", { + configurable: false, + enumerable: true, + value: 1 + }); + + return Object.getOwnPropertyDescriptor(foo, prop); + } +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "bar"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-not-configurable-targetdesc-is-undefined.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-not-configurable-targetdesc-is-undefined.js new file mode 100644 index 0000000000..0b10a46f15 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-is-not-configurable-targetdesc-is-undefined.js @@ -0,0 +1,50 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if trap result is not configurable but target + property descriptor is undefined. +info: | + [[GetOwnProperty]] (P) + + ... + 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 5. Let target be the value of the [[ProxyTarget]] internal slot of O. + 6. Let trap be GetMethod(handler, "getOwnPropertyDescriptor"). + ... + 9. Let trapResultObj be Call(trap, handler, «target, P»). + ... + 12. Let targetDesc be target.[[GetOwnProperty]](P). + ... + 17. Let resultDesc be ToPropertyDescriptor(trapResultObj). + ... + 22. If resultDesc.[[Configurable]] is false, then + a. If targetDesc is undefined or targetDesc.[[Configurable]] is true, then + i. Throw a TypeError exception. + +features: [Proxy] +---*/ + +var target = {}; + +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + var foo = {}; + + Object.defineProperty(foo, "bar", { + configurable: false, + enumerable: true, + value: 1 + }); + + return Object.getOwnPropertyDescriptor(foo, prop); + } +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "bar"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-return-configurable.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-return-configurable.js new file mode 100644 index 0000000000..f33fe9201e --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-return-configurable.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Return descriptor from trap result if it has the same value as the target + property descriptor. +features: [Proxy] +---*/ + +var target = {}; +var descriptor = { + configurable: true, + enumerable: true, + value: 1 +}; + +Object.defineProperty(target, "bar", descriptor); + +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + return Object.getOwnPropertyDescriptor(t, prop); + } +}); + +var proxyDesc = Object.getOwnPropertyDescriptor(p, "bar"); + +assert(proxyDesc.configurable); +assert(proxyDesc.enumerable); +assert.sameValue(proxyDesc.value, 1); +assert.sameValue(proxyDesc.writable, false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-return-not-configurable.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-return-not-configurable.js new file mode 100644 index 0000000000..9c6bd04c92 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/resultdesc-return-not-configurable.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Return descriptor from trap result if it has the same value as the target + property descriptor and they're not configurable. +features: [Proxy] +---*/ + +var target = {}; + +Object.defineProperty(target, "attr", { + configurable: false, + enumerable: true, + value: 1 +}); + +var p = new Proxy(target, { + getOwnPropertyDescriptor: function(t, prop) { + return Object.getOwnPropertyDescriptor(t, prop); + } +}); + +var proxyDesc = Object.getOwnPropertyDescriptor(p, "attr"); + +assert.sameValue(proxyDesc.configurable, false); +assert(proxyDesc.enumerable); +assert.sameValue(proxyDesc.value, 1); +assert.sameValue(proxyDesc.writable, false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/return-is-abrupt.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/return-is-abrupt.js new file mode 100644 index 0000000000..2d0a0f8613 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/return-is-abrupt.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Trap returns abrupt. +info: | + [[GetOwnProperty]] (P) + + ... + 9. Let trapResultObj be Call(trap, handler, «target, P»). + 10. ReturnIfAbrupt(trapResultObj). + ... +features: [Proxy] +---*/ + +var p = new Proxy({}, { + getOwnPropertyDescriptor: function(t, prop) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.getOwnPropertyDescriptor(p, "attr"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/shell.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/shell.js diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-missing-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-missing-target-is-proxy.js new file mode 100644 index 0000000000..4a81b6dab4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-missing-target-is-proxy.js @@ -0,0 +1,48 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-getownproperty-p +description: > + If "getOwnPropertyDescriptor" trap is null or undefined, [[GetOwnProperty]] + call is properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[GetOwnProperty]] ( P ) + + [...] + 5. Let target be O.[[ProxyTarget]]. + 6. Let trap be ? GetMethod(handler, "getOwnPropertyDescriptor"). + 7. If trap is undefined, then + a. Return ? target.[[GetOwnProperty]](P). +includes: [propertyHelper.js] +features: [Proxy] +---*/ + +var stringTarget = new Proxy(new String("str"), {}); +var stringProxy = new Proxy(stringTarget, {}); + +verifyProperty(stringProxy, "0", { + value: "s", + writable: false, + enumerable: true, + configurable: false, +}); + +verifyProperty(stringProxy, "length", { + value: 3, + writable: false, + enumerable: false, + configurable: false, +}); + + +var functionTarget = new Proxy(function() {}, {}); +var functionProxy = new Proxy(functionTarget, {}); + +verifyProperty(functionProxy, "prototype", { + writable: true, + enumerable: false, + configurable: false, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-not-callable-realm.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-not-callable-realm.js new file mode 100644 index 0000000000..4af4ed3a63 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-not-callable-realm.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-getownproperty-p +description: > + Throws if trap is not callable (honoring the Realm of the current execution + context) +info: | + [[GetOwnProperty]] (P) + + ... + 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 5. Let target be the value of the [[ProxyTarget]] internal slot of O. + 6. Let trap be GetMethod(handler, "getOwnPropertyDescriptor"). + ... + 7.3.9 GetMethod (O, P) + ... + 2. Let func be GetV(O, P). + 5. If IsCallable(func) is false, throw a TypeError exception. + ... +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var p = new OProxy({}, { + getOwnPropertyDescriptor: {} +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "foo"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-not-callable.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-not-callable.js new file mode 100644 index 0000000000..912d38c5ea --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-not-callable.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Throws a TypeError exception if trap is not callable. +info: | + [[GetOwnProperty]] (P) + + ... + 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 5. Let target be the value of the [[ProxyTarget]] internal slot of O. + 6. Let trap be GetMethod(handler, "getOwnPropertyDescriptor"). + ... + 7.3.9 GetMethod (O, P) + ... + 2. Let func be GetV(O, P). + 5. If IsCallable(func) is false, throw a TypeError exception. + ... +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + getOwnPropertyDescriptor: {} +}); + +assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(p, "foo"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-null-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-null-target-is-proxy.js new file mode 100644 index 0000000000..3e4d33c74e --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-null-target-is-proxy.js @@ -0,0 +1,64 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-getownproperty-p +description: > + If "getOwnPropertyDescriptor" trap is null or undefined, [[GetOwnProperty]] + call is properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[GetOwnProperty]] ( P ) + + [...] + 5. Let target be O.[[ProxyTarget]]. + 6. Let trap be ? GetMethod(handler, "getOwnPropertyDescriptor"). + 7. If trap is undefined, then + a. Return ? target.[[GetOwnProperty]](P). +includes: [propertyHelper.js] +features: [Proxy] +---*/ + +var plainObjectTarget = new Proxy({foo: 1}, {}); +var plainObjectProxy = new Proxy(plainObjectTarget, { + getOwnPropertyDescriptor: null, +}); + +verifyProperty(plainObjectProxy, "bar", undefined); +verifyProperty(plainObjectProxy, "foo", { + value: 1, + writable: true, + enumerable: true, + configurable: true, +}); + + +var fooDescriptor = { + get: function() {}, + set: function(_value) {}, + enumerable: false, + configurable: true, +}; + +var target = new Proxy({}, { + getOwnPropertyDescriptor: function(_target, key) { + if (key === "foo") { + return fooDescriptor; + } + }, + deleteProperty: function(_target, key) { + if (key === "foo") { + fooDescriptor = undefined; + } + + return true; + }, +}); + +var proxy = new Proxy(target, { + getOwnPropertyDescriptor: null, +}); + +verifyProperty(proxy, "bar", undefined); +verifyProperty(proxy, "foo", fooDescriptor); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-undefined-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-undefined-target-is-proxy.js new file mode 100644 index 0000000000..38b797de3a --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-undefined-target-is-proxy.js @@ -0,0 +1,53 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-getownproperty-p +description: > + If "getOwnPropertyDescriptor" trap is null or undefined, [[GetOwnProperty]] + call is properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[GetOwnProperty]] ( P ) + + [...] + 5. Let target be O.[[ProxyTarget]]. + 6. Let trap be ? GetMethod(handler, "getOwnPropertyDescriptor"). + 7. If trap is undefined, then + a. Return ? target.[[GetOwnProperty]](P). +includes: [propertyHelper.js] +features: [Proxy] +---*/ + +var arrayTarget = new Proxy([42], {}); +var arrayProxy = new Proxy(arrayTarget, { + getOwnPropertyDescriptor: undefined, +}); + +verifyProperty(arrayProxy, "0", { + value: 42, + writable: true, + enumerable: true, + configurable: true, +}); + +verifyProperty(arrayProxy, "length", { + value: 1, + // writable: true, + enumerable: false, + configurable: false, +}); + + +var regExpTarget = new Proxy(/(?:)/, {}); +var regExpProxy = new Proxy(regExpTarget, { + getOwnPropertyDescriptor: undefined, +}); + +verifyProperty(regExpProxy, "lastIndex", { + value: 0, + writable: true, + enumerable: false, + configurable: false, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-undefined.js b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-undefined.js new file mode 100644 index 0000000000..3b23435417 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getOwnPropertyDescriptor/trap-is-undefined.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.5 +description: > + Return target.[[GetOwnProperty]](P) if trap is undefined. +info: | + [[GetOwnProperty]] (P) + + ... + 8. If trap is undefined, then + a. Return target.[[GetOwnProperty]](P). + ... +includes: [propertyHelper.js] +features: [Proxy] +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, {}); + +var proxyDesc = Object.getOwnPropertyDescriptor(p, "attr"); + +verifyEqualTo(p, "attr", 1); +verifyWritable(p, "attr"); +verifyEnumerable(p, "attr"); +verifyConfigurable(p, "attr"); + +reportCompare(0, 0); |