mirror of
https://github.com/tc39/test262.git
synced 2025-07-29 17:04:31 +02:00
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) 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.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
es6id: 26.1.1
|
esid: sec-reflect.apply
|
||||||
description: >
|
description: >
|
||||||
Return abrupt if argumentsList is not an ArrayLike object.
|
Return abrupt if argumentsList is not an ArrayLike object.
|
||||||
info: |
|
info: |
|
||||||
26.1.1 Reflect.apply ( target, thisArgument, argumentsList )
|
Reflect.apply ( target, thisArgument, argumentsList )
|
||||||
|
|
||||||
...
|
...
|
||||||
2. Let args be CreateListFromArrayLike(argumentsList).
|
Let args be ? CreateListFromArrayLike(argumentsList).
|
||||||
3. ReturnIfAbrupt(args).
|
|
||||||
...
|
|
||||||
|
|
||||||
7.3.17 CreateListFromArrayLike (obj [, elementTypes] )
|
|
||||||
|
CreateListFromArrayLike (obj [, elementTypes] )
|
||||||
|
|
||||||
...
|
...
|
||||||
3. If Type(obj) is not Object, throw a TypeError exception.
|
If Type(obj) is not Object, throw a TypeError exception.
|
||||||
4. Let len be ToLength(Get(obj, "length")).
|
features: [Reflect, arrow-function, Symbol]
|
||||||
5. ReturnIfAbrupt(len).
|
|
||||||
...
|
|
||||||
features: [Reflect]
|
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
function fn() {}
|
let count = 0;
|
||||||
var o = {};
|
|
||||||
|
|
||||||
Object.defineProperty(o, 'length', {
|
function fn() {
|
||||||
get: function() {
|
count++;
|
||||||
throw new Test262Error();
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.throws(Test262Error, function() {
|
assert.throws(Test262Error, () => {
|
||||||
Reflect.apply(fn, 1, o);
|
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() {
|
assert.throws(TypeError, () => {
|
||||||
Reflect.apply(fn, 1, 1);
|
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');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user