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

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: Implemented review feedback: CHECK_OBJECT_COERCIBLE macro to check for null/undefined. Created 6 years, 11 months 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 8e4b896eae5492bab3c1efb5a7222a4c6b9be654..74230c986411247d7d8f5dfdea869a1efff5c49e 100644
--- a/src/string.js
+++ b/src/string.js
@@ -186,6 +186,28 @@ 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) {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
+
+ var form = form ? TO_STRING_INLINE(form) : 'NFC';
+ var normalizationForm = NORMALIZATION_FORMS.indexOf(form);
arv (Not doing code reviews) 2014/04/10 18:20:10 same here?
mnita 2014/04/10 21:20:30 Done.
+ if (normalizationForm === -1) {
+ throw new $RangeError('The normalization form should be one of '
+ + NORMALIZATION_FORMS.join(', ') + '.');
arv (Not doing code reviews) 2014/04/10 18:20:10 and here
mnita 2014/04/10 21:20:30 Done.
+ }
+
+ 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
@@ -942,6 +964,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