mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 22:15:24 +02:00
Proxy: enumerate
This commit is contained in:
parent
d9edb3593a
commit
28f9d8dbd2
30
test/built-ins/Proxy/enumerate/call-parameters.js
Normal file
30
test/built-ins/Proxy/enumerate/call-parameters.js
Normal file
@ -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.11
|
||||
description: >
|
||||
Trap called as trap.call(handler, target)
|
||||
info: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
8. Let trapResult be Call(trap, handler, «target»).
|
||||
---*/
|
||||
|
||||
var x, _target, _handler;
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var handler = {
|
||||
enumerate: function(t) {
|
||||
_target = t;
|
||||
_handler = this;
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
try {
|
||||
for (x in p) {}
|
||||
} catch(e) {}
|
||||
|
||||
assert.sameValue(_handler, handler);
|
||||
assert.sameValue(_target, target);
|
20
test/built-ins/Proxy/enumerate/null-handler.js
Normal file
20
test/built-ins/Proxy/enumerate/null-handler.js
Normal file
@ -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.11
|
||||
description: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
2. If handler is null, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var p = Proxy.revocable({}, {});
|
||||
|
||||
p.revoke();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
for (x in p.proxy) {
|
||||
x;
|
||||
}
|
||||
});
|
@ -0,0 +1,23 @@
|
||||
// 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.11
|
||||
description: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
The result must be an Object
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
enumerate: function() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
for (x in p) {}
|
||||
});
|
@ -0,0 +1,23 @@
|
||||
// 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.11
|
||||
description: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
The result must be an Object
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
enumerate: function() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
for (x in p) {}
|
||||
});
|
@ -0,0 +1,23 @@
|
||||
// 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.11
|
||||
description: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
The result must be an Object
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
enumerate: function() {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
for (x 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.11
|
||||
description: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
The result must be an Object
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
enumerate: function() {
|
||||
return Symbol();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
for (x in p) {}
|
||||
});
|
@ -0,0 +1,23 @@
|
||||
// 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.11
|
||||
description: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
The result must be an Object
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {
|
||||
enumerate: function() {
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
for (x in p) {}
|
||||
});
|
24
test/built-ins/Proxy/enumerate/return-is-abrupt.js
Normal file
24
test/built-ins/Proxy/enumerate/return-is-abrupt.js
Normal file
@ -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.11
|
||||
description: >
|
||||
Trap returns abrupt.
|
||||
info: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
8. Let trapResult be Call(trap, handler, «target»).
|
||||
9. ReturnIfAbrupt(trapResult).
|
||||
includes: [Test262Error.js]
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var p = new Proxy({}, {
|
||||
enumerate: function(t) {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
for (x in p) {}
|
||||
});
|
@ -0,0 +1,23 @@
|
||||
// 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.11
|
||||
description: >
|
||||
Trap returns an iterator whose IteratorResult does not contain a value
|
||||
property.
|
||||
info: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
11. Return trapResult
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var p = new Proxy([1,2,3], {
|
||||
enumerate: function(t) {
|
||||
return {next: function() { return { done:true }; } };
|
||||
}
|
||||
});
|
||||
|
||||
for (x in p) {
|
||||
$ERROR("returned iterable interface from trap is flagged as done.");
|
||||
}
|
36
test/built-ins/Proxy/enumerate/return-trap-result.js
Normal file
36
test/built-ins/Proxy/enumerate/return-trap-result.js
Normal file
@ -0,0 +1,36 @@
|
||||
// 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.11
|
||||
description: >
|
||||
Trap returns a iterable result.
|
||||
info: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
11. Return trapResult
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var iter = [
|
||||
{done: false, value: 1},
|
||||
{done: false, value: 2},
|
||||
{done: false, value: 3},
|
||||
{done: true, value: 42}
|
||||
];
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var foo = { bar: 1 };
|
||||
var p = new Proxy(target, {
|
||||
enumerate: function() {
|
||||
return { next: function() { return iter.shift(); } };
|
||||
}
|
||||
});
|
||||
|
||||
var results = [];
|
||||
for (x in p) {
|
||||
results.push(x);
|
||||
}
|
||||
|
||||
assert(compareArray(results, [1,2,3]));
|
25
test/built-ins/Proxy/enumerate/trap-is-not-callable.js
Normal file
25
test/built-ins/Proxy/enumerate/trap-is-not-callable.js
Normal file
@ -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.11
|
||||
description: >
|
||||
Trap is not callable.
|
||||
info: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
5. Let trap be GetMethod(handler, "enumerate").
|
||||
...
|
||||
|
||||
7.3.9 GetMethod (O, P)
|
||||
|
||||
5. If IsCallable(func) is false, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var p = new Proxy({attr:1}, {
|
||||
enumerate: {}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
for (x in p) {}
|
||||
});
|
22
test/built-ins/Proxy/enumerate/trap-is-undefined.js
Normal file
22
test/built-ins/Proxy/enumerate/trap-is-undefined.js
Normal file
@ -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.
|
||||
/*---
|
||||
es6id: 9.5.11
|
||||
description: >
|
||||
[[Enumerate]] ()
|
||||
|
||||
7. If trap is undefined, then Return target.[[Enumerate]]().
|
||||
---*/
|
||||
|
||||
var x;
|
||||
var target = {
|
||||
attr: 1
|
||||
};
|
||||
var p = new Proxy(target, {});
|
||||
|
||||
var count = 0;
|
||||
for (x in p) {
|
||||
count++;
|
||||
}
|
||||
|
||||
assert.sameValue(count, 1);
|
Loading…
x
Reference in New Issue
Block a user