From e9f7b74855ed1323dabc7620f5c17fcdefa06677 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Mon, 5 Oct 2020 12:21:59 -0400 Subject: [PATCH] Coverage: improved Reflect.apply testing with various inputs at args position. Fixes gh-2844 --- ...-list-is-not-array-like-but-still-valid.js | 80 ++++++++++++++++++ .../apply/arguments-list-is-not-array-like.js | 81 +++++++++++++------ 2 files changed, 137 insertions(+), 24 deletions(-) create mode 100644 test/built-ins/Reflect/apply/arguments-list-is-not-array-like-but-still-valid.js diff --git a/test/built-ins/Reflect/apply/arguments-list-is-not-array-like-but-still-valid.js b/test/built-ins/Reflect/apply/arguments-list-is-not-array-like-but-still-valid.js new file mode 100644 index 0000000000..9dca5a6141 --- /dev/null +++ b/test/built-ins/Reflect/apply/arguments-list-is-not-array-like-but-still-valid.js @@ -0,0 +1,80 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-reflect.apply +description: > + Return abrupt if argumentsList is not an ArrayLike object. +info: | + Reflect.apply ( target, thisArgument, argumentsList ) + + ... + Let args be ? CreateListFromArrayLike(argumentsList). + + + CreateListFromArrayLike (obj [, elementTypes] ) + + ... + If Type(obj) is not Object, throw a TypeError exception. + Let len be ? LengthOfArrayLike(obj). + Let list be a new empty List. + Let index be 0. + Repeat, while index < len, + Let indexName be ! ToString(index). + Let next be ? Get(obj, indexName). + If Type(next) is not an element of elementTypes, throw a TypeError exception. + Append next as the last element of list. + Set index to index + 1. + Return list. +includes: [compareArray.js] +features: [Reflect, arrow-function, Symbol] +---*/ + +let count = 0; + +function fn(...args) { + count++; + return args; +} + +let f_unction = new Function(); + +Object.defineProperty(f_unction, "length", { + get() { + return 1; + } +}); + +assert.compareArray(Reflect.apply(fn, null, f_unction), [undefined]); + +let object = new Object(); + +Object.defineProperty(object, "length", { + get() { + return 1; + } +}); + +assert.compareArray(Reflect.apply(fn, null, object), [undefined]); + +let number = new Number(); + +Object.defineProperty(number, "length", { + get() { + return 1; + } +}); + +assert.compareArray(Reflect.apply(fn, null, number), [undefined]); + +let boolean = new Boolean(); + +Object.defineProperty(boolean, "length", { + get() { + return 1; + } +}); + +assert.compareArray(Reflect.apply(fn, null, boolean), [undefined]); + +assert.sameValue(count, 4, 'The value of `count` is 1'); 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 index 5483682683..e0ff5503f4 100644 --- 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 @@ -1,40 +1,73 @@ // Copyright (C) 2015 the V8 project authors. All rights reserved. +// Copyright (C) 2020 Rick Waldron. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 26.1.1 +esid: sec-reflect.apply description: > Return abrupt if argumentsList is not an ArrayLike object. info: | - 26.1.1 Reflect.apply ( target, thisArgument, argumentsList ) + Reflect.apply ( target, thisArgument, argumentsList ) ... - 2. Let args be CreateListFromArrayLike(argumentsList). - 3. ReturnIfAbrupt(args). - ... + Let args be ? CreateListFromArrayLike(argumentsList). - 7.3.17 CreateListFromArrayLike (obj [, elementTypes] ) + + 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). - ... -features: [Reflect] + If Type(obj) is not Object, throw a TypeError exception. +features: [Reflect, arrow-function, Symbol] ---*/ -function fn() {} -var o = {}; +let count = 0; -Object.defineProperty(o, 'length', { - get: function() { - throw new Test262Error(); - } -}); +function fn() { + count++; +} -assert.throws(Test262Error, function() { - Reflect.apply(fn, 1, o); -}); +assert.throws(Test262Error, () => { + Reflect.apply(fn, null, { + get length() { + throw new Test262Error(); + } + }); +}, '`Reflect.apply(fn, null, {get length() {throw new Test262Error();}})` throws a Test262Error exception'); -assert.throws(TypeError, function() { - Reflect.apply(fn, 1, 1); -}); +assert.throws(TypeError, () => { + Reflect.apply(fn, null /* empty */); +}, '`Reflect.apply(fn, null /* empty */)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, Symbol()); +}, '`Reflect.apply(fn, null, Symbol())` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, 1); +}, '`Reflect.apply(fn, null, 1)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, Infinity); +}, '`Reflect.apply(fn, null, Infinity)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, null); +}, '`Reflect.apply(fn, null, null)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, undefined); +}, '`Reflect.apply(fn, null, undefined)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, false); +}, '`Reflect.apply(fn, null, false)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, true); +}, '`Reflect.apply(fn, null, true)` throws a TypeError exception'); + +assert.throws(TypeError, () => { + Reflect.apply(fn, null, NaN); +}, '`Reflect.apply(fn, null, NaN)` throws a TypeError exception'); + + +assert.sameValue(count, 0, 'The value of `count` is 0');