5 #ifndef V8_INTL_SUPPORT 6 #error Internationalization is expected to be enabled. 7 #endif // V8_INTL_SUPPORT 13 #include "src/builtins/builtins-utils-inl.h" 14 #include "src/builtins/builtins.h" 15 #include "src/counters.h" 17 #include "src/elements.h" 18 #include "src/objects-inl.h" 19 #include "src/objects/intl-objects.h" 20 #include "src/objects/js-array-inl.h" 21 #include "src/objects/js-break-iterator-inl.h" 22 #include "src/objects/js-collator-inl.h" 23 #include "src/objects/js-date-time-format-inl.h" 24 #include "src/objects/js-list-format-inl.h" 25 #include "src/objects/js-locale-inl.h" 26 #include "src/objects/js-number-format-inl.h" 27 #include "src/objects/js-plural-rules-inl.h" 28 #include "src/objects/js-relative-time-format-inl.h" 29 #include "src/objects/js-segment-iterator-inl.h" 30 #include "src/objects/js-segmenter-inl.h" 31 #include "src/objects/smi.h" 32 #include "src/property-descriptor.h" 34 #include "unicode/brkiter.h" 39 BUILTIN(StringPrototypeToUpperCaseIntl) {
40 HandleScope scope(isolate);
41 TO_THIS_STRING(
string,
"String.prototype.toUpperCase");
42 string = String::Flatten(isolate,
string);
43 RETURN_RESULT_OR_FAILURE(isolate, Intl::ConvertToUpper(isolate,
string));
46 BUILTIN(StringPrototypeNormalizeIntl) {
47 HandleScope handle_scope(isolate);
48 TO_THIS_STRING(
string,
"String.prototype.normalize");
50 Handle<Object> form_input = args.atOrUndefined(isolate, 1);
52 RETURN_RESULT_OR_FAILURE(isolate,
53 Intl::Normalize(isolate,
string, form_input));
56 BUILTIN(V8BreakIteratorSupportedLocalesOf) {
57 HandleScope scope(isolate);
58 Handle<Object> locales = args.atOrUndefined(isolate, 1);
59 Handle<Object> options = args.atOrUndefined(isolate, 2);
61 RETURN_RESULT_OR_FAILURE(
62 isolate, Intl::SupportedLocalesOf(
63 isolate,
"Intl.v8BreakIterator.supportedLocalesOf",
64 JSV8BreakIterator::GetAvailableLocales(), locales, options));
67 BUILTIN(NumberFormatSupportedLocalesOf) {
68 HandleScope scope(isolate);
69 Handle<Object> locales = args.atOrUndefined(isolate, 1);
70 Handle<Object> options = args.atOrUndefined(isolate, 2);
72 RETURN_RESULT_OR_FAILURE(
73 isolate, Intl::SupportedLocalesOf(
74 isolate,
"Intl.NumberFormat.supportedLocalesOf",
75 JSNumberFormat::GetAvailableLocales(), locales, options));
78 BUILTIN(NumberFormatPrototypeFormatToParts) {
79 const char*
const method =
"Intl.NumberFormat.prototype.formatToParts";
80 HandleScope handle_scope(isolate);
81 CHECK_RECEIVER(JSNumberFormat, number_format, method);
84 if (args.length() >= 2) {
85 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x,
86 Object::ToNumber(isolate, args.at(1)));
88 x = isolate->factory()->nan_value();
91 RETURN_RESULT_OR_FAILURE(isolate, JSNumberFormat::FormatToParts(
92 isolate, number_format, x->Number()));
95 BUILTIN(DateTimeFormatPrototypeResolvedOptions) {
96 const char*
const method =
"Intl.DateTimeFormat.prototype.resolvedOptions";
97 HandleScope scope(isolate);
98 CHECK_RECEIVER(JSReceiver, format_holder, method);
101 Handle<JSDateTimeFormat> date_time_format;
102 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
103 isolate, date_time_format,
104 JSDateTimeFormat::UnwrapDateTimeFormat(isolate, format_holder));
106 RETURN_RESULT_OR_FAILURE(
107 isolate, JSDateTimeFormat::ResolvedOptions(isolate, date_time_format));
110 BUILTIN(DateTimeFormatSupportedLocalesOf) {
111 HandleScope scope(isolate);
112 Handle<Object> locales = args.atOrUndefined(isolate, 1);
113 Handle<Object> options = args.atOrUndefined(isolate, 2);
115 RETURN_RESULT_OR_FAILURE(
116 isolate, Intl::SupportedLocalesOf(
117 isolate,
"Intl.DateTimeFormat.supportedLocalesOf",
118 JSDateTimeFormat::GetAvailableLocales(), locales, options));
121 BUILTIN(DateTimeFormatPrototypeFormatToParts) {
122 const char*
const method =
"Intl.DateTimeFormat.prototype.formatToParts";
123 HandleScope handle_scope(isolate);
124 CHECK_RECEIVER(JSObject, date_format_holder, method);
125 Factory* factory = isolate->factory();
127 if (!date_format_holder->IsJSDateTimeFormat()) {
128 THROW_NEW_ERROR_RETURN_FAILURE(
129 isolate, NewTypeError(MessageTemplate::kIncompatibleMethodReceiver,
130 factory->NewStringFromAsciiChecked(method),
131 date_format_holder));
133 Handle<JSDateTimeFormat> dtf =
134 Handle<JSDateTimeFormat>::cast(date_format_holder);
136 Handle<Object> x = args.atOrUndefined(isolate, 1);
137 if (x->IsUndefined(isolate)) {
138 x = factory->NewNumber(JSDate::CurrentTimeValue(isolate));
140 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x,
141 Object::ToNumber(isolate, args.at(1)));
144 double date_value = DateCache::TimeClip(x->Number());
145 if (std::isnan(date_value)) {
146 THROW_NEW_ERROR_RETURN_FAILURE(
147 isolate, NewRangeError(MessageTemplate::kInvalidTimeValue));
150 RETURN_RESULT_OR_FAILURE(
151 isolate, JSDateTimeFormat::FormatToParts(isolate, dtf, date_value));
155 Handle<JSFunction> CreateBoundFunction(Isolate* isolate,
156 Handle<JSObject>
object,
157 Builtins::Name builtin_id,
int len) {
158 Handle<NativeContext> native_context(isolate->context()->native_context(),
160 Handle<Context> context = isolate->factory()->NewBuiltinContext(
162 static_cast<int>(Intl::BoundFunctionContextSlot::kLength));
164 context->set(static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction),
167 Handle<SharedFunctionInfo> info =
168 isolate->factory()->NewSharedFunctionInfoForBuiltin(
169 isolate->factory()->empty_string(), builtin_id, kNormalFunction);
170 info->set_internal_formal_parameter_count(len);
171 info->set_length(len);
173 Handle<Map> map = isolate->strict_function_without_prototype_map();
175 Handle<JSFunction> new_bound_function =
176 isolate->factory()->NewFunctionFromSharedFunctionInfo(map, info, context);
177 return new_bound_function;
185 Object* LegacyFormatConstructor(BuiltinArguments args, Isolate* isolate,
186 v8::Isolate::UseCounterFeature feature,
187 Handle<Object> constructor,
188 const char* method) {
189 isolate->CountUsage(feature);
190 Handle<JSReceiver> new_target;
193 if (args.new_target()->IsUndefined(isolate)) {
194 new_target = args.target();
196 new_target = Handle<JSReceiver>::cast(args.new_target());
200 Handle<JSFunction> target = args.target();
202 Handle<Object> locales = args.atOrUndefined(isolate, 1);
203 Handle<Object> options = args.atOrUndefined(isolate, 2);
208 Handle<JSObject> obj;
209 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
211 JSObject::New(target, new_target, Handle<AllocationSite>::null()));
212 Handle<T> format = Handle<T>::cast(obj);
215 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
216 isolate, format, T::Initialize(isolate, format, locales, options));
218 Handle<Object> receiver = args.receiver();
225 Handle<Object> is_instance_of_obj;
226 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
227 isolate, is_instance_of_obj,
228 Object::InstanceOf(isolate, receiver, constructor));
231 bool is_instance_of = is_instance_of_obj->BooleanValue(isolate);
233 if (args.new_target()->IsUndefined(isolate) && is_instance_of) {
234 if (!receiver->IsJSReceiver()) {
235 THROW_NEW_ERROR_RETURN_FAILURE(
237 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver,
238 isolate->factory()->NewStringFromAsciiChecked(method),
241 Handle<JSReceiver> rec = Handle<JSReceiver>::cast(receiver);
245 PropertyDescriptor desc;
246 desc.set_value(format);
247 desc.set_writable(
false);
248 desc.set_enumerable(
false);
249 desc.set_configurable(
false);
250 Maybe<bool> success = JSReceiver::DefineOwnProperty(
251 isolate, rec, isolate->factory()->intl_fallback_symbol(), &desc,
253 MAYBE_RETURN(success, ReadOnlyRoots(isolate).exception());
254 CHECK(success.FromJust());
267 Object* DisallowCallConstructor(BuiltinArguments args, Isolate* isolate,
268 v8::Isolate::UseCounterFeature feature,
269 const char* method) {
270 isolate->CountUsage(feature);
273 if (args.new_target()->IsUndefined(isolate)) {
274 THROW_NEW_ERROR_RETURN_FAILURE(
276 NewTypeError(MessageTemplate::kConstructorNotFunction,
277 isolate->factory()->NewStringFromAsciiChecked(method)));
280 Handle<JSFunction> target = args.target();
281 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target());
283 Handle<JSObject> obj;
286 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
288 JSObject::New(target, new_target, Handle<AllocationSite>::null()));
289 Handle<T> result = Handle<T>::cast(obj);
290 result->set_flags(0);
292 Handle<Object> locales = args.atOrUndefined(isolate, 1);
293 Handle<Object> options = args.atOrUndefined(isolate, 2);
296 RETURN_RESULT_OR_FAILURE(isolate,
297 T::Initialize(isolate, result, locales, options));
304 Object* CallOrConstructConstructor(BuiltinArguments args, Isolate* isolate) {
305 Handle<JSReceiver> new_target;
307 if (args.new_target()->IsUndefined(isolate)) {
308 new_target = args.target();
310 new_target = Handle<JSReceiver>::cast(args.new_target());
314 Handle<JSFunction> target = args.target();
316 Handle<Object> locales = args.atOrUndefined(isolate, 1);
317 Handle<Object> options = args.atOrUndefined(isolate, 2);
319 Handle<JSObject> obj;
320 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
322 JSObject::New(target, new_target, Handle<AllocationSite>::null()));
323 Handle<T> result = Handle<T>::cast(obj);
325 RETURN_RESULT_OR_FAILURE(isolate,
326 T::Initialize(isolate, result, locales, options));
330 BUILTIN(NumberFormatConstructor) {
331 HandleScope scope(isolate);
333 return LegacyFormatConstructor<JSNumberFormat>(
334 args, isolate, v8::Isolate::UseCounterFeature::kNumberFormat,
335 isolate->intl_number_format_function(),
"Intl.NumberFormat");
338 BUILTIN(NumberFormatPrototypeResolvedOptions) {
339 HandleScope scope(isolate);
340 const char*
const method =
"Intl.NumberFormat.prototype.resolvedOptions";
344 CHECK_RECEIVER(JSReceiver, number_format_holder, method);
347 Handle<JSNumberFormat> number_format;
348 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
349 isolate, number_format,
350 JSNumberFormat::UnwrapNumberFormat(isolate, number_format_holder));
352 return *JSNumberFormat::ResolvedOptions(isolate, number_format);
355 BUILTIN(NumberFormatPrototypeFormatNumber) {
356 const char*
const method =
"get Intl.NumberFormat.prototype.format";
357 HandleScope scope(isolate);
361 CHECK_RECEIVER(JSReceiver, receiver, method);
364 Handle<JSNumberFormat> number_format;
365 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
366 isolate, number_format,
367 JSNumberFormat::UnwrapNumberFormat(isolate, receiver));
369 Handle<Object> bound_format(number_format->bound_format(), isolate);
372 if (!bound_format->IsUndefined(isolate)) {
373 DCHECK(bound_format->IsJSFunction());
375 return *bound_format;
378 Handle<JSFunction> new_bound_format_function = CreateBoundFunction(
379 isolate, number_format, Builtins::kNumberFormatInternalFormatNumber, 1);
382 number_format->set_bound_format(*new_bound_format_function);
385 return *new_bound_format_function;
388 BUILTIN(NumberFormatInternalFormatNumber) {
389 HandleScope scope(isolate);
391 Handle<Context> context = Handle<Context>(isolate->context(), isolate);
396 Handle<JSNumberFormat> number_format = Handle<JSNumberFormat>(
397 JSNumberFormat::cast(context->get(
398 static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
402 Handle<Object> value = args.atOrUndefined(isolate, 1);
405 Handle<Object> number_obj;
406 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_obj,
407 Object::ToNumber(isolate, value));
410 if (number_obj->IsMinusZero()) {
411 number_obj = Handle<Smi>(Smi::zero(), isolate);
414 double number = number_obj->Number();
415 icu::NumberFormat* icu_number_format =
416 number_format->icu_number_format()->raw();
417 CHECK_NOT_NULL(icu_number_format);
420 RETURN_RESULT_OR_FAILURE(isolate, JSNumberFormat::FormatNumber(
421 isolate, *icu_number_format, number));
424 BUILTIN(DateTimeFormatConstructor) {
425 HandleScope scope(isolate);
427 return LegacyFormatConstructor<JSDateTimeFormat>(
428 args, isolate, v8::Isolate::UseCounterFeature::kDateTimeFormat,
429 isolate->intl_date_time_format_function(),
"Intl.DateTimeFormat");
432 BUILTIN(DateTimeFormatPrototypeFormat) {
433 const char*
const method =
"get Intl.DateTimeFormat.prototype.format";
434 HandleScope scope(isolate);
438 CHECK_RECEIVER(JSReceiver, receiver, method);
441 Handle<JSDateTimeFormat> format;
442 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
444 JSDateTimeFormat::UnwrapDateTimeFormat(isolate, receiver));
446 Handle<Object> bound_format = Handle<Object>(format->bound_format(), isolate);
449 if (!bound_format->IsUndefined(isolate)) {
450 DCHECK(bound_format->IsJSFunction());
452 return *bound_format;
455 Handle<JSFunction> new_bound_format_function = CreateBoundFunction(
456 isolate, format, Builtins::kDateTimeFormatInternalFormat, 1);
459 format->set_bound_format(*new_bound_format_function);
462 return *new_bound_format_function;
465 BUILTIN(DateTimeFormatInternalFormat) {
466 HandleScope scope(isolate);
467 Handle<Context> context = Handle<Context>(isolate->context(), isolate);
472 Handle<JSDateTimeFormat> date_format_holder = Handle<JSDateTimeFormat>(
473 JSDateTimeFormat::cast(context->get(
474 static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
477 Handle<Object> date = args.atOrUndefined(isolate, 1);
479 RETURN_RESULT_OR_FAILURE(isolate, JSDateTimeFormat::DateTimeFormat(
480 isolate, date_format_holder, date));
483 BUILTIN(IntlGetCanonicalLocales) {
484 HandleScope scope(isolate);
485 Handle<Object> locales = args.atOrUndefined(isolate, 1);
487 RETURN_RESULT_OR_FAILURE(isolate,
488 Intl::GetCanonicalLocales(isolate, locales));
491 BUILTIN(ListFormatConstructor) {
492 HandleScope scope(isolate);
494 return DisallowCallConstructor<JSListFormat>(
495 args, isolate, v8::Isolate::UseCounterFeature::kListFormat,
499 BUILTIN(ListFormatPrototypeResolvedOptions) {
500 HandleScope scope(isolate);
501 CHECK_RECEIVER(JSListFormat, format_holder,
502 "Intl.ListFormat.prototype.resolvedOptions");
503 return *JSListFormat::ResolvedOptions(isolate, format_holder);
506 BUILTIN(ListFormatSupportedLocalesOf) {
507 HandleScope scope(isolate);
508 Handle<Object> locales = args.atOrUndefined(isolate, 1);
509 Handle<Object> options = args.atOrUndefined(isolate, 2);
511 RETURN_RESULT_OR_FAILURE(
512 isolate, Intl::SupportedLocalesOf(
513 isolate,
"Intl.ListFormat.supportedLocalesOf",
514 JSListFormat::GetAvailableLocales(), locales, options));
519 MaybeHandle<JSLocale> CreateLocale(Isolate* isolate,
520 Handle<JSFunction> constructor,
521 Handle<JSReceiver> new_target,
522 Handle<Object> tag, Handle<Object> options) {
523 Handle<JSObject> locale;
526 ASSIGN_RETURN_ON_EXCEPTION(
528 JSObject::New(constructor, new_target, Handle<AllocationSite>::null()),
532 if (!tag->IsString() && !tag->IsJSReceiver()) {
533 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kLocaleNotEmpty),
537 Handle<String> locale_string;
540 if (tag->IsJSLocale() && Handle<JSLocale>::cast(tag)->locale()->IsString()) {
543 Handle<String>(Handle<JSLocale>::cast(tag)->locale(), isolate);
546 ASSIGN_RETURN_ON_EXCEPTION(isolate, locale_string,
547 Object::ToString(isolate, tag), JSLocale);
550 Handle<JSReceiver> options_object;
552 if (options->IsUndefined(isolate)) {
554 options_object = isolate->factory()->NewJSObjectWithNullProto();
557 ASSIGN_RETURN_ON_EXCEPTION(isolate, options_object,
558 Object::ToObject(isolate, options), JSLocale);
561 return JSLocale::Initialize(isolate, Handle<JSLocale>::cast(locale),
562 locale_string, options_object);
568 BUILTIN(LocaleConstructor) {
569 HandleScope scope(isolate);
571 isolate->CountUsage(v8::Isolate::UseCounterFeature::kLocale);
573 if (args.new_target()->IsUndefined(isolate)) {
574 THROW_NEW_ERROR_RETURN_FAILURE(
575 isolate, NewTypeError(MessageTemplate::kConstructorNotFunction,
576 isolate->factory()->NewStringFromAsciiChecked(
580 Handle<JSFunction> target = args.target();
581 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target());
583 Handle<Object> tag = args.atOrUndefined(isolate, 1);
584 Handle<Object> options = args.atOrUndefined(isolate, 2);
586 RETURN_RESULT_OR_FAILURE(
587 isolate, CreateLocale(isolate, target, new_target, tag, options));
590 BUILTIN(LocalePrototypeMaximize) {
591 HandleScope scope(isolate);
592 CHECK_RECEIVER(JSLocale, locale_holder,
"Intl.Locale.prototype.maximize");
593 Handle<JSFunction> constructor(
594 isolate->native_context()->intl_locale_function(), isolate);
595 RETURN_RESULT_OR_FAILURE(
597 CreateLocale(isolate, constructor, constructor,
598 JSLocale::Maximize(isolate, locale_holder->locale()),
599 isolate->factory()->NewJSObjectWithNullProto()));
602 BUILTIN(LocalePrototypeMinimize) {
603 HandleScope scope(isolate);
604 CHECK_RECEIVER(JSLocale, locale_holder,
"Intl.Locale.prototype.minimize");
605 Handle<JSFunction> constructor(
606 isolate->native_context()->intl_locale_function(), isolate);
607 RETURN_RESULT_OR_FAILURE(
609 CreateLocale(isolate, constructor, constructor,
610 JSLocale::Minimize(isolate, locale_holder->locale()),
611 isolate->factory()->NewJSObjectWithNullProto()));
614 BUILTIN(RelativeTimeFormatSupportedLocalesOf) {
615 HandleScope scope(isolate);
616 Handle<Object> locales = args.atOrUndefined(isolate, 1);
617 Handle<Object> options = args.atOrUndefined(isolate, 2);
619 RETURN_RESULT_OR_FAILURE(
621 Intl::SupportedLocalesOf(
622 isolate,
"Intl.RelativeTimeFormat.supportedLocalesOf",
623 JSRelativeTimeFormat::GetAvailableLocales(), locales, options));
626 BUILTIN(RelativeTimeFormatPrototypeFormat) {
627 HandleScope scope(isolate);
632 CHECK_RECEIVER(JSRelativeTimeFormat, format_holder,
633 "Intl.RelativeTimeFormat.prototype.format");
634 Handle<Object> value_obj = args.atOrUndefined(isolate, 1);
635 Handle<Object> unit_obj = args.atOrUndefined(isolate, 2);
637 RETURN_RESULT_OR_FAILURE(
638 isolate, JSRelativeTimeFormat::Format(isolate, value_obj, unit_obj,
639 format_holder,
"format",
false));
642 BUILTIN(RelativeTimeFormatPrototypeFormatToParts) {
643 HandleScope scope(isolate);
648 CHECK_RECEIVER(JSRelativeTimeFormat, format_holder,
649 "Intl.RelativeTimeFormat.prototype.formatToParts");
650 Handle<Object> value_obj = args.atOrUndefined(isolate, 1);
651 Handle<Object> unit_obj = args.atOrUndefined(isolate, 2);
652 RETURN_RESULT_OR_FAILURE(isolate, JSRelativeTimeFormat::Format(
653 isolate, value_obj, unit_obj,
654 format_holder,
"formatToParts",
true));
658 BUILTIN(LocalePrototypeLanguage) {
659 HandleScope scope(isolate);
661 CHECK_RECEIVER(JSLocale, locale_holder,
"Intl.Locale.prototype.language");
663 return locale_holder->language();
666 BUILTIN(LocalePrototypeScript) {
667 HandleScope scope(isolate);
668 CHECK_RECEIVER(JSLocale, locale_holder,
"Intl.Locale.prototype.script");
670 return locale_holder->script();
673 BUILTIN(LocalePrototypeRegion) {
674 HandleScope scope(isolate);
675 CHECK_RECEIVER(JSLocale, locale_holder,
"Intl.Locale.prototype.region");
677 return locale_holder->region();
680 BUILTIN(LocalePrototypeBaseName) {
681 HandleScope scope(isolate);
682 CHECK_RECEIVER(JSLocale, locale_holder,
"Intl.Locale.prototype.baseName");
684 return locale_holder->base_name();
687 BUILTIN(LocalePrototypeCalendar) {
688 HandleScope scope(isolate);
689 CHECK_RECEIVER(JSLocale, locale_holder,
"Intl.Locale.prototype.calendar");
691 return locale_holder->calendar();
694 BUILTIN(LocalePrototypeCaseFirst) {
695 HandleScope scope(isolate);
696 CHECK_RECEIVER(JSLocale, locale_holder,
"Intl.Locale.prototype.caseFirst");
698 return *(locale_holder->CaseFirstAsString());
701 BUILTIN(LocalePrototypeCollation) {
702 HandleScope scope(isolate);
703 CHECK_RECEIVER(JSLocale, locale_holder,
"Intl.Locale.prototype.collation");
705 return locale_holder->collation();
708 BUILTIN(LocalePrototypeHourCycle) {
709 HandleScope scope(isolate);
710 CHECK_RECEIVER(JSLocale, locale_holder,
"Intl.Locale.prototype.hourCycle");
712 return *(locale_holder->HourCycleAsString());
715 BUILTIN(LocalePrototypeNumeric) {
716 HandleScope scope(isolate);
717 CHECK_RECEIVER(JSLocale, locale_holder,
"Intl.Locale.prototype.numeric");
719 switch (locale_holder->numeric()) {
720 case JSLocale::Numeric::TRUE_VALUE:
721 return *(isolate->factory()->true_value());
722 case JSLocale::Numeric::FALSE_VALUE:
723 return *(isolate->factory()->false_value());
724 case JSLocale::Numeric::NOTSET:
725 return *(isolate->factory()->undefined_value());
726 case JSLocale::Numeric::COUNT:
731 BUILTIN(LocalePrototypeNumberingSystem) {
732 HandleScope scope(isolate);
733 CHECK_RECEIVER(JSLocale, locale_holder,
734 "Intl.Locale.prototype.numberingSystem");
736 return locale_holder->numbering_system();
739 BUILTIN(LocalePrototypeToString) {
740 HandleScope scope(isolate);
741 CHECK_RECEIVER(JSLocale, locale_holder,
"Intl.Locale.prototype.toString");
743 return locale_holder->locale();
746 BUILTIN(RelativeTimeFormatConstructor) {
747 HandleScope scope(isolate);
749 return DisallowCallConstructor<JSRelativeTimeFormat>(
750 args, isolate, v8::Isolate::UseCounterFeature::kRelativeTimeFormat,
751 "Intl.RelativeTimeFormat");
754 BUILTIN(RelativeTimeFormatPrototypeResolvedOptions) {
755 HandleScope scope(isolate);
756 CHECK_RECEIVER(JSRelativeTimeFormat, format_holder,
757 "Intl.RelativeTimeFormat.prototype.resolvedOptions");
758 return *JSRelativeTimeFormat::ResolvedOptions(isolate, format_holder);
761 BUILTIN(StringPrototypeToLocaleLowerCase) {
762 HandleScope scope(isolate);
764 isolate->CountUsage(v8::Isolate::UseCounterFeature::kStringToLocaleLowerCase);
766 TO_THIS_STRING(
string,
"String.prototype.toLocaleLowerCase");
768 RETURN_RESULT_OR_FAILURE(
769 isolate, Intl::StringLocaleConvertCase(isolate,
string,
false,
770 args.atOrUndefined(isolate, 1)));
773 BUILTIN(StringPrototypeToLocaleUpperCase) {
774 HandleScope scope(isolate);
776 isolate->CountUsage(v8::Isolate::UseCounterFeature::kStringToLocaleUpperCase);
778 TO_THIS_STRING(
string,
"String.prototype.toLocaleUpperCase");
780 RETURN_RESULT_OR_FAILURE(
781 isolate, Intl::StringLocaleConvertCase(isolate,
string,
true,
782 args.atOrUndefined(isolate, 1)));
785 BUILTIN(PluralRulesConstructor) {
786 HandleScope scope(isolate);
788 return DisallowCallConstructor<JSPluralRules>(
789 args, isolate, v8::Isolate::UseCounterFeature::kPluralRules,
793 BUILTIN(PluralRulesPrototypeResolvedOptions) {
794 HandleScope scope(isolate);
795 CHECK_RECEIVER(JSPluralRules, plural_rules_holder,
796 "Intl.PluralRules.prototype.resolvedOptions");
797 return *JSPluralRules::ResolvedOptions(isolate, plural_rules_holder);
800 BUILTIN(PluralRulesPrototypeSelect) {
801 HandleScope scope(isolate);
807 CHECK_RECEIVER(JSPluralRules, plural_rules,
808 "Intl.PluralRules.prototype.select");
811 Handle<Object> number = args.atOrUndefined(isolate, 1);
812 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number,
813 Object::ToNumber(isolate, number));
814 double number_double = number->Number();
817 RETURN_RESULT_OR_FAILURE(isolate, JSPluralRules::ResolvePlural(
818 isolate, plural_rules, number_double));
821 BUILTIN(PluralRulesSupportedLocalesOf) {
822 HandleScope scope(isolate);
823 Handle<Object> locales = args.atOrUndefined(isolate, 1);
824 Handle<Object> options = args.atOrUndefined(isolate, 2);
826 RETURN_RESULT_OR_FAILURE(
827 isolate, Intl::SupportedLocalesOf(
828 isolate,
"Intl.PluralRules.supportedLocalesOf",
829 JSPluralRules::GetAvailableLocales(), locales, options));
832 BUILTIN(CollatorConstructor) {
833 HandleScope scope(isolate);
835 isolate->CountUsage(v8::Isolate::UseCounterFeature::kCollator);
837 return CallOrConstructConstructor<JSCollator>(args, isolate);
840 BUILTIN(CollatorPrototypeResolvedOptions) {
841 HandleScope scope(isolate);
842 CHECK_RECEIVER(JSCollator, collator_holder,
843 "Intl.Collator.prototype.resolvedOptions");
844 return *JSCollator::ResolvedOptions(isolate, collator_holder);
847 BUILTIN(CollatorSupportedLocalesOf) {
848 HandleScope scope(isolate);
849 Handle<Object> locales = args.atOrUndefined(isolate, 1);
850 Handle<Object> options = args.atOrUndefined(isolate, 2);
852 RETURN_RESULT_OR_FAILURE(
853 isolate, Intl::SupportedLocalesOf(
854 isolate,
"Intl.Collator.supportedLocalesOf",
855 JSCollator::GetAvailableLocales(), locales, options));
858 BUILTIN(CollatorPrototypeCompare) {
859 const char*
const method =
"get Intl.Collator.prototype.compare";
860 HandleScope scope(isolate);
866 CHECK_RECEIVER(JSCollator, collator, method);
869 Handle<Object> bound_compare(collator->bound_compare(), isolate);
870 if (!bound_compare->IsUndefined(isolate)) {
871 DCHECK(bound_compare->IsJSFunction());
873 return *bound_compare;
876 Handle<JSFunction> new_bound_compare_function = CreateBoundFunction(
877 isolate, collator, Builtins::kCollatorInternalCompare, 2);
880 collator->set_bound_compare(*new_bound_compare_function);
883 return *new_bound_compare_function;
886 BUILTIN(CollatorInternalCompare) {
887 HandleScope scope(isolate);
888 Handle<Context> context = Handle<Context>(isolate->context(), isolate);
893 Handle<JSCollator> collator = Handle<JSCollator>(
894 JSCollator::cast(context->get(
895 static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
899 Handle<Object> x = args.atOrUndefined(isolate, 1);
901 Handle<Object> y = args.atOrUndefined(isolate, 2);
904 Handle<String> string_x;
905 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, string_x,
906 Object::ToString(isolate, x));
908 Handle<String> string_y;
909 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, string_y,
910 Object::ToString(isolate, y));
913 icu::Collator* icu_collator = collator->icu_collator()->raw();
914 CHECK_NOT_NULL(icu_collator);
915 return *Intl::CompareStrings(isolate, *icu_collator, string_x, string_y);
919 BUILTIN(SegmentIteratorPrototypeBreakType) {
920 const char*
const method =
"get %SegmentIteratorPrototype%.breakType";
921 HandleScope scope(isolate);
923 CHECK_RECEIVER(JSSegmentIterator, segment_iterator, method);
924 return *segment_iterator->BreakType();
928 BUILTIN(SegmentIteratorPrototypeFollowing) {
929 const char*
const method =
"%SegmentIteratorPrototype%.following";
930 HandleScope scope(isolate);
931 CHECK_RECEIVER(JSSegmentIterator, segment_iterator, method);
933 Handle<Object> from = args.atOrUndefined(isolate, 1);
935 Maybe<bool> success =
936 JSSegmentIterator::Following(isolate, segment_iterator, from);
937 MAYBE_RETURN(success, ReadOnlyRoots(isolate).exception());
938 return *isolate->factory()->ToBoolean(success.FromJust());
942 BUILTIN(SegmentIteratorPrototypeNext) {
943 const char*
const method =
"%SegmentIteratorPrototype%.next";
944 HandleScope scope(isolate);
945 CHECK_RECEIVER(JSSegmentIterator, segment_iterator, method);
947 RETURN_RESULT_OR_FAILURE(isolate,
948 JSSegmentIterator::Next(isolate, segment_iterator));
952 BUILTIN(SegmentIteratorPrototypePreceding) {
953 const char*
const method =
"%SegmentIteratorPrototype%.preceding";
954 HandleScope scope(isolate);
955 CHECK_RECEIVER(JSSegmentIterator, segment_iterator, method);
957 Handle<Object> from = args.atOrUndefined(isolate, 1);
959 Maybe<bool> success =
960 JSSegmentIterator::Preceding(isolate, segment_iterator, from);
961 MAYBE_RETURN(success, ReadOnlyRoots(isolate).exception());
962 return *isolate->factory()->ToBoolean(success.FromJust());
966 BUILTIN(SegmentIteratorPrototypePosition) {
967 const char*
const method =
"get %SegmentIteratorPrototype%.position";
968 HandleScope scope(isolate);
970 CHECK_RECEIVER(JSSegmentIterator, segment_iterator, method);
971 return *JSSegmentIterator::Position(isolate, segment_iterator);
974 BUILTIN(SegmenterConstructor) {
975 HandleScope scope(isolate);
977 return DisallowCallConstructor<JSSegmenter>(
978 args, isolate, v8::Isolate::UseCounterFeature::kSegmenter,
982 BUILTIN(SegmenterSupportedLocalesOf) {
983 HandleScope scope(isolate);
984 Handle<Object> locales = args.atOrUndefined(isolate, 1);
985 Handle<Object> options = args.atOrUndefined(isolate, 2);
987 RETURN_RESULT_OR_FAILURE(
988 isolate, Intl::SupportedLocalesOf(
989 isolate,
"Intl.Segmenter.supportedLocalesOf",
990 JSSegmenter::GetAvailableLocales(), locales, options));
993 BUILTIN(SegmenterPrototypeResolvedOptions) {
994 HandleScope scope(isolate);
995 CHECK_RECEIVER(JSSegmenter, segmenter_holder,
996 "Intl.Segmenter.prototype.resolvedOptions");
997 return *JSSegmenter::ResolvedOptions(isolate, segmenter_holder);
1001 BUILTIN(SegmenterPrototypeSegment) {
1002 HandleScope scope(isolate);
1003 CHECK_RECEIVER(JSSegmenter, segmenter_holder,
1004 "Intl.Segmenter.prototype.segment");
1005 Handle<Object> input_text = args.atOrUndefined(isolate, 1);
1007 Handle<String> text;
1008 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, text,
1009 Object::ToString(isolate, input_text));
1012 RETURN_RESULT_OR_FAILURE(
1014 JSSegmentIterator::Create(
1015 isolate, segmenter_holder->icu_break_iterator()->raw()->clone(),
1016 segmenter_holder->granularity(), text));
1019 BUILTIN(V8BreakIteratorConstructor) {
1020 HandleScope scope(isolate);
1022 return CallOrConstructConstructor<JSV8BreakIterator>(args, isolate);
1025 BUILTIN(V8BreakIteratorPrototypeResolvedOptions) {
1026 HandleScope scope(isolate);
1027 CHECK_RECEIVER(JSV8BreakIterator, break_iterator,
1028 "Intl.v8BreakIterator.prototype.resolvedOptions");
1029 return *JSV8BreakIterator::ResolvedOptions(isolate, break_iterator);
1032 BUILTIN(V8BreakIteratorPrototypeAdoptText) {
1033 const char*
const method =
"get Intl.v8BreakIterator.prototype.adoptText";
1034 HandleScope scope(isolate);
1036 CHECK_RECEIVER(JSV8BreakIterator, break_iterator, method);
1038 Handle<Object> bound_adopt_text(break_iterator->bound_adopt_text(), isolate);
1039 if (!bound_adopt_text->IsUndefined(isolate)) {
1040 DCHECK(bound_adopt_text->IsJSFunction());
1041 return *bound_adopt_text;
1044 Handle<JSFunction> new_bound_adopt_text_function = CreateBoundFunction(
1045 isolate, break_iterator, Builtins::kV8BreakIteratorInternalAdoptText, 1);
1046 break_iterator->set_bound_adopt_text(*new_bound_adopt_text_function);
1047 return *new_bound_adopt_text_function;
1050 BUILTIN(V8BreakIteratorInternalAdoptText) {
1051 HandleScope scope(isolate);
1052 Handle<Context> context = Handle<Context>(isolate->context(), isolate);
1054 Handle<JSV8BreakIterator> break_iterator = Handle<JSV8BreakIterator>(
1055 JSV8BreakIterator::cast(context->get(
1056 static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
1059 Handle<Object> input_text = args.atOrUndefined(isolate, 1);
1060 Handle<String> text;
1061 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, text,
1062 Object::ToString(isolate, input_text));
1064 JSV8BreakIterator::AdoptText(isolate, break_iterator, text);
1065 return ReadOnlyRoots(isolate).undefined_value();
1068 BUILTIN(V8BreakIteratorPrototypeFirst) {
1069 const char*
const method =
"get Intl.v8BreakIterator.prototype.first";
1070 HandleScope scope(isolate);
1072 CHECK_RECEIVER(JSV8BreakIterator, break_iterator, method);
1074 Handle<Object> bound_first(break_iterator->bound_first(), isolate);
1075 if (!bound_first->IsUndefined(isolate)) {
1076 DCHECK(bound_first->IsJSFunction());
1077 return *bound_first;
1080 Handle<JSFunction> new_bound_first_function = CreateBoundFunction(
1081 isolate, break_iterator, Builtins::kV8BreakIteratorInternalFirst, 0);
1082 break_iterator->set_bound_first(*new_bound_first_function);
1083 return *new_bound_first_function;
1086 BUILTIN(V8BreakIteratorInternalFirst) {
1087 HandleScope scope(isolate);
1088 Handle<Context> context = Handle<Context>(isolate->context(), isolate);
1090 Handle<JSV8BreakIterator> break_iterator = Handle<JSV8BreakIterator>(
1091 JSV8BreakIterator::cast(context->get(
1092 static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
1095 return *JSV8BreakIterator::First(isolate, break_iterator);
1098 BUILTIN(V8BreakIteratorPrototypeNext) {
1099 const char*
const method =
"get Intl.v8BreakIterator.prototype.next";
1100 HandleScope scope(isolate);
1102 CHECK_RECEIVER(JSV8BreakIterator, break_iterator, method);
1104 Handle<Object> bound_next(break_iterator->bound_next(), isolate);
1105 if (!bound_next->IsUndefined(isolate)) {
1106 DCHECK(bound_next->IsJSFunction());
1110 Handle<JSFunction> new_bound_next_function = CreateBoundFunction(
1111 isolate, break_iterator, Builtins::kV8BreakIteratorInternalNext, 0);
1112 break_iterator->set_bound_next(*new_bound_next_function);
1113 return *new_bound_next_function;
1116 BUILTIN(V8BreakIteratorInternalNext) {
1117 HandleScope scope(isolate);
1118 Handle<Context> context = Handle<Context>(isolate->context(), isolate);
1120 Handle<JSV8BreakIterator> break_iterator = Handle<JSV8BreakIterator>(
1121 JSV8BreakIterator::cast(context->get(
1122 static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
1124 return *JSV8BreakIterator::Next(isolate, break_iterator);
1127 BUILTIN(V8BreakIteratorPrototypeCurrent) {
1128 const char*
const method =
"get Intl.v8BreakIterator.prototype.current";
1129 HandleScope scope(isolate);
1131 CHECK_RECEIVER(JSV8BreakIterator, break_iterator, method);
1133 Handle<Object> bound_current(break_iterator->bound_current(), isolate);
1134 if (!bound_current->IsUndefined(isolate)) {
1135 DCHECK(bound_current->IsJSFunction());
1136 return *bound_current;
1139 Handle<JSFunction> new_bound_current_function = CreateBoundFunction(
1140 isolate, break_iterator, Builtins::kV8BreakIteratorInternalCurrent, 0);
1141 break_iterator->set_bound_current(*new_bound_current_function);
1142 return *new_bound_current_function;
1145 BUILTIN(V8BreakIteratorInternalCurrent) {
1146 HandleScope scope(isolate);
1147 Handle<Context> context = Handle<Context>(isolate->context(), isolate);
1149 Handle<JSV8BreakIterator> break_iterator = Handle<JSV8BreakIterator>(
1150 JSV8BreakIterator::cast(context->get(
1151 static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
1153 return *JSV8BreakIterator::Current(isolate, break_iterator);
1156 BUILTIN(V8BreakIteratorPrototypeBreakType) {
1157 const char*
const method =
"get Intl.v8BreakIterator.prototype.breakType";
1158 HandleScope scope(isolate);
1160 CHECK_RECEIVER(JSV8BreakIterator, break_iterator, method);
1162 Handle<Object> bound_break_type(break_iterator->bound_break_type(), isolate);
1163 if (!bound_break_type->IsUndefined(isolate)) {
1164 DCHECK(bound_break_type->IsJSFunction());
1165 return *bound_break_type;
1168 Handle<JSFunction> new_bound_break_type_function = CreateBoundFunction(
1169 isolate, break_iterator, Builtins::kV8BreakIteratorInternalBreakType, 0);
1170 break_iterator->set_bound_break_type(*new_bound_break_type_function);
1171 return *new_bound_break_type_function;
1174 BUILTIN(V8BreakIteratorInternalBreakType) {
1175 HandleScope scope(isolate);
1176 Handle<Context> context = Handle<Context>(isolate->context(), isolate);
1178 Handle<JSV8BreakIterator> break_iterator = Handle<JSV8BreakIterator>(
1179 JSV8BreakIterator::cast(context->get(
1180 static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
1182 return JSV8BreakIterator::BreakType(isolate, break_iterator);