diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Proxy/getPrototypeOf')
21 files changed, 531 insertions, 0 deletions
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); |