summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/String/prototype/isWellFormed
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/isWellFormed/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/isWellFormed/length.js24
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/isWellFormed/name.js24
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/isWellFormed/not-a-constructor.js35
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/isWellFormed/prop-desc.js28
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/isWellFormed/return-abrupt-from-this.js25
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/isWellFormed/returns-boolean.js47
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/isWellFormed/shell.js0
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/isWellFormed/to-string-primitive.js35
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/isWellFormed/to-string.js30
10 files changed, 248 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/isWellFormed/browser.js b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/browser.js
diff --git a/js/src/tests/test262/built-ins/String/prototype/isWellFormed/length.js b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/length.js
new file mode 100644
index 0000000000..25dacc03cf
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/length.js
@@ -0,0 +1,24 @@
+// |reftest| shell-option(--enable-well-formed-unicode-strings) skip-if(!String.prototype.isWellFormed||!xulRuntime.shell) -- String.prototype.isWellFormed is not enabled unconditionally, requires shell-options
+// Copyright (C) 2022 Jordan Harband. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-string.prototype.iswellformed
+description: >
+ String.prototype.isWellFormed.length value and descriptor.
+info: |
+ String.prototype.isWellFormed( )
+
+ 17 ECMAScript Standard Built-in Objects
+
+includes: [propertyHelper.js]
+features: [String.prototype.isWellFormed]
+---*/
+
+verifyProperty(String.prototype.isWellFormed, 'length', {
+ configurable: true,
+ enumerable: false,
+ writable: false,
+ value: 0
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/isWellFormed/name.js b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/name.js
new file mode 100644
index 0000000000..273e21c0df
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/name.js
@@ -0,0 +1,24 @@
+// |reftest| shell-option(--enable-well-formed-unicode-strings) skip-if(!String.prototype.isWellFormed||!xulRuntime.shell) -- String.prototype.isWellFormed is not enabled unconditionally, requires shell-options
+// Copyright (C) 2022 Jordan Harband. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-string.prototype.iswellformed
+description: >
+ String.prototype.isWellFormed.name value and descriptor.
+info: |
+ String.prototype.isWellFormed( )
+
+ 17 ECMAScript Standard Built-in Objects
+
+includes: [propertyHelper.js]
+features: [String.prototype.isWellFormed]
+---*/
+
+verifyProperty(String.prototype.isWellFormed, 'name', {
+ enumerable: false,
+ writable: false,
+ configurable: true,
+ value: 'isWellFormed'
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/isWellFormed/not-a-constructor.js b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/not-a-constructor.js
new file mode 100644
index 0000000000..edadd4ba0a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/not-a-constructor.js
@@ -0,0 +1,35 @@
+// |reftest| shell-option(--enable-well-formed-unicode-strings) skip-if(!String.prototype.isWellFormed||!xulRuntime.shell) -- String.prototype.isWellFormed is not enabled unconditionally, requires shell-options
+// Copyright (C) 2022 Jordan Harband. 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.includes 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: [String.prototype.isWellFormed, Reflect.construct]
+---*/
+
+assert.sameValue(
+ isConstructor(String.prototype.isWellFormed),
+ false,
+ 'isConstructor(String.prototype.isWellFormed) must return false'
+);
+
+assert.throws(TypeError, function () {
+ new String.prototype.isWellFormed();
+}, '`new String.prototype.isWellFormed()` throws TypeError');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/isWellFormed/prop-desc.js b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/prop-desc.js
new file mode 100644
index 0000000000..e32cba4f00
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/prop-desc.js
@@ -0,0 +1,28 @@
+// |reftest| shell-option(--enable-well-formed-unicode-strings) skip-if(!String.prototype.isWellFormed||!xulRuntime.shell) -- String.prototype.isWellFormed is not enabled unconditionally, requires shell-options
+// Copyright (C) 2022 Jordan Harband. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-string.prototype.iswellformed
+description: >
+ Property type and descriptor.
+info: |
+ String.prototype.isWellFormed( )
+
+ 17 ECMAScript Standard Built-in Objects
+includes: [propertyHelper.js]
+features: [String.prototype.isWellFormed]
+---*/
+
+assert.sameValue(
+ typeof String.prototype.isWellFormed,
+ 'function',
+ 'The value of `typeof String.prototype.isWellFormed` is "function"'
+);
+
+verifyProperty(String.prototype, 'isWellFormed', {
+ enumerable: false,
+ writable: true,
+ configurable: true
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/isWellFormed/return-abrupt-from-this.js b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/return-abrupt-from-this.js
new file mode 100644
index 0000000000..5796e786f7
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/return-abrupt-from-this.js
@@ -0,0 +1,25 @@
+// |reftest| shell-option(--enable-well-formed-unicode-strings) skip-if(!String.prototype.isWellFormed||!xulRuntime.shell) -- String.prototype.isWellFormed is not enabled unconditionally, requires shell-options
+// Copyright (C) 2022 Jordan Harband. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-string.prototype.iswellformed
+description: >
+ Return abrupt from RequireObjectCoercible(this value).
+info: |
+ String.prototype.isWellFormed( )
+
+ 1. Let O be ? RequireObjectCoercible(this value).
+
+features: [String.prototype.isWellFormed]
+---*/
+assert.sameValue(typeof String.prototype.isWellFormed, 'function');
+
+assert.throws(TypeError, function () {
+ String.prototype.isWellFormed.call(undefined);
+}, '`String.prototype.isWellFormed.call(undefined)` throws TypeError');
+
+assert.throws(TypeError, function () {
+ String.prototype.isWellFormed.call(null);
+}, '`String.prototype.isWellFormed.call(null)` throws TypeError');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/isWellFormed/returns-boolean.js b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/returns-boolean.js
new file mode 100644
index 0000000000..1109670e53
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/returns-boolean.js
@@ -0,0 +1,47 @@
+// |reftest| shell-option(--enable-well-formed-unicode-strings) skip-if(!String.prototype.isWellFormed||!xulRuntime.shell) -- String.prototype.isWellFormed is not enabled unconditionally, requires shell-options
+// Copyright (C) 2022 Jordan Harband. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-string.prototype.iswellformed
+description: >
+ The method should return a boolean.
+info: |
+ String.prototype.isWellFormed ( )
+
+ 1. Let O be ? RequireObjectCoercible(this value).
+ 2. Let S be ? ToString(O).
+ 3. Return IsStringWellFormedUnicode(S).
+
+features: [String.prototype.isWellFormed]
+---*/
+assert.sameValue(typeof String.prototype.isWellFormed, 'function');
+
+var leadingPoo = '\uD83D';
+var trailingPoo = '\uDCA9';
+var wholePoo = leadingPoo + trailingPoo;
+
+assert.sameValue(
+ ('a' + leadingPoo + 'c' + leadingPoo + 'e').isWellFormed(),
+ false,
+ 'lone leading surrogates are not well-formed'
+);
+assert.sameValue(
+ ('a' + trailingPoo + 'c' + trailingPoo + 'e').isWellFormed(),
+ false,
+ 'lone trailing surrogates are not well-formed'
+);
+assert.sameValue(
+ ('a' + trailingPoo + leadingPoo + 'd').isWellFormed(),
+ false,
+ 'a wrong-ordered surrogate pair is not well-formed'
+)
+
+assert.sameValue('a💩c'.isWellFormed(), true, 'a surrogate pair using a literal code point is well-formed');
+assert.sameValue('a\uD83D\uDCA9c'.isWellFormed(), true, 'a surrogate pair formed by escape sequences is well-formed');
+assert.sameValue(('a' + leadingPoo + trailingPoo + 'd').isWellFormed(), true, 'a surrogate pair formed by concatenation is well-formed');
+assert.sameValue(wholePoo.slice(0, 1).isWellFormed(), false, 'a surrogate pair sliced to the leading surrogate is not well-formed');
+assert.sameValue(wholePoo.slice(1).isWellFormed(), false, 'a surrogate pair sliced to the trailing surrogate is not well-formed');
+assert.sameValue('abc'.isWellFormed(), true, 'a latin-1 string is well-formed');
+assert.sameValue('a\u25A8c'.isWellFormed(), true, 'a non-ASCII character is well-formed');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/isWellFormed/shell.js b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/shell.js
diff --git a/js/src/tests/test262/built-ins/String/prototype/isWellFormed/to-string-primitive.js b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/to-string-primitive.js
new file mode 100644
index 0000000000..5ef95cf21a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/to-string-primitive.js
@@ -0,0 +1,35 @@
+// |reftest| shell-option(--enable-well-formed-unicode-strings) skip-if(!String.prototype.isWellFormed||!xulRuntime.shell) -- String.prototype.isWellFormed is not enabled unconditionally, requires shell-options
+// Copyright (C) 2022 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-string.prototype.iswellformed
+description: >
+ The method should coerce the receiver to a string.
+info: |
+ String.prototype.isWellFormed ( )
+
+ 2. Let S be ? ToString(O).
+ …
+
+features: [String.prototype.isWellFormed]
+---*/
+
+const tests = [
+ [true, Boolean.prototype],
+ [1, Number.prototype],
+ [1n, BigInt.prototype],
+];
+
+for (const [v, proto] of tests) {
+ proto.toString = function() {
+ throw new Test262Error(`should not call toString on the prototype for ${typeof v}`);
+ }
+ let result = String.prototype.isWellFormed.call(v);
+ delete proto.toString;
+ assert.sameValue(result, true, `isWellFormed for ${typeof v}`);
+}
+
+Symbol.prototype.toString = function() { throw new TypeError("should not call toString on the prototype for Symbol"); }
+assert.throws(TypeError, () => String.prototype.isWellFormed.call(Symbol()), `Built-in result for Symbol`);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/isWellFormed/to-string.js b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/to-string.js
new file mode 100644
index 0000000000..1d5035d9b4
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/isWellFormed/to-string.js
@@ -0,0 +1,30 @@
+// |reftest| shell-option(--enable-well-formed-unicode-strings) skip-if(!String.prototype.isWellFormed||!xulRuntime.shell) -- String.prototype.isWellFormed is not enabled unconditionally, requires shell-options
+// Copyright (C) 2022 Jordan Harband. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-string.prototype.iswellformed
+description: >
+ The method should coerce the receiver to a string.
+info: |
+ String.prototype.isWellFormed ( )
+
+ 1. Let O be ? RequireObjectCoercible(this value).
+ 2. Let S be ? ToString(O).
+ 3. Return IsStringWellFormedUnicode(S).
+
+features: [String.prototype.isWellFormed]
+---*/
+
+var obj = {
+ toString: function () {
+ throw new Test262Error('calls ToString');
+ }
+};
+
+assert.throws(
+ Test262Error,
+ function () { String.prototype.isWellFormed.call(obj); },
+ 'coerces the receiver to a string'
+);
+
+reportCompare(0, 0);