-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve is/toWellFormedString coverage.
- Loading branch information
Showing
4 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
test/built-ins/String/prototype/isWellFormed/to-string-primitive.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
test/built-ins/String/prototype/toWellFormed/to-string-primitive.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); |