diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/String/prototype/toWellFormed')
10 files changed, 259 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/toWellFormed/browser.js b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/browser.js diff --git a/js/src/tests/test262/built-ins/String/prototype/toWellFormed/length.js b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/length.js new file mode 100644 index 0000000000..8da16feb4e --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/length.js @@ -0,0 +1,24 @@ +// |reftest| shell-option(--enable-well-formed-unicode-strings) skip-if(!String.prototype.toWellFormed||!xulRuntime.shell) -- String.prototype.toWellFormed 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.towellformed +description: > + String.prototype.toWellFormed.length value and descriptor. +info: | + String.prototype.toWellFormed( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [String.prototype.toWellFormed] +---*/ + +verifyProperty(String.prototype.toWellFormed, 'length', { + configurable: true, + enumerable: false, + writable: false, + value: 0 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/toWellFormed/name.js b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/name.js new file mode 100644 index 0000000000..f1befc1eea --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/name.js @@ -0,0 +1,24 @@ +// |reftest| shell-option(--enable-well-formed-unicode-strings) skip-if(!String.prototype.toWellFormed||!xulRuntime.shell) -- String.prototype.toWellFormed 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.towellformed +description: > + String.prototype.toWellFormed.name value and descriptor. +info: | + String.prototype.toWellFormed( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [String.prototype.toWellFormed] +---*/ + +verifyProperty(String.prototype.toWellFormed, 'name', { + enumerable: false, + writable: false, + configurable: true, + value: 'toWellFormed' +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/toWellFormed/not-a-constructor.js b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/not-a-constructor.js new file mode 100644 index 0000000000..d8c64b85b8 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/not-a-constructor.js @@ -0,0 +1,35 @@ +// |reftest| shell-option(--enable-well-formed-unicode-strings) skip-if(!String.prototype.toWellFormed||!xulRuntime.shell) -- String.prototype.toWellFormed 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.toWellFormed, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(String.prototype.toWellFormed), + false, + 'isConstructor(String.prototype.toWellFormed) must return false' +); + +assert.throws(TypeError, function () { + new String.prototype.toWellFormed(); +}, '`new String.prototype.toWellFormed()` throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/toWellFormed/prop-desc.js b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/prop-desc.js new file mode 100644 index 0000000000..c0217bd63f --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/prop-desc.js @@ -0,0 +1,28 @@ +// |reftest| shell-option(--enable-well-formed-unicode-strings) skip-if(!String.prototype.toWellFormed||!xulRuntime.shell) -- String.prototype.toWellFormed 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.towellformed +description: > + Property type and descriptor. +info: | + String.prototype.toWellFormed( ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [String.prototype.toWellFormed] +---*/ + +assert.sameValue( + typeof String.prototype.toWellFormed, + 'function', + 'The value of `typeof String.prototype.toWellFormed` is "function"' +); + +verifyProperty(String.prototype, 'toWellFormed', { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/toWellFormed/return-abrupt-from-this.js b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/return-abrupt-from-this.js new file mode 100644 index 0000000000..7053c7cc42 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/return-abrupt-from-this.js @@ -0,0 +1,25 @@ +// |reftest| shell-option(--enable-well-formed-unicode-strings) skip-if(!String.prototype.toWellFormed||!xulRuntime.shell) -- String.prototype.toWellFormed 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.towellformed +description: > + Return abrupt from RequireObjectCoercible(this value). +info: | + String.prototype.toWellFormed( ) + + 1. Let O be ? RequireObjectCoercible(this value). + +features: [String.prototype.toWellFormed] +---*/ +assert.sameValue(typeof String.prototype.toWellFormed, 'function'); + +assert.throws(TypeError, function () { + String.prototype.toWellFormed.call(undefined); +}, '`String.prototype.toWellFormed.call(undefined)` throws TypeError'); + +assert.throws(TypeError, function () { + String.prototype.toWellFormed.call(null); +}, '`String.prototype.toWellFormed.call(null)` throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/toWellFormed/returns-well-formed-string.js b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/returns-well-formed-string.js new file mode 100644 index 0000000000..df77f0c598 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/returns-well-formed-string.js @@ -0,0 +1,58 @@ +// |reftest| shell-option(--enable-well-formed-unicode-strings) skip-if(!String.prototype.toWellFormed||!xulRuntime.shell) -- String.prototype.toWellFormed 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.towellformed +description: > + The method should return a well-formed string. +info: | + String.prototype.toWellFormed ( ) + + 1. Let O be ? RequireObjectCoercible(this value). + 2. Let S be ? ToString(O). + 3. Let strLen be the length of S. + 4. Let k be 0. + 5. Let result be the empty String. + 6. Repeat, while k < strLen, + a. Let cp be CodePointAt(S, k). + b. If cp.[[IsUnpairedSurrogate]] is true, then + i. Set result to the string-concatenation of result and 0xFFFD (REPLACEMENT CHARACTER). + c. Else, + i. Set result to the string-concatenation of result and UTF16EncodeCodePoint(cp.[[CodePoint]]). + d. Set k to k + cp.[[CodeUnitCount]]. + 7. Return result. + +features: [String.prototype.toWellFormed] +---*/ +assert.sameValue(typeof String.prototype.toWellFormed, 'function'); + +var replacementChar = '\uFFFD'; +var leadingPoo = '\uD83D'; +var trailingPoo = '\uDCA9'; +var wholePoo = leadingPoo + trailingPoo; + +assert.sameValue( + ('a' + leadingPoo + 'c' + leadingPoo + 'e').toWellFormed(), + 'a' + replacementChar + 'c' + replacementChar + 'e', + 'lone leading surrogates are replaced with the expected replacement character' +); +assert.sameValue( + ('a' + trailingPoo + 'c' + trailingPoo + 'e').toWellFormed(), + 'a' + replacementChar + 'c' + replacementChar + 'e', + 'lone trailing surrogates are replaced with the expected replacement character' +); +assert.sameValue( + ('a' + trailingPoo + leadingPoo + 'd').toWellFormed(), + 'a' + replacementChar + replacementChar + 'd', + 'a wrong-ordered surrogate pair is replaced with two replacement characters' +) + +assert.sameValue('a💩c'.toWellFormed(), 'a💩c', 'a surrogate pair using a literal code point is already well-formed'); +assert.sameValue('a\uD83D\uDCA9c'.toWellFormed(), 'a\uD83D\uDCA9c', 'a surrogate pair formed by escape sequences is already well-formed'); +assert.sameValue(('a' + leadingPoo + trailingPoo + 'd').toWellFormed(), 'a' + wholePoo + 'd', 'a surrogate pair formed by concatenation is already well-formed'); +assert.sameValue(wholePoo.slice(0, 1).toWellFormed(), replacementChar, 'a surrogate pair sliced to the leading surrogate is replaced with the expected replacement character'); +assert.sameValue(wholePoo.slice(1).toWellFormed(), replacementChar, 'a surrogate pair sliced to the trailing surrogate is replaced with the expected replacement character'); +assert.sameValue('abc'.toWellFormed(), 'abc', 'a latin-1 string is already well-formed'); +assert.sameValue('a\u25A8c'.toWellFormed(), 'a\u25A8c', 'a string with a non-ASCII character is already well-formed'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/toWellFormed/shell.js b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/shell.js diff --git a/js/src/tests/test262/built-ins/String/prototype/toWellFormed/to-string-primitive.js b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/to-string-primitive.js new file mode 100644 index 0000000000..81584490b0 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/to-string-primitive.js @@ -0,0 +1,35 @@ +// |reftest| shell-option(--enable-well-formed-unicode-strings) skip-if(!String.prototype.toWellFormed||!xulRuntime.shell) -- String.prototype.toWellFormed 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.towellformed +description: > + The method should coerce the receiver to a string. +info: | + String.prototype.toWellFormed ( ) + + 2. Let S be ? ToString(O). + … + +features: [String.prototype.toWellFormed] +---*/ + +const tests = [ + [true, "true", Boolean.prototype], + [1, "1", Number.prototype], + [1n, "1", BigInt.prototype], +]; + +for (const [v, expected, proto] of tests) { + proto.toString = function() { + throw new Test262Error(`should not call toString on the prototype for ${typeof v}`); + } + let result = String.prototype.toWellFormed.call(v); + delete proto.toString; + assert.sameValue(result, expected, `toWellFormed for ${typeof v}`); +} + +Symbol.prototype.toString = function() { throw new TypeError("should not call toString on the prototype for Symbol"); } +assert.throws(TypeError, () => String.prototype.toWellFormed.call(Symbol()), `Built-in result for Symbol`); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/toWellFormed/to-string.js b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/to-string.js new file mode 100644 index 0000000000..200f9ccd16 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/toWellFormed/to-string.js @@ -0,0 +1,30 @@ +// |reftest| shell-option(--enable-well-formed-unicode-strings) skip-if(!String.prototype.toWellFormed||!xulRuntime.shell) -- String.prototype.toWellFormed 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.towellformed +description: > + The method should coerce the receiver to a string. +info: | + String.prototype.toWellFormed ( ) + + 1. Let O be ? RequireObjectCoercible(this value). + 2. Let S be ? ToString(O). + … + +features: [String.prototype.toWellFormed] +---*/ + +var obj = { + toString: function () { + throw new Test262Error('calls ToString'); + } +}; + +assert.throws( + Test262Error, + function () { String.prototype.toWellFormed.call(obj); }, + 'coerces the receiver to a string' +); + +reportCompare(0, 0); |