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

Unified Diff: src/i18n.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
« no previous file with comments | « no previous file | src/runtime.h » ('j') | src/string.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/i18n.js
diff --git a/src/i18n.js b/src/i18n.js
index 6b563a00f915a867056e73c02856f8132226d5eb..2e5485749ae766fc469c8cd52c8257fe5b57e7b4 100644
--- a/src/i18n.js
+++ b/src/i18n.js
@@ -45,6 +45,11 @@ var AVAILABLE_SERVICES = ['collator',
'dateformat',
'breakiterator'];
+var NORMALIZATION_FORMS = ['NFC',
+ 'NFD',
+ 'NFKC',
+ 'NFKD'];
+
/**
* Caches available locales for each service.
*/
@@ -1987,6 +1992,40 @@ $Object.defineProperty($String.prototype, 'localeCompare', {
/**
+ * Unicode normalization. This method is called with one argument that
+ * specifies the normalization form.
+ * If none is specified, "NFC" is assumed.
+ * If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw
+ * a RangeError Exception.
+ */
+$Object.defineProperty($String.prototype, 'normalize', {
+ value: function(that) {
+ if (%_IsConstructCall()) {
+ throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
arv (Not doing code reviews) 2014/04/10 18:20:10 Does the spec really mandate this?
mnita 2014/04/10 21:20:30 Hmmmm... Not in spec, sorry. I will remove this wh
+ }
+
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
+
+ var form = $String(%_Arguments(0) || 'NFC');
+
+ var normalizationForm = NORMALIZATION_FORMS.indexOf(form);
arv (Not doing code reviews) 2014/04/10 18:20:10 Does this need to ensure we are calling the origin
mnita 2014/04/10 21:20:30 Done.
+ if (normalizationForm === -1) {
+ throw new $RangeError('The normalization form should be one of '
+ + NORMALIZATION_FORMS.join(', ') + '.');
+ }
+
+ return %StringNormalize(this, normalizationForm);
+ },
+ writable: true,
+ configurable: true,
+ enumerable: false
+});
+%FunctionSetName($String.prototype.normalize, 'normalize');
+%FunctionRemovePrototype($String.prototype.normalize);
+%SetNativeFlag($String.prototype.normalize);
+
+
+/**
* Formats a Number object (this) using locale and options values.
* If locale or options are omitted, defaults are used.
*/
« no previous file with comments | « no previous file | src/runtime.h » ('j') | src/string.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698