summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/String/prototype/toString
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/String/prototype/toString')
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/toString/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/toString/length.js29
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/toString/name.js29
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/toString/non-generic-realm.js60
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/toString/non-generic.js57
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/toString/not-a-constructor.js35
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/toString/shell.js0
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/toString/string-object.js28
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/toString/string-primitive.js23
9 files changed, 261 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/toString/browser.js b/js/src/tests/test262/built-ins/String/prototype/toString/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/toString/browser.js
diff --git a/js/src/tests/test262/built-ins/String/prototype/toString/length.js b/js/src/tests/test262/built-ins/String/prototype/toString/length.js
new file mode 100644
index 0000000000..ba4b6fa655
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/toString/length.js
@@ -0,0 +1,29 @@
+// 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.tostring
+description: >
+ String.prototype.toString.length is 0.
+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(String.prototype.toString, 'length', {
+ value: 0,
+ writable: false,
+ enumerable: false,
+ configurable: true,
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/toString/name.js b/js/src/tests/test262/built-ins/String/prototype/toString/name.js
new file mode 100644
index 0000000000..bd3891423d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/toString/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.tostring
+description: >
+ String.prototype.toString.name is "toString".
+info: |
+ String.prototype.toString ( )
+
+ 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.toString, 'name', {
+ value: 'toString',
+ writable: false,
+ enumerable: false,
+ configurable: true,
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/toString/non-generic-realm.js b/js/src/tests/test262/built-ins/String/prototype/toString/non-generic-realm.js
new file mode 100644
index 0000000000..4f27e3528e
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/toString/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.tostring
+description: >
+ Throws a TypeError if called on neither String primitive nor String object
+ (honoring the Realm of the current execution context)
+info: |
+ String.prototype.toString ( )
+
+ 1. Return ? thisStringValue(this value).
+
+ thisStringValue ( value )
+
+ [...]
+ 3. Throw a TypeError exception.
+features: [cross-realm]
+---*/
+
+var other = $262.createRealm().global;
+var otherToString = other.String.prototype.toString;
+
+assert.throws(other.TypeError, function() {
+ otherToString.call(true);
+});
+
+assert.throws(other.TypeError, function() {
+ otherToString.call(0);
+});
+
+assert.throws(other.TypeError, function() {
+ otherToString.call(null);
+});
+
+assert.throws(other.TypeError, function() {
+ otherToString.call();
+});
+
+assert.throws(other.TypeError, function() {
+ otherToString.call(Symbol('desc'));
+});
+
+assert.throws(other.TypeError, function() {
+ otherToString.call({
+ valueOf: function() {
+ return 'str';
+ },
+ });
+});
+
+assert.throws(other.TypeError, function() {
+ otherToString.call([1]);
+});
+
+assert.throws(other.TypeError, function() {
+ 'str'.concat({toString: otherToString});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/toString/non-generic.js b/js/src/tests/test262/built-ins/String/prototype/toString/non-generic.js
new file mode 100644
index 0000000000..1a78132963
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/toString/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.tostring
+description: >
+ Throws a TypeError if called on neither String primitive nor String object
+info: |
+ String.prototype.toString ( )
+
+ 1. Return ? thisStringValue(this value).
+
+ thisStringValue ( value )
+
+ [...]
+ 3. Throw a TypeError exception.
+---*/
+
+var toString = String.prototype.toString;
+
+assert.throws(TypeError, function() {
+ toString.call(false);
+});
+
+assert.throws(TypeError, function() {
+ toString.call(1);
+});
+
+assert.throws(TypeError, function() {
+ toString.call(null);
+});
+
+assert.throws(TypeError, function() {
+ toString.call();
+});
+
+assert.throws(TypeError, function() {
+ toString.call(Symbol('desc'));
+});
+
+assert.throws(TypeError, function() {
+ toString.call({
+ toString: function() {
+ return 'str';
+ },
+ });
+});
+
+assert.throws(TypeError, function() {
+ toString.call(['s', 't', 'r']);
+});
+
+assert.throws(TypeError, function() {
+ ''.concat({toString: toString});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/toString/not-a-constructor.js b/js/src/tests/test262/built-ins/String/prototype/toString/not-a-constructor.js
new file mode 100644
index 0000000000..59cdfc18e5
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/toString/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.toString 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.toString),
+ false,
+ 'isConstructor(String.prototype.toString) must return false'
+);
+
+assert.throws(TypeError, () => {
+ new String.prototype.toString();
+}, '`new String.prototype.toString()` throws TypeError');
+
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/toString/shell.js b/js/src/tests/test262/built-ins/String/prototype/toString/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/toString/shell.js
diff --git a/js/src/tests/test262/built-ins/String/prototype/toString/string-object.js b/js/src/tests/test262/built-ins/String/prototype/toString/string-object.js
new file mode 100644
index 0000000000..834a4f41b9
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/toString/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.tostring
+description: >
+ If called on a String object, returns [[StringData]] slot
+info: |
+ String.prototype.toString ( )
+
+ 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 toString = String.prototype.toString;
+
+assert.sameValue(Object('str').toString(), 'str');
+assert.sameValue(toString.call(new String('')), '');
+assert.sameValue('a'.concat(Object('b')), 'ab');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/toString/string-primitive.js b/js/src/tests/test262/built-ins/String/prototype/toString/string-primitive.js
new file mode 100644
index 0000000000..18ce6eb295
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/toString/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.tostring
+description: >
+ If called on String primitive, returns it
+info: |
+ String.prototype.toString ( )
+
+ 1. Return ? thisStringValue(this value).
+
+ thisStringValue ( value )
+
+ 1. If Type(value) is String, return value.
+---*/
+
+var toString = String.prototype.toString;
+
+assert.sameValue(''.toString(), '');
+assert.sameValue(toString.call('str'), 'str');
+
+reportCompare(0, 0);