mirror of https://github.com/tc39/test262.git
Improve Proxy/apply coverage (#2156)
This commit is contained in:
parent
2682ab57cf
commit
8c1819484e
|
@ -1,6 +1,7 @@
|
|||
// 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
|
||||
es6id: 9.5.13
|
||||
description: >
|
||||
trap is called with handler object as its context, and parameters are:
|
||||
|
@ -13,8 +14,8 @@ features: [Proxy]
|
|||
---*/
|
||||
|
||||
var _target, _args, _handler, _context;
|
||||
var target = function(a, b) {
|
||||
return a + b;
|
||||
var target = function() {
|
||||
throw new Test262Error('target should not be called');
|
||||
};
|
||||
var handler = {
|
||||
apply: function(t, c, args) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// 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
|
||||
es6id: 9.5.13
|
||||
description: >
|
||||
Return the result from the trap method.
|
||||
|
@ -11,15 +12,13 @@ info: |
|
|||
features: [Proxy]
|
||||
---*/
|
||||
|
||||
var target = function(a, b) {
|
||||
return a + b;
|
||||
};
|
||||
var result = {};
|
||||
var handler = {
|
||||
var p = new Proxy(function() {
|
||||
throw new Test262Error('target should not be called');
|
||||
}, {
|
||||
apply: function(t, c, args) {
|
||||
return result;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
},
|
||||
});
|
||||
|
||||
assert.sameValue(p.call(), result);
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
// 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();
|
||||
});
|
|
@ -1,6 +1,7 @@
|
|||
// 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
|
||||
es6id: 9.5.13
|
||||
description: >
|
||||
[[Call]] (thisArgument, argumentsList)
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
// 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
|
||||
es6id: 9.5.13
|
||||
description: >
|
||||
Return is an abrupt completion
|
||||
features: [Proxy]
|
||||
---*/
|
||||
|
||||
var target = function(a, b) {
|
||||
return a + b;
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
var p = new Proxy(function() {
|
||||
throw 'not the Test262Error you are looking for';
|
||||
}, {
|
||||
apply: function(t, c, args) {
|
||||
throw new Test262Error();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// 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
|
||||
es6id: 9.5.13
|
||||
description: >
|
||||
Throws if trap is not callable.
|
||||
|
|
|
@ -24,17 +24,23 @@ features: [Proxy]
|
|||
---*/
|
||||
|
||||
var calls = 0;
|
||||
var _context;
|
||||
|
||||
function target(a, b) {
|
||||
assert.sameValue(this, ctx);
|
||||
calls += 1;
|
||||
return a + b;
|
||||
}
|
||||
var target = new Proxy(function() {}, {
|
||||
apply: function(_target, context, args) {
|
||||
calls++;
|
||||
_context = context;
|
||||
return args[0] + args[1];
|
||||
}
|
||||
})
|
||||
|
||||
var ctx = {};
|
||||
var p = new Proxy(target, {
|
||||
apply: null
|
||||
});
|
||||
var res = p.call(ctx, 1, 2);
|
||||
assert.sameValue(res, 3, "`apply` trap is `null`");
|
||||
assert.sameValue(calls, 1, "target is called once");
|
||||
|
||||
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");
|
||||
|
|
|
@ -24,15 +24,20 @@ features: [Proxy]
|
|||
---*/
|
||||
|
||||
var calls = 0;
|
||||
var _context;
|
||||
|
||||
function target(a, b) {
|
||||
assert.sameValue(this, ctx);
|
||||
calls += 1;
|
||||
return a + b;
|
||||
}
|
||||
var target = new Proxy(function() {}, {
|
||||
apply: function(_target, context, args) {
|
||||
calls++;
|
||||
_context = context;
|
||||
return args[0] + args[1];
|
||||
}
|
||||
})
|
||||
|
||||
var ctx = {};
|
||||
var p = new Proxy(target, {});
|
||||
var res = p.call(ctx, 1, 2);
|
||||
assert.sameValue(res, 3, "`apply` trap is missing");
|
||||
assert.sameValue(calls, 1, "target is called once");
|
||||
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");
|
||||
|
|
|
@ -24,17 +24,23 @@ features: [Proxy]
|
|||
---*/
|
||||
|
||||
var calls = 0;
|
||||
var _context;
|
||||
|
||||
function target(a, b) {
|
||||
assert.sameValue(this, ctx);
|
||||
calls += 1;
|
||||
return a + b;
|
||||
}
|
||||
var target = new Proxy(function() {}, {
|
||||
apply: function(_target, context, args) {
|
||||
calls++;
|
||||
_context = context;
|
||||
return args[0] + args[1];
|
||||
}
|
||||
})
|
||||
|
||||
var ctx = {};
|
||||
var p = new Proxy(target, {
|
||||
apply: undefined
|
||||
});
|
||||
var res = p.call(ctx, 1, 2);
|
||||
assert.sameValue(res, 3, "`apply` trap is `null`");
|
||||
assert.sameValue(calls, 1, "target is called once");
|
||||
|
||||
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");
|
||||
|
|
Loading…
Reference in New Issue