Skip to content

Commit

Permalink
Improve is/toWellFormedString coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger committed Dec 21, 2022
1 parent 06b982d commit 920a567
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
1 change: 0 additions & 1 deletion test/built-ins/String/prototype/isWellFormed/prop-desc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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`);
3 changes: 1 addition & 2 deletions test/built-ins/String/prototype/toWellFormed/prop-desc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"'
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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`);

0 comments on commit 920a567

Please sign in to comment.