mirror of https://github.com/tc39/test262.git
Add tests for Reflect.preventExtensions
This commit is contained in:
parent
bc51cfa0e0
commit
e7f5f3cf58
|
@ -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: 26.1.12
|
||||
description: >
|
||||
Always returns true when target is an ordinary object.
|
||||
info: >
|
||||
26.1.12 Reflect.preventExtensions ( target )
|
||||
|
||||
...
|
||||
2. Return target.[[PreventExtensions]]().
|
||||
|
||||
9.1.4 [[PreventExtensions]] ( )
|
||||
|
||||
1. Set the value of the [[Extensible]] internal slot of O to false.
|
||||
2. Return true.
|
||||
---*/
|
||||
|
||||
var o = {};
|
||||
assert.sameValue(
|
||||
Reflect.preventExtensions(o), true,
|
||||
'returns true after preventing extentions on an object'
|
||||
);
|
||||
assert.sameValue(
|
||||
Reflect.preventExtensions(o), true,
|
||||
'returns true even if the object already prevents extentions'
|
||||
);
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 26.1.12
|
||||
description: >
|
||||
Reflect.preventExtensions.length value and property descriptor
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
Reflect.preventExtensions.length, 1,
|
||||
'The value of `Reflect.preventExtensions.length` is `1`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(Reflect.preventExtensions, 'length');
|
||||
verifyNotWritable(Reflect.preventExtensions, 'length');
|
||||
verifyConfigurable(Reflect.preventExtensions, 'length');
|
|
@ -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: 26.1.12
|
||||
description: >
|
||||
Reflect.preventExtensions.name value and property descriptor
|
||||
info: >
|
||||
26.1.12 Reflect.preventExtensions ( target )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
Reflect.preventExtensions.name, 'preventExtensions',
|
||||
'The value of `Reflect.preventExtensions.name` is `"preventExtensions"`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(Reflect.preventExtensions, 'name');
|
||||
verifyNotWritable(Reflect.preventExtensions, 'name');
|
||||
verifyConfigurable(Reflect.preventExtensions, 'name');
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 26.1.12
|
||||
description: >
|
||||
Prevent extentions on target.
|
||||
info: >
|
||||
26.1.12 Reflect.preventExtensions ( target )
|
||||
|
||||
...
|
||||
2. Return target.[[PreventExtensions]]().
|
||||
|
||||
9.1.4 [[PreventExtensions]] ( )
|
||||
|
||||
1. Set the value of the [[Extensible]] internal slot of O to false.
|
||||
...
|
||||
---*/
|
||||
|
||||
var o = {};
|
||||
Reflect.preventExtensions(o);
|
||||
assert.sameValue(Object.isExtensible(o), false, 'object is not extensible');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Object.defineProperty(o, 'y', {});
|
||||
});
|
||||
assert.throws(TypeError, function() {
|
||||
Object.setPrototypeOf(o, Array.prototype);
|
||||
});
|
||||
|
||||
Reflect.preventExtensions(o);
|
||||
assert.sameValue(
|
||||
Object.isExtensible(o), false,
|
||||
'object is still not extensible on exhausted calls'
|
||||
);
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 26.1.12
|
||||
description: >
|
||||
Reflect.preventExtensions is configurable, writable and not enumerable.
|
||||
info: >
|
||||
26.1.12 Reflect.preventExtensions ( target )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
verifyNotEnumerable(Reflect, 'preventExtensions');
|
||||
verifyWritable(Reflect, 'preventExtensions');
|
||||
verifyConfigurable(Reflect, 'preventExtensions');
|
|
@ -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: 26.1.12
|
||||
description: >
|
||||
Return abrupt result.
|
||||
info: >
|
||||
26.1.12 Reflect.preventExtensions ( target )
|
||||
|
||||
...
|
||||
2. Return target.[[PreventExtensions]]().
|
||||
features: [Proxy]
|
||||
---*/
|
||||
|
||||
var o1 = {};
|
||||
var p = new Proxy(o1, {
|
||||
preventExtensions: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
Reflect.preventExtensions(p);
|
||||
});
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 26.1.12
|
||||
description: >
|
||||
Returns boolean from Proxy object.
|
||||
info: >
|
||||
26.1.12 Reflect.preventExtensions ( target )
|
||||
|
||||
...
|
||||
2. Return target.[[PreventExtensions]]().
|
||||
|
||||
9.5.4 [[PreventExtensions]] ( )
|
||||
|
||||
8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)).
|
||||
9. ReturnIfAbrupt(booleanTrapResult).
|
||||
10. If booleanTrapResult is true, then
|
||||
a. Let targetIsExtensible be target.[[IsExtensible]]().
|
||||
b. ReturnIfAbrupt(targetIsExtensible).
|
||||
c. If targetIsExtensible is true, throw a TypeError exception.
|
||||
11. Return booleanTrapResult.
|
||||
features: [Proxy]
|
||||
---*/
|
||||
|
||||
var p1 = new Proxy({}, {
|
||||
preventExtensions: function() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
assert.sameValue(
|
||||
Reflect.preventExtensions(p1), false,
|
||||
'returns false from Proxy handler'
|
||||
);
|
||||
|
||||
var p2 = new Proxy({}, {
|
||||
preventExtensions: function(target) {
|
||||
Object.preventExtensions(target);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
assert.sameValue(
|
||||
Reflect.preventExtensions(p2), true,
|
||||
'returns true from Proxy handler'
|
||||
);
|
|
@ -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: 26.1.10
|
||||
description: >
|
||||
Throws a TypeError if target is not an Object.
|
||||
info: >
|
||||
26.1.10 Reflect.isExtensible (target)
|
||||
|
||||
1. If Type(target) is not Object, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.isExtensible(1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.isExtensible(null);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.isExtensible(undefined);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.isExtensible('');
|
||||
});
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 26.1.10
|
||||
description: >
|
||||
Throws a TypeError if target is a Symbol
|
||||
info: >
|
||||
26.1.10 Reflect.isExtensible (target)
|
||||
|
||||
1. If Type(target) is not Object, throw a TypeError exception.
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.isExtensible(Symbol(1));
|
||||
});
|
Loading…
Reference in New Issue