Merge pull request #2163 from shvaikalesh/function-apply

Improve Function#apply coverage
This commit is contained in:
Leo Balter 2019-05-15 14:43:16 -04:00 committed by GitHub
commit 0c67d0f1b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 218 additions and 230 deletions

View File

@ -1,27 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The Function.prototype.apply.length property has the attribute ReadOnly
es5id: 15.3.4.3_A10
description: >
Checking if varying the Function.prototype.apply.length property
fails
includes: [propertyHelper.js]
---*/
//CHECK#1
if (!(Function.prototype.apply.hasOwnProperty('length'))) {
$ERROR('#1: the Function.prototype.apply has length property.');
}
var obj = Function.prototype.apply.length;
verifyNotWritable(Function.prototype.apply, "length", null, function() {
return "shifted";
});
//CHECK#2
if (Function.prototype.apply.length !== obj) {
$ERROR('#2: the Function.prototype.apply length property has the attributes ReadOnly.');
}

View File

@ -1,27 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The Function.prototype.apply.length property has the attribute DontEnum
es5id: 15.3.4.3_A11
description: >
TChecking if enumerating the Function.prototype.apply.length
property fails
---*/
//CHECK#0
if (!(Function.prototype.apply.hasOwnProperty('length'))) {
$ERROR('#0: the Function.prototype.apply has length property.');
}
// CHECK#1
if (Function.prototype.apply.propertyIsEnumerable('length')) {
$ERROR('#1: the Function.prototype.apply.length property has the attributes DontEnum');
}
// CHECK#2
for (var p in Function.prototype.apply) {
if (p === "length")
$ERROR('#2: the Function.prototype.apply.length property has the attributes DontEnum');
}

View File

@ -1,11 +0,0 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es5id: 15.3.4.3_A13
description: If IsCallable(func) is false, then throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
Function.prototype.apply.call(undefined, {}, []);
});

View File

@ -1,11 +0,0 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es5id: 15.3.4.3_A14
description: If IsCallable(func) is false, then throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
Function.prototype.apply.call(null, {}, []);
});

View File

@ -1,11 +0,0 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es5id: 15.3.4.3_A15
description: If IsCallable(func) is false, then throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
Function.prototype.apply.call({}, {}, []);
});

View File

@ -1,26 +0,0 @@
// Copyright 2011 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: If IsCallable(func) is false, then throw a TypeError exception.
es5id: 15.3.4.3_A16
description: >
A RegExp is not a function, but it may be callable. Iff it is,
it's typeof should be 'function', in which case apply should
accept it as a valid this value.
---*/
var re = (/x/);
if (typeof re === 'function') {
Function.prototype.apply.call(re, undefined, ['x']);
} else {
try {
Function.prototype.bind.call(re, undefined);
$ERROR('#1: If IsCallable(func) is false, ' +
'then (bind should) throw a TypeError exception');
} catch (e) {
if (!(e instanceof TypeError)) {
$ERROR('#1: TypeError expected. Actual: ' + e);
}
}
}

View File

@ -1,23 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The length property of the apply method is 2
es5id: 15.3.4.3_A2_T1
description: Checking Function.prototype.apply.length
---*/
//CHECK#1
if (typeof Function.prototype.apply !== "function") {
$ERROR('#1: apply method defined');
}
//CHECK#2
if (typeof Function.prototype.apply.length === "undefined") {
$ERROR('#2: length property of apply method defined');
}
//CHECK#3
if (Function.prototype.apply.length !== 2) {
$ERROR('#3: The length property of the apply method is 2');
}

View File

@ -1,25 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: The length property of the apply method is 2
es5id: 15.3.4.3_A2_T2
description: Checking f.apply.length, where f is new Function
---*/
var f = new Function;
//CHECK#1
if (typeof f.apply !== "function") {
$ERROR('#1: apply method accessed');
}
//CHECK#2
if (typeof f.apply.length === "undefined") {
$ERROR('#2: length property of apply method defined');
}
//CHECK#3
if (f.apply.length !== 2) {
$ERROR('#3: The length property of the apply method is 2');
}

View File

@ -1,20 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: |
if argArray is neither an array nor an arguments object (see 10.1.8), a
TypeError exception is thrown
es5id: 15.3.4.3_A6_T2
description: argArray is (null,1)
---*/
//CHECK#1
try {
Function().apply(null, 1);
$ERROR('#1: if argArray is neither an array nor an arguments object (see 10.1.8), a TypeError exception is thrown');
} catch (e) {
if (!(e instanceof TypeError)) {
$ERROR('#1.1: if argArray is neither an array nor an arguments object (see 10.1.8), a TypeError exception is thrown');
}
}

View File

@ -1,22 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: |
if argArray is neither an array nor an arguments object (see 10.1.8), a
TypeError exception is thrown
es5id: 15.3.4.3_A6_T3
description: argArray is (object,"1,3,4")
---*/
var obj = {};
//CHECK#1
try {
Function().apply(obj, "1,3,4");
$ERROR('#1: if argArray is neither an array nor an arguments object (see 10.1.8), a TypeError exception is thrown');
} catch (e) {
if (!(e instanceof TypeError)) {
$ERROR('#1.1: if argArray is neither an array nor an arguments object (see 10.1.8), a TypeError exception is thrown');
}
}

View File

