mirror of https://github.com/tc39/test262.git
Proxy: has
This commit is contained in:
parent
b2d4bcfd0e
commit
54e82687d7
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
A `in` check trigger trap.call(handler, target, P);
|
||||
info: >
|
||||
[[HasProperty]] (P)
|
||||
|
||||
...
|
||||
9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)).
|
||||
...
|
||||
---*/
|
||||
|
||||
var _handler, _target, _prop;
|
||||
var target = {};
|
||||
var handler = {
|
||||
has: function(t, prop) {
|
||||
_handler = this;
|
||||
_target = t;
|
||||
_prop = prop;
|
||||
|
||||
return prop in t;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
"attr" in p;
|
||||
|
||||
assert.sameValue(_handler, handler, "handler is context");
|
||||
assert.sameValue(_target, target, "target is the first parameter");
|
||||
assert.sameValue(_prop, "attr", "given prop is the second paramter");
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
`.. in Object.create(proxy)` triggers trap.call(handler, target, P);
|
||||
info: >
|
||||
[[HasProperty]] (P)
|
||||
|
||||
...
|
||||
2. Let handler be the value of the [[ProxyHandler]] internal slot of O.
|
||||
...
|
||||
5. Let target be the value of the [[ProxyTarget]] internal slot of O.
|
||||
6. Let trap be GetMethod(handler, "has").
|
||||
...
|
||||
9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)).
|
||||
...
|
||||
---*/
|
||||
|
||||
var _handler, _target, _prop;
|
||||
var target = {};
|
||||
var handler = {
|
||||
has: function(t, prop) {
|
||||
_handler = this;
|
||||
_target = t;
|
||||
_prop = prop;
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
"attr" in Object.create(p);
|
||||
|
||||
assert.sameValue(_handler, handler, "handler is context");
|
||||
assert.sameValue(_target, target, "target is the first parameter");
|
||||
assert.sameValue(_prop, "attr", "given prop is the second paramter");
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
A `with` variable check trigger trap.call(handler, target, P);
|
||||
info: >
|
||||
[[HasProperty]] (P)
|
||||
|
||||
...
|
||||
9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)).
|
||||
...
|
||||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var _handler, _target, _prop;
|
||||
var target = {};
|
||||
var handler = {
|
||||
has: function(t, prop) {
|
||||
_handler = this;
|
||||
_target = t;
|
||||
_prop = prop;
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
with (p) {
|
||||
(attr);
|
||||
}
|
||||
|
||||
assert.sameValue(_handler, handler);
|
||||
assert.sameValue(_target, target);
|
||||
assert.sameValue(_prop, "attr");
|
|
@ -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.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
Throws a TypeError exception if handler is null.
|
||||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var p = Proxy.revocable({}, {});
|
||||
|
||||
p.revoke();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
with (p.proxy) {
|
||||
(attr);
|
||||
}
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
Throws a TypeError exception if handler is null.
|
||||
---*/
|
||||
|
||||
var p = Proxy.revocable({}, {});
|
||||
|
||||
p.revoke();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
"attr" in p.proxy;
|
||||
});
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
A property cannot be reported as non-existent, if it exists as an own
|
||||
property of the target object and the target object is not extensible.
|
||||
info: >
|
||||
[[HasProperty]] (P)
|
||||
|
||||
...
|
||||
11. If booleanTrapResult is false, then
|
||||
a. Let targetDesc be target.[[GetOwnProperty]](P).
|
||||
b. ReturnIfAbrupt(targetDesc).
|
||||
c. If targetDesc is not undefined, then
|
||||
...
|
||||
ii. Let extensibleTarget be IsExtensible(target).
|
||||
...
|
||||
iv. If extensibleTarget is false, throw a TypeError exception.
|
||||
...
|
||||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var handler = {
|
||||
has: function(t, prop) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
Object.defineProperty(target, 'attr', {
|
||||
configurable: true,
|
||||
value: 1
|
||||
});
|
||||
|
||||
Object.preventExtensions(target);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
with (p) {
|
||||
(attr);
|
||||
}
|
||||
});
|
|
@ -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.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
A property cannot be reported as non-existent, if it exists as an own
|
||||
property of the target object and the target object is not extensible.
|
||||
info: >
|
||||
[[HasProperty]] (P)
|
||||
|
||||
...
|
||||
11. If booleanTrapResult is false, then
|
||||
a. Let targetDesc be target.[[GetOwnProperty]](P).
|
||||
b. ReturnIfAbrupt(targetDesc).
|
||||
c. If targetDesc is not undefined, then
|
||||
...
|
||||
ii. Let extensibleTarget be IsExtensible(target).
|
||||
...
|
||||
iv. If extensibleTarget is false, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var handler = {
|
||||
has: function(t, prop) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
Object.defineProperty(target, "attr", {
|
||||
configurable: true,
|
||||
value: 1
|
||||
});
|
||||
|
||||
Object.preventExtensions(target);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
"attr" in p;
|
||||
});
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
The result of [[HasProperty]] is a Boolean value and will affect has
|
||||
checkings. False returned when target property exists;
|
||||
info: >
|
||||
[[HasProperty]] (P)
|
||||
|
||||
...
|
||||
12. Return booleanTrapResult.
|
||||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
has: function(t, prop) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
var attr = 0;
|
||||
with (p) {
|
||||
assert.sameValue(attr, 0);
|
||||
}
|
|
@ -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.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
The result of [[HasProperty]] is a Boolean value and will affect has
|
||||
checkings. False returned when target property exists;
|
||||
info: >
|
||||
[[HasProperty]] (P)
|
||||
|
||||
...
|
||||
12. Return booleanTrapResult.
|
||||
---*/
|
||||
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
has: function(t, prop) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
assert.sameValue(("attr" in p), false);
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
A property cannot be reported as non-existent, if it exists as a
|
||||
non-configurable own property of the target object.
|
||||
info: >
|
||||
[[HasProperty]] (P)
|
||||
|
||||
...
|
||||
11. If booleanTrapResult is false, then
|
||||
...
|
||||
c. If targetDesc is not undefined, then
|
||||
i. If targetDesc.[[Configurable]] is false, throw a TypeError
|
||||
exception.
|
||||
...
|
||||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var handler = {
|
||||
has: function(t, prop) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
Object.defineProperty(target, "attr", {
|
||||
configurable: false,
|
||||
value: 1
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
with (p) {
|
||||
(attr);
|
||||
}
|
||||
});
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
A property cannot be reported as non-existent, if it exists as a
|
||||
non-configurable own property of the target object.
|
||||
info: >
|
||||
[[HasProperty]] (P)
|
||||
|
||||
...
|
||||
11. If booleanTrapResult is false, then
|
||||
...
|
||||
c. If targetDesc is not undefined, then
|
||||
i. If targetDesc.[[Configurable]] is false, throw a TypeError
|
||||
exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var handler = {
|
||||
has: function(t, prop) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
Object.defineProperty(target, "attr", {
|
||||
configurable: false,
|
||||
value: 1
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
"attr" in p;
|
||||
});
|
|
@ -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.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
Trap returns abrupt. Using `prop in obj`.
|
||||
info: >
|
||||
[[HasProperty]] (P)
|
||||
|
||||
...
|
||||
9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)).
|
||||
10. ReturnIfAbrupt(booleanTrapResult).
|
||||
...
|
||||
includes: [Test262Error.js]
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
has: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
"attr" in p;
|
||||
});
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
Trap returns abrupt. Using `with`.
|
||||
info: >
|
||||
[[HasProperty]] (P)
|
||||
|
||||
...
|
||||
9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)).
|
||||
10. ReturnIfAbrupt(booleanTrapResult).
|
||||
...
|
||||
flags: [noStrict]
|
||||
includes: [Test262Error.js]
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
has: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
with (p) {
|
||||
(attr);
|
||||
}
|
||||
});
|
|
@ -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.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
The result of [[HasProperty]] is a Boolean value and will affect has
|
||||
checkings. True returned when target property exists;
|
||||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
has: function(t, prop) {
|
||||
if (prop !== "assert") {
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var attr = 0;
|
||||
with (p) {
|
||||
assert.sameValue(attr, 1);
|
||||
}
|
|
@ -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.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
The result of [[HasProperty]] is a Boolean value and will affect has
|
||||
checkings. True returned when target property exists;
|
||||
---*/
|
||||
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
has: function(t, prop) {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
assert.sameValue(("attr" in p), true);
|
|
@ -0,0 +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.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
The result of [[HasProperty]] is a Boolean value and will affect has
|
||||
checkings. True returned when target property doesn't exists;
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
has: function(t, prop) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
assert.sameValue(("attr" in p), true);
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
Throws a TypeError exception if trap is not callable.
|
||||
info: >
|
||||
[[HasProperty]] (P)
|
||||
|
||||
...
|
||||
6. Let trap be GetMethod(handler, "has").
|
||||
...
|
||||
7.3.9 GetMethod (O, P)
|
||||
...
|
||||
2. Let func be GetV(O, P).
|
||||
5. If IsCallable(func) is false, throw a TypeError exception.
|
||||
...
|
||||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
has: {}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
with (p) {
|
||||
(attr);
|
||||
}
|
||||
});
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
Throws a TypeError exception if trap is not callable.
|
||||
info: >
|
||||
[[HasProperty]] (P)
|
||||
|
||||
...
|
||||
6. Let trap be GetMethod(handler, "has").
|
||||
...
|
||||
7.3.9 GetMethod (O, P)
|
||||
...
|
||||
2. Let func be GetV(O, P).
|
||||
5. If IsCallable(func) is false, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
has: {}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
"attr" in p;
|
||||
});
|
|
@ -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.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
Return target.[[HasProperty]](P) if trap is undefined.
|
||||
info: >
|
||||
[[HasProperty]] (P)
|
||||
|
||||
...
|
||||
8. If trap is undefined, then
|
||||
a. Return target.[[HasProperty]](P).
|
||||
...
|
||||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var target = Object.create(Array.prototype);
|
||||
var p = new Proxy(target, {});
|
||||
|
||||
var foo = 3;
|
||||
with (target) {
|
||||
assert.sameValue(length, 0);
|
||||
assert.sameValue(foo, 3);
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 9.5.7
|
||||
description: >
|
||||
Return target.[[HasProperty]](P) if trap is undefined.
|
||||
info: >
|
||||
[[HasProperty]] (P)
|
||||
|
||||
...
|
||||
8. If trap is undefined, then
|
||||
a. Return target.[[HasProperty]](P).
|
||||
...
|
||||
---*/
|
||||
|
||||
var target = Object.create(Array.prototype);
|
||||
var p = new Proxy(target, {});
|
||||
|
||||
assert.sameValue(("foo" in p), false);
|
||||
assert.sameValue(("length" in p), true);
|
Loading…
Reference in New Issue