From f4e60b8f204c6408a9ab3f75fecf36564948825d Mon Sep 17 00:00:00 2001 From: Leo Balter Date: Wed, 24 Apr 2019 11:49:43 -0400 Subject: [PATCH] Add a case for non extensible targets of proxies GetPrototypeOf (#2122) --- .../instanceof-custom-return-accepted.js | 38 +++++++++++++++ .../getPrototypeOf/instanceof-return-true.js | 19 -------- ...et-not-extensible-not-same-proto-throws.js | 47 +++++++++++++++++++ 3 files changed, 85 insertions(+), 19 deletions(-) create mode 100644 test/built-ins/Proxy/getPrototypeOf/instanceof-custom-return-accepted.js delete mode 100644 test/built-ins/Proxy/getPrototypeOf/instanceof-return-true.js create mode 100644 test/built-ins/Proxy/getPrototypeOf/instanceof-target-not-extensible-not-same-proto-throws.js diff --git a/test/built-ins/Proxy/getPrototypeOf/instanceof-custom-return-accepted.js b/test/built-ins/Proxy/getPrototypeOf/instanceof-custom-return-accepted.js new file mode 100644 index 0000000000..c562f96b6e --- /dev/null +++ b/test/built-ins/Proxy/getPrototypeOf/instanceof-custom-return-accepted.js @@ -0,0 +1,38 @@ +// 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); diff --git a/test/built-ins/Proxy/getPrototypeOf/instanceof-return-true.js b/test/built-ins/Proxy/getPrototypeOf/instanceof-return-true.js deleted file mode 100644 index 8ef1e2458f..0000000000 --- a/test/built-ins/Proxy/getPrototypeOf/instanceof-return-true.js +++ /dev/null @@ -1,19 +0,0 @@ -// 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. -features: [Proxy] ----*/ - -function CustomClass() {} - -var p = new Proxy({}, { - getPrototypeOf: function() { - return CustomClass.prototype; - } -}); - -assert(p instanceof CustomClass, 'Expected p to be the instance of CustomClass, but was not.'); diff --git a/test/built-ins/Proxy/getPrototypeOf/instanceof-target-not-extensible-not-same-proto-throws.js b/test/built-ins/Proxy/getPrototypeOf/instanceof-target-not-extensible-not-same-proto-throws.js new file mode 100644 index 0000000000..7145470902 --- /dev/null +++ b/test/built-ins/Proxy/getPrototypeOf/instanceof-target-not-extensible-not-same-proto-throws.js @@ -0,0 +1,47 @@ +// 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 +});