Skip to content
Snippets Groups Projects
Commit bdcf4fd8 authored by Leonardo Balter's avatar Leonardo Balter
Browse files

Add tests for Reflect.apply

parent ff961826
No related branches found
No related tags found
No related merge requests found
// 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');
// 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);
});
// 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);
// 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');
// 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');
// 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);
// 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, []);
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment