diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Proxy/construct | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Proxy/construct')
31 files changed, 959 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Proxy/construct/arguments-realm.js b/js/src/tests/test262/built-ins/Proxy/construct/arguments-realm.js new file mode 100644 index 0000000000..feb7ec55a0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/arguments-realm.js @@ -0,0 +1,21 @@ +// 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-construct-argumentslist-newtarget +description: > + Arguments array is created in the Realm of the current execution context +info: | + [...] + 7. Let argArray be CreateArrayFromList(argumentsList). + 8. Let newObj be ? Call(trap, handler, « target, argArray, newTarget »). + [...] +features: [cross-realm] +---*/ + +var C = $262.createRealm().global.eval( + 'new Proxy(function() {}, { construct: function(_, args) { return args; } })' +); + +assert.sameValue(new C().constructor, Array); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/browser.js b/js/src/tests/test262/built-ins/Proxy/construct/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/browser.js diff --git a/js/src/tests/test262/built-ins/Proxy/construct/call-parameters-new-target.js b/js/src/tests/test262/built-ins/Proxy/construct/call-parameters-new-target.js new file mode 100644 index 0000000000..353c4f4092 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/call-parameters-new-target.js @@ -0,0 +1,42 @@ +// Copyright (C) 2017 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-construct-argumentslist-newtarget +description: > + trap is called with handler object as its context, and parameters are: + target, an array list with the called arguments and the NewTarget +info: | + [[Construct]] (argumentsList, newTarget) + + 9. Let newObj be Call(trap, handler, «target, argArray, newTarget»). +features: [Proxy, Reflect, Reflect.construct] +---*/ + +function Target() {} + +function NewTarget() {} + +var handler = { + construct: function(target, args, newTarget) { + assert.sameValue(this, handler, "trap context is the handler object"); + assert.sameValue(target, Target, "first parameter is the target object"); + assert.sameValue(args.length, 2, "arguments list contains all construct arguments"); + + var a = args[0]; + var b = args[1]; + assert.sameValue(a, 1, "arguments list has first construct argument"); + assert.sameValue(b, 2, "arguments list has second construct argument"); + assert.sameValue(newTarget, NewTarget, "newTarget is passed as the third parameter"); + + return { + sum: a + b + }; + }, +}; + +var P = new Proxy(Target, handler); +var res = Reflect.construct(P, [1, 2], NewTarget); +assert.sameValue(res.sum, 3); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/call-parameters.js b/js/src/tests/test262/built-ins/Proxy/construct/call-parameters.js new file mode 100644 index 0000000000..cb771c9fb4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/call-parameters.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 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-construct-argumentslist-newtarget +description: > + trap is called with handler object as its context, and parameters are: + target, an array list with the called arguments and the new target, and the + constructor new.target. +info: | + [[Construct]] ( argumentsList, newTarget) + + 9. Let newObj be Call(trap, handler, «target, argArray, newTarget »). +features: [Proxy] +---*/ + +var _target, _handler, _args, _P; + +function Target() {} + +var handler = { + construct: function(t, args, newTarget) { + _handler = this; + _target = t; + _args = args; + _P = newTarget; + + return new t(args[0], args[1]); + } +}; +var P = new Proxy(Target, handler); + +new P(1, 2); + +assert.sameValue(_handler, handler, "trap context is the handler object"); +assert.sameValue(_target, Target, "first parameter is the target object"); +assert.sameValue(_args.length, 2, "arguments list contains all call arguments"); +assert.sameValue(_args[0], 1, "arguments list has first call argument"); +assert.sameValue(_args[1], 2, "arguments list has second call argument"); +assert.sameValue(_P, P, "constructor is sent as the third parameter"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/call-result.js b/js/src/tests/test262/built-ins/Proxy/construct/call-result.js new file mode 100644 index 0000000000..709016ff62 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/call-result.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 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-construct-argumentslist-newtarget +description: > + Return the result from the trap method. +info: | + [[Construct]] ( argumentsList, newTarget) + + 12. Return newObj +features: [Proxy] +---*/ + +var P = new Proxy(function() { + throw new Test262Error('target should not be called'); +}, { + construct: function(t, c, args) { + return { + sum: 42 + }; + } +}); + +assert.sameValue((new P(1, 2)).sum, 42); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/null-handler-realm.js b/js/src/tests/test262/built-ins/Proxy/construct/null-handler-realm.js new file mode 100644 index 0000000000..a17fb95e33 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/null-handler-realm.js @@ -0,0 +1,22 @@ +// 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-construct-argumentslist-newtarget +description: > + [[Construct]] (argumentsList, newTarget) + + 1. Let handler be O.[[ProxyHandler]]. + 2. If handler is null, throw a TypeError exception. +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var p = OProxy.revocable(function() {}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + new p.proxy(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/null-handler.js b/js/src/tests/test262/built-ins/Proxy/construct/null-handler.js new file mode 100644 index 0000000000..90a310e4fd --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/null-handler.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 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-construct-argumentslist-newtarget +description: > + [[Construct]] ( argumentsList, newTarget) + + 2. If handler is null, throw a TypeError exception. +features: [Proxy] +---*/ + + +var p = Proxy.revocable(function() {}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + new p.proxy(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/return-is-abrupt.js b/js/src/tests/test262/built-ins/Proxy/construct/return-is-abrupt.js new file mode 100644 index 0000000000..d1b2381407 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/return-is-abrupt.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 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-construct-argumentslist-newtarget +description: > + Return abrupt from constructor call. +info: | + [[Construct]] ( argumentsList, newTarget) + + 9. Let newObj be Call(trap, handler, «target, argArray, newTarget »). + 10. ReturnIfAbrupt(newObj). +features: [Proxy] +---*/ + +function Target() {} +var P = new Proxy(Target, { + construct: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + new P(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-boolean-realm.js b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-boolean-realm.js new file mode 100644 index 0000000000..fa19b3df39 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-boolean-realm.js @@ -0,0 +1,29 @@ +// 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-construct-argumentslist-newtarget +description: > + Throws a TypeError if trap result is not an Object: Boolean + (honoring the Realm of the current execution context) +info: | + [[Construct]] (argumentsList, newTarget) + + [...] + 11. If Type(newObj) is not Object, throw a TypeError exception. +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var P = new OProxy(function() { + throw new Test262Error('target should not be called'); +}, { + construct: function() { + return true; + }, +}); + +assert.throws(TypeError, function() { + new P(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-boolean.js b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-boolean.js new file mode 100644 index 0000000000..f3c6857513 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-boolean.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 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-construct-argumentslist-newtarget +description: > + Throws a TypeError if trap result is not an Object: Boolean +info: | + [[Construct]] ( argumentsList, newTarget) + + 11. If Type(newObj) is not Object, throw a TypeError exception. +features: [Proxy] +---*/ + +var P = new Proxy(function() { + throw new Test262Error('target should not be called'); +}, { + construct: function() { + return true; + } +}); + +assert.throws(TypeError, function() { + new P(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-null-realm.js b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-null-realm.js new file mode 100644 index 0000000000..2342dd07b1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-null-realm.js @@ -0,0 +1,29 @@ +// 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-construct-argumentslist-newtarget +description: > + Throws a TypeError if trap result is not an Object: null + (honoring the Realm of the current execution context) +info: | + [[Construct]] (argumentsList, newTarget) + + [...] + 11. If Type(newObj) is not Object, throw a TypeError exception. +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var P = new OProxy(function() { + throw new Test262Error('target should not be called'); +}, { + construct: function() { + return null; + }, +}); + +assert.throws(TypeError, function() { + new P(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-null.js b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-null.js new file mode 100644 index 0000000000..f14da08eba --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-null.js @@ -0,0 +1,27 @@ +// 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-construct-argumentslist-newtarget +description: > + Throws a TypeError if trap result is not an Object: null +info: | + [[Construct]] (argumentsList, newTarget) + + [...] + 11. If Type(newObj) is not Object, throw a TypeError exception. +features: [Proxy] +---*/ + +var P = new Proxy(function() { + throw new Test262Error('target should not be called'); +}, { + construct: function() { + return null; + }, +}); + +assert.throws(TypeError, function() { + new P(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-number-realm.js b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-number-realm.js new file mode 100644 index 0000000000..999159287c --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-number-realm.js @@ -0,0 +1,29 @@ +// 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-construct-argumentslist-newtarget +description: > + Throws a TypeError if trap result is not an Object: Number + (honoring the Realm of the current execution context) +info: | + [[Construct]] (argumentsList, newTarget) + + [...] + 11. If Type(newObj) is not Object, throw a TypeError exception. +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var P = new OProxy(function() { + throw new Test262Error('target should not be called'); +}, { + construct: function() { + return 1; + }, +}); + +assert.throws(TypeError, function() { + new P(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-number.js b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-number.js new file mode 100644 index 0000000000..bc1c591b28 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-number.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 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-construct-argumentslist-newtarget +description: > + Throws a TypeError if trap result is not an Object: Number +info: | + [[Construct]] ( argumentsList, newTarget) + + 11. If Type(newObj) is not Object, throw a TypeError exception. +features: [Proxy] +---*/ + +var P = new Proxy(function() { + throw new Test262Error('target should not be called'); +}, { + construct: function() { + return 0; + } +}); + +assert.throws(TypeError, function() { + new P(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-string-realm.js b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-string-realm.js new file mode 100644 index 0000000000..6d607d7ffb --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-string-realm.js @@ -0,0 +1,29 @@ +// 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-construct-argumentslist-newtarget +description: > + Throws a TypeError if trap result is not an Object: String + (honoring the Realm of the current execution context) +info: | + [[Construct]] (argumentsList, newTarget) + + [...] + 11. If Type(newObj) is not Object, throw a TypeError exception. +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var P = new OProxy(function() { + throw new Test262Error('target should not be called'); +}, { + construct: function() { + return ''; + }, +}); + +assert.throws(TypeError, function() { + new P(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-string.js b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-string.js new file mode 100644 index 0000000000..32bb69bfa5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-string.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 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-construct-argumentslist-newtarget +description: > + Throws a TypeError if trap result is not an Object: String +info: | + [[Construct]] ( argumentsList, newTarget) + + 11. If Type(newObj) is not Object, throw a TypeError exception. +features: [Proxy] +---*/ + +var P = new Proxy(function() { + throw new Test262Error('target should not be called'); +}, { + construct: function() { + return ""; + } +}); + +assert.throws(TypeError, function() { + new P(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-symbol-realm.js b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-symbol-realm.js new file mode 100644 index 0000000000..90640df61f --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-symbol-realm.js @@ -0,0 +1,29 @@ +// 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-construct-argumentslist-newtarget +description: > + Throws a TypeError if trap result is not an Object: Symbol + (honoring the Realm of the current execution context) +info: | + [[Construct]] (argumentsList, newTarget) + + [...] + 11. If Type(newObj) is not Object, throw a TypeError exception. +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var P = new OProxy(function() { + throw new Test262Error('target should not be called'); +}, { + construct: function() { + return Symbol(); + }, +}); + +assert.throws(TypeError, function() { + new P(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-symbol.js b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-symbol.js new file mode 100644 index 0000000000..857e0b6ae7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-symbol.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 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-construct-argumentslist-newtarget +description: > + Throws a TypeError if trap result is not an Object: Symbol +info: | + [[Construct]] ( argumentsList, newTarget) + + 11. If Type(newObj) is not Object, throw a TypeError exception. +features: [Proxy, Symbol] +---*/ + +var P = new Proxy(function() { + throw new Test262Error('target should not be called'); +}, { + construct: function() { + return Symbol(); + } +}); + +assert.throws(TypeError, function() { + new P(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-undefined-realm.js b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-undefined-realm.js new file mode 100644 index 0000000000..300f9010f6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-undefined-realm.js @@ -0,0 +1,27 @@ +// 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-construct-argumentslist-newtarget +description: > + Throws a TypeError if trap result is not an Object: undefined + (honoring the Realm of the current execution context) +info: | + [[Construct]] (argumentsList, newTarget) + + [...] + 11. If Type(newObj) is not Object, throw a TypeError exception. +features: [cross-realm, Proxy] +---*/ + +var OProxy = $262.createRealm().global.Proxy; +var P = new OProxy(function() { + throw new Test262Error('target should not be called'); +}, { + construct: function() {}, +}); + +assert.throws(TypeError, function() { + new P(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-undefined.js b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-undefined.js new file mode 100644 index 0000000000..dab78c14d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/return-not-object-throws-undefined.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. +/*--- +esid: sec-proxy-object-internal-methods-and-internal-slots-construct-argumentslist-newtarget +description: > + Throws a TypeError if trap result is not an Object: undefined +info: | + [[Construct]] ( argumentsList, newTarget) + + 11. If Type(newObj) is not Object, throw a TypeError exception. +features: [Proxy] +---*/ + +var P = new Proxy(function() { + throw new Test262Error('target should not be called'); +}, { + construct: function() {} +}); + +assert.throws(TypeError, function() { + new P(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/shell.js b/js/src/tests/test262/built-ins/Proxy/construct/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/shell.js diff --git a/js/src/tests/test262/built-ins/Proxy/construct/trap-is-missing-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-missing-target-is-proxy.js new file mode 100644 index 0000000000..08b9fc06a9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-missing-target-is-proxy.js @@ -0,0 +1,40 @@ +// 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-construct-argumentslist-newtarget +description: > + If "construct" trap is null or undefined, [[Construct]] call is + properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[Construct]] ( argumentsList, newTarget ) + + [...] + 4. Let target be O.[[ProxyTarget]]. + 5. Assert: IsConstructor(target) is true. + 6. Let trap be ? GetMethod(handler, "construct"). + 7. If trap is undefined, then + a. Return ? Construct(target, argumentsList, newTarget). +features: [class, Proxy, Reflect, Reflect.construct] +includes: [compareArray.js] +---*/ + +var ArrayTarget = new Proxy(Array, {}); +var ArrayProxy = new Proxy(ArrayTarget, {}); + +var array = new ArrayProxy(1, 2, 3); +assert(Array.isArray(array)); +assert.compareArray(array, [1, 2, 3]); + +class MyArray extends Array { + get isMyArray() { + return true; + } +} + +var myArray = Reflect.construct(ArrayProxy, [], MyArray); +assert(Array.isArray(myArray)); +assert(myArray instanceof MyArray); +assert(myArray.isMyArray); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/trap-is-not-callable-realm.js b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-not-callable-realm.js new file mode 100644 index 0000000000..c93e0b0bbb --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/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-construct-argumentslist-newtarget +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(function() {}, { + construct: {} +}); + +assert.throws(TypeError, function() { + new p(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/trap-is-not-callable.js b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-not-callable.js new file mode 100644 index 0000000000..acb58e6dd1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-not-callable.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 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-construct-argumentslist-newtarget +description: > + Throws if trap is not callable. +features: [Proxy] +---*/ + +function Target() {} +var p = new Proxy(Target, { + construct: {} +}); + +assert.throws(TypeError, function() { + new p(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/trap-is-null-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-null-target-is-proxy.js new file mode 100644 index 0000000000..7cdaa8c741 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-null-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-construct-argumentslist-newtarget +description: > + If "construct" trap is null or undefined, [[Construct]] call is + properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[Construct]] ( argumentsList, newTarget ) + + [...] + 4. Let target be O.[[ProxyTarget]]. + 5. Assert: IsConstructor(target) is true. + 6. Let trap be ? GetMethod(handler, "construct"). + 7. If trap is undefined, then + a. Return ? Construct(target, argumentsList, newTarget). +features: [class, Proxy, Reflect, Reflect.construct] +---*/ + +class Foo { + constructor(arg) { + this.arg = arg; + } +} + +var FooTarget = new Proxy(Foo, {}); +var FooProxy = new Proxy(FooTarget, { + construct: null, +}); + +var foo = new FooProxy(1); +assert(foo instanceof Foo); +assert.sameValue(foo.arg, 1); + +class Bar extends Foo { + get isBar() { + return true; + } +} + +var bar = Reflect.construct(FooProxy, [2], Bar); +assert(bar instanceof Bar); +assert.sameValue(bar.arg, 2); +assert(bar.isBar); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/trap-is-null.js b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-null.js new file mode 100644 index 0000000000..962e97c0f0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-null.js @@ -0,0 +1,52 @@ +// Copyright (C) 2015 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-construct-argumentslist-newtarget +description: > + If the construct trap value is null, propagate the construct to the target object. +info: | + [[Construct]] (argumentsList, newTarget) + + ... + 5. Let trap be ? GetMethod(handler, "construct"). + 6. If trap is undefined, then + a. Assert: target has a [[Construct]] internal method. + b. Return ? Construct(target, argumentsList, newTarget). + ... + + GetMethod ( V, P ) + + ... + 3. If func is either undefined or null, return undefined. + ... +features: [Proxy, Reflect, Reflect.construct] +---*/ + +var calls = 0; +var _NewTarget; + +var Target = new Proxy(function() { + throw new Test262Error('target should not be called'); +}, { + construct: function(_Target, args, NewTarget) { + calls += 1; + _NewTarget = NewTarget; + return { + sum: args[0] + args[1] + }; + } +}) + +var P = new Proxy(Target, { + construct: null +}); + +var NewTarget = function() {}; +var obj = Reflect.construct(P, [3, 4], NewTarget); + +assert.sameValue(calls, 1, "construct is null: [[Construct]] is invoked once"); +assert.sameValue(_NewTarget, NewTarget, "construct is null: NewTarget is passed to [[Construct]]"); +assert.sameValue(obj.sum, 7, "construct is null: result of [[Construct]] is returned"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/trap-is-undefined-no-property.js b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-undefined-no-property.js new file mode 100644 index 0000000000..5a5204cd6a --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-undefined-no-property.js @@ -0,0 +1,48 @@ +// Copyright (C) 2015 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-construct-argumentslist-newtarget +description: > + If the construct trap is not set, propagate the construct to the target object. +info: | + [[Construct]] (argumentsList, newTarget) + + ... + 5. Let trap be ? GetMethod(handler, "construct"). + 6. If trap is undefined, then + a. Assert: target has a [[Construct]] internal method. + b. Return ? Construct(target, argumentsList, newTarget). + ... + + GetMethod ( V, P ) + + ... + 3. If func is either undefined or null, return undefined. + ... +features: [Proxy, Reflect, Reflect.construct] +---*/ + +var calls = 0; +var _NewTarget; + +var Target = new Proxy(function() { + throw new Test262Error('target should not be called'); +}, { + construct: function(_Target, args, NewTarget) { + calls += 1; + _NewTarget = NewTarget; + return { + sum: args[0] + args[1] + }; + } +}) + +var P = new Proxy(Target, {}); +var NewTarget = function() {}; +var obj = Reflect.construct(P, [3, 4], NewTarget); + +assert.sameValue(calls, 1, "construct is missing: [[Construct]] is invoked once"); +assert.sameValue(_NewTarget, NewTarget, "construct is missing: NewTarget is passed to [[Construct]]"); +assert.sameValue(obj.sum, 7, "construct is missing: result of [[Construct]] is returned"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/trap-is-undefined-proto-from-cross-realm-newtarget.js b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-undefined-proto-from-cross-realm-newtarget.js new file mode 100644 index 0000000000..04834fdb5f --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-undefined-proto-from-cross-realm-newtarget.js @@ -0,0 +1,49 @@ +// 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-construct-argumentslist-newtarget +description: > + If trap is undefined, propagate [[Construct]] to target, + passing correct newTarget parameter +info: | + [[Construct]] ( argumentsList, newTarget ) + + [...] + 7. If trap is undefined, then + b. Return ? Construct(target, argumentsList, newTarget). + + Construct ( F [ , argumentsList [ , newTarget ] ] ) + + [...] + 5. Return ? F.[[Construct]](argumentsList, newTarget). + + [[Construct]] ( argumentsList, newTarget ) + + [...] + 5. If kind is "base", then + a. Let thisArgument be ? OrdinaryCreateFromConstructor(newTarget, "%ObjectPrototype%"). + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + [...] + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + [...] + 5. Return proto. +features: [cross-realm, Proxy, Reflect, Reflect.construct] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); + +var P = new Proxy(function() {}, {}); +var p = Reflect.construct(P, [], C); + +assert.sameValue(Object.getPrototypeOf(p), C.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/trap-is-undefined-proto-from-newtarget-realm.js b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-undefined-proto-from-newtarget-realm.js new file mode 100644 index 0000000000..dd96640ce5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-undefined-proto-from-newtarget-realm.js @@ -0,0 +1,58 @@ +// 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-construct-argumentslist-newtarget +description: > + If trap is undefined, propagate [[Construct]] to target, + passing correct newTarget parameter +info: | + [[Construct]] ( argumentsList, newTarget ) + + [...] + 7. If trap is undefined, then + b. Return ? Construct(target, argumentsList, newTarget). + + Construct ( F [ , argumentsList [ , newTarget ] ] ) + + [...] + 5. Return ? F.[[Construct]](argumentsList, newTarget). + + [[Construct]] ( argumentsList, newTarget ) + + [...] + 5. If kind is "base", then + a. Let thisArgument be ? OrdinaryCreateFromConstructor(newTarget, "%ObjectPrototype%"). + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + [...] + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(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]]. +features: [cross-realm, Proxy, Reflect, Reflect.construct] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +var P = new Proxy(function() {}, {}); +var p = Reflect.construct(P, [], C); + +assert.sameValue(Object.getPrototypeOf(p), other.Object.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/trap-is-undefined-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-undefined-target-is-proxy.js new file mode 100644 index 0000000000..068159253c --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-undefined-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-construct-argumentslist-newtarget +description: > + If "construct" trap is null or undefined, [[Construct]] call is + properly forwarded to [[ProxyTarget]] (which is also a Proxy object). +info: | + [[Construct]] ( argumentsList, newTarget ) + + [...] + 4. Let target be O.[[ProxyTarget]]. + 5. Assert: IsConstructor(target) is true. + 6. Let trap be ? GetMethod(handler, "construct"). + 7. If trap is undefined, then + a. Return ? Construct(target, argumentsList, newTarget). +features: [class, Proxy, Reflect, Reflect.construct] +---*/ + +class Foo { + constructor(a, b) { + this.sum = a + b; + } +} + +var FooBound = Foo.bind(null, 1); +var FooTarget = new Proxy(FooBound, {}); +var FooProxy = new Proxy(FooTarget, { + construct: undefined, +}); + +var foo = new FooBound(2); +assert(foo instanceof Foo); +assert.sameValue(foo.sum, 3); + +class Bar extends Foo { + get isBar() { + return true; + } +} + +var bar = Reflect.construct(FooProxy, [3], Bar); +assert(bar instanceof Bar); +assert.sameValue(bar.sum, 4); +assert(bar.isBar); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Proxy/construct/trap-is-undefined.js b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-undefined.js new file mode 100644 index 0000000000..5682638564 --- /dev/null +++ b/js/src/tests/test262/built-ins/Proxy/construct/trap-is-undefined.js @@ -0,0 +1,52 @@ +// Copyright (C) 2015 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-construct-argumentslist-newtarget +description: > + If the construct trap value is undefined, propagate the construct to the target object. +info: | + [[Construct]] (argumentsList, newTarget) + + ... + 5. Let trap be ? GetMethod(handler, "construct"). + 6. If trap is undefined, then + a. Assert: target has a [[Construct]] internal method. + b. Return ? Construct(target, argumentsList, newTarget). + ... + + GetMethod ( V, P ) + + ... + 3. If func is either undefined or null, return undefined. + ... +features: [Proxy, Reflect, Reflect.construct] +---*/ + +var calls = 0; +var _NewTarget; + +var Target = new Proxy(function() { + throw new Test262Error('target should not be called'); +}, { + construct: function(_Target, args, NewTarget) { + calls += 1; + _NewTarget = NewTarget; + return { + sum: args[0] + args[1] + }; + }, +}); + +var P = new Proxy(Target, { + construct: undefined +}); + +var NewTarget = function() {}; +var obj = Reflect.construct(P, [3, 4], NewTarget); + +assert.sameValue(calls, 1, "construct is undefined: [[Construct]] is invoked once"); +assert.sameValue(_NewTarget, NewTarget, "construct is undefined: NewTarget is passed to [[Construct]]"); +assert.sameValue(obj.sum, 7, "construct is undefined: result of [[Construct]] is returned"); + +reportCompare(0, 0); |