mirror of https://github.com/tc39/test262.git
Proxy: preventExtensions
This commit is contained in:
parent
15a9a15815
commit
79a256cd5a
|
@ -0,0 +1,31 @@
|
|||
// 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.4
|
||||
description: >
|
||||
Trap is called with handler on its context and target as the first
|
||||
parameter.
|
||||
info: >
|
||||
[[PreventExtensions]] ( )
|
||||
|
||||
...
|
||||
8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)).
|
||||
...
|
||||
---*/
|
||||
|
||||
var _target, _handler;
|
||||
var target = {};
|
||||
var handler = {
|
||||
preventExtensions: function(t) {
|
||||
_handler = this;
|
||||
_target = t;
|
||||
|
||||
return Object.preventExtensions(target);
|
||||
}
|
||||
};
|
||||
var p = new Proxy(target, handler);
|
||||
|
||||
Object.preventExtensions(p);
|
||||
|
||||
assert.sameValue(_handler, handler);
|
||||
assert.sameValue(_target, target);
|
|
@ -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.4
|
||||
description: >
|
||||
Throws a TypeError exception if handler is null.
|
||||
---*/
|
||||
|
||||
var p = Proxy.revocable({}, {});
|
||||
|
||||
p.revoke();
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.preventExtensions(p.proxy);
|
||||
});
|
|
@ -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.
|
||||
/*---
|
||||
es6id: 9.5.4
|
||||
description: >
|
||||
If boolean trap result if false, return false.
|
||||
features: [Reflect]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy({}, {
|
||||
preventExtensions: function(t) {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
assert.sameValue(Reflect.preventExtensions(p), false);
|
||||
|
||||
Object.preventExtensions(target);
|
||||
|
||||
assert.sameValue(Reflect.preventExtensions(p), false);
|
|
@ -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.4
|
||||
description: >
|
||||
Trap returns abrupt.
|
||||
info: >
|
||||
[[PreventExtensions]] ( )
|
||||
|
||||
...
|
||||
8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)).
|
||||
9. ReturnIfAbrupt(booleanTrapResult).
|
||||
...
|
||||
includes: [Test262Error.js]
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
preventExtensions: function(t) {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
Object.preventExtensions(p);
|
||||
});
|
|
@ -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.4
|
||||
description: >
|
||||
Throws a TypeError exception if boolean trap result is true and target is
|
||||
extensible.
|
||||
info: >
|
||||
[[PreventExtensions]] ( )
|
||||
|
||||
...
|
||||
10. If booleanTrapResult is true, then
|
||||
...
|
||||
c. If targetIsExtensible is true, throw a TypeError exception.
|
||||
11. Return booleanTrapResult.
|
||||
...
|
||||
---*/
|
||||
|
||||
var p = new Proxy({}, {
|
||||
preventExtensions: function(t) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.preventExtensions(p);
|
||||
});
|
|
@ -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.4
|
||||
description: >
|
||||
Return boolean trap result if its true and target is not extensible.
|
||||
features: [Reflect]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {
|
||||
preventExtensions: function(t) {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
Object.preventExtensions(target);
|
||||
|
||||
assert(Reflect.preventExtensions(p));
|
|
@ -0,0 +1,29 @@
|
|||
// 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.4
|
||||
description: >
|
||||
Throws a TypeError exception if trap is not callable.
|
||||
info: >
|
||||
[[PreventExtensions]] ( )
|
||||
|
||||
...
|
||||
1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
|
||||
...
|
||||
5. Let trap be GetMethod(handler, "preventExtensions").
|
||||
...
|
||||
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, {
|
||||
preventExtensions: {}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.preventExtensions(p);
|
||||
});
|
|
@ -0,0 +1,13 @@
|
|||
// 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.4
|
||||
description: >
|
||||
Return target.[[PreventExtensions]]() if target is undefined.
|
||||
features: [Reflect]
|
||||
---*/
|
||||
|
||||
var target = {};
|
||||
var p = new Proxy(target, {});
|
||||
|
||||
assert.sameValue(Reflect.preventExtensions(p), true);
|
Loading…
Reference in New Issue