diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/String/prototype/valueOf')
9 files changed, 264 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/valueOf/browser.js b/js/src/tests/test262/built-ins/String/prototype/valueOf/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/valueOf/browser.js diff --git a/js/src/tests/test262/built-ins/String/prototype/valueOf/length.js b/js/src/tests/test262/built-ins/String/prototype/valueOf/length.js new file mode 100644 index 0000000000..9655e6500f --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/valueOf/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.valueof +description: > + String.prototype.valueOf.length is 0. +info: | + String.prototype.valueOf ( ) + + 17 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. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + 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(String.prototype.valueOf, 'length', { + value: 0, + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/valueOf/name.js b/js/src/tests/test262/built-ins/String/prototype/valueOf/name.js new file mode 100644 index 0000000000..e5ae351739 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/valueOf/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.valueof +description: > + String.prototype.valueOf.name is "valueOf". +info: | + String.prototype.valueOf ( ) + + 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] +---*/ + +verifyProperty(String.prototype.valueOf, 'name', { + value: 'valueOf', + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/valueOf/non-generic-realm.js b/js/src/tests/test262/built-ins/String/prototype/valueOf/non-generic-realm.js new file mode 100644 index 0000000000..31caef4a3a --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/valueOf/non-generic-realm.js @@ -0,0 +1,60 @@ +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.valueof +description: > + Throws a TypeError if called on neither String primitive nor String object + (honoring the Realm of the current execution context) +info: | + String.prototype.valueOf ( ) + + 1. Return ? thisStringValue(this value). + + thisStringValue ( value ) + + [...] + 3. Throw a TypeError exception. +features: [cross-realm] +---*/ + +var other = $262.createRealm().global; +var otherValueOf = other.String.prototype.valueOf; + +assert.throws(other.TypeError, function() { + otherValueOf.call(false); +}); + +assert.throws(other.TypeError, function() { + otherValueOf.call(-1); +}); + +assert.throws(other.TypeError, function() { + otherValueOf.call(null); +}); + +assert.throws(other.TypeError, function() { + otherValueOf.call(); +}); + +assert.throws(other.TypeError, function() { + otherValueOf.call(Symbol('desc')); +}); + +assert.throws(other.TypeError, function() { + otherValueOf.call({ + valueOf: function() { + return ''; + }, + }); +}); + +assert.throws(other.TypeError, function() { + otherValueOf.call([3]); +}); + +assert.throws(other.TypeError, function() { + '' + {valueOf: otherValueOf}; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/valueOf/non-generic.js b/js/src/tests/test262/built-ins/String/prototype/valueOf/non-generic.js new file mode 100644 index 0000000000..761655d04d --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/valueOf/non-generic.js @@ -0,0 +1,57 @@ +// Copyright (C) 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.valueof +description: > + Throws a TypeError if called on neither String primitive nor String object +info: | + String.prototype.valueOf ( ) + + 1. Return ? thisStringValue(this value). + + thisStringValue ( value ) + + [...] + 3. Throw a TypeError exception. +---*/ + +var valueOf = String.prototype.valueOf; + +assert.throws(TypeError, function() { + valueOf.call(true); +}); + +assert.throws(TypeError, function() { + valueOf.call(-0); +}); + +assert.throws(TypeError, function() { + valueOf.call(null); +}); + +assert.throws(TypeError, function() { + valueOf.call(); +}); + +assert.throws(TypeError, function() { + valueOf.call(Symbol('desc')); +}); + +assert.throws(TypeError, function() { + valueOf.call({ + toString: function() { + return 'str'; + }, + }); +}); + +assert.throws(TypeError, function() { + valueOf.call(['s', 't', 'r']); +}); + +assert.throws(TypeError, function() { + 'str' + {valueOf: valueOf}; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/valueOf/not-a-constructor.js b/js/src/tests/test262/built-ins/String/prototype/valueOf/not-a-constructor.js new file mode 100644 index 0000000000..81afa416d4 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/valueOf/not-a-constructor.js @@ -0,0 +1,35 @@ +// 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: > + String.prototype.valueOf 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(String.prototype.valueOf), + false, + 'isConstructor(String.prototype.valueOf) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.valueOf(); +}, '`new String.prototype.valueOf()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/valueOf/shell.js b/js/src/tests/test262/built-ins/String/prototype/valueOf/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/valueOf/shell.js diff --git a/js/src/tests/test262/built-ins/String/prototype/valueOf/string-object.js b/js/src/tests/test262/built-ins/String/prototype/valueOf/string-object.js new file mode 100644 index 0000000000..68ae989392 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/valueOf/string-object.js @@ -0,0 +1,28 @@ +// Copyright (C) 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.valueof +description: > + If called on a String object, returns [[StringData]] slot +info: | + String.prototype.valueOf ( ) + + 1. Return ? thisStringValue(this value). + + thisStringValue ( value ) + + [...] + 2. If Type(value) is Object and value has a [[StringData]] internal slot, then + a. Let s be value.[[StringData]]. + b. Assert: Type(s) is String. + c. Return s. +---*/ + +var valueOf = String.prototype.valueOf; + +assert.sameValue(Object('').valueOf(), ''); +assert.sameValue(valueOf.call(new String('str')), 'str'); +assert.sameValue('a' + new String('b'), 'ab'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/valueOf/string-primitive.js b/js/src/tests/test262/built-ins/String/prototype/valueOf/string-primitive.js new file mode 100644 index 0000000000..8d951a9cfc --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/valueOf/string-primitive.js @@ -0,0 +1,23 @@ +// Copyright (C) 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.valueof +description: > + If called on String primitive, returns it +info: | + String.prototype.valueOf ( ) + + 1. Return ? thisStringValue(this value). + + thisStringValue ( value ) + + 1. If Type(value) is String, return value. +---*/ + +var valueOf = String.prototype.valueOf; + +assert.sameValue('str'.valueOf(), 'str'); +assert.sameValue(valueOf.call(''), ''); + +reportCompare(0, 0); |