mirror of https://github.com/tc39/test262.git
Coverage: improved Reflect.apply testing with various inputs at args position. Fixes gh-2844
This commit is contained in:
parent
fd65b84378
commit
e9f7b74855
|
@ -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');
|
|
@ -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() {
|
||||
function fn() {
|
||||
count++;
|
||||
}
|
||||
|
||||
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(Test262Error, function() {
|
||||
Reflect.apply(fn, 1, o);
|
||||
});
|
||||
assert.throws(TypeError, () => {
|
||||
Reflect.apply(fn, null /* empty */);
|
||||
}, '`Reflect.apply(fn, null /* empty */)` throws a TypeError exception');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Reflect.apply(fn, 1, 1);
|
||||
});
|
||||
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');
|
||||
|
|
Loading…
Reference in New Issue