@ -1,27 +0,0 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: |
The Function.prototype.apply.length property does not have the attribute
DontDelete
es5id: 15.3.4.3_A9
description: >
Checking if deleting the Function.prototype.apply.length property
fails
---*/
//CHECK#0
if (!(Function.prototype.apply.hasOwnProperty('length'))) {
$ERROR('#0: the Function.prototype.apply has length property');
}
//CHECK#1
if (!delete Function.prototype.apply.length) {
$ERROR('#1: The Function.prototype.apply.length property does not have the attributes DontDelete');
}
//CHECK#2
if (Function.prototype.apply.hasOwnProperty('length')) {
$ERROR('#2: The Function.prototype.apply.length property does not have the attributes DontDelete');
}

View File

@ -0,0 +1,38 @@
// Copyright 2019 Aleksey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function.prototype.apply
description: >
Throws a TypeError exception if argArray is not an object
(honoring the Realm of the current execution context)
info: |
Function.prototype.apply ( thisArg, argArray )
[...]
4. Let argList be ? CreateListFromArrayLike(argArray).
CreateListFromArrayLike ( obj [ , elementTypes ] )
[...]
2. If Type(obj) is not Object, throw a TypeError exception.
features: [cross-realm]
---*/
var other = $262.createRealm().global;
var fn = new other.Function();
assert.throws(other.TypeError, function() {
fn.apply(null, false);
});
assert.throws(other.TypeError, function() {
fn.apply(null, 1234.5678);
});
assert.throws(other.TypeError, function() {
fn.apply(null, '');
});
assert.throws(other.TypeError, function() {
fn.apply(null, Symbol('desc'));
});

View File

@ -0,0 +1,35 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function.prototype.apply
description: >
Throws a TypeError exception if argArray is not an object
info: |
Function.prototype.apply ( thisArg, argArray )
[...]
4. Let argList be ? CreateListFromArrayLike(argArray).
CreateListFromArrayLike ( obj [ , elementTypes ] )
[...]
2. If Type(obj) is not Object, throw a TypeError exception.
---*/
function fn() {}
assert.throws(TypeError, function() {
fn.apply(null, true);
});
assert.throws(TypeError, function() {
fn.apply(null, NaN);
});
assert.throws(TypeError, function() {
fn.apply(null, '1,2,3');
});
assert.throws(TypeError, function() {
fn.apply(null, Symbol());
});

View File

@ -0,0 +1,31 @@
// Copyright 2019 Aleksey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function.prototype.apply
description: >
Return abrupt completion from Get(obj, indexName)
info: |
Function.prototype.apply ( thisArg, argArray )
[...]
4. Let argList be ? CreateListFromArrayLike(argArray).
CreateListFromArrayLike ( obj [ , elementTypes ] )
[...]
6. Repeat, while index < len
a. Let indexName be ! ToString(index).
b. Let next be ? Get(obj, indexName).
---*/
var arrayLike = {
length: 2,
0: 0,
get 1() {
throw new Test262Error();
},
};
assert.throws(Test262Error, function() {
(function() {}).apply(null, arrayLike);
});

View File

@ -0,0 +1,27 @@
// Copyright 2019 Aleksey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function.prototype.apply
description: >
Return abrupt completion from Get(obj, "length")
info: |
Function.prototype.apply ( thisArg, argArray )
[...]
4. Let argList be ? CreateListFromArrayLike(argArray).
CreateListFromArrayLike ( obj [ , elementTypes ] )
[...]
3. Let len be ? ToLength(? Get(obj, "length")).
---*/
var arrayLike = {
get length() {
throw new Test262Error();
},
};
assert.throws(Test262Error, function() {
(function() {}).apply(null, arrayLike);
});

View File

@ -0,0 +1,26 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function.prototype.apply
description: >
Function.prototype.apply.length is 2.
info: |
ECMAScript Standard Built-in Objects
...
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this value
is equal to the largest number of named arguments shown in the subclause
headings for the function description, including optional parameters.
...
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
---*/
verifyProperty(Function.prototype.apply, 'length', {
value: 2,
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,33 @@
// Copyright 2019 Aleksey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function.prototype.apply
description: >
Throws a TypeError exception if this value is not callable
(honoring the Realm of the current execution context)
info: |
Function.prototype.apply ( thisArg, argArray )
1. Let func be the this value.
2. If IsCallable(func) is false, throw a TypeError exception.
features: [cross-realm]
---*/
var other = $262.createRealm().global;
var otherApply = other.Function.prototype.apply;
assert.throws(other.TypeError, function() {
otherApply.call(undefined, {}, []);
});
assert.throws(other.TypeError, function() {
otherApply.call(null, {}, []);
});
assert.throws(other.TypeError, function() {
otherApply.call({}, {}, []);
});
assert.throws(other.TypeError, function() {
otherApply.call(/re/, {}, []);
});

View File

@ -0,0 +1,28 @@
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function.prototype.apply
description: >
Throws a TypeError exception if this value is not callable
info: |
Function.prototype.apply ( thisArg, argArray )
1. Let func be the this value.
2. If IsCallable(func) is false, throw a TypeError exception.
---*/
assert.throws(TypeError, function() {
Function.prototype.apply.call(undefined, {}, []);
});
assert.throws(TypeError, function() {
Function.prototype.apply.call(null, {}, []);
});
assert.throws(TypeError, function() {
Function.prototype.apply.call({}, {}, []);
});
assert.throws(TypeError, function() {
Function.prototype.apply.call(/re/, {}, []);
});