Add tests for Reflect.apply

This commit is contained in:
Leonardo Balter 2015-07-28 14:37:08 -04:00
parent ff961826da
commit bdcf4fd877
7 changed files with 182 additions and 0 deletions

View File

@ -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.1
description: >
Reflect.apply is configurable, writable and not enumerable.
info: >
26.1.1 Reflect.apply ( target, thisArgument, argumentsList )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(Reflect, 'apply');
verifyWritable(Reflect, 'apply');
verifyConfigurable(Reflect, 'apply');

View File

@ -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.1
description: >
Return abrupt if argumentsList is not an ArrayLike object.
info: >
26.1.1 Reflect.apply ( target, thisArgument, argumentsList )
...
2. Let args be CreateListFromArrayLike(argumentsList).
3. 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.apply(fn, 1, o);
});
assert.throws(TypeError, function() {
Reflect.apply(fn, 1, 1);
});

View File

@ -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.1
description: >
Call target with thisArgument and argumentsList
info: >
26.1.1 Reflect.apply ( target, thisArgument, argumentsList )
...
4. Perform PrepareForTailCall().
5. Return Call(target, thisArgument, args).
---*/
var o = {};
var count = 0;
var results, args;
function fn() {
count++;
results = {
thisArg: this,
args: arguments
};
}
Reflect.apply(fn, o, ['arg1', 2, , null]);
assert.sameValue(count, 1, 'Called target once');
assert.sameValue(results.thisArg, o, 'Called target with `o` as `this` object');
assert.sameValue(results.args.length, 4, 'Called target with 4 arguments');
assert.sameValue(results.args[0], 'arg1');
assert.sameValue(results.args[1], 2);
assert.sameValue(results.args[2], undefined);
assert.sameValue(results.args[3], null);

View File

@ -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.1
description: >
Reflect.apply.length value and property descriptor
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.apply.length, 3,
'The value of `Reflect.apply.length` is `3`'
);
verifyNotEnumerable(Reflect.apply, 'length');
verifyNotWritable(Reflect.apply, 'length');
verifyConfigurable(Reflect.apply, 'length');

View 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: 26.1.1
description: >
Reflect.apply.name value and property descriptor
info: >
26.1.1 Reflect.apply ( target, thisArgument, argumentsList )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.apply.name, 'apply',
'The value of `Reflect.apply.name` is `"apply"`'
);
verifyNotEnumerable(Reflect.apply, 'name');
verifyNotWritable(Reflect.apply, 'name');
verifyConfigurable(Reflect.apply, 'name');

View 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: 26.1.1
description: >
Return target result
info: >
26.1.1 Reflect.apply ( target, thisArgument, argumentsList )
...
4. Perform PrepareForTailCall().
5. Return Call(target, thisArgument, args).
---*/
var o = {};
function fn() {
return o;
}
var result = Reflect.apply(fn, 1, []);
assert.sameValue(result, o);

View File

@ -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: 26.1.1
description: >
Throws a TypeError if `target` is not callable.
info: >
26.1.1 Reflect.apply ( target, thisArgument, argumentsList )
1. If IsCallable(target) is false, throw a TypeError exception.
...
7.2.3 IsCallable ( argument )
1. ReturnIfAbrupt(argument).
2. If Type(argument) is not Object, return false.
3. If argument has a [[Call]] internal method, return true.
4. Return false.
---*/
assert.throws(TypeError, function() {
Reflect.apply(1, 1, []);
});
assert.throws(TypeError, function() {
Reflect.apply(null, 1, []);
});
assert.throws(TypeError, function() {
Reflect.apply({}, 1, []);
});