diff options
Diffstat (limited to '')
67 files changed, 2051 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Proxy/get-fn-realm-recursive.js b/js/src/tests/test262/built-ins/Proxy/get-fn-realm-recursive.js new file mode 100644 index 0000000000..b06687a91c --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get-fn-realm-recursive.js @@ -0,0 +1,59 @@ +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-getfunctionrealm +description: > + The realm of a Proxy exotic object is the realm of its target function. + GetFunctionRealm is called recursively. +info: | + Boolean ( value ) + + [...] + 3. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Boolean.prototype%", « [[BooleanData]] »). + [...] + 5. Return O. + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + [...] + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return OrdinaryObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. + + GetFunctionRealm ( obj ) + + [...] + 2. If obj has a [[Realm]] internal slot, then + a. Return obj.[[Realm]]. + [...] + 4. If obj is a Proxy exotic object, then + [...] + b. Let proxyTarget be obj.[[ProxyTarget]]. + c. Return ? GetFunctionRealm(proxyTarget). +features: [cross-realm, Reflect, Proxy] +---*/ + +var realm1 = $262.createRealm().global; +var realm2 = $262.createRealm().global; +var realm3 = $262.createRealm().global; +var realm4 = $262.createRealm().global; + +var newTarget = new realm1.Function(); +newTarget.prototype = null; + +var newTargetProxy = new realm2.Proxy(newTarget, {}); +var newTargetProxyProxy = new realm3.Proxy(newTargetProxy, {}); +var boolean = Reflect.construct(realm4.Boolean, [], newTargetProxyProxy); + +assert(boolean instanceof realm1.Boolean); +assert.sameValue(Object.getPrototypeOf(boolean), realm1.Boolean.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get-fn-realm.js b/js/src/tests/test262/built-ins/Proxy/get-fn-realm.js new file mode 100644 index 0000000000..5077891673 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get-fn-realm.js @@ -0,0 +1,55 @@ +// 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-getfunctionrealm +description: > + The realm of a Proxy exotic object is the realm of its target function. +info: | + Array ( ) + + [...] + 4. Let proto be ? GetPrototypeFromConstructor(newTarget, "%Array.prototype%"). + 5. Return ! ArrayCreate(0, proto). + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + [...] + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return OrdinaryObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. + + GetFunctionRealm ( obj ) + + [...] + 2. If obj has a [[Realm]] internal slot, then + a. Return obj.[[Realm]]. + [...] + 4. If obj is a Proxy exotic object, then + [...] + b. Let proxyTarget be obj.[[ProxyTarget]]. + c. Return ? GetFunctionRealm(proxyTarget). +features: [cross-realm, Reflect, Proxy] +---*/ + +var realm1 = $262.createRealm().global; +var realm2 = $262.createRealm().global; +var realm3 = $262.createRealm().global; + +var newTarget = new realm1.Function(); +newTarget.prototype = false; + +var newTargetProxy = new realm2.Proxy(newTarget, {}); +var array = Reflect.construct(realm3.Array, [], newTargetProxy); + +assert(array instanceof realm1.Array); +assert.sameValue(Object.getPrototypeOf(array), realm1.Array.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/accessor-get-is-undefined-throws.js b/js/src/tests/test262/built-ins/Proxy/get/accessor-get-is-undefined-throws.js new file mode 100644 index 0000000000..422a7a60aa --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/accessor-get-is-undefined-throws.js @@ -0,0 +1,39 @@ +// 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.8 +description: > + [[Get]] (P, Receiver) + + if trap result is not undefined, then proxy must report the same value for a + non-configurable accessor property with an undefined get. +info: | + 13. If targetDesc is not undefined, then + b. If IsAccessorDescriptor(targetDesc) and targetDesc.[[Configurable]] + is false and targetDesc.[[Get]] is undefined, then + i. If trapResult is not undefined, throw a TypeError exception. + +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: false, + get: undefined +}); + +assert.throws(TypeError, function() { + p.attr; +}); + +assert.throws(TypeError, function() { + p['attr']; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/browser.js b/js/src/tests/test262/built-ins/Proxy/get/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/browser.js diff --git a/js/src/tests/test262/built-ins/Proxy/get/call-parameters.js b/js/src/tests/test262/built-ins/Proxy/get/call-parameters.js new file mode 100644 index 0000000000..538815bd4b --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/call-parameters.js @@ -0,0 +1,44 @@ +// 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.8 +description: > + [[Get]] (P, Receiver) + + 9. Let trapResult be Call(trap, handler, «target, P, Receiver»). +info: | + 6.1.7.2 Object Internal Methods and Internal Slots + + (...) Receiver is used as the this value when evaluating the code +features: [Proxy] +---*/ + +var _target, _handler, _prop, _receiver; +var target = { + attr: 1 +}; +var handler = { + get: function(t, prop, receiver) { + _handler = this; + _target = t; + _prop = prop; + _receiver = receiver; + } +}; +var p = new Proxy(target, handler); + +p.attr; + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); +assert.sameValue(_prop, "attr"); +assert.sameValue(_receiver, p, "receiver is the Proxy object"); + +_prop = null; +p["attr"]; +assert.sameValue( + _prop, "attr", + "trap is triggered both by p.attr and p['attr']" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/not-same-value-configurable-false-writable-false-throws.js b/js/src/tests/test262/built-ins/Proxy/get/not-same-value-configurable-false-writable-false-throws.js new file mode 100644 index 0000000000..790bf1997d --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/not-same-value-configurable-false-writable-false-throws.js @@ -0,0 +1,40 @@ +// 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.8 +description: > + Throws if proxy return has not the same value for a non-writable, + non-configurable property +info: | + [[Get]] (P, Receiver) + + 13. If targetDesc is not undefined, then + a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is + false and targetDesc.[[Writable]] is false, then + i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a + TypeError exception. +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: false, + writable: false, + value: 1 +}); + +assert.throws(TypeError, function() { + p.attr; +}); + +assert.throws(TypeError, function() { + p['attr']; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/null-handler.js b/js/src/tests/test262/built-ins/Proxy/get/null-handler.js new file mode 100644 index 0000000000..a5b4716301 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/null-handler.js @@ -0,0 +1,24 @@ +// 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.8 +description: > + [[Get]] (P, Receiver) + + 2. If handler is null, throw a TypeError exception. +features: [Proxy] +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + p.proxy.attr; +}); + +assert.throws(TypeError, function() { + p.proxy['attr']; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/return-is-abrupt.js b/js/src/tests/test262/built-ins/Proxy/get/return-is-abrupt.js new file mode 100644 index 0000000000..03bfe37967 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/return-is-abrupt.js @@ -0,0 +1,29 @@ +// 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.8 +description: > + Trap returns abrupt. +info: | + [[Get]] (P, Receiver) + + 9. Let trapResult be Call(trap, handler, «target, P, Receiver»). + 10. ReturnIfAbrupt(trapResult). +features: [Proxy] +---*/ + +var p = new Proxy({}, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + p.attr; +}); + +assert.throws(Test262Error, function() { + p["attr"]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-accessor-property.js b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-accessor-property.js new file mode 100644 index 0000000000..3c6b8c685e --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-accessor-property.js @@ -0,0 +1,28 @@ +// 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.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + get: function() { + return 1; + } +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p['attr'], 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-false-writable-true.js b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-false-writable-true.js new file mode 100644 index 0000000000..fae30cd0ff --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-false-writable-true.js @@ -0,0 +1,28 @@ +// 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.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: false, + writable: true, + value: 1 +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p['attr'], 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-true-assessor-get-undefined.js b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-true-assessor-get-undefined.js new file mode 100644 index 0000000000..03598c2187 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-true-assessor-get-undefined.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.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: true, + get: undefined +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p['attr'], 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-true-writable-false.js b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-true-writable-false.js new file mode 100644 index 0000000000..f24884412f --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-configurable-true-writable-false.js @@ -0,0 +1,28 @@ +// 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.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: true, + writable: false, + value: 1 +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p['attr'], 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-same-value-configurable-false-writable-false.js b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-same-value-configurable-false-writable-false.js new file mode 100644 index 0000000000..852873df97 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result-same-value-configurable-false-writable-false.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.8 +description: > + Proxy must report the same value for a non-writable, non-configurable + property. +info: | + [[Get]] (P, Receiver) + + 13. If targetDesc is not undefined, then + a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is + false and targetDesc.[[Writable]] is false, then + i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a + TypeError exception. + ... + 14. Return trapResult. +features: [Proxy] +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 1; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: false, + writable: false, + value: 1 +}); + +assert.sameValue(p.attr, 1); +assert.sameValue(p['attr'], 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/return-trap-result.js b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result.js new file mode 100644 index 0000000000..f953d77ebe --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/return-trap-result.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.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +features: [Proxy] +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p.foo, 2); + +assert.sameValue(p['attr'], 2); +assert.sameValue(p['foo'], 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/shell.js b/js/src/tests/test262/built-ins/Proxy/get/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/shell.js diff --git a/js/src/tests/test262/built-ins/Proxy/get/trap-is-missing-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/get/trap-is-missing-target-is-proxy.js new file mode 100644 index 0000000000..effefcacdb --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/trap-is-missing-target-is-proxy.js @@ -0,0 +1,33 @@ +// 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-get-p-receiver +description: > + If "get" trap is null or undefined, [[Get]] call is properly + forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[Get]] ( P, Receiver ) + + [...] + 5. Let target be O.[[ProxyTarget]]. + 6. Let trap be ? GetMethod(handler, "get"). + 7. If trap is undefined, then + a. Return ? target.[[Get]](P, Receiver). +features: [Proxy, Symbol.match] +---*/ + +var regExp = /(?:)/i; +var regExpTarget = new Proxy(regExp, {}); +var regExpProxy = new Proxy(regExpTarget, {}); + +assert.sameValue(Object.create(regExpProxy).lastIndex, 0); +assert.sameValue(regExpProxy[Symbol.match], RegExp.prototype[Symbol.match]); + + +var functionTarget = new Proxy(function(_arg) {}, {}); +var functionProxy = new Proxy(functionTarget, {}); + +assert.sameValue(Object.create(functionProxy).length, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/trap-is-not-callable-realm.js b/js/src/tests/test262/built-ins/Proxy/get/trap-is-not-callable-realm.js new file mode 100644 index 0000000000..a9e4cb115c --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/trap-is-not-callable-realm.js @@ -0,0 +1,33 @@ +// 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-get-p-receiver +description: > + Throws if trap is not callable (honoring the Realm of the current execution + context) +info: | + [[Get]] (P, Receiver) + + 6. Let trap be GetMethod(handler, "get"). + ... + + 7.3.9 GetMethod (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({}, { + get: {} +}); + +assert.throws(TypeError, function() { + p.attr; +}); + +assert.throws(TypeError, function() { + p["attr"]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/trap-is-not-callable.js b/js/src/tests/test262/built-ins/Proxy/get/trap-is-not-callable.js new file mode 100644 index 0000000000..f0b1d975e5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/trap-is-not-callable.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.8 +description: > + Trap is not callable. +info: | + [[Get]] (P, Receiver) + + 6. Let trap be GetMethod(handler, "get"). + ... + + 7.3.9 GetMethod (O, P) + + 5. If IsCallable(func) is false, throw a TypeError exception. +features: [Proxy] +---*/ + +var p = new Proxy({}, { + get: {} +}); + +assert.throws(TypeError, function() { + p.attr; +}); + +assert.throws(TypeError, function() { + p["attr"]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/trap-is-null-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/get/trap-is-null-target-is-proxy.js new file mode 100644 index 0000000000..6d9b09e759 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/trap-is-null-target-is-proxy.js @@ -0,0 +1,50 @@ +// 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-get-p-receiver +description: > + If "get" trap is null or undefined, [[Get]] call is properly + forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[Get]] ( P, Receiver ) + + [...] + 5. Let target be O.[[ProxyTarget]]. + 6. Let trap be ? GetMethod(handler, "get"). + 7. If trap is undefined, then + a. Return ? target.[[Get]](P, Receiver). +features: [Proxy, Symbol] +---*/ + +var stringTarget = new Proxy(new String("str"), {}); +var stringProxy = new Proxy(stringTarget, { + get: null, +}); + +assert.sameValue(stringProxy.length, 3); +assert.sameValue(stringProxy[0], "s"); +assert.sameValue(stringProxy[4], undefined); + + +var sym = Symbol(); +var target = new Proxy({}, { + get: function(_target, key) { + switch (key) { + case sym: return 1; + case "10": return 2; + case "foo": return 3; + } + }, +}); + +var proxy = new Proxy(target, { + get: null, +}); + +assert.sameValue(proxy[sym], 1); +assert.sameValue(proxy[10], 2); +assert.sameValue(Object.create(proxy).foo, 3); +assert.sameValue(proxy.bar, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-no-property.js b/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-no-property.js new file mode 100644 index 0000000000..6a5dd05f1a --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-no-property.js @@ -0,0 +1,22 @@ +// 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.8 +description: > + [[Get]] (P, Receiver) + + 8. If trap is undefined, then return target.[[Get]](P, Receiver). +features: [Proxy] +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, {}); + +assert.sameValue(p.attr, 1, 'return target.attr'); +assert.sameValue(p.foo, undefined, 'return target.foo'); +assert.sameValue(p['attr'], 1, 'return target.attr'); +assert.sameValue(p['foo'], undefined, 'return target.foo'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-receiver.js b/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-receiver.js new file mode 100644 index 0000000000..b714484819 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-receiver.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 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-get-p-receiver +description: > + Pass to target's [[Get]] correct receiver if trap is missing +info: | + [[Get]] (P, Receiver) + + 7. If trap is undefined, then + a. Return ? target.[[Get]](P, Receiver). +features: [Proxy] +---*/ + +var target = { + get attr() { + return this; + } +}; + +var p = new Proxy(target, { + get: null +}); +assert.sameValue(p.attr, p); + +var pParent = Object.create(new Proxy(target, {})); +assert.sameValue(pParent.attr, pParent); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-target-is-proxy.js new file mode 100644 index 0000000000..a8e627d2e6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined-target-is-proxy.js @@ -0,0 +1,47 @@ +// 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-get-p-receiver +description: > + If "get" trap is null or undefined, [[Get]] call is properly + forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[Get]] ( P, Receiver ) + + [...] + 5. Let target be O.[[ProxyTarget]]. + 6. Let trap be ? GetMethod(handler, "get"). + 7. If trap is undefined, then + a. Return ? target.[[Get]](P, Receiver). +features: [Proxy] +includes: [compareArray.js] +---*/ + +var plainObject = { + get 0() { + return 1; + }, + foo: 2, + set bar(_value) {}, +}; + +var plainObjectTarget = new Proxy(plainObject, {}); +var plainObjectProxy = new Proxy(plainObjectTarget, { + get: undefined, +}); + +assert.sameValue(Object.create(plainObjectProxy)[0], 1); +assert.sameValue(plainObjectProxy.foo, 2); +assert.sameValue(plainObjectProxy.bar, undefined); + + +var array = [1, 2, 3]; +var arrayTarget = new Proxy(array, {}); +var arrayProxy = new Proxy(arrayTarget, { + get: undefined, +}); + +assert.compareArray(arrayProxy, array); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined.js b/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined.js new file mode 100644 index 0000000000..03bb20a99f --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/get/trap-is-undefined.js @@ -0,0 +1,23 @@ +// 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.8 +description: > + [[Get]] (P, Receiver) + + 8. If trap is undefined, then return target.[[Get]](P, Receiver). + +features: [Proxy] +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, { + get: undefined +}); + +assert.sameValue(p.attr, 1, 'return target.attr'); +assert.sameValue(p.foo, undefined, 'return target.foo'); + +reportCompare(0, 0); 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); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/browser.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/browser.js diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/call-parameters.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/call-parameters.js new file mode 100644 index 0000000000..a85ec120ca --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/call-parameters.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.1 +description: > + Trap is called with handler as context and target as the first parameter. +info: | + [[GetPrototypeOf]] ( ) + + ... + 8. Let handlerProto be Call(trap, handler, «target»). + ... + +features: [Proxy] +---*/ + +var _handler, _target; +var target = {}; +var handler = { + getPrototypeOf: function(t) { + _handler = this; + _target = t; + return {}; + } +}; + +var p = new Proxy(target, handler); + +Object.getPrototypeOf(p); + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/extensible-target-return-handlerproto.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/extensible-target-return-handlerproto.js new file mode 100644 index 0000000000..f9ba75c1b3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/extensible-target-return-handlerproto.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.1 +description: > + Return trap result if it's an Object and target is extensible. +info: | + [[GetPrototypeOf]] ( ) + + ... + 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 4. Let target be the value of the [[ProxyTarget]] internal slot of O. + 5. Let trap be GetMethod(handler, "getPrototypeOf"). + ... + 8. Let handlerProto be Call(trap, handler, «target»). + ... + 11. Let extensibleTarget be IsExtensible(target). + 12. ReturnIfAbrupt(extensibleTarget). + 13. If extensibleTarget is true, return handlerProto. + ... + +features: [Proxy] +---*/ + +var prot = { + foo: 1 +}; +var p = new Proxy({}, { + getPrototypeOf: function() { + return prot; + } +}); + +assert.sameValue(Object.getPrototypeOf(p), prot); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/instanceof-custom-return-accepted.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/instanceof-custom-return-accepted.js new file mode 100644 index 0000000000..ab82562dc4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/instanceof-custom-return-accepted.js @@ -0,0 +1,40 @@ +// Copyright (C) 2019 ta7sudan. 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-getprototypeof +description: > + instanceof operator will return true if trap result is the prototype of the function. +info: | + Runtime Semantics: InstanceofOperator ( V, target ) + + 5. Return ? OrdinaryHasInstance(target, V). + + OrdinaryHasInstance ( C, O ) + + 4. Let P be ? Get(C, "prototype"). + ... + 6. Repeat, + a. Set O to ? O.[[GetPrototypeOf]](). + b. If O is null, return false. + c. If SameValue(P, O) is true, return true. + + [[GetPrototypeOf]] ( ) + + 7. Let handlerProto be ? Call(trap, handler, « target »). + 8. If Type(handlerProto) is neither Object nor Null, throw a TypeError exception. + 9. Let extensibleTarget be ? IsExtensible(target). + 10. If extensibleTarget is true, return handlerProto. +features: [Proxy] +---*/ + +function Custom() {} + +var p = new Proxy({}, { + getPrototypeOf() { + return Custom.prototype; + } +}); + +assert(p instanceof Custom); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/instanceof-target-not-extensible-not-same-proto-throws.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/instanceof-target-not-extensible-not-same-proto-throws.js new file mode 100644 index 0000000000..7084f5e92a --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/instanceof-target-not-extensible-not-same-proto-throws.js @@ -0,0 +1,49 @@ +// Copyright (C) 2019 Leo Balter. 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-getprototypeof +description: > + instanceof operator observes the TypeError from a custom trap result that would return true if + the target were extensible. +info: | + Runtime Semantics: InstanceofOperator ( V, target ) + + 5. Return ? OrdinaryHasInstance(target, V). + + OrdinaryHasInstance ( C, O ) + + 4. Let P be ? Get(C, "prototype"). + ... + 6. Repeat, + a. Set O to ? O.[[GetPrototypeOf]](). + b. If O is null, return false. + c. If SameValue(P, O) is true, return true. + + [[GetPrototypeOf]] ( ) + + 7. Let handlerProto be ? Call(trap, handler, « target »). + 8. If Type(handlerProto) is neither Object nor Null, throw a TypeError exception. + 9. Let extensibleTarget be ? IsExtensible(target). + 10. If extensibleTarget is true, return handlerProto. + 11. Let targetProto be ? target.[[GetPrototypeOf]](). + 12. If SameValue(handlerProto, targetProto) is false, throw a TypeError exception. +features: [Proxy] +---*/ + +function Custom() {} + +var target = {}; + +var p = new Proxy(target, { + getPrototypeOf() { + return Custom.prototype; + } +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, () => { + p instanceof Custom +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/not-extensible-not-same-proto-throws.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/not-extensible-not-same-proto-throws.js new file mode 100644 index 0000000000..8d454a5aa4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/not-extensible-not-same-proto-throws.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.1 +description: > + Throws a TypeError if the target is not extensible and the trap result is + not the same as the target.[[GetPrototypeOf]] result. +info: | + [[GetPrototypeOf]] ( ) + + ... + 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 4. Let target be the value of the [[ProxyTarget]] internal slot of O. + 5. Let trap be GetMethod(handler, "getPrototypeOf"). + ... + 8. Let handlerProto be Call(trap, handler, «target»). + ... + 11. Let extensibleTarget be IsExtensible(target). + ... + 14. Let targetProto be target.[[GetPrototypeOf]](). + 15. ReturnIfAbrupt(targetProto). + 16. If SameValue(handlerProto, targetProto) is false, throw a TypeError + exception. + ... +features: [Proxy] +---*/ + +var target = Object.create({ + foo: 1 +}); + +var p = new Proxy(target, { + getPrototypeOf: function() { + return {}; + } +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/not-extensible-same-proto.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/not-extensible-same-proto.js new file mode 100644 index 0000000000..3ee48b1581 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/not-extensible-same-proto.js @@ -0,0 +1,40 @@ +// 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.1 +description: > + Return trap result is target is not extensible, but trap result has the same + value as target.[[GetPrototypeOf]] result. +info: | + [[GetPrototypeOf]] ( ) + + ... + 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 4. Let target be the value of the [[ProxyTarget]] internal slot of O. + 5. Let trap be GetMethod(handler, "getPrototypeOf"). + ... + 8. Let handlerProto be Call(trap, handler, «target»). + ... + 11. Let extensibleTarget be IsExtensible(target). + ... + 14. Let targetProto be target.[[GetPrototypeOf]](). + ... + 17. Return handlerProto. + +features: [Proxy] +---*/ + +var target = Object.create(Array.prototype); + +var p = new Proxy(target, { + getPrototypeOf: function() { + return Array.prototype; + } +}); + +Object.preventExtensions(target); + +assert.sameValue(Object.getPrototypeOf(p), Array.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/null-handler.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/null-handler.js new file mode 100644 index 0000000000..4899c2c091 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/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.1 +description: > + Throws a TypeError exception if handler is null. +features: [Proxy] +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p.proxy); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/return-is-abrupt.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/return-is-abrupt.js new file mode 100644 index 0000000000..c55a7dca39 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/return-is-abrupt.js @@ -0,0 +1,23 @@ +// 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.1 +description: > + Trap returns abrupt. +info: | + 8. Let handlerProto be Call(trap, handler, «target»). + 9. ReturnIfAbrupt(handlerProto). +features: [Proxy] +---*/ + +var p = new Proxy({}, { + getPrototypeOf: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.getPrototypeOf(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/shell.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/shell.js diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-missing-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-missing-target-is-proxy.js new file mode 100644 index 0000000000..d391cba76f --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-missing-target-is-proxy.js @@ -0,0 +1,38 @@ +// 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-getprototypeof +description: > + If "getPrototypeOf" trap is null or undefined, [[GetPrototypeOf]] call + is properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[GetPrototypeOf]] ( ) + + [...] + 4. Let target be O.[[ProxyTarget]]. + 5. Let trap be ? GetMethod(handler, "getPrototypeOf"). + 6. If trap is undefined, then + a. Return ? target.[[GetPrototypeOf]]() + + [[GetPrototypeOf]] ( ) + + [...] + 7. Let handlerProto be ? Call(trap, handler, « target »). + [...] + 13. Return handlerProto. +features: [Proxy] +---*/ + +var targetPrototype = {}; +var target = new Proxy({}, { + getPrototypeOf: function(_target) { + return targetPrototype; + }, +}); + +var proxy = new Proxy(target, {}); + +assert.sameValue(Object.getPrototypeOf(proxy), targetPrototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-not-callable-realm.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-not-callable-realm.js new file mode 100644 index 0000000000..a4f15eff41 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-not-callable-realm.js @@ -0,0 +1,20 @@ +// 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-getprototypeof +description: > + Throws if trap is not callable (honoring the Realm of the current execution + context) +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var p = new OProxy({}, { + getPrototypeOf: {} +}); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-not-callable.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-not-callable.js new file mode 100644 index 0000000000..9dc697dfdb --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-not-callable.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.1 +description: > + Throws if trap is not callable. +features: [Proxy] +---*/ + +var p = new Proxy({}, { + getPrototypeOf: {} +}); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-null-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-null-target-is-proxy.js new file mode 100644 index 0000000000..d48d7fa789 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-null-target-is-proxy.js @@ -0,0 +1,27 @@ +// 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-getprototypeof +description: > + If "getPrototypeOf" trap is null or undefined, [[GetPrototypeOf]] call + is properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[GetPrototypeOf]] ( ) + + [...] + 4. Let target be O.[[ProxyTarget]]. + 5. Let trap be ? GetMethod(handler, "getPrototypeOf"). + 6. If trap is undefined, then + a. Return ? target.[[GetPrototypeOf]]() +features: [Proxy] +---*/ + +var plainObjectTarget = new Proxy(Object.create(null), {}); +var plainObjectProxy = new Proxy(plainObjectTarget, { + getPrototypeOf: null, +}); + +assert.sameValue(Object.getPrototypeOf(plainObjectProxy), null); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-undefined-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-undefined-target-is-proxy.js new file mode 100644 index 0000000000..00146ad19e --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-undefined-target-is-proxy.js @@ -0,0 +1,27 @@ +// 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-getprototypeof +description: > + If "getPrototypeOf" trap is null or undefined, [[GetPrototypeOf]] call + is properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[GetPrototypeOf]] ( ) + + [...] + 4. Let target be O.[[ProxyTarget]]. + 5. Let trap be ? GetMethod(handler, "getPrototypeOf"). + 6. If trap is undefined, then + a. Return ? target.[[GetPrototypeOf]]() +features: [Proxy] +---*/ + +var arrayTarget = new Proxy([], {}); +var arrayProxy = new Proxy(arrayTarget, { + getPrototypeOf: undefined, +}); + +assert.sameValue(Object.getPrototypeOf(arrayProxy), Array.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-undefined.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-undefined.js new file mode 100644 index 0000000000..21cf51daf6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-is-undefined.js @@ -0,0 +1,15 @@ +// 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.1 +description: > + Return target.[[GetPrototypeOf]]() if trap is undefined. +features: [Proxy] +---*/ + +var target = Object.create(Array.prototype); +var p = new Proxy(target, {}); + +assert.sameValue(Object.getPrototypeOf(p), Array.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-boolean.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-boolean.js new file mode 100644 index 0000000000..fcdc647b84 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-boolean.js @@ -0,0 +1,20 @@ +// 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.1 +description: > + Throw a TypeError exception if trap result is false. +features: [Proxy] +---*/ + +var p = new Proxy({}, { + getPrototypeOf: function() { + return false; + } +}); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-number.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-number.js new file mode 100644 index 0000000000..115d015f89 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-number.js @@ -0,0 +1,20 @@ +// 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.1 +description: > + Throw a TypeError exception if trap result is a Number. +features: [Proxy] +---*/ + +var p = new Proxy({}, { + getPrototypeOf: function() { + return 0; + } +}); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-string.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-string.js new file mode 100644 index 0000000000..2307f58cfc --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-string.js @@ -0,0 +1,20 @@ +// 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.1 +description: > + throw a TypeError exception if trap result is a String. +features: [Proxy] +---*/ + +var p = new Proxy({}, { + getPrototypeOf: function() { + return ""; + } +}); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-symbol.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-symbol.js new file mode 100644 index 0000000000..569723a04e --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-symbol.js @@ -0,0 +1,20 @@ +// 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.1 +description: > + Throw a TypeError exception if trap result is a Symbol. +features: [Proxy, Symbol] +---*/ + +var p = new Proxy({}, { + getPrototypeOf: function() { + return Symbol(); + } +}); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-undefined.js b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-undefined.js new file mode 100644 index 0000000000..80bd0c9bd3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/getPrototypeOf/trap-result-neither-object-nor-null-throws-undefined.js @@ -0,0 +1,20 @@ +// 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.1 +description: > + Throw a TypeError exception if trap result is undefined. +features: [Proxy] +---*/ + +var p = new Proxy({}, { + getPrototypeOf: function() { + return undefined; + } +}); + +assert.throws(TypeError, function() { + Object.getPrototypeOf(p); +}); + +reportCompare(0, 0); |