Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(532)

Unified Diff: src/string.js

Issue 68133016: Implements ES6 String.prototype.normalize method. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/string.js
diff --git a/src/string.js b/src/string.js
index 14b44ca41f3d7f248a5756b54983f09ab3a55c8e..809d24f033fdc70b0547fe47c0ed887fa855c3ff 100644
--- a/src/string.js
+++ b/src/string.js
@@ -200,6 +200,31 @@ function StringMatch(regexp) {
}
+var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD'];
+
+
+// ECMA-262 v6, section 21.1.3.12
+//
+// For now we do nothing, as proper normalization requires big tables.
+// If Intl is enabled, then i18n.js will override it and provide the the
+// proper functionality.
+function StringNormalize(form) {
+ if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
mathias 2014/01/29 09:05:55 While this is correct, it might be better to just
+ throw MakeTypeError("called_on_null_or_undefined",
+ ["String.prototype.localeCompare"]);
mathias 2014/01/29 09:05:55 s/localeCompare/normalize/
+ }
+
+ var form = form ? TO_STRING_INLINE(form) : 'NFC';
+ var normalizationForm = NORMALIZATION_FORMS.indexOf(form);
+ if (normalizationForm === -1) {
+ throw new $RangeError('The normalization form should be one of '
+ + NORMALIZATION_FORMS.join(', ') + '.');
+ }
+
+ return %_ValueOf(this);
+}
+
+
// This has the same size as the lastMatchInfo array, and can be used for
// functions that expect that structure to be returned. It is used when the
// needle is a string rather than a regexp. In this case we can't update
@@ -984,6 +1009,7 @@ function SetUpString() {
"lastIndexOf", StringLastIndexOf,
"localeCompare", StringLocaleCompare,
"match", StringMatch,
+ "normalize", StringNormalize,
"replace", StringReplace,
"search", StringSearch,
"slice", StringSlice,
« src/i18n.js ('K') | « src/runtime.cc ('k') | test/intl/string/normalization.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698