mirror of https://github.com/tc39/test262.git
Add tests for Reflect.construct
This commit is contained in:
parent
bdcf4fd877
commit
980e50441f
|
@ -0,0 +1,39 @@
|
|||
// 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.2
|
||||
description: >
|
||||
Return abrupt if argumentsList is not an ArrayLike object.
|
||||
info: >
|
||||
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
|
||||
|
||||
...
|
||||
4. Let args be CreateListFromArrayLike(argumentsList).
|
||||
5. ReturnIfAbrupt(args).
|
||||
...
|
||||
|
||||
7.3.17 CreateListFromArrayLike (obj [, elementTypes] )
|
||||
|
||||
...
|
||||
3. If Type(obj) is not Object, throw a TypeError exception.
|
||||
4. Let len be ToLength(Get(obj, "length")).
|
||||
5. ReturnIfAbrupt(len).
|
||||
...
|
||||
---*/
|
||||
|
||||
function fn() {}
|
||||
var o = {};
|
||||
|
||||
Object.defineProperty(o, 'length', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
Reflect.construct(fn, o);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.construct(fn, 1);
|
||||
});
|
|
@ -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.2
|
||||
description: >
|
||||
Reflect.construct is configurable, writable and not enumerable.
|
||||
info: >
|
||||
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
verifyNotEnumerable(Reflect, 'construct');
|
||||
verifyWritable(Reflect, 'construct');
|
||||
verifyConfigurable(Reflect, 'construct');
|
|
@ -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: 26.1.2
|
||||
description: >
|
||||
Reflect.construct.length value and property descriptor
|
||||
info: >
|
||||
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
|
||||
|
||||
The length property of the construct function is 2.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
Reflect.construct.length, 2,
|
||||
'The value of `Reflect.construct.length` is `2`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(Reflect.construct, 'length');
|
||||
verifyNotWritable(Reflect.construct, 'length');
|
||||
verifyConfigurable(Reflect.construct, '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.2
|
||||
description: >
|
||||
Reflect.construct.name value and property descriptor
|
||||
info: >
|
||||
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
Reflect.construct.name, 'construct',
|
||||
'The value of `Reflect.construct.name` is `"construct"`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(Reflect.construct, 'name');
|
||||
verifyNotWritable(Reflect.construct, 'name');
|
||||
verifyConfigurable(Reflect.construct, 'name');
|
|
@ -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: 26.1.2
|
||||
description: >
|
||||
Throws a TypeError if `newTarget` is not a constructor.
|
||||
info: >
|
||||
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
|
||||
|
||||
...
|
||||
2. If newTarget is not present, let newTarget be target.
|
||||
3. Else, if IsConstructor(newTarget) is false, throw a TypeError exception.
|
||||
...
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.construct(function() {}, [], 1);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.construct(function() {}, [], null);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.construct(function() {}, [], {});
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.construct(function() {}, [], Date.now);
|
||||
});
|
|
@ -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: 26.1.2
|
||||
description: >
|
||||
Return target result using newTarget argument.
|
||||
info: >
|
||||
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
|
||||
|
||||
...
|
||||
2. If newTarget is not present, let newTarget be target.
|
||||
...
|
||||
6. Return Construct(target, args, newTarget).
|
||||
---*/
|
||||
|
||||
var o = {};
|
||||
var internPrototype;
|
||||
function fn() {
|
||||
this.o = o;
|
||||
internPrototype = Object.getPrototypeOf(this);
|
||||
}
|
||||
|
||||
var result = Reflect.construct(fn, [], Array);
|
||||
assert.sameValue(Object.getPrototypeOf(result), Array.prototype);
|
||||
assert.sameValue(
|
||||
internPrototype, Array.prototype,
|
||||
'prototype of this from within the constructor function is Array.prototype'
|
||||
);
|
||||
assert.sameValue(result.o, o);
|
|
@ -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.2
|
||||
description: >
|
||||
Return target result
|
||||
info: >
|
||||
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
|
||||
|
||||
...
|
||||
2. If newTarget is not present, let newTarget be target.
|
||||
...
|
||||
6. Return Construct(target, args, newTarget).
|
||||
---*/
|
||||
|
||||
var o = {};
|
||||
function fn() {
|
||||
this.o = o;
|
||||
}
|
||||
|
||||
var result = Reflect.construct(fn, []);
|
||||
|
||||
assert.sameValue(result.o, o);
|
||||
assert(result instanceof fn);
|
|
@ -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.2
|
||||
description: >
|
||||
Throws a TypeError if `target` is not a constructor.
|
||||
info: >
|
||||
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
|
||||
|
||||
1. If IsConstructor(target) is false, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.construct(1, []);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.construct(null, []);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.construct({}, []);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.construct(Date.now, []);
|
||||
});
|
|
@ -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: 26.1.2
|
||||
description: >
|
||||
Construct with given argumentsList
|
||||
info: >
|
||||
26.1.2 Reflect.construct ( target, argumentsList [, newTarget] )
|
||||
|
||||
...
|
||||
2. If newTarget is not present, let newTarget be target.
|
||||
...
|
||||
6. Return Construct(target, args, newTarget).
|
||||
---*/
|
||||
|
||||
function fn() {
|
||||
this.args = arguments;
|
||||
}
|
||||
|
||||
var result = Reflect.construct(fn, [42, 'Mike', 'Leo']);
|
||||
|
||||
assert.sameValue(result.args.length, 3, 'result.args.length');
|
||||
assert.sameValue(result.args[0], 42);
|
||||
assert.sameValue(result.args[1], 'Mike');
|
||||
assert.sameValue(result.args[2], 'Leo');
|
Loading…
Reference in New Issue