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.
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// 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
|
es6id: 9.5.13
|
||||||
description: >
|
description: >
|
||||||
trap is called with handler object as its context, and parameters are:
|
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, _args, _handler, _context;
|
||||||
var target = function(a, b) {
|
var target = function() {
|
||||||
return a + b;
|
throw new Test262Error('target should not be called');
|
||||||
};
|
};
|
||||||
var handler = {
|
var handler = {
|
||||||
apply: function(t, c, args) {
|
apply: function(t, c, args) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// 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
|
es6id: 9.5.13
|
||||||
description: >
|
description: >
|
||||||
Return the result from the trap method.
|
Return the result from the trap method.
|
||||||
|
@ -11,15 +12,13 @@ info: |
|
||||||
features: [Proxy]
|
features: [Proxy]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
var target = function(a, b) {
|
|
||||||
return a + b;
|
|
||||||
};
|
|
||||||
var result = {};
|
var result = {};
|
||||||
var handler = {
|
var p = new Proxy(function() {
|
||||||
|
throw new Test262Error('target should not be called');
|
||||||
|
}, {
|
||||||
apply: function(t, c, args) {
|
apply: function(t, c, args) {
|
||||||
return result;
|
return result;
|
||||||
}
|
},
|
||||||
};
|
});
|
||||||
var p = new Proxy(target, handler);
|
|
||||||
|
|
||||||
assert.sameValue(p.call(), result);
|
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.
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// 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
|
es6id: 9.5.13
|
||||||
description: >
|
description: >
|
||||||
[[Call]] (thisArgument, argumentsList)
|
[[Call]] (thisArgument, argumentsList)
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// 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
|
es6id: 9.5.13
|
||||||
description: >
|
description: >
|
||||||
Return is an abrupt completion
|
Return is an abrupt completion
|
||||||
features: [Proxy]
|
features: [Proxy]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
var target = function(a, b) {
|
var p = new Proxy(function() {
|
||||||
return a + b;
|
throw 'not the Test262Error you are looking for';
|
||||||
};
|
}, {
|
||||||
var p = new Proxy(target, {
|
|
||||||
apply: function(t, c, args) {
|
apply: function(t, c, args) {
|
||||||
throw new Test262Error();
|
throw new Test262Error();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// 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
|
es6id: 9.5.13
|
||||||
description: >
|
description: >
|
||||||
Throws if trap is not callable.
|
Throws if trap is not callable.
|
||||||
|
|
|
@ -24,17 +24,23 @@ features: [Proxy]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
var calls = 0;
|
var calls = 0;
|
||||||
|
var _context;
|
||||||
|
|
||||||
function target(a, b) {
|
var target = new Proxy(function() {}, {
|
||||||
assert.sameValue(this, ctx);
|
apply: function(_target, context, args) {
|
||||||
calls += 1;
|
calls++;
|
||||||
return a + b;
|
_context = context;
|
||||||
}
|
return args[0] + args[1];
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
var ctx = {};
|
|
||||||
var p = new Proxy(target, {
|
var p = new Proxy(target, {
|
||||||
apply: null
|
apply: null
|
||||||
});
|
});
|
||||||
var res = p.call(ctx, 1, 2);
|
|
||||||
assert.sameValue(res, 3, "`apply` trap is `null`");
|
var context = {};
|
||||||
assert.sameValue(calls, 1, "target is called once");
|
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 calls = 0;
|
||||||
|
var _context;
|
||||||
|
|
||||||
function target(a, b) {
|
var target = new Proxy(function() {}, {
|
||||||
assert.sameValue(this, ctx);
|
apply: function(_target, context, args) {
|
||||||
calls += 1;
|
calls++;
|
||||||
return a + b;
|
_context = context;
|
||||||
}
|
return args[0] + args[1];
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
var ctx = {};
|
|
||||||
var p = new Proxy(target, {});
|
var p = new Proxy(target, {});
|
||||||
var res = p.call(ctx, 1, 2);
|
var context = {};
|
||||||
assert.sameValue(res, 3, "`apply` trap is missing");
|
var res = p.call(context, 1, 2);
|
||||||
assert.sameValue(calls, 1, "target is called once");
|
|
||||||
|
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 calls = 0;
|
||||||
|
var _context;
|
||||||
|
|
||||||
function target(a, b) {
|
var target = new Proxy(function() {}, {
|
||||||
assert.sameValue(this, ctx);
|
apply: function(_target, context, args) {
|
||||||
calls += 1;
|
calls++;
|
||||||
return a + b;
|
_context = context;
|
||||||
}
|
return args[0] + args[1];
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
var ctx = {};
|
|
||||||
var p = new Proxy(target, {
|
var p = new Proxy(target, {
|
||||||
apply: undefined
|
apply: undefined
|
||||||
});
|
});
|
||||||
var res = p.call(ctx, 1, 2);
|
|
||||||
assert.sameValue(res, 3, "`apply` trap is `null`");
|
var context = {};
|
||||||
assert.sameValue(calls, 1, "target is called once");
|
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