From bdcf4fd877e1bf5891778d48fd961cb43cc5a48d Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Tue, 28 Jul 2015 14:37:08 -0400 Subject: [PATCH] Add tests for Reflect.apply --- test/built-ins/Reflect/apply/apply.js | 17 ++++++++ .../apply/arguments-list-is-not-array-like.js | 39 +++++++++++++++++++ test/built-ins/Reflect/apply/call-target.js | 34 ++++++++++++++++ test/built-ins/Reflect/apply/length.js | 17 ++++++++ test/built-ins/Reflect/apply/name.js | 22 +++++++++++ .../apply/return-target-call-result.js | 22 +++++++++++ .../apply/target-is-not-callable-throws.js | 31 +++++++++++++++ 7 files changed, 182 insertions(+) create mode 100644 test/built-ins/Reflect/apply/apply.js create mode 100644 test/built-ins/Reflect/apply/arguments-list-is-not-array-like.js create mode 100644 test/built-ins/Reflect/apply/call-target.js create mode 100644 test/built-ins/Reflect/apply/length.js create mode 100644 test/built-ins/Reflect/apply/name.js create mode 100644 test/built-ins/Reflect/apply/return-target-call-result.js create mode 100644 test/built-ins/Reflect/apply/target-is-not-callable-throws.js diff --git a/test/built-ins/Reflect/apply/apply.js b/test/built-ins/Reflect/apply/apply.js new file mode 100644 index 0000000000..776c220cc0 --- /dev/null +++ b/test/built-ins/Reflect/apply/apply.js @@ -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'); diff --git a/test/built-ins/Reflect/apply/arguments-list-is-not-array-like.js b/test/built-ins/Reflect/apply/arguments-list-is-not-array-like.js new file mode 100644 index 0000000000..e99367ac54 --- /dev/null +++ b/test/built-ins/Reflect/apply/arguments-list-is-not-array-like.js @@ -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); +}); diff --git a/test/built-ins/Reflect/apply/call-target.js b/test/built-ins/Reflect/apply/call-target.js new file mode 100644 index 0000000000..cc6d8a7c76 --- /dev/null +++ b/test/built-ins/Reflect/apply/call-target.js @@ -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); diff --git a/test/built-ins/Reflect/apply/length.js b/test/built-ins/Reflect/apply/length.js new file mode 100644 index 0000000000..ed670ec794 --- /dev/null +++ b/test/built-ins/Reflect/apply/length.js @@ -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'); diff --git a/test/built-ins/Reflect/apply/name.js b/test/built-ins/Reflect/apply/name.js new file mode 100644 index 0000000000..cefc338d9d --- /dev/null +++ b/test/built-ins/Reflect/apply/name.js @@ -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'); diff --git a/test/built-ins/Reflect/apply/return-target-call-result.js b/test/built-ins/Reflect/apply/return-target-call-result.js new file mode 100644 index 0000000000..26cf62968e --- /dev/null +++ b/test/built-ins/Reflect/apply/return-target-call-result.js @@ -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); diff --git a/test/built-ins/Reflect/apply/target-is-not-callable-throws.js b/test/built-ins/Reflect/apply/target-is-not-callable-throws.js new file mode 100644 index 0000000000..5206a8c110 --- /dev/null +++ b/test/built-ins/Reflect/apply/target-is-not-callable-throws.js @@ -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, []); +});