14 #include "unicode/brkiter.h"
15 #include "unicode/calendar.h"
16 #include "unicode/coll.h"
17 #include "unicode/curramt.h"
18 #include "unicode/datefmt.h"
19 #include "unicode/dcfmtsym.h"
20 #include "unicode/decimfmt.h"
21 #include "unicode/dtfmtsym.h"
22 #include "unicode/dtptngen.h"
23 #include "unicode/locid.h"
24 #include "unicode/numfmt.h"
25 #include "unicode/numsys.h"
26 #include "unicode/rbbi.h"
27 #include "unicode/smpdtfmt.h"
28 #include "unicode/timezone.h"
29 #include "unicode/uchar.h"
30 #include "unicode/ucol.h"
31 #include "unicode/ucurr.h"
32 #include "unicode/uloc.h"
33 #include "unicode/unum.h"
34 #include "unicode/uversion.h"
41 HandleScope scope(isolate);
42 Factory* factory = isolate->factory();
44 DCHECK(args.length() == 1);
50 const char*
const kInvalidTag =
"invalid-tag";
52 UErrorCode error = U_ZERO_ERROR;
53 char icu_result[ULOC_FULLNAME_CAPACITY];
56 uloc_forLanguageTag(*locale_id, icu_result, ULOC_FULLNAME_CAPACITY,
58 if (U_FAILURE(error) || icu_length == 0) {
59 return *factory->NewStringFromAsciiChecked(kInvalidTag);
62 char result[ULOC_FULLNAME_CAPACITY];
65 uloc_toLanguageTag(icu_result, result, ULOC_FULLNAME_CAPACITY, TRUE, &error);
67 if (U_FAILURE(error)) {
68 return *factory->NewStringFromAsciiChecked(kInvalidTag);
71 return *factory->NewStringFromAsciiChecked(result);
76 HandleScope scope(isolate);
77 Factory* factory = isolate->factory();
79 DCHECK(args.length() == 1);
82 const icu::Locale* available_locales =
NULL;
85 if (service->IsUtf8EqualTo(
CStrVector(
"collator"))) {
86 available_locales = icu::Collator::getAvailableLocales(count);
87 }
else if (service->IsUtf8EqualTo(
CStrVector(
"numberformat"))) {
88 available_locales = icu::NumberFormat::getAvailableLocales(count);
89 }
else if (service->IsUtf8EqualTo(
CStrVector(
"dateformat"))) {
90 available_locales = icu::DateFormat::getAvailableLocales(count);
91 }
else if (service->IsUtf8EqualTo(
CStrVector(
"breakiterator"))) {
92 available_locales = icu::BreakIterator::getAvailableLocales(count);
95 UErrorCode error = U_ZERO_ERROR;
96 char result[ULOC_FULLNAME_CAPACITY];
97 Handle<JSObject> locales = factory->NewJSObject(isolate->object_function());
100 const char* icu_name = available_locales[
i].getName();
102 error = U_ZERO_ERROR;
104 uloc_toLanguageTag(icu_name, result, ULOC_FULLNAME_CAPACITY, FALSE, &error);
105 if (U_FAILURE(error)) {
112 locales, factory->NewStringFromAsciiChecked(result),
113 factory->NewNumber(
i),
NONE));
121 HandleScope scope(isolate);
122 Factory* factory = isolate->factory();
124 DCHECK(args.length() == 0);
126 icu::Locale default_locale;
129 char result[ULOC_FULLNAME_CAPACITY];
130 UErrorCode status = U_ZERO_ERROR;
131 uloc_toLanguageTag(default_locale.getName(), result, ULOC_FULLNAME_CAPACITY,
133 if (U_SUCCESS(status)) {
134 return *factory->NewStringFromAsciiChecked(result);
137 return *factory->NewStringFromStaticChars(
"und");
142 HandleScope scope(isolate);
143 Factory* factory = isolate->factory();
145 DCHECK(args.length() == 1);
153 Handle<FixedArray> output = factory->NewFixedArray(length);
154 Handle<Name> maximized = factory->NewStringFromStaticChars(
"maximized");
155 Handle<Name> base = factory->NewStringFromStaticChars(
"base");
156 for (
unsigned int i = 0;
i < length; ++
i) {
157 Handle<Object> locale_id;
160 if (!locale_id->IsString()) {
161 return isolate->Throw(*factory->illegal_argument_string());
167 UErrorCode error = U_ZERO_ERROR;
171 char icu_locale[ULOC_FULLNAME_CAPACITY];
172 int icu_locale_length = 0;
173 uloc_forLanguageTag(*utf8_locale_id, icu_locale, ULOC_FULLNAME_CAPACITY,
174 &icu_locale_length, &error);
175 if (U_FAILURE(error) || icu_locale_length == 0) {
176 return isolate->Throw(*factory->illegal_argument_string());
181 char icu_max_locale[ULOC_FULLNAME_CAPACITY];
182 uloc_addLikelySubtags(icu_locale, icu_max_locale, ULOC_FULLNAME_CAPACITY,
187 char icu_base_max_locale[ULOC_FULLNAME_CAPACITY];
188 uloc_getBaseName(icu_max_locale, icu_base_max_locale,
189 ULOC_FULLNAME_CAPACITY, &error);
193 char icu_base_locale[ULOC_FULLNAME_CAPACITY];
194 uloc_getBaseName(icu_locale, icu_base_locale, ULOC_FULLNAME_CAPACITY,
199 char base_max_locale[ULOC_FULLNAME_CAPACITY];
200 uloc_toLanguageTag(icu_base_max_locale, base_max_locale,
201 ULOC_FULLNAME_CAPACITY, FALSE, &error);
204 char base_locale[ULOC_FULLNAME_CAPACITY];
205 uloc_toLanguageTag(icu_base_locale, base_locale, ULOC_FULLNAME_CAPACITY,
208 if (U_FAILURE(error)) {
209 return isolate->Throw(*factory->illegal_argument_string());
212 Handle<JSObject> result = factory->NewJSObject(isolate->object_function());
213 Handle<String> value = factory->NewStringFromAsciiChecked(base_max_locale);
215 value = factory->NewStringFromAsciiChecked(base_locale);
217 output->set(
i, *result);
220 Handle<JSArray> result = factory->NewJSArrayWithElements(output);
227 HandleScope scope(isolate);
229 DCHECK(args.length() == 1);
233 if (!input->IsJSObject())
return isolate->heap()->false_value();
236 Handle<String> marker = isolate->factory()->intl_initialized_marker_string();
237 Handle<Object> tag(obj->GetHiddenProperty(marker), isolate);
238 return isolate->heap()->ToBoolean(!tag->IsTheHole());
243 HandleScope scope(isolate);
245 DCHECK(args.length() == 2);
250 if (!input->IsJSObject())
return isolate->heap()->false_value();
253 Handle<String> marker = isolate->factory()->intl_initialized_marker_string();
254 Handle<Object> tag(obj->GetHiddenProperty(marker), isolate);
255 return isolate->heap()->ToBoolean(tag->IsString() &&
256 String::cast(*tag)->Equals(*expected_type));
261 HandleScope scope(isolate);
263 DCHECK(args.length() == 3);
269 Handle<String> marker = isolate->factory()->intl_initialized_marker_string();
272 marker = isolate->factory()->intl_impl_object_string();
275 return isolate->heap()->undefined_value();
280 HandleScope scope(isolate);
282 DCHECK(args.length() == 1);
286 if (!input->IsJSObject()) {
287 Vector<Handle<Object> > arguments =
HandleVector(&input, 1);
289 NewTypeError(
"not_intl_object", arguments));
294 Handle<String> marker = isolate->factory()->intl_impl_object_string();
295 Handle<Object> impl(obj->GetHiddenProperty(marker), isolate);
296 if (impl->IsTheHole()) {
297 Vector<Handle<Object> > arguments =
HandleVector(&obj, 1);
299 NewTypeError(
"not_intl_object", arguments));
306 HandleScope scope(isolate);
308 DCHECK(args.length() == 3);
317 Handle<JSObject> local_object;
319 isolate, local_object,
320 Execution::InstantiateObject(date_format_template));
323 icu::SimpleDateFormat* date_format =
326 if (!date_format)
return isolate->ThrowIllegalOperation();
328 local_object->SetInternalField(0,
reinterpret_cast<Smi*
>(date_format));
330 Factory* factory = isolate->factory();
331 Handle<String> key = factory->NewStringFromStaticChars(
"dateFormat");
332 Handle<String> value = factory->NewStringFromStaticChars(
"valid");
336 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
338 reinterpret_cast<void*
>(wrapper.location()),
340 return *local_object;
345 HandleScope scope(isolate);
347 DCHECK(args.length() == 2);
352 Handle<Object> value;
356 icu::SimpleDateFormat* date_format =
358 if (!date_format)
return isolate->ThrowIllegalOperation();
360 icu::UnicodeString result;
361 date_format->format(value->Number(), result);
363 Handle<String> result_str;
366 isolate->factory()->NewStringFromTwoByte(Vector<const uint16_t>(
367 reinterpret_cast<const uint16_t*
>(result.getBuffer()),
374 HandleScope scope(isolate);
376 DCHECK(args.length() == 2);
382 icu::UnicodeString u_date(icu::UnicodeString::fromUTF8(*utf8_date));
383 icu::SimpleDateFormat* date_format =
385 if (!date_format)
return isolate->ThrowIllegalOperation();
387 UErrorCode status = U_ZERO_ERROR;
388 UDate date = date_format->parse(u_date, status);
389 if (U_FAILURE(status))
return isolate->heap()->undefined_value();
391 Handle<Object> result;
393 isolate, result, Execution::NewDate(isolate,
static_cast<double>(date)));
394 DCHECK(result->IsJSDate());
400 HandleScope scope(isolate);
402 DCHECK(args.length() == 3);
408 Handle<ObjectTemplateInfo> number_format_template =
412 Handle<JSObject> local_object;
414 isolate, local_object,
415 Execution::InstantiateObject(number_format_template));
418 icu::DecimalFormat* number_format =
421 if (!number_format)
return isolate->ThrowIllegalOperation();
423 local_object->SetInternalField(0,
reinterpret_cast<Smi*
>(number_format));
425 Factory* factory = isolate->factory();
426 Handle<String> key = factory->NewStringFromStaticChars(
"numberFormat");
427 Handle<String> value = factory->NewStringFromStaticChars(
"valid");
430 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
432 reinterpret_cast<void*
>(wrapper.location()),
434 return *local_object;
439 HandleScope scope(isolate);
441 DCHECK(args.length() == 2);
446 Handle<Object> value;
450 icu::DecimalFormat* number_format =
452 if (!number_format)
return isolate->ThrowIllegalOperation();
454 icu::UnicodeString result;
455 number_format->format(value->Number(), result);
457 Handle<String> result_str;
460 isolate->factory()->NewStringFromTwoByte(Vector<const uint16_t>(
461 reinterpret_cast<const uint16_t*
>(result.getBuffer()),
468 HandleScope scope(isolate);
470 DCHECK(args.length() == 2);
476 icu::UnicodeString u_number(icu::UnicodeString::fromUTF8(*utf8_number));
477 icu::DecimalFormat* number_format =
479 if (!number_format)
return isolate->ThrowIllegalOperation();
481 UErrorCode status = U_ZERO_ERROR;
482 icu::Formattable result;
489 number_format->parse(u_number, result, status);
490 if (U_FAILURE(status))
return isolate->heap()->undefined_value();
492 switch (result.getType()) {
493 case icu::Formattable::kDouble:
494 return *isolate->factory()->NewNumber(result.getDouble());
495 case icu::Formattable::kLong:
496 return *isolate->factory()->NewNumberFromInt(result.getLong());
497 case icu::Formattable::kInt64:
498 return *isolate->factory()->NewNumber(
499 static_cast<double>(result.getInt64()));
501 return isolate->heap()->undefined_value();
507 HandleScope scope(isolate);
509 DCHECK(args.length() == 3);
518 Handle<JSObject> local_object;
520 isolate, local_object, Execution::InstantiateObject(collator_template));
523 icu::Collator* collator =
526 if (!collator)
return isolate->ThrowIllegalOperation();
528 local_object->SetInternalField(0,
reinterpret_cast<Smi*
>(collator));
530 Factory* factory = isolate->factory();
531 Handle<String> key = factory->NewStringFromStaticChars(
"collator");
532 Handle<String> value = factory->NewStringFromStaticChars(
"valid");
535 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
537 reinterpret_cast<void*
>(wrapper.location()),
539 return *local_object;
544 HandleScope scope(isolate);
546 DCHECK(args.length() == 3);
553 if (!collator)
return isolate->ThrowIllegalOperation();
557 const UChar* u_string1 =
reinterpret_cast<const UChar*
>(*string_value1);
558 const UChar* u_string2 =
reinterpret_cast<const UChar*
>(*string_value2);
559 UErrorCode status = U_ZERO_ERROR;
560 UCollationResult result =
561 collator->compare(u_string1, string_value1.length(), u_string2,
562 string_value2.length(), status);
563 if (U_FAILURE(status))
return isolate->ThrowIllegalOperation();
565 return *isolate->factory()->NewNumberFromInt(result);
570 HandleScope scope(isolate);
571 static const UNormalizationMode normalizationForms[] = {
572 UNORM_NFC, UNORM_NFD, UNORM_NFKC, UNORM_NFKD};
574 DCHECK(args.length() == 2);
579 static_cast<size_t>(form_id) <
arraysize(normalizationForms));
582 const UChar* u_value =
reinterpret_cast<const UChar*
>(*string_value);
585 UErrorCode status = U_ZERO_ERROR;
586 icu::UnicodeString result;
587 icu::Normalizer::normalize(u_value, normalizationForms[form_id], 0, result,
589 if (U_FAILURE(status)) {
590 return isolate->heap()->undefined_value();
593 Handle<String> result_str;
596 isolate->factory()->NewStringFromTwoByte(Vector<const uint16_t>(
597 reinterpret_cast<const uint16_t*
>(result.getBuffer()),
604 HandleScope scope(isolate);
606 DCHECK(args.length() == 3);
612 Handle<ObjectTemplateInfo> break_iterator_template =
616 Handle<JSObject> local_object;
618 isolate, local_object,
619 Execution::InstantiateObject(break_iterator_template));
623 isolate, locale, options, resolved);
625 if (!break_iterator)
return isolate->ThrowIllegalOperation();
627 local_object->SetInternalField(0,
reinterpret_cast<Smi*
>(break_iterator));
629 local_object->SetInternalField(1,
reinterpret_cast<Smi*
>(
NULL));
631 Factory* factory = isolate->factory();
632 Handle<String> key = factory->NewStringFromStaticChars(
"breakIterator");
633 Handle<String> value = factory->NewStringFromStaticChars(
"valid");
638 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
640 reinterpret_cast<void*
>(wrapper.location()),
642 return *local_object;
647 HandleScope scope(isolate);
649 DCHECK(args.length() == 2);
654 icu::BreakIterator* break_iterator =
656 if (!break_iterator)
return isolate->ThrowIllegalOperation();
658 icu::UnicodeString* u_text =
reinterpret_cast<icu::UnicodeString*
>(
659 break_iterator_holder->GetInternalField(1));
663 u_text =
new icu::UnicodeString(
reinterpret_cast<const UChar*
>(*text_value),
664 text_value.length());
665 break_iterator_holder->SetInternalField(1,
reinterpret_cast<Smi*
>(u_text));
667 break_iterator->setText(*u_text);
669 return isolate->heap()->undefined_value();
674 HandleScope scope(isolate);
676 DCHECK(args.length() == 1);
680 icu::BreakIterator* break_iterator =
682 if (!break_iterator)
return isolate->ThrowIllegalOperation();
684 return *isolate->factory()->NewNumberFromInt(break_iterator->first());
689 HandleScope scope(isolate);
691 DCHECK(args.length() == 1);
695 icu::BreakIterator* break_iterator =
697 if (!break_iterator)
return isolate->ThrowIllegalOperation();
699 return *isolate->factory()->NewNumberFromInt(break_iterator->next());
704 HandleScope scope(isolate);
706 DCHECK(args.length() == 1);
710 icu::BreakIterator* break_iterator =
712 if (!break_iterator)
return isolate->ThrowIllegalOperation();
714 return *isolate->factory()->NewNumberFromInt(break_iterator->current());
719 HandleScope scope(isolate);
721 DCHECK(args.length() == 1);
725 icu::BreakIterator* break_iterator =
727 if (!break_iterator)
return isolate->ThrowIllegalOperation();
730 icu::RuleBasedBreakIterator* rule_based_iterator =
731 static_cast<icu::RuleBasedBreakIterator*
>(break_iterator);
732 int32_t status = rule_based_iterator->getRuleStatus();
734 if (status >= UBRK_WORD_NONE && status < UBRK_WORD_NONE_LIMIT) {
735 return *isolate->factory()->NewStringFromStaticChars(
"none");
736 }
else if (status >= UBRK_WORD_NUMBER && status < UBRK_WORD_NUMBER_LIMIT) {
737 return *isolate->factory()->number_string();
738 }
else if (status >= UBRK_WORD_LETTER && status < UBRK_WORD_LETTER_LIMIT) {
739 return *isolate->factory()->NewStringFromStaticChars(
"letter");
740 }
else if (status >= UBRK_WORD_KANA && status < UBRK_WORD_KANA_LIMIT) {
741 return *isolate->factory()->NewStringFromStaticChars(
"kana");
742 }
else if (status >= UBRK_WORD_IDEO && status < UBRK_WORD_IDEO_LIMIT) {
743 return *isolate->factory()->NewStringFromStaticChars(
"ideo");
745 return *isolate->factory()->NewStringFromStaticChars(
"unknown");
Converts an object to a UTF-8-encoded character array.
Converts an object to a two-byte string.
static Local< Context > ToLocal(v8::internal::Handle< v8::internal::Context > obj)
static icu::BreakIterator * UnpackBreakIterator(Isolate *isolate, Handle< JSObject > obj)
static icu::BreakIterator * InitializeBreakIterator(Isolate *isolate, Handle< String > locale, Handle< JSObject > options, Handle< JSObject > resolved)
static void DeleteBreakIterator(const v8::WeakCallbackData< v8::Value, void > &data)
static icu::Collator * UnpackCollator(Isolate *isolate, Handle< JSObject > obj)
static void DeleteCollator(const v8::WeakCallbackData< v8::Value, void > &data)
static icu::Collator * InitializeCollator(Isolate *isolate, Handle< String > locale, Handle< JSObject > options, Handle< JSObject > resolved)
static void MakeWeak(Object **location, void *parameter, WeakCallback weak_callback)
static Handle< T > cast(Handle< S > that)
static Handle< ObjectTemplateInfo > GetTemplate(Isolate *isolate)
static Handle< ObjectTemplateInfo > GetTemplate2(Isolate *isolate)
static Handle< Object > SetHiddenProperty(Handle< JSObject > object, Handle< Name > key, Handle< Object > value)
static void AddProperty(Handle< JSObject > object, Handle< Name > key, Handle< Object > value, PropertyAttributes attributes)
static MUST_USE_RESULT MaybeHandle< Object > SetOwnPropertyIgnoreAttributes(Handle< JSObject > object, Handle< Name > key, Handle< Object > value, PropertyAttributes attributes, ExecutableAccessorInfoHandling handling=DEFAULT_HANDLING)
static MUST_USE_RESULT MaybeHandle< Object > GetElement(Isolate *isolate, Handle< Object > object, uint32_t index)
static Smi * FromInt(int value)
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, dst, call)
#define THROW_NEW_ERROR_RETURN_FAILURE(isolate, call)
#define RETURN_FAILURE_ON_EXCEPTION(isolate, call)
#define DCHECK(condition)
Vector< const char > CStrVector(const char *data)
int ToNumber(Register reg)
kSerializedDataOffset Object
Vector< Handle< Object > > HandleVector(v8::internal::Handle< T > *elms, int length)
Debugger support for the V8 JavaScript engine.
#define RUNTIME_ASSERT(value)
#define CONVERT_ARG_HANDLE_CHECKED(Type, name, index)
#define CONVERT_NUMBER_CHECKED(type, name, Type, obj)