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

Side by Side Diff: src/runtime.cc

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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 14045 matching lines...) Expand 10 before | Expand all | Expand 10 after
14056 string_value1.length(), 14056 string_value1.length(),
14057 u_string2, 14057 u_string2,
14058 string_value2.length(), 14058 string_value2.length(),
14059 status); 14059 status);
14060 if (U_FAILURE(status)) return isolate->ThrowIllegalOperation(); 14060 if (U_FAILURE(status)) return isolate->ThrowIllegalOperation();
14061 14061
14062 return *isolate->factory()->NewNumberFromInt(result); 14062 return *isolate->factory()->NewNumberFromInt(result);
14063 } 14063 }
14064 14064
14065 14065
14066 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringNormalize) {
14067 HandleScope scope(isolate);
14068 static const UNormalizationMode normalizationForms[] =
14069 { UNORM_NFC, UNORM_NFD, UNORM_NFKC, UNORM_NFKD };
14070
14071 ASSERT(args.length() == 2);
14072
14073 CONVERT_ARG_HANDLE_CHECKED(String, stringValue, 0);
14074 CONVERT_NUMBER_CHECKED(int, form_id, Int32, args[1]);
14075
14076 v8::String::Value string_value(v8::Utils::ToLocal(stringValue));
14077 const UChar* u_value = reinterpret_cast<const UChar*>(*string_value);
14078
14079 // TODO(mnita): check Normalizer2 (not available in ICU 46)
14080 UErrorCode status = U_ZERO_ERROR;
14081 icu::UnicodeString result;
14082 icu::Normalizer::normalize(u_value, normalizationForms[form_id], 0,
14083 result, status);
14084 if (U_FAILURE(status)) {
14085 return isolate->heap()->undefined_value();
14086 }
14087
14088 return *isolate->factory()->NewStringFromTwoByte(
14089 Vector<const uint16_t>(
14090 reinterpret_cast<const uint16_t*>(result.getBuffer()),
14091 result.length()));
14092 }
14093
14094
14066 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateBreakIterator) { 14095 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateBreakIterator) {
14067 HandleScope scope(isolate); 14096 HandleScope scope(isolate);
14068 14097
14069 ASSERT(args.length() == 3); 14098 ASSERT(args.length() == 3);
14070 14099
14071 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0); 14100 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0);
14072 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1); 14101 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1);
14073 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2); 14102 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2);
14074 14103
14075 Handle<ObjectTemplateInfo> break_iterator_template = 14104 Handle<ObjectTemplateInfo> break_iterator_template =
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
14878 // Handle last resort GC and make sure to allow future allocations 14907 // Handle last resort GC and make sure to allow future allocations
14879 // to grow the heap without causing GCs (if possible). 14908 // to grow the heap without causing GCs (if possible).
14880 isolate->counters()->gc_last_resort_from_js()->Increment(); 14909 isolate->counters()->gc_last_resort_from_js()->Increment();
14881 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14910 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14882 "Runtime::PerformGC"); 14911 "Runtime::PerformGC");
14883 } 14912 }
14884 } 14913 }
14885 14914
14886 14915
14887 } } // namespace v8::internal 14916 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698