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

Unified Diff: src/runtime.cc

Issue 40133004: Implements ES6 String.prototype.normalize method. (Closed) Base URL: git://github.com/v8/v8.git@bleeding_edge
Patch Set: Created 7 years, 2 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/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 0b39a436d3f9763fc72b89d201c2a0c36b0a2ad8..320084bce76287717276cbff05f4a5e92fe9be88 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -14064,6 +14064,32 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalCompare) {
}
+RUNTIME_FUNCTION(MaybeObject*, Runtime_StringNormalize) {
+ HandleScope scope(isolate);
+ static const UNormalizationMode normForms[] =
Nebojša Ćirić 2013/10/24 19:54:18 normalizationForms[]
mnita 2013/10/25 15:22:10 Done.
+ { UNORM_NFC, UNORM_NFD, UNORM_NFKC, UNORM_NFKD };
+
+ ASSERT(args.length() == 2);
+
+ CONVERT_ARG_HANDLE_CHECKED(String, stringValue, 0);
+ CONVERT_NUMBER_CHECKED(int, form_id, Int32, args[1]);
+
+ v8::String::Value string_value(v8::Utils::ToLocal(stringValue));
+ const UChar* u_value = reinterpret_cast<const UChar*>(*string_value);
+
+ // TODO(mnita) check Normalizer2 (not available in ICU 46)
Nebojša Ćirić 2013/10/24 19:54:18 // TODO(mnita): switch to Normalizer2 when we swit
mnita 2013/10/25 15:22:10 Done.
+ UErrorCode status = U_ZERO_ERROR;
+ icu::UnicodeString result;
+ icu::Normalizer::normalize(u_value, normForms[form_id], 0, result, status);
+ if (U_FAILURE(status)) return isolate->heap()->undefined_value();
Nebojša Ćirić 2013/10/24 19:54:18 if () { statement; } not if () statement;
mnita 2013/10/25 15:22:10 Done.
+
+ return *isolate->factory()->NewStringFromTwoByte(
+ Vector<const uint16_t>(
+ reinterpret_cast<const uint16_t*>(result.getBuffer()),
+ result.length()));
+}
+
+
RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateBreakIterator) {
HandleScope scope(isolate);

Powered by Google App Engine
This is Rietveld 408576698