diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/Function/prototype/apply | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Function/prototype/apply')
49 files changed, 1108 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/15.3.4.3-1-s-strict.js b/js/src/tests/test262/built-ins/Function/prototype/apply/15.3.4.3-1-s-strict.js new file mode 100644 index 0000000000..7476a5e793 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/15.3.4.3-1-s-strict.js @@ -0,0 +1,20 @@ +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 15.3.4.3-1-s +description: > + Strict Mode - 'this' value is a string which cannot be converted + to wrapper objects when the function is called with an array of + arguments +flags: [onlyStrict] +---*/ + +function fun() { + return (this instanceof String); +} + +assert.sameValue(fun.apply("", Array), false, 'fun.apply("", Array)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/15.3.4.3-2-s-strict.js b/js/src/tests/test262/built-ins/Function/prototype/apply/15.3.4.3-2-s-strict.js new file mode 100644 index 0000000000..0c10432012 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/15.3.4.3-2-s-strict.js @@ -0,0 +1,20 @@ +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 15.3.4.3-2-s +description: > + Strict Mode - 'this' value is a number which cannot be converted + to wrapper objects when the function is called with an array of + arguments +flags: [onlyStrict] +---*/ + +function fun() { + return (this instanceof Number); +} + +assert.sameValue(fun.apply(-12, Array), false, 'fun.apply(-12, Array)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/15.3.4.3-3-s-strict.js b/js/src/tests/test262/built-ins/Function/prototype/apply/15.3.4.3-3-s-strict.js new file mode 100644 index 0000000000..6cb8cbeca1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/15.3.4.3-3-s-strict.js @@ -0,0 +1,20 @@ +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 15.3.4.3-3-s +description: > + Strict Mode - 'this' value is a boolean which cannot be converted + to wrapper objects when the function is called with an array of + arguments +flags: [onlyStrict] +---*/ + +function fun() { + return (this instanceof Boolean); +} + +assert.sameValue(fun.apply(false, Array), false, 'fun.apply(false, Array)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A12.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A12.js new file mode 100644 index 0000000000..d57a3bd809 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A12.js @@ -0,0 +1,17 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Function.prototype.apply has not prototype property +es5id: 15.3.4.3_A12 +description: > + Checking if obtaining the prototype property of + Function.prototype.apply fails +---*/ +assert.sameValue( + Function.prototype.apply.prototype, + undefined, + 'The value of Function.prototype.apply.prototype is expected to equal undefined' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A1_T1.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A1_T1.js new file mode 100644 index 0000000000..dee75c43ec --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A1_T1.js @@ -0,0 +1,32 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The apply method performs a function call using the [[Call]] property of + the object. If the object does not have a [[Call]] property, a TypeError + exception is thrown +es5id: 15.3.4.3_A1_T1 +description: > + Calling "apply" method of the object that does not have a [[Call]] + property. Prototype of the object is Function() +---*/ + +var proto = Function(); + +function FACTORY() {} + +FACTORY.prototype = proto; + +var obj = new FACTORY; + +assert.sameValue(typeof obj.apply, "function", 'The value of `typeof obj.apply` is expected to be "function"'); + +try { + obj.apply(); + throw new Test262Error('#2: If the object does not have a [[Call]] property, a TypeError exception is thrown'); +} catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A1_T2.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A1_T2.js new file mode 100644 index 0000000000..3bf968716d --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A1_T2.js @@ -0,0 +1,30 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The apply method performs a function call using the [[Call]] property of + the object. If the object does not have a [[Call]] property, a TypeError + exception is thrown +es5id: 15.3.4.3_A1_T2 +description: > + Calling "apply" method of the object that does not have a [[Call]] + property. Prototype of the object is Function.prototype +---*/ + +function FACTORY() {} + +FACTORY.prototype = Function.prototype; + +var obj = new FACTORY; + +assert.sameValue(typeof obj.apply, "function", 'The value of `typeof obj.apply` is expected to be "function"'); + +try { + obj.apply(); + throw new Test262Error('#2: If the object does not have a [[Call]] property, a TypeError exception is thrown'); +} catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T1.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T1.js new file mode 100644 index 0000000000..024b06f90c --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T1.js @@ -0,0 +1,16 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T1 +description: Not any arguments at apply function +---*/ + +Function("this.field=\"strawberry\"").apply(); + +assert.sameValue(this["field"], "strawberry", 'The value of this["field"] is expected to be "strawberry"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T10.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T10.js new file mode 100644 index 0000000000..2b572d62ec --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T10.js @@ -0,0 +1,17 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T10 +description: Checking by using eval, no any arguments at apply function +flags: [noStrict] +---*/ + +eval(" (function(){this.feat=1}).apply()"); + +assert.sameValue(this["feat"], 1, 'The value of this["feat"] is expected to be 1'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T2.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T2.js new file mode 100644 index 0000000000..91c17f39cf --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T2.js @@ -0,0 +1,16 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T2 +description: Argument at apply function is null +---*/ + +Function("this.field=\"green\"").apply(null); + +assert.sameValue(this["field"], "green", 'The value of this["field"] is expected to be "green"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T3.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T3.js new file mode 100644 index 0000000000..a104a919b7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T3.js @@ -0,0 +1,16 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T3 +description: Argument at apply function is void 0 +---*/ + +Function("this.field=\"battle\"").apply(void 0); + +assert.sameValue(this["field"], "battle", 'The value of this["field"] is expected to be "battle"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T4.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T4.js new file mode 100644 index 0000000000..ae0aaa4519 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T4.js @@ -0,0 +1,16 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T4 +description: Argument at apply function is undefined +---*/ + +Function("this.field=\"oil\"").apply(undefined); + +assert.sameValue(this["field"], "oil", 'The value of this["field"] is expected to be "oil"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T5.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T5.js new file mode 100644 index 0000000000..7e898f1b28 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T5.js @@ -0,0 +1,23 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T5 +description: > + No any arguments at apply function and it called inside function + declaration +---*/ + +function FACTORY() { + Function("this.feat=\"in da haus\"").apply(); +} + +var obj = new FACTORY; + +assert.sameValue(this["feat"], "in da haus", 'The value of this["feat"] is expected to be "in da haus"'); +assert.sameValue(typeof obj.feat, "undefined", 'The value of `typeof obj.feat` is expected to be "undefined"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T6.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T6.js new file mode 100644 index 0000000000..3da4007a09 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T6.js @@ -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. + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T6 +description: > + Argument at apply function is null and it called inside function + declaration +flags: [noStrict] +---*/ + +function FACTORY() { + (function() { + this.feat = "kamon beyba" + }).apply(null); +} + +var obj = new FACTORY; + +assert.sameValue(this["feat"], "kamon beyba", 'The value of this["feat"] is expected to be "kamon beyba"'); +assert.sameValue(typeof obj.feat, "undefined", 'The value of `typeof obj.feat` is expected to be "undefined"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T7.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T7.js new file mode 100644 index 0000000000..db00cfd8ad --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T7.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T7 +description: > + Argument at apply function is void 0 and it called inside function + declaration +---*/ + +(function FACTORY() { + Function("this.feat=\"in da haus\"").apply(void 0); +})(); + + +assert.sameValue(this["feat"], "in da haus", 'The value of this["feat"] is expected to be "in da haus"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T8.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T8.js new file mode 100644 index 0000000000..40fcf50b57 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T8.js @@ -0,0 +1,23 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T8 +description: > + Argument at apply function is undefined and it called inside + function declaration +flags: [noStrict] +---*/ + +(function FACTORY() { + (function() { + this.feat = "kamon beyba" + }).apply(undefined); +})(); + +assert.sameValue(this["feat"], "kamon beyba", 'The value of this["feat"] is expected to be "kamon beyba"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T9.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T9.js new file mode 100644 index 0000000000..87ea761026 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A3_T9.js @@ -0,0 +1,16 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T9 +description: Checking by using eval, argument at apply function is void 0 +---*/ + +eval(" Function(\"this.feat=1\").apply(void 0) "); + +assert.sameValue(this["feat"], 1, 'The value of this["feat"] is expected to be 1'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T1.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T1.js new file mode 100644 index 0000000000..ae2c48c6dc --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T1.js @@ -0,0 +1,19 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.3_A5_T1 +description: thisArg is number +---*/ + +var obj = 1; + +var retobj = Function("this.touched= true; return this;").apply(obj); + +assert.sameValue(typeof obj.touched, "undefined", 'The value of `typeof obj.touched` is expected to be "undefined"'); +assert(retobj["touched"], 'The value of retobj["touched"] is expected to be true'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T2.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T2.js new file mode 100644 index 0000000000..051f441a1d --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T2.js @@ -0,0 +1,19 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.3_A5_T2 +description: thisArg is boolean true +---*/ + +var obj = true; + +var retobj = new Function("this.touched= true; return this;").apply(obj); + +assert.sameValue(typeof obj.touched, "undefined", 'The value of `typeof obj.touched` is expected to be "undefined"'); +assert(retobj["touched"], 'The value of retobj["touched"] is expected to be true'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T3.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T3.js new file mode 100644 index 0000000000..42848413ef --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T3.js @@ -0,0 +1,23 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.3_A5_T3 +description: thisArg is string +flags: [noStrict] +---*/ + +var obj = "soap"; + +var retobj = (function() { + this.touched = true; + return this; +}).apply(obj); + +assert.sameValue(typeof obj.touched, "undefined", 'The value of `typeof obj.touched` is expected to be "undefined"'); +assert(retobj["touched"], 'The value of retobj["touched"] is expected to be true'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T4.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T4.js new file mode 100644 index 0000000000..4a572f5e03 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T4.js @@ -0,0 +1,25 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.3_A5_T4 +description: thisArg is function variable that return this +flags: [noStrict] +---*/ + +f = function() { + this.touched = true; + return this; +}; + +retobj = f.apply(obj); + +assert.sameValue(typeof obj, "undefined", 'The value of `typeof obj` is expected to be "undefined"'); +assert(retobj["touched"], 'The value of retobj["touched"] is expected to be true'); + +var obj; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T5.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T5.js new file mode 100644 index 0000000000..ee39f67ee9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T5.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.3_A5_T5 +description: thisArg is function variable +---*/ + +var f = function() { + this.touched = true; +}; + +var obj = {}; + +f.apply(obj); + +assert(obj.touched, 'The value of obj.touched is expected to be true'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T6.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T6.js new file mode 100644 index 0000000000..1251383daf --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T6.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.3_A5_T6 +description: thisArg is new String() +---*/ + +var obj = new String("soap"); + +(function() { + this.touched = true; +}).apply(obj); + +assert(obj.touched, 'The value of obj.touched is expected to be true'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T7.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T7.js new file mode 100644 index 0000000000..3e73fd5c22 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T7.js @@ -0,0 +1,18 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.3_A5_T7 +description: thisArg is new Number() +---*/ + +var obj = new Number(1); + +Function("this.touched= true;").apply(obj); + +assert(obj.touched, 'The value of obj.touched is expected to be true'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T8.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T8.js new file mode 100644 index 0000000000..4107519a6e --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A5_T8.js @@ -0,0 +1,18 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.3_A5_T8 +description: thisArg is Function() +---*/ + +var obj = Function(); + +new Function("this.touched= true; return this;").apply(obj); + +assert(obj.touched, 'The value of obj.touched is expected to be true'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T1.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T1.js new file mode 100644 index 0000000000..b87d4f9477 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T1.js @@ -0,0 +1,16 @@ +// 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 either an array or an arguments object, + the function is passed the (ToUint32(argArray.length)) arguments argArray[0], argArray[1],...,argArray[ToUint32(argArray.length)-1] +es5id: 15.3.4.3_A7_T1 +description: argArray is (null,[1]) +---*/ + +Function("a1,a2,a3", "this.shifted=a1;").apply(null, [1]); + +assert.sameValue(this["shifted"], 1, 'The value of this["shifted"] is expected to be 1'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T10.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T10.js new file mode 100644 index 0000000000..82dbdec6af --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T10.js @@ -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. + +/*--- +info: | + If argArray is either an array or an arguments object, + the function is passed the (ToUint32(argArray.length)) arguments argArray[0], argArray[1],...,argArray[ToUint32(argArray.length)-1] +es5id: 15.3.4.3_A7_T10 +description: > + argArray is (empty object, arguments), inside function call + without declaration used +---*/ + +var obj = {}; + +(function() { + Function("a1,a2,a3", "this.shifted=a1+a2+a3;").apply(obj, arguments); +})("", 4, 2); + +assert.sameValue(obj["shifted"], "42", 'The value of obj["shifted"] is expected to be "42"'); + +assert.sameValue( + typeof this["shifted"], + "undefined", + 'The value of `typeof this["shifted"]` is expected to be "undefined"' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T2.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T2.js new file mode 100644 index 0000000000..6a567da061 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T2.js @@ -0,0 +1,16 @@ +// 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 either an array or an arguments object, + the function is passed the (ToUint32(argArray.length)) arguments argArray[0], argArray[1],...,argArray[ToUint32(argArray.length)-1] +es5id: 15.3.4.3_A7_T2 +description: argArray is (null,[1,2,3]) +---*/ + +new Function("a1,a2", "a3", "this.shifted=a2;").apply(null, [1, 2, 3]); + +assert.sameValue(this["shifted"], 2, 'The value of this["shifted"] is expected to be 2'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T3.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T3.js new file mode 100644 index 0000000000..cc892830b3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T3.js @@ -0,0 +1,32 @@ +// 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 either an array or an arguments object, + the function is passed the (ToUint32(argArray.length)) arguments argArray[0], argArray[1],...,argArray[ToUint32(argArray.length)-1] +es5id: 15.3.4.3_A7_T3 +description: argArray is (empty object, new Array("nine","inch","nails")) +---*/ + +var i = 0; + +var p = { + toString: function() { + return "a" + (++i); + } +}; + +var obj = {}; + +Function(p, "a2,a3", "this.shifted=a1;").apply(obj, new Array("nine", "inch", "nails")); + +assert.sameValue(obj["shifted"], "nine", 'The value of obj["shifted"] is expected to be "nine"'); + +assert.sameValue( + typeof this["shifted"], + "undefined", + 'The value of `typeof this["shifted"]` is expected to be "undefined"' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T4.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T4.js new file mode 100644 index 0000000000..cba2cedc06 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T4.js @@ -0,0 +1,36 @@ +// 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 either an array or an arguments object, + the function is passed the (ToUint32(argArray.length)) arguments argArray[0], argArray[1],...,argArray[ToUint32(argArray.length)-1] +es5id: 15.3.4.3_A7_T4 +description: > + argArray is (empty object, ( function(){return arguments;}) + ("a","b","c")) +---*/ + +var i = 0; + +var p = { + toString: function() { + return "a" + (++i); + } +}; + +var obj = {}; + +new Function(p, p, p, "this.shifted=a3;").apply(obj, (function() { + return arguments; +})("a", "b", "c")); + +assert.sameValue(obj["shifted"], "c", 'The value of obj["shifted"] is expected to be "c"'); + +assert.sameValue( + typeof this["shifted"], + "undefined", + 'The value of `typeof this["shifted"]` is expected to be "undefined"' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T5.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T5.js new file mode 100644 index 0000000000..42df4ad2c0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T5.js @@ -0,0 +1,21 @@ +// 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 either an array or an arguments object, + the function is passed the (ToUint32(argArray.length)) arguments argArray[0], argArray[1],...,argArray[ToUint32(argArray.length)-1] +es5id: 15.3.4.3_A7_T5 +description: argArray is (null, arguments), inside function declaration used +---*/ + +function FACTORY() { + Function("a1,a2,a3", "this.shifted=a1+a2+a3;").apply(null, arguments); +} + +var obj = new FACTORY("", 1, 2); + +assert.sameValue(this["shifted"], "12", 'The value of this["shifted"] is expected to be "12"'); +assert.sameValue(typeof obj.shifted, "undefined", 'The value of `typeof obj.shifted` is expected to be "undefined"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T6.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T6.js new file mode 100644 index 0000000000..fd83bfcb70 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T6.js @@ -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. + +/*--- +info: | + If argArray is either an array or an arguments object, + the function is passed the (ToUint32(argArray.length)) arguments argArray[0], argArray[1],...,argArray[ToUint32(argArray.length)-1] +es5id: 15.3.4.3_A7_T6 +description: argArray is (this, arguments), inside function declaration used +---*/ + +function FACTORY() { + Function("a1,a2,a3", "this.shifted=a1+a2+a3;").apply(this, arguments); +} + +var obj = new FACTORY("", 4, 2); + +assert.sameValue(obj["shifted"], "42", 'The value of obj["shifted"] is expected to be "42"'); + +assert.sameValue( + typeof this["shifted"], + "undefined", + 'The value of `typeof this["shifted"]` is expected to be "undefined"' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T7.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T7.js new file mode 100644 index 0000000000..7bea364ab3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T7.js @@ -0,0 +1,20 @@ +// 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 either an array or an arguments object, + the function is passed the (ToUint32(argArray.length)) arguments argArray[0], argArray[1],...,argArray[ToUint32(argArray.length)-1] +es5id: 15.3.4.3_A7_T7 +description: > + argArray is (null, arguments), inside function call without + declaration used +---*/ + +(function() { + Function("a1,a2,a3", "this.shifted=a1+a2+a3;").apply(null, arguments); +})("", 1, 2); + +assert.sameValue(this["shifted"], "12", 'The value of this["shifted"] is expected to be "12"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T8.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T8.js new file mode 100644 index 0000000000..cec72bf167 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T8.js @@ -0,0 +1,20 @@ +// 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 either an array or an arguments object, + the function is passed the (ToUint32(argArray.length)) arguments argArray[0], argArray[1],...,argArray[ToUint32(argArray.length)-1] +es5id: 15.3.4.3_A7_T8 +description: > + argArray is (this, arguments), inside function call without + declaration used +---*/ + +(function() { + Function("a1,a2,a3", "this.shifted=a1+a2+a3;").apply(this, arguments); +})("", 4, 2); + +assert.sameValue(this["shifted"], "42", 'The value of this["shifted"] is expected to be "42"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T9.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T9.js new file mode 100644 index 0000000000..3b5b7295e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A7_T9.js @@ -0,0 +1,30 @@ +// 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 either an array or an arguments object, + the function is passed the (ToUint32(argArray.length)) arguments argArray[0], argArray[1],...,argArray[ToUint32(argArray.length)-1] +es5id: 15.3.4.3_A7_T9 +description: > + argArray is (empty object, arguments), inside function declaration + used +---*/ + +function FACTORY() { + var obj = {}; + Function("a1,a2,a3", "this.shifted=a1+a2+a3;").apply(obj, arguments); + return obj; +} + +var obj = new FACTORY("", 1, 2); + +assert.sameValue( + typeof this["shifted"], + "undefined", + 'The value of `typeof this["shifted"]` is expected to be "undefined"' +); + +assert.sameValue(obj.shifted, "12", 'The value of obj.shifted is expected to be "12"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A8_T3.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A8_T3.js new file mode 100644 index 0000000000..6abf2d0887 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A8_T3.js @@ -0,0 +1,17 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Function.prototype.apply can`t be used as [[Construct]] caller +es5id: 15.3.4.3_A8_T3 +description: Checking if creating "new Function.apply" fails +---*/ + +try { + var obj = new Function.apply; + throw new Test262Error('#1: Function.prototype.apply can\'t be used as [[Construct]] caller'); +} catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A8_T4.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A8_T4.js new file mode 100644 index 0000000000..d2a4f31ecb --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A8_T4.js @@ -0,0 +1,17 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Function.prototype.apply can`t be used as [[Construct]] caller +es5id: 15.3.4.3_A8_T4 +description: Checking if creating "new (Function("this.p1=1").apply)" fails +---*/ + +try { + var obj = new(Function("this.p1=1").apply); + throw new Test262Error('#1: Function.prototype.apply can\'t be used as [[Construct]] caller'); +} catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A8_T5.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A8_T5.js new file mode 100644 index 0000000000..f5adac61f1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A8_T5.js @@ -0,0 +1,18 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Function.prototype.apply can`t be used as [[Construct]] caller +es5id: 15.3.4.3_A8_T5 +description: Checking if creating "new Function("this.p1=1").apply" fails +---*/ + +try { + var FACTORY = Function("this.p1=1").apply; + var obj = new FACTORY(); + throw new Test262Error('#1: Function.prototype.apply can\'t be used as [[Construct]] caller'); +} catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A8_T6.js b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A8_T6.js new file mode 100644 index 0000000000..4f278d44c1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/S15.3.4.3_A8_T6.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Function.prototype.apply can`t be used as [[Construct]] caller +es5id: 15.3.4.3_A8_T6 +description: > + Checking if creating "new (Function("function + f(){this.p1=1;};return f").apply())" fails +---*/ + +try { + var obj = new(Function("function f(){this.p1=1;};return f").apply()); +} catch (e) { + throw new Test262Error('#1: Function.prototype.apply can\'t be used as [[Construct]] caller'); +} + +assert.sameValue(obj.p1, 1, 'The value of obj.p1 is expected to be 1'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/argarray-not-object-realm.js b/js/src/tests/test262/built-ins/Function/prototype/apply/argarray-not-object-realm.js new file mode 100644 index 0000000000..9706b9c315 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/argarray-not-object-realm.js @@ -0,0 +1,40 @@ +// 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')); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/argarray-not-object.js b/js/src/tests/test262/built-ins/Function/prototype/apply/argarray-not-object.js new file mode 100644 index 0000000000..2c860c7833 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/argarray-not-object.js @@ -0,0 +1,37 @@ +// 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()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/browser.js b/js/src/tests/test262/built-ins/Function/prototype/apply/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/browser.js diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/get-index-abrupt.js b/js/src/tests/test262/built-ins/Function/prototype/apply/get-index-abrupt.js new file mode 100644 index 0000000000..56c9c95d89 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/get-index-abrupt.js @@ -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: > + 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/get-length-abrupt.js b/js/src/tests/test262/built-ins/Function/prototype/apply/get-length-abrupt.js new file mode 100644 index 0000000000..b559cb0504 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/get-length-abrupt.js @@ -0,0 +1,29 @@ +// 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/length.js b/js/src/tests/test262/built-ins/Function/prototype/apply/length.js new file mode 100644 index 0000000000..82b7758dd0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/length.js @@ -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: > + 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, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/name.js b/js/src/tests/test262/built-ins/Function/prototype/apply/name.js new file mode 100644 index 0000000000..528cf8f58a --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 19.2.3.1 +description: > + Function.prototype.apply.name is "apply". +info: | + Function.prototype.apply ( thisArg, argArray ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Function.prototype.apply.name, "apply"); + +verifyNotEnumerable(Function.prototype.apply, "name"); +verifyNotWritable(Function.prototype.apply, "name"); +verifyConfigurable(Function.prototype.apply, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/not-a-constructor.js b/js/src/tests/test262/built-ins/Function/prototype/apply/not-a-constructor.js new file mode 100644 index 0000000000..43275e54f0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/not-a-constructor.js @@ -0,0 +1,38 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Function.prototype.apply does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Function.prototype.apply), + false, + 'isConstructor(Function.prototype.apply) must return false' +); + +assert.throws(TypeError, () => { + new Function.prototype.apply; +}, '`new Function.prototype.apply` throws TypeError'); + +assert.throws(TypeError, () => { + new Function.prototype.apply(); +}, '`new Function.prototype.apply()` throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/shell.js b/js/src/tests/test262/built-ins/Function/prototype/apply/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/shell.js diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/this-not-callable-realm.js b/js/src/tests/test262/built-ins/Function/prototype/apply/this-not-callable-realm.js new file mode 100644 index 0000000000..506f5f2597 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/this-not-callable-realm.js @@ -0,0 +1,35 @@ +// 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/, {}, []); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Function/prototype/apply/this-not-callable.js b/js/src/tests/test262/built-ins/Function/prototype/apply/this-not-callable.js new file mode 100644 index 0000000000..f0b6b63382 --- /dev/null +++ b/js/src/tests/test262/built-ins/Function/prototype/apply/this-not-callable.js @@ -0,0 +1,30 @@ +// 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/, {}, []); +}); + +reportCompare(0, 0); |