summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Proxy/apply
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Proxy/apply')
-rw-r--r--js/src/tests/test262/built-ins/Proxy/apply/arguments-realm.js20
-rw-r--r--js/src/tests/test262/built-ins/Proxy/apply/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/Proxy/apply/call-parameters.js40
-rw-r--r--js/src/tests/test262/built-ins/Proxy/apply/call-result.js25
-rw-r--r--js/src/tests/test262/built-ins/Proxy/apply/null-handler-realm.js25
-rw-r--r--js/src/tests/test262/built-ins/Proxy/apply/null-handler.js21
-rw-r--r--js/src/tests/test262/built-ins/Proxy/apply/return-abrupt.js22
-rw-r--r--js/src/tests/test262/built-ins/Proxy/apply/shell.js0
-rw-r--r--js/src/tests/test262/built-ins/Proxy/apply/trap-is-missing-target-is-proxy.js28
-rw-r--r--js/src/tests/test262/built-ins/Proxy/apply/trap-is-not-callable-realm.js20
-rw-r--r--js/src/tests/test262/built-ins/Proxy/apply/trap-is-not-callable.js18
-rw-r--r--js/src/tests/test262/built-ins/Proxy/apply/trap-is-null-target-is-proxy.js33
-rw-r--r--js/src/tests/test262/built-ins/Proxy/apply/trap-is-null.js47
-rw-r--r--js/src/tests/test262/built-ins/Proxy/apply/trap-is-undefined-no-property.js44
-rw-r--r--js/src/tests/test262/built-ins/Proxy/apply/trap-is-undefined-target-is-proxy.js35
-rw-r--r--js/src/tests/test262/built-ins/Proxy/apply/trap-is-undefined.js47
16 files changed, 425 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Proxy/apply/arguments-realm.js b/js/src/tests/test262/built-ins/Proxy/apply/arguments-realm.js
new file mode 100644
index 0000000000..41359d9e69
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Proxy/apply/arguments-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-call-thisargument-argumentslist
+description: >
+ Arguments array is created in the Realm of the current execution context
+info: |
+ [...]
+ 7. Let argArray be CreateArrayFromList(argumentsList).
+ 8. Return ? Call(trap, handler, « target, thisArgument, argArray »).
+features: [cross-realm]
+---*/
+
+var f = $262.createRealm().global.eval(
+ 'new Proxy(function() {}, { apply: function(_, __, args) { return args; } })'
+);
+
+assert.sameValue(f().constructor, Array);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Proxy/apply/browser.js b/js/src/tests/test262/built-ins/Proxy/apply/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Proxy/apply/browser.js
diff --git a/js/src/tests/test262/built-ins/Proxy/apply/call-parameters.js b/js/src/tests/test262/built-ins/Proxy/apply/call-parameters.js
new file mode 100644
index 0000000000..35e641e1c0
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Proxy/apply/call-parameters.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.
+/*---
+esid: sec-proxy-object-internal-methods-and-internal-slots-call-thisargument-argumentslist
+description: >
+ trap is called with handler object as its context, and parameters are:
+ target, the call context and and an array list with the called arguments
+info: |
+ [[Call]] (thisArgument, argumentsList)
+
+ 9. Return Call(trap, handler, «target, thisArgument, argArray»).
+features: [Proxy]
+---*/
+
+var _target, _args, _handler, _context;
+var target = function() {
+ throw new Test262Error('target should not be called');
+};
+var handler = {
+ apply: function(t, c, args) {
+ _handler = this;
+ _target = t;
+ _context = c;
+ _args = args;
+ }
+};
+var p = new Proxy(target, handler);
+
+var context = {};
+
+p.call(context, 1, 2);
+
+assert.sameValue(_handler, handler, "trap context is the handler object");
+assert.sameValue(_target, target, "first parameter is the target object");
+assert.sameValue(_context, context, "second parameter is the call context");
+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");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Proxy/apply/call-result.js b/js/src/tests/test262/built-ins/Proxy/apply/call-result.js
new file mode 100644
index 0000000000..23175ea80b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Proxy/apply/call-result.js
@@ -0,0 +1,25 @@
+// 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-call-thisargument-argumentslist
+description: >
+ Return the result from the trap method.
+info: |
+ [[Call]] (thisArgument, argumentsList)
+
+ 9. Return Call(trap, handler, «target, thisArgument, argArray»).
+features: [Proxy]
+---*/
+
+var result = {};
+var p = new Proxy(function() {
+ throw new Test262Error('target should not be called');
+}, {
+ apply: function(t, c, args) {
+ return result;
+ },
+});
+
+assert.sameValue(p.call(), result);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Proxy/apply/null-handler-realm.js b/js/src/tests/test262/built-ins/Proxy/apply/null-handler-realm.js
new file mode 100644
index 0000000000..1b4af39513
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Proxy/apply/null-handler-realm.js
@@ -0,0 +1,25 @@
+// 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-call-thisargument-argumentslist
+description: >
+ Throws a TypeError exception if handler is null (honoring the realm of the
+ current execution context).
+info: |
+ [[Call]] (thisArgument, argumentsList)
+
+ 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() {
+ p.proxy();
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Proxy/apply/null-handler.js b/js/src/tests/test262/built-ins/Proxy/apply/null-handler.js
new file mode 100644
index 0000000000..c94729ba1d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Proxy/apply/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-call-thisargument-argumentslist
+description: >
+ [[Call]] (thisArgument, argumentsList)
+
+ 2. If handler is null, throw a TypeError exception.
+features: [Proxy]
+---*/
+
+
+var p = Proxy.revocable(function() {}, {});
+
+p.revoke();
+
+assert.throws(TypeError, function() {
+ p.proxy();
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Proxy/apply/return-abrupt.js b/js/src/tests/test262/built-ins/Proxy/apply/return-abrupt.js
new file mode 100644
index 0000000000..d8641fa809
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Proxy/apply/return-abrupt.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.
+/*---
+esid: sec-proxy-object-internal-methods-and-internal-slots-call-thisargument-argumentslist
+description: >
+ Return is an abrupt completion
+features: [Proxy]
+---*/
+
+var p = new Proxy(function() {
+ throw 'not the Test262Error you are looking for';
+}, {
+ apply: function(t, c, args) {
+ throw new Test262Error();
+ }
+});
+
+assert.throws(Test262Error, function() {
+ p.call();
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Proxy/apply/shell.js b/js/src/tests/test262/built-ins/Proxy/apply/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Proxy/apply/shell.js
diff --git a/js/src/tests/test262/built-ins/Proxy/apply/trap-is-missing-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/apply/trap-is-missing-target-is-proxy.js
new file mode 100644
index 0000000000..35e72dbb8c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Proxy/apply/trap-is-missing-target-is-proxy.js
@@ -0,0 +1,28 @@
+// 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-call-thisargument-argumentslist
+description: >
+ If "apply" trap is null or undefined, [[Call]] is properly
+ forwarded to [[ProxyTarget]] (which is also a Proxy object).
+info: |
+ [[Call]] ( thisArgument, argumentsList )
+
+ [...]
+ 4. Let target be O.[[ProxyTarget]].
+ 5. Let trap be ? GetMethod(handler, "apply").
+ 6. If trap is undefined, then
+ a. Return ? Call(target, thisArgument, argumentsList).
+features: [Proxy, Reflect]
+---*/
+
+var hasOwn = Object.prototype.hasOwnProperty;
+var hasOwnTarget = new Proxy(hasOwn, {});
+var hasOwnProxy = new Proxy(hasOwnTarget, {});
+
+var obj = {foo: 1};
+assert(hasOwnProxy.call(obj, "foo"));
+assert(!Reflect.apply(hasOwnProxy, obj, ["bar"]));
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Proxy/apply/trap-is-not-callable-realm.js b/js/src/tests/test262/built-ins/Proxy/apply/trap-is-not-callable-realm.js
new file mode 100644
index 0000000000..4daf79f976
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Proxy/apply/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-call-thisargument-argumentslist
+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() {}, {
+ apply: {}
+});
+
+assert.throws(TypeError, function() {
+ p();
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Proxy/apply/trap-is-not-callable.js b/js/src/tests/test262/built-ins/Proxy/apply/trap-is-not-callable.js
new file mode 100644
index 0000000000..fd5a57c646
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Proxy/apply/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.
+/*---
+esid: sec-proxy-object-internal-methods-and-internal-slots-call-thisargument-argumentslist
+description: >
+ Throws if trap is not callable.
+features: [Proxy]
+---*/
+
+var p = new Proxy(function() {}, {
+ apply: {}
+});
+
+assert.throws(TypeError, function() {
+ p();
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Proxy/apply/trap-is-null-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/apply/trap-is-null-target-is-proxy.js
new file mode 100644
index 0000000000..246fa7f57b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Proxy/apply/trap-is-null-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-call-thisargument-argumentslist
+description: >
+ If "apply" trap is null or undefined, [[Call]] is properly
+ forwarded to [[ProxyTarget]] (which is also a Proxy object).
+info: |
+ [[Call]] ( thisArgument, argumentsList )
+
+ [...]
+ 4. Let target be O.[[ProxyTarget]].
+ 5. Let trap be ? GetMethod(handler, "apply").
+ 6. If trap is undefined, then
+ a. Return ? Call(target, thisArgument, argumentsList).
+features: [Proxy]
+---*/
+
+var sum = function(a, b) {
+ return this.foo + a + b;
+};
+
+var sumBound = sum.bind({foo: 10}, 1);
+var sumTarget = new Proxy(sumBound, {});
+var sumProxy = new Proxy(sumTarget, {
+ apply: null,
+});
+
+assert.sameValue(sumProxy(2), 13);
+assert.sameValue(sumProxy.call({foo: 20}, 3), 14);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Proxy/apply/trap-is-null.js b/js/src/tests/test262/built-ins/Proxy/apply/trap-is-null.js
new file mode 100644
index 0000000000..b843e97831
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Proxy/apply/trap-is-null.js
@@ -0,0 +1,47 @@
+// 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-call-thisargument-argumentslist
+description: >
+ If the apply trap value is null, propagate the call to the target object.
+info: |
+ [[Call]] (thisArgument, argumentsList)
+
+ ...
+ 5. Let trap be ? GetMethod(handler, "apply").
+ 6. If trap is undefined, then
+ a. Return ? Call(target, thisArgument, argumentsList).
+ ...
+
+ GetMethod ( V, P )
+
+ ...
+ 3. If func is either undefined or null, return undefined.
+ ...
+features: [Proxy]
+---*/
+
+var calls = 0;
+var _context;
+
+var target = new Proxy(function() {}, {
+ apply: function(_target, context, args) {
+ calls++;
+ _context = context;
+ return args[0] + args[1];
+ }
+})
+
+var p = new Proxy(target, {
+ apply: null
+});
+
+var context = {};
+var res = p.call(context, 1, 2);
+
+assert.sameValue(calls, 1, "apply is null: [[Call]] is invoked once");
+assert.sameValue(_context, context, "apply is null: context is passed to [[Call]]");
+assert.sameValue(res, 3, "apply is null: result of [[Call]] is returned");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Proxy/apply/trap-is-undefined-no-property.js b/js/src/tests/test262/built-ins/Proxy/apply/trap-is-undefined-no-property.js
new file mode 100644
index 0000000000..bac61d38e8
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Proxy/apply/trap-is-undefined-no-property.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.
+
+/*---
+esid: sec-proxy-object-internal-methods-and-internal-slots-call-thisargument-argumentslist
+description: >
+ If trap is not set, propagate the call to the target object.
+info: |
+ [[Call]] (thisArgument, argumentsList)
+
+ ...
+ 5. Let trap be ? GetMethod(handler, "apply").
+ 6. If trap is undefined, then
+ a. Return ? Call(target, thisArgument, argumentsList).
+ ...
+
+ GetMethod ( V, P )
+
+ ...
+ 3. If func is either undefined or null, return undefined.
+ ...
+features: [Proxy]
+---*/
+
+var calls = 0;
+var _context;
+
+var target = new Proxy(function() {}, {
+ apply: function(_target, context, args) {
+ calls++;
+ _context = context;
+ return args[0] + args[1];
+ }
+})
+
+var p = new Proxy(target, {});
+var context = {};
+var res = p.call(context, 1, 2);
+
+assert.sameValue(calls, 1, "apply is missing: [[Call]] is invoked once");
+assert.sameValue(_context, context, "apply is missing: context is passed to [[Call]]");
+assert.sameValue(res, 3, "apply is missing: result of [[Call]] is returned");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Proxy/apply/trap-is-undefined-target-is-proxy.js b/js/src/tests/test262/built-ins/Proxy/apply/trap-is-undefined-target-is-proxy.js
new file mode 100644
index 0000000000..bd34cb9a8d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Proxy/apply/trap-is-undefined-target-is-proxy.js
@@ -0,0 +1,35 @@
+// 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-call-thisargument-argumentslist
+description: >
+ If "apply" trap is null or undefined, [[Call]] is properly
+ forwarded to [[ProxyTarget]] (which is also a Proxy object).
+info: |
+ [[Call]] ( thisArgument, argumentsList )
+
+ [...]
+ 4. Let target be O.[[ProxyTarget]].
+ 5. Let trap be ? GetMethod(handler, "apply").
+ 6. If trap is undefined, then
+ a. Return ? Call(target, thisArgument, argumentsList).
+features: [generators, Proxy, Reflect]
+includes: [compareArray.js]
+---*/
+
+var sum = function* (arg) {
+ yield this.foo;
+ yield arg;
+};
+
+var sumTarget = new Proxy(sum, {});
+var sumProxy = new Proxy(sumTarget, {
+ apply: undefined,
+});
+
+var gen = Reflect.apply(sumProxy, {foo: 10}, [1]);
+
+assert.compareArray(Array.from(gen), [10, 1]);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Proxy/apply/trap-is-undefined.js b/js/src/tests/test262/built-ins/Proxy/apply/trap-is-undefined.js
new file mode 100644
index 0000000000..7c8b6dae6b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Proxy/apply/trap-is-undefined.js
@@ -0,0 +1,47 @@
+// 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-call-thisargument-argumentslist
+description: >
+ If the apply trap value is undefined, propagate the call to the target object.
+info: |
+ [[Call]] (thisArgument, argumentsList)
+
+ ...
+ 5. Let trap be ? GetMethod(handler, "apply").
+ 6. If trap is undefined, then
+ a. Return ? Call(target, thisArgument, argumentsList).
+ ...
+
+ GetMethod ( V, P )
+
+ ...
+ 3. If func is either undefined or null, return undefined.
+ ...
+features: [Proxy]
+---*/
+
+var calls = 0;
+var _context;
+
+var target = new Proxy(function() {}, {
+ apply: function(_target, context, args) {
+ calls++;
+ _context = context;
+ return args[0] + args[1];
+ }
+})
+
+var p = new Proxy(target, {
+ apply: undefined
+});
+
+var context = {};
+var res = p.call(context, 1, 2);
+
+assert.sameValue(calls, 1, "apply is undefined: [[Call]] is invoked once");
+assert.sameValue(_context, context, "apply is undefined: context is passed to [[Call]]");
+assert.sameValue(res, 3, "apply is undefined: result of [[Call]] is returned");
+
+reportCompare(0, 0);