From 920a567b72433deed172180d8649df23dbca1607 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 20 Dec 2022 17:53:12 +0100 Subject: [PATCH] Improve is/toWellFormedString coverage. --- .../prototype/isWellFormed/prop-desc.js | 1 - .../isWellFormed/to-string-primitive.js | 32 +++++++++++++++++++ .../prototype/toWellFormed/prop-desc.js | 3 +- .../toWellFormed/to-string-primitive.js | 32 +++++++++++++++++++ 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 test/built-ins/String/prototype/isWellFormed/to-string-primitive.js create mode 100644 test/built-ins/String/prototype/toWellFormed/to-string-primitive.js diff --git a/test/built-ins/String/prototype/isWellFormed/prop-desc.js b/test/built-ins/String/prototype/isWellFormed/prop-desc.js index 8591c80b75..a155b8d929 100644 --- a/test/built-ins/String/prototype/isWellFormed/prop-desc.js +++ b/test/built-ins/String/prototype/isWellFormed/prop-desc.js @@ -11,7 +11,6 @@ info: | includes: [propertyHelper.js] features: [String.prototype.isWellFormed] ---*/ -assert.sameValue(typeof String.prototype.isWellFormed, 'function'); assert.sameValue( typeof String.prototype.isWellFormed, diff --git a/test/built-ins/String/prototype/isWellFormed/to-string-primitive.js b/test/built-ins/String/prototype/isWellFormed/to-string-primitive.js new file mode 100644 index 0000000000..dfc69f8b72 --- /dev/null +++ b/test/built-ins/String/prototype/isWellFormed/to-string-primitive.js @@ -0,0 +1,32 @@ +// 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`); diff --git a/test/built-ins/String/prototype/toWellFormed/prop-desc.js b/test/built-ins/String/prototype/toWellFormed/prop-desc.js index 2e568e43b2..6e0ee94688 100644 --- a/test/built-ins/String/prototype/toWellFormed/prop-desc.js +++ b/test/built-ins/String/prototype/toWellFormed/prop-desc.js @@ -11,10 +11,9 @@ info: | includes: [propertyHelper.js] features: [String.prototype.toWellFormed] ---*/ -assert.sameValue(typeof String.prototype.toWellFormed, 'function'); assert.sameValue( - typeof String.prototype.isWellFormed, + typeof String.prototype.toWellFormed, 'function', 'The value of `typeof String.prototype.toWellFormed` is "function"' ); diff --git a/test/built-ins/String/prototype/toWellFormed/to-string-primitive.js b/test/built-ins/String/prototype/toWellFormed/to-string-primitive.js new file mode 100644 index 0000000000..6bbb8c2900 --- /dev/null +++ b/test/built-ins/String/prototype/toWellFormed/to-string-primitive.js @@ -0,0 +1,32 @@ +// 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`);