Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[JSC] Implement String#isWellFormed and String#toWellFormed
https://bugs.webkit.org/show_bug.cgi?id=248588 rdar://problem/102849210 Reviewed by Ross Kirsling. This patch implements String#isWellFormed and String#toWellFormed proposal[1]. String#isWellFormed returns true if String does not have wrong surrogate pairs (e.g. non-paired surrogate). String#toWellFormed returns a string, which replaces non well-formed characters with unicode replacement character (\ufffd). [1]: https://github.com/tc39/proposal-is-usv-string * JSTests/stress/string-well-formed.js: Added. (shouldBe): * LayoutTests/js/Object-getOwnPropertyNames-expected.txt: * LayoutTests/js/script-tests/Object-getOwnPropertyNames.js: * Source/JavaScriptCore/runtime/CommonIdentifiers.h: * Source/JavaScriptCore/runtime/OptionsList.h: * Source/JavaScriptCore/runtime/StringPrototype.cpp: (JSC::StringPrototype::finishCreation): (JSC::nonWellFormedIndex): (JSC::JSC_DEFINE_HOST_FUNCTION): Canonical link: https://commits.webkit.org/257250@main
- Loading branch information
1 parent
2c29849
commit 6ccd7405a513dab05d5a59359330af76e177f968
Showing
6 changed files
with
157 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//@ requireOptions("--useStringWellFormed=1") | ||
function shouldBe(actual, expected) { | ||
if (actual !== expected) | ||
throw new Error('bad value: ' + actual); | ||
} | ||
|
||
shouldBe("".isWellFormed(), true); | ||
shouldBe("".toWellFormed(), ""); | ||
|
||
shouldBe("Hello World".isWellFormed(), true); | ||
shouldBe("Hello World".toWellFormed(), "Hello World"); | ||
|
||
shouldBe("こんにちわ".isWellFormed(), true); | ||
shouldBe("こんにちわ".toWellFormed(), "こんにちわ"); | ||
|
||
shouldBe("𠮷野家".isWellFormed(), true); | ||
shouldBe("𠮷野家".toWellFormed(), "𠮷野家"); | ||
|
||
shouldBe("A\uD842".isWellFormed(), false); | ||
shouldBe("A\uD842".toWellFormed(), "A\uFFFD"); | ||
|
||
shouldBe("A\uD842A".isWellFormed(), false); | ||
shouldBe("A\uD842A".toWellFormed(), "A\uFFFDA"); | ||
|
||
shouldBe("A\uD842\uDFB7".isWellFormed(), true); | ||
shouldBe("A\uD842\uDFB7".toWellFormed(), "A\uD842\uDFB7"); | ||
|
||
shouldBe("A\uDFB7".isWellFormed(), false); | ||
shouldBe("A\uDFB7".toWellFormed(), "A\uFFFD"); | ||
|
||
shouldBe("A\uDFB7\uD842".isWellFormed(), false); | ||
shouldBe("A\uDFB7\uD842".toWellFormed(), "A\uFFFD\uFFFD"); |
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
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
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
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
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