Line data Source code
1 : // Copyright 2017 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #ifndef V8_INTL_SUPPORT
6 : #error Internationalization is expected to be enabled.
7 : #endif // V8_INTL_SUPPORT
8 :
9 : #include <cmath>
10 : #include <list>
11 : #include <memory>
12 :
13 : #include "src/builtins/builtins-utils-inl.h"
14 : #include "src/builtins/builtins.h"
15 : #include "src/counters.h"
16 : #include "src/date.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"
33 :
34 : #include "unicode/brkiter.h"
35 :
36 : namespace v8 {
37 : namespace internal {
38 :
39 18452 : BUILTIN(StringPrototypeToUpperCaseIntl) {
40 : HandleScope scope(isolate);
41 14163 : TO_THIS_STRING(string, "String.prototype.toUpperCase");
42 4451 : string = String::Flatten(isolate, string);
43 8902 : RETURN_RESULT_OR_FAILURE(isolate, Intl::ConvertToUpper(isolate, string));
44 : }
45 :
46 9252 : BUILTIN(StringPrototypeNormalizeIntl) {
47 : HandleScope handle_scope(isolate);
48 6939 : TO_THIS_STRING(string, "String.prototype.normalize");
49 :
50 2313 : Handle<Object> form_input = args.atOrUndefined(isolate, 1);
51 :
52 4725 : RETURN_RESULT_OR_FAILURE(isolate,
53 : Intl::Normalize(isolate, string, form_input));
54 : }
55 :
56 0 : BUILTIN(V8BreakIteratorSupportedLocalesOf) {
57 : HandleScope scope(isolate);
58 0 : Handle<Object> locales = args.atOrUndefined(isolate, 1);
59 0 : Handle<Object> options = args.atOrUndefined(isolate, 2);
60 :
61 0 : RETURN_RESULT_OR_FAILURE(
62 : isolate, Intl::SupportedLocalesOf(
63 : isolate, "Intl.v8BreakIterator.supportedLocalesOf",
64 : JSV8BreakIterator::GetAvailableLocales(), locales, options));
65 : }
66 :
67 504 : BUILTIN(NumberFormatSupportedLocalesOf) {
68 : HandleScope scope(isolate);
69 126 : Handle<Object> locales = args.atOrUndefined(isolate, 1);
70 126 : Handle<Object> options = args.atOrUndefined(isolate, 2);
71 :
72 387 : RETURN_RESULT_OR_FAILURE(
73 : isolate, Intl::SupportedLocalesOf(
74 : isolate, "Intl.NumberFormat.supportedLocalesOf",
75 : JSNumberFormat::GetAvailableLocales(), locales, options));
76 : }
77 :
78 1080 : BUILTIN(NumberFormatPrototypeFormatToParts) {
79 : const char* const method = "Intl.NumberFormat.prototype.formatToParts";
80 : HandleScope handle_scope(isolate);
81 540 : CHECK_RECEIVER(JSNumberFormat, number_format, method);
82 :
83 : Handle<Object> x;
84 270 : if (args.length() >= 2) {
85 540 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x,
86 : Object::ToNumber(isolate, args.at(1)));
87 : } else {
88 : x = isolate->factory()->nan_value();
89 : }
90 :
91 540 : RETURN_RESULT_OR_FAILURE(isolate, JSNumberFormat::FormatToParts(
92 : isolate, number_format, x->Number()));
93 : }
94 :
95 9792 : BUILTIN(DateTimeFormatPrototypeResolvedOptions) {
96 : const char* const method = "Intl.DateTimeFormat.prototype.resolvedOptions";
97 : HandleScope scope(isolate);
98 4896 : CHECK_RECEIVER(JSReceiver, format_holder, method);
99 :
100 : // 3. Let dtf be ? UnwrapDateTimeFormat(dtf).
101 : Handle<JSDateTimeFormat> date_time_format;
102 4896 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
103 : isolate, date_time_format,
104 : JSDateTimeFormat::UnwrapDateTimeFormat(isolate, format_holder));
105 :
106 4896 : RETURN_RESULT_OR_FAILURE(
107 : isolate, JSDateTimeFormat::ResolvedOptions(isolate, date_time_format));
108 : }
109 :
110 504 : BUILTIN(DateTimeFormatSupportedLocalesOf) {
111 : HandleScope scope(isolate);
112 126 : Handle<Object> locales = args.atOrUndefined(isolate, 1);
113 126 : Handle<Object> options = args.atOrUndefined(isolate, 2);
114 :
115 387 : RETURN_RESULT_OR_FAILURE(
116 : isolate, Intl::SupportedLocalesOf(
117 : isolate, "Intl.DateTimeFormat.supportedLocalesOf",
118 : JSDateTimeFormat::GetAvailableLocales(), locales, options));
119 : }
120 :
121 792 : BUILTIN(DateTimeFormatPrototypeFormatToParts) {
122 : const char* const method = "Intl.DateTimeFormat.prototype.formatToParts";
123 : HandleScope handle_scope(isolate);
124 423 : CHECK_RECEIVER(JSObject, date_format_holder, method);
125 : Factory* factory = isolate->factory();
126 :
127 378 : if (!date_format_holder->IsJSDateTimeFormat()) {
128 27 : THROW_NEW_ERROR_RETURN_FAILURE(
129 : isolate, NewTypeError(MessageTemplate::kIncompatibleMethodReceiver,
130 : factory->NewStringFromAsciiChecked(method),
131 : date_format_holder));
132 : }
133 : Handle<JSDateTimeFormat> dtf =
134 180 : Handle<JSDateTimeFormat>::cast(date_format_holder);
135 :
136 : Handle<Object> x = args.atOrUndefined(isolate, 1);
137 360 : if (x->IsUndefined(isolate)) {
138 18 : x = factory->NewNumber(JSDate::CurrentTimeValue(isolate));
139 : } else {
140 324 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x,
141 : Object::ToNumber(isolate, args.at(1)));
142 : }
143 :
144 180 : double date_value = DateCache::TimeClip(x->Number());
145 180 : if (std::isnan(date_value)) {
146 54 : THROW_NEW_ERROR_RETURN_FAILURE(
147 : isolate, NewRangeError(MessageTemplate::kInvalidTimeValue));
148 : }
149 :
150 306 : RETURN_RESULT_OR_FAILURE(
151 : isolate, JSDateTimeFormat::FormatToParts(isolate, dtf, date_value));
152 : }
153 :
154 : namespace {
155 993 : 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(),
159 1986 : isolate);
160 : Handle<Context> context = isolate->factory()->NewBuiltinContext(
161 : native_context,
162 993 : static_cast<int>(Intl::BoundFunctionContextSlot::kLength));
163 :
164 : context->set(static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction),
165 1986 : *object);
166 :
167 : Handle<SharedFunctionInfo> info =
168 : isolate->factory()->NewSharedFunctionInfoForBuiltin(
169 993 : isolate->factory()->empty_string(), builtin_id, kNormalFunction);
170 : info->set_internal_formal_parameter_count(len);
171 : info->set_length(len);
172 :
173 993 : Handle<Map> map = isolate->strict_function_without_prototype_map();
174 :
175 : Handle<JSFunction> new_bound_function =
176 993 : isolate->factory()->NewFunctionFromSharedFunctionInfo(map, info, context);
177 993 : return new_bound_function;
178 : }
179 :
180 : /**
181 : * Common code shared between DateTimeFormatConstructor and
182 : * NumberFormatConstrutor
183 : */
184 : template <class T>
185 4347 : Object LegacyFormatConstructor(BuiltinArguments args, Isolate* isolate,
186 : v8::Isolate::UseCounterFeature feature,
187 : Handle<Object> constructor, const char* method) {
188 4347 : isolate->CountUsage(feature);
189 : Handle<JSReceiver> new_target;
190 : // 1. If NewTarget is undefined, let newTarget be the active
191 : // function object, else let newTarget be NewTarget.
192 13041 : if (args.new_target()->IsUndefined(isolate)) {
193 891 : new_target = args.target();
194 : } else {
195 3456 : new_target = Handle<JSReceiver>::cast(args.new_target());
196 : }
197 :
198 : // [[Construct]]
199 4347 : Handle<JSFunction> target = args.target();
200 :
201 4347 : Handle<Object> locales = args.atOrUndefined(isolate, 1);
202 4347 : Handle<Object> options = args.atOrUndefined(isolate, 2);
203 :
204 : // 2. Let format be ? OrdinaryCreateFromConstructor(newTarget,
205 : // "%<T>Prototype%", ...).
206 :
207 : Handle<JSObject> obj;
208 8694 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
209 : isolate, obj,
210 : JSObject::New(target, new_target, Handle<AllocationSite>::null()));
211 4347 : Handle<T> format = Handle<T>::cast(obj);
212 :
213 : // 3. Perform ? Initialize<T>(Format, locales, options).
214 9036 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
215 : isolate, format, T::Initialize(isolate, format, locales, options));
216 : // 4. Let this be the this value.
217 : Handle<Object> receiver = args.receiver();
218 :
219 : // 5. If NewTarget is undefined and ? InstanceofOperator(this, %<T>%)
220 : // is true, then
221 : //
222 : // Look up the intrinsic value that has been stored on the context.
223 : // Call the instanceof function
224 : Handle<Object> is_instance_of_obj;
225 8010 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
226 : isolate, is_instance_of_obj,
227 : Object::InstanceOf(isolate, receiver, constructor));
228 :
229 : // Get the boolean value of the result
230 4005 : bool is_instance_of = is_instance_of_obj->BooleanValue(isolate);
231 :
232 12015 : if (args.new_target()->IsUndefined(isolate) && is_instance_of) {
233 144 : if (!receiver->IsJSReceiver()) {
234 54 : THROW_NEW_ERROR_RETURN_FAILURE(
235 : isolate,
236 : NewTypeError(MessageTemplate::kIncompatibleMethodReceiver,
237 : isolate->factory()->NewStringFromAsciiChecked(method),
238 : receiver));
239 : }
240 54 : Handle<JSReceiver> rec = Handle<JSReceiver>::cast(receiver);
241 : // a. Perform ? DefinePropertyOrThrow(this,
242 : // %Intl%.[[FallbackSymbol]], PropertyDescriptor{ [[Value]]: format,
243 : // [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }).
244 : PropertyDescriptor desc;
245 : desc.set_value(format);
246 : desc.set_writable(false);
247 : desc.set_enumerable(false);
248 : desc.set_configurable(false);
249 : Maybe<bool> success = JSReceiver::DefineOwnProperty(
250 : isolate, rec, isolate->factory()->intl_fallback_symbol(), &desc,
251 54 : kThrowOnError);
252 72 : MAYBE_RETURN(success, ReadOnlyRoots(isolate).exception());
253 36 : CHECK(success.FromJust());
254 : // b. b. Return this.
255 : return *receiver;
256 : }
257 : // 6. Return format.
258 3933 : return *format;
259 : }
260 :
261 : /**
262 : * Common code shared by ListFormat, RelativeTimeFormat, PluralRules, and
263 : * Segmenter
264 : */
265 : template <class T>
266 3132 : Object DisallowCallConstructor(BuiltinArguments args, Isolate* isolate,
267 : v8::Isolate::UseCounterFeature feature,
268 : const char* method) {
269 3132 : isolate->CountUsage(feature);
270 :
271 : // 1. If NewTarget is undefined, throw a TypeError exception.
272 9396 : if (args.new_target()->IsUndefined(isolate)) { // [[Call]]
273 81 : THROW_NEW_ERROR_RETURN_FAILURE(
274 : isolate,
275 : NewTypeError(MessageTemplate::kConstructorNotFunction,
276 : isolate->factory()->NewStringFromAsciiChecked(method)));
277 : }
278 : // [[Construct]]
279 3105 : Handle<JSFunction> target = args.target();
280 3105 : Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target());
281 :
282 : Handle<JSObject> obj;
283 : // 2. Let result be OrdinaryCreateFromConstructor(NewTarget,
284 : // "%<T>Prototype%").
285 6210 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
286 : isolate, obj,
287 : JSObject::New(target, new_target, Handle<AllocationSite>::null()));
288 3105 : Handle<T> result = Handle<T>::cast(obj);
289 : result->set_flags(0);
290 :
291 3105 : Handle<Object> locales = args.atOrUndefined(isolate, 1);
292 3105 : Handle<Object> options = args.atOrUndefined(isolate, 2);
293 :
294 : // 3. Return Initialize<T>(t, locales, options).
295 6417 : RETURN_RESULT_OR_FAILURE(isolate,
296 : T::Initialize(isolate, result, locales, options));
297 : }
298 :
299 : /**
300 : * Common code shared by Collator and V8BreakIterator
301 : */
302 : template <class T>
303 799 : Object CallOrConstructConstructor(BuiltinArguments args, Isolate* isolate) {
304 : Handle<JSReceiver> new_target;
305 :
306 2397 : if (args.new_target()->IsUndefined(isolate)) {
307 115 : new_target = args.target();
308 : } else {
309 684 : new_target = Handle<JSReceiver>::cast(args.new_target());
310 : }
311 :
312 : // [[Construct]]
313 799 : Handle<JSFunction> target = args.target();
314 :
315 799 : Handle<Object> locales = args.atOrUndefined(isolate, 1);
316 799 : Handle<Object> options = args.atOrUndefined(isolate, 2);
317 :
318 : Handle<JSObject> obj;
319 1598 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
320 : isolate, obj,
321 : JSObject::New(target, new_target, Handle<AllocationSite>::null()));
322 799 : Handle<T> result = Handle<T>::cast(obj);
323 :
324 1607 : RETURN_RESULT_OR_FAILURE(isolate,
325 : T::Initialize(isolate, result, locales, options));
326 : }
327 : } // namespace
328 :
329 5436 : BUILTIN(NumberFormatConstructor) {
330 : HandleScope scope(isolate);
331 :
332 : return LegacyFormatConstructor<JSNumberFormat>(
333 : args, isolate, v8::Isolate::UseCounterFeature::kNumberFormat,
334 4077 : isolate->intl_number_format_function(), "Intl.NumberFormat");
335 : }
336 :
337 2916 : BUILTIN(NumberFormatPrototypeResolvedOptions) {
338 : HandleScope scope(isolate);
339 : const char* const method = "Intl.NumberFormat.prototype.resolvedOptions";
340 :
341 : // 1. Let nf be the this value.
342 : // 2. If Type(nf) is not Object, throw a TypeError exception.
343 1458 : CHECK_RECEIVER(JSReceiver, number_format_holder, method);
344 :
345 : // 3. Let nf be ? UnwrapNumberFormat(nf)
346 : Handle<JSNumberFormat> number_format;
347 1458 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
348 : isolate, number_format,
349 : JSNumberFormat::UnwrapNumberFormat(isolate, number_format_holder));
350 :
351 1458 : return *JSNumberFormat::ResolvedOptions(isolate, number_format);
352 : }
353 :
354 3060 : BUILTIN(NumberFormatPrototypeFormatNumber) {
355 : const char* const method = "get Intl.NumberFormat.prototype.format";
356 : HandleScope scope(isolate);
357 :
358 : // 1. Let nf be the this value.
359 : // 2. If Type(nf) is not Object, throw a TypeError exception.
360 1530 : CHECK_RECEIVER(JSReceiver, receiver, method);
361 :
362 : // 3. Let nf be ? UnwrapNumberFormat(nf).
363 : Handle<JSNumberFormat> number_format;
364 1575 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
365 : isolate, number_format,
366 : JSNumberFormat::UnwrapNumberFormat(isolate, receiver));
367 :
368 1440 : Handle<Object> bound_format(number_format->bound_format(), isolate);
369 :
370 : // 4. If nf.[[BoundFormat]] is undefined, then
371 1440 : if (!bound_format->IsUndefined(isolate)) {
372 : DCHECK(bound_format->IsJSFunction());
373 : // 5. Return nf.[[BoundFormat]].
374 : return *bound_format;
375 : }
376 :
377 : Handle<JSFunction> new_bound_format_function = CreateBoundFunction(
378 297 : isolate, number_format, Builtins::kNumberFormatInternalFormatNumber, 1);
379 :
380 : // 4. c. Set nf.[[BoundFormat]] to F.
381 594 : number_format->set_bound_format(*new_bound_format_function);
382 :
383 : // 5. Return nf.[[BoundFormat]].
384 297 : return *new_bound_format_function;
385 : }
386 :
387 2808 : BUILTIN(NumberFormatInternalFormatNumber) {
388 : HandleScope scope(isolate);
389 :
390 : Handle<Context> context = Handle<Context>(isolate->context(), isolate);
391 :
392 : // 1. Let nf be F.[[NumberFormat]].
393 : // 2. Assert: Type(nf) is Object and nf has an
394 : // [[InitializedNumberFormat]] internal slot.
395 : Handle<JSNumberFormat> number_format = Handle<JSNumberFormat>(
396 : JSNumberFormat::cast(context->get(
397 : static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
398 1404 : isolate);
399 :
400 : // 3. If value is not provided, let value be undefined.
401 702 : Handle<Object> value = args.atOrUndefined(isolate, 1);
402 :
403 : // 4. Let x be ? ToNumber(value).
404 : Handle<Object> number_obj;
405 1404 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_obj,
406 : Object::ToNumber(isolate, value));
407 :
408 702 : double number = number_obj->Number();
409 : icu::NumberFormat* icu_number_format =
410 1404 : number_format->icu_number_format()->raw();
411 702 : CHECK_NOT_NULL(icu_number_format);
412 :
413 : // Return FormatNumber(nf, x).
414 1404 : RETURN_RESULT_OR_FAILURE(isolate, JSNumberFormat::FormatNumber(
415 : isolate, *icu_number_format, number));
416 : }
417 :
418 11952 : BUILTIN(DateTimeFormatConstructor) {
419 : HandleScope scope(isolate);
420 :
421 : return LegacyFormatConstructor<JSDateTimeFormat>(
422 : args, isolate, v8::Isolate::UseCounterFeature::kDateTimeFormat,
423 8964 : isolate->intl_date_time_format_function(), "Intl.DateTimeFormat");
424 : }
425 :
426 2412 : BUILTIN(DateTimeFormatPrototypeFormat) {
427 : const char* const method = "get Intl.DateTimeFormat.prototype.format";
428 : HandleScope scope(isolate);
429 :
430 : // 1. Let dtf be this value.
431 : // 2. If Type(dtf) is not Object, throw a TypeError exception.
432 1206 : CHECK_RECEIVER(JSReceiver, receiver, method);
433 :
434 : // 3. Let dtf be ? UnwrapDateTimeFormat(dtf).
435 : Handle<JSDateTimeFormat> format;
436 1251 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
437 : isolate, format,
438 : JSDateTimeFormat::UnwrapDateTimeFormat(isolate, receiver));
439 :
440 1116 : Handle<Object> bound_format = Handle<Object>(format->bound_format(), isolate);
441 :
442 : // 4. If dtf.[[BoundFormat]] is undefined, then
443 1116 : if (!bound_format->IsUndefined(isolate)) {
444 : DCHECK(bound_format->IsJSFunction());
445 : // 5. Return dtf.[[BoundFormat]].
446 : return *bound_format;
447 : }
448 :
449 : Handle<JSFunction> new_bound_format_function = CreateBoundFunction(
450 387 : isolate, format, Builtins::kDateTimeFormatInternalFormat, 1);
451 :
452 : // 4.c. Set dtf.[[BoundFormat]] to F.
453 774 : format->set_bound_format(*new_bound_format_function);
454 :
455 : // 5. Return dtf.[[BoundFormat]].
456 387 : return *new_bound_format_function;
457 : }
458 :
459 2160 : BUILTIN(DateTimeFormatInternalFormat) {
460 : HandleScope scope(isolate);
461 : Handle<Context> context = Handle<Context>(isolate->context(), isolate);
462 :
463 : // 1. Let dtf be F.[[DateTimeFormat]].
464 : // 2. Assert: Type(dtf) is Object and dtf has an [[InitializedDateTimeFormat]]
465 : // internal slot.
466 : Handle<JSDateTimeFormat> date_format_holder = Handle<JSDateTimeFormat>(
467 : JSDateTimeFormat::cast(context->get(
468 : static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
469 1080 : isolate);
470 :
471 540 : Handle<Object> date = args.atOrUndefined(isolate, 1);
472 :
473 1134 : RETURN_RESULT_OR_FAILURE(isolate, JSDateTimeFormat::DateTimeFormat(
474 : isolate, date_format_holder, date));
475 : }
476 :
477 1260 : BUILTIN(IntlGetCanonicalLocales) {
478 : HandleScope scope(isolate);
479 315 : Handle<Object> locales = args.atOrUndefined(isolate, 1);
480 :
481 639 : RETURN_RESULT_OR_FAILURE(isolate,
482 : Intl::GetCanonicalLocales(isolate, locales));
483 : }
484 :
485 4068 : BUILTIN(ListFormatConstructor) {
486 : HandleScope scope(isolate);
487 :
488 : return DisallowCallConstructor<JSListFormat>(
489 : args, isolate, v8::Isolate::UseCounterFeature::kListFormat,
490 2034 : "Intl.ListFormat");
491 : }
492 :
493 1260 : BUILTIN(ListFormatPrototypeResolvedOptions) {
494 : HandleScope scope(isolate);
495 630 : CHECK_RECEIVER(JSListFormat, format_holder,
496 : "Intl.ListFormat.prototype.resolvedOptions");
497 630 : return *JSListFormat::ResolvedOptions(isolate, format_holder);
498 : }
499 :
500 144 : BUILTIN(ListFormatSupportedLocalesOf) {
501 : HandleScope scope(isolate);
502 36 : Handle<Object> locales = args.atOrUndefined(isolate, 1);
503 36 : Handle<Object> options = args.atOrUndefined(isolate, 2);
504 :
505 108 : RETURN_RESULT_OR_FAILURE(
506 : isolate, Intl::SupportedLocalesOf(
507 : isolate, "Intl.ListFormat.supportedLocalesOf",
508 : JSListFormat::GetAvailableLocales(), locales, options));
509 : }
510 :
511 : namespace {
512 :
513 52974 : MaybeHandle<JSLocale> CreateLocale(Isolate* isolate,
514 : Handle<JSFunction> constructor,
515 : Handle<JSReceiver> new_target,
516 : Handle<Object> tag, Handle<Object> options) {
517 : Handle<JSObject> locale;
518 : // 6. Let locale be ? OrdinaryCreateFromConstructor(NewTarget,
519 : // %LocalePrototype%, internalSlotsList).
520 105948 : ASSIGN_RETURN_ON_EXCEPTION(
521 : isolate, locale,
522 : JSObject::New(constructor, new_target, Handle<AllocationSite>::null()),
523 : JSLocale);
524 :
525 : // 7. If Type(tag) is not String or Object, throw a TypeError exception.
526 106056 : if (!tag->IsString() && !tag->IsJSReceiver()) {
527 54 : THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kLocaleNotEmpty),
528 : JSLocale);
529 : }
530 :
531 : Handle<String> locale_string;
532 : // 8. If Type(tag) is Object and tag has an [[InitializedLocale]] internal
533 : // slot, then
534 105840 : if (tag->IsJSLocale()) {
535 : // a. Let tag be tag.[[Locale]].
536 0 : locale_string = JSLocale::ToString(isolate, Handle<JSLocale>::cast(tag));
537 : } else { // 9. Else,
538 : // a. Let tag be ? ToString(tag).
539 105840 : ASSIGN_RETURN_ON_EXCEPTION(isolate, locale_string,
540 : Object::ToString(isolate, tag), JSLocale);
541 : }
542 :
543 : Handle<JSReceiver> options_object;
544 : // 10. If options is undefined, then
545 105840 : if (options->IsUndefined(isolate)) {
546 : // a. Let options be ! ObjectCreate(null).
547 6948 : options_object = isolate->factory()->NewJSObjectWithNullProto();
548 : } else { // 11. Else
549 : // a. Let options be ? ToObject(options).
550 91944 : ASSIGN_RETURN_ON_EXCEPTION(isolate, options_object,
551 : Object::ToObject(isolate, options), JSLocale);
552 : }
553 :
554 : return JSLocale::Initialize(isolate, Handle<JSLocale>::cast(locale),
555 52920 : locale_string, options_object);
556 : }
557 :
558 : } // namespace
559 :
560 : // Intl.Locale implementation
561 28584 : BUILTIN(LocaleConstructor) {
562 : HandleScope scope(isolate);
563 :
564 7146 : isolate->CountUsage(v8::Isolate::UseCounterFeature::kLocale);
565 :
566 21438 : if (args.new_target()->IsUndefined(isolate)) { // [[Call]]
567 27 : THROW_NEW_ERROR_RETURN_FAILURE(
568 : isolate, NewTypeError(MessageTemplate::kConstructorNotFunction,
569 : isolate->factory()->NewStringFromAsciiChecked(
570 : "Intl.Locale")));
571 : }
572 : // [[Construct]]
573 7137 : Handle<JSFunction> target = args.target();
574 7137 : Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target());
575 :
576 7137 : Handle<Object> tag = args.atOrUndefined(isolate, 1);
577 7137 : Handle<Object> options = args.atOrUndefined(isolate, 2);
578 :
579 14436 : RETURN_RESULT_OR_FAILURE(
580 : isolate, CreateLocale(isolate, target, new_target, tag, options));
581 : }
582 :
583 91620 : BUILTIN(LocalePrototypeMaximize) {
584 : HandleScope scope(isolate);
585 45810 : CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.maximize");
586 : Handle<JSFunction> constructor(
587 68715 : isolate->native_context()->intl_locale_function(), isolate);
588 22905 : Handle<String> locale_str = JSLocale::ToString(isolate, locale);
589 91620 : RETURN_RESULT_OR_FAILURE(
590 : isolate, CreateLocale(isolate, constructor, constructor,
591 : JSLocale::Maximize(isolate, *locale_str),
592 : isolate->factory()->NewJSObjectWithNullProto()));
593 : }
594 :
595 91728 : BUILTIN(LocalePrototypeMinimize) {
596 : HandleScope scope(isolate);
597 45864 : CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.minimize");
598 : Handle<JSFunction> constructor(
599 68796 : isolate->native_context()->intl_locale_function(), isolate);
600 22932 : Handle<String> locale_str = JSLocale::ToString(isolate, locale);
601 91728 : RETURN_RESULT_OR_FAILURE(
602 : isolate, CreateLocale(isolate, constructor, constructor,
603 : JSLocale::Minimize(isolate, *locale_str),
604 : isolate->factory()->NewJSObjectWithNullProto()));
605 : }
606 :
607 144 : BUILTIN(RelativeTimeFormatSupportedLocalesOf) {
608 : HandleScope scope(isolate);
609 36 : Handle<Object> locales = args.atOrUndefined(isolate, 1);
610 36 : Handle<Object> options = args.atOrUndefined(isolate, 2);
611 :
612 108 : RETURN_RESULT_OR_FAILURE(
613 : isolate,
614 : Intl::SupportedLocalesOf(
615 : isolate, "Intl.RelativeTimeFormat.supportedLocalesOf",
616 : JSRelativeTimeFormat::GetAvailableLocales(), locales, options));
617 : }
618 :
619 23184 : BUILTIN(RelativeTimeFormatPrototypeFormat) {
620 : HandleScope scope(isolate);
621 : // 1. Let relativeTimeFormat be the this value.
622 : // 2. If Type(relativeTimeFormat) is not Object or relativeTimeFormat does not
623 : // have an [[InitializedRelativeTimeFormat]] internal slot whose value is
624 : // true, throw a TypeError exception.
625 11592 : CHECK_RECEIVER(JSRelativeTimeFormat, format_holder,
626 : "Intl.RelativeTimeFormat.prototype.format");
627 5796 : Handle<Object> value_obj = args.atOrUndefined(isolate, 1);
628 5796 : Handle<Object> unit_obj = args.atOrUndefined(isolate, 2);
629 :
630 13572 : RETURN_RESULT_OR_FAILURE(
631 : isolate, JSRelativeTimeFormat::Format(isolate, value_obj, unit_obj,
632 : format_holder, "format", false));
633 : }
634 :
635 2628 : BUILTIN(RelativeTimeFormatPrototypeFormatToParts) {
636 : HandleScope scope(isolate);
637 : // 1. Let relativeTimeFormat be the this value.
638 : // 2. If Type(relativeTimeFormat) is not Object or relativeTimeFormat does not
639 : // have an [[InitializedRelativeTimeFormat]] internal slot whose value is
640 : // true, throw a TypeError exception.
641 1314 : CHECK_RECEIVER(JSRelativeTimeFormat, format_holder,
642 : "Intl.RelativeTimeFormat.prototype.formatToParts");
643 657 : Handle<Object> value_obj = args.atOrUndefined(isolate, 1);
644 657 : Handle<Object> unit_obj = args.atOrUndefined(isolate, 2);
645 1548 : RETURN_RESULT_OR_FAILURE(isolate, JSRelativeTimeFormat::Format(
646 : isolate, value_obj, unit_obj,
647 : format_holder, "formatToParts", true));
648 : }
649 :
650 : // Locale getters.
651 72 : BUILTIN(LocalePrototypeLanguage) {
652 : HandleScope scope(isolate);
653 : // CHECK_RECEIVER will case locale_holder to JSLocale.
654 36 : CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.language");
655 :
656 36 : return *JSLocale::Language(isolate, locale);
657 : }
658 :
659 108 : BUILTIN(LocalePrototypeScript) {
660 : HandleScope scope(isolate);
661 54 : CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.script");
662 :
663 54 : return *JSLocale::Script(isolate, locale);
664 : }
665 :
666 72 : BUILTIN(LocalePrototypeRegion) {
667 : HandleScope scope(isolate);
668 36 : CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.region");
669 :
670 36 : return *JSLocale::Region(isolate, locale);
671 : }
672 :
673 72 : BUILTIN(LocalePrototypeBaseName) {
674 : HandleScope scope(isolate);
675 36 : CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.baseName");
676 :
677 36 : return *JSLocale::BaseName(isolate, locale);
678 : }
679 :
680 72 : BUILTIN(LocalePrototypeCalendar) {
681 : HandleScope scope(isolate);
682 36 : CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.calendar");
683 :
684 36 : return *JSLocale::Calendar(isolate, locale);
685 : }
686 :
687 72 : BUILTIN(LocalePrototypeCaseFirst) {
688 : HandleScope scope(isolate);
689 36 : CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.caseFirst");
690 :
691 36 : return *JSLocale::CaseFirst(isolate, locale);
692 : }
693 :
694 72 : BUILTIN(LocalePrototypeCollation) {
695 : HandleScope scope(isolate);
696 36 : CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.collation");
697 :
698 36 : return *JSLocale::Collation(isolate, locale);
699 : }
700 :
701 72 : BUILTIN(LocalePrototypeHourCycle) {
702 : HandleScope scope(isolate);
703 36 : CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.hourCycle");
704 :
705 36 : return *JSLocale::HourCycle(isolate, locale);
706 : }
707 :
708 72 : BUILTIN(LocalePrototypeNumeric) {
709 : HandleScope scope(isolate);
710 36 : CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.numeric");
711 :
712 36 : return *JSLocale::Numeric(isolate, locale);
713 : }
714 :
715 72 : BUILTIN(LocalePrototypeNumberingSystem) {
716 : HandleScope scope(isolate);
717 36 : CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.numberingSystem");
718 :
719 36 : return *JSLocale::NumberingSystem(isolate, locale);
720 : }
721 :
722 296208 : BUILTIN(LocalePrototypeToString) {
723 : HandleScope scope(isolate);
724 148104 : CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.toString");
725 :
726 148104 : return *JSLocale::ToString(isolate, locale);
727 : }
728 :
729 3168 : BUILTIN(RelativeTimeFormatConstructor) {
730 : HandleScope scope(isolate);
731 :
732 : return DisallowCallConstructor<JSRelativeTimeFormat>(
733 : args, isolate, v8::Isolate::UseCounterFeature::kRelativeTimeFormat,
734 1584 : "Intl.RelativeTimeFormat");
735 : }
736 :
737 2052 : BUILTIN(RelativeTimeFormatPrototypeResolvedOptions) {
738 : HandleScope scope(isolate);
739 1080 : CHECK_RECEIVER(JSRelativeTimeFormat, format_holder,
740 : "Intl.RelativeTimeFormat.prototype.resolvedOptions");
741 990 : return *JSRelativeTimeFormat::ResolvedOptions(isolate, format_holder);
742 : }
743 :
744 2232 : BUILTIN(StringPrototypeToLocaleLowerCase) {
745 : HandleScope scope(isolate);
746 :
747 558 : isolate->CountUsage(v8::Isolate::UseCounterFeature::kStringToLocaleLowerCase);
748 :
749 1998 : TO_THIS_STRING(string, "String.prototype.toLocaleLowerCase");
750 :
751 810 : RETURN_RESULT_OR_FAILURE(
752 : isolate, Intl::StringLocaleConvertCase(isolate, string, false,
753 : args.atOrUndefined(isolate, 1)));
754 : }
755 :
756 2268 : BUILTIN(StringPrototypeToLocaleUpperCase) {
757 : HandleScope scope(isolate);
758 :
759 567 : isolate->CountUsage(v8::Isolate::UseCounterFeature::kStringToLocaleUpperCase);
760 :
761 2025 : TO_THIS_STRING(string, "String.prototype.toLocaleUpperCase");
762 :
763 828 : RETURN_RESULT_OR_FAILURE(
764 : isolate, Intl::StringLocaleConvertCase(isolate, string, true,
765 : args.atOrUndefined(isolate, 1)));
766 : }
767 :
768 180 : BUILTIN(PluralRulesConstructor) {
769 : HandleScope scope(isolate);
770 :
771 : return DisallowCallConstructor<JSPluralRules>(
772 : args, isolate, v8::Isolate::UseCounterFeature::kPluralRules,
773 90 : "Intl.PluralRules");
774 : }
775 :
776 0 : BUILTIN(PluralRulesPrototypeResolvedOptions) {
777 : HandleScope scope(isolate);
778 0 : CHECK_RECEIVER(JSPluralRules, plural_rules_holder,
779 : "Intl.PluralRules.prototype.resolvedOptions");
780 0 : return *JSPluralRules::ResolvedOptions(isolate, plural_rules_holder);
781 : }
782 :
783 1512 : BUILTIN(PluralRulesPrototypeSelect) {
784 : HandleScope scope(isolate);
785 :
786 : // 1. Let pr be the this value.
787 : // 2. If Type(pr) is not Object, throw a TypeError exception.
788 : // 3. If pr does not have an [[InitializedPluralRules]] internal slot, throw a
789 : // TypeError exception.
790 756 : CHECK_RECEIVER(JSPluralRules, plural_rules,
791 : "Intl.PluralRules.prototype.select");
792 :
793 : // 4. Let n be ? ToNumber(value).
794 : Handle<Object> number = args.atOrUndefined(isolate, 1);
795 756 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number,
796 : Object::ToNumber(isolate, number));
797 378 : double number_double = number->Number();
798 :
799 : // 5. Return ? ResolvePlural(pr, n).
800 756 : RETURN_RESULT_OR_FAILURE(isolate, JSPluralRules::ResolvePlural(
801 : isolate, plural_rules, number_double));
802 : }
803 :
804 504 : BUILTIN(PluralRulesSupportedLocalesOf) {
805 : HandleScope scope(isolate);
806 126 : Handle<Object> locales = args.atOrUndefined(isolate, 1);
807 126 : Handle<Object> options = args.atOrUndefined(isolate, 2);
808 :
809 387 : RETURN_RESULT_OR_FAILURE(
810 : isolate, Intl::SupportedLocalesOf(
811 : isolate, "Intl.PluralRules.supportedLocalesOf",
812 : JSPluralRules::GetAvailableLocales(), locales, options));
813 : }
814 :
815 2276 : BUILTIN(CollatorConstructor) {
816 : HandleScope scope(isolate);
817 :
818 569 : isolate->CountUsage(v8::Isolate::UseCounterFeature::kCollator);
819 :
820 1138 : return CallOrConstructConstructor<JSCollator>(args, isolate);
821 : }
822 :
823 1584 : BUILTIN(CollatorPrototypeResolvedOptions) {
824 : HandleScope scope(isolate);
825 792 : CHECK_RECEIVER(JSCollator, collator_holder,
826 : "Intl.Collator.prototype.resolvedOptions");
827 792 : return *JSCollator::ResolvedOptions(isolate, collator_holder);
828 : }
829 :
830 684 : BUILTIN(CollatorSupportedLocalesOf) {
831 : HandleScope scope(isolate);
832 171 : Handle<Object> locales = args.atOrUndefined(isolate, 1);
833 171 : Handle<Object> options = args.atOrUndefined(isolate, 2);
834 :
835 558 : RETURN_RESULT_OR_FAILURE(
836 : isolate, Intl::SupportedLocalesOf(
837 : isolate, "Intl.Collator.supportedLocalesOf",
838 : JSCollator::GetAvailableLocales(), locales, options));
839 : }
840 :
841 8900 : BUILTIN(CollatorPrototypeCompare) {
842 : const char* const method = "get Intl.Collator.prototype.compare";
843 : HandleScope scope(isolate);
844 :
845 : // 1. Let collator be this value.
846 : // 2. If Type(collator) is not Object, throw a TypeError exception.
847 : // 3. If collator does not have an [[InitializedCollator]] internal slot,
848 : // throw a TypeError exception.
849 4639 : CHECK_RECEIVER(JSCollator, collator, method);
850 :
851 : // 4. If collator.[[BoundCompare]] is undefined, then
852 4324 : Handle<Object> bound_compare(collator->bound_compare(), isolate);
853 4324 : if (!bound_compare->IsUndefined(isolate)) {
854 : DCHECK(bound_compare->IsJSFunction());
855 : // 5. Return collator.[[BoundCompare]].
856 : return *bound_compare;
857 : }
858 :
859 : Handle<JSFunction> new_bound_compare_function = CreateBoundFunction(
860 164 : isolate, collator, Builtins::kCollatorInternalCompare, 2);
861 :
862 : // 4.c. Set collator.[[BoundCompare]] to F.
863 328 : collator->set_bound_compare(*new_bound_compare_function);
864 :
865 : // 5. Return collator.[[BoundCompare]].
866 164 : return *new_bound_compare_function;
867 : }
868 :
869 12716 : BUILTIN(CollatorInternalCompare) {
870 : HandleScope scope(isolate);
871 : Handle<Context> context = Handle<Context>(isolate->context(), isolate);
872 :
873 : // 1. Let collator be F.[[Collator]].
874 : // 2. Assert: Type(collator) is Object and collator has an
875 : // [[InitializedCollator]] internal slot.
876 : Handle<JSCollator> collator = Handle<JSCollator>(
877 : JSCollator::cast(context->get(
878 : static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
879 6358 : isolate);
880 :
881 : // 3. If x is not provided, let x be undefined.
882 3179 : Handle<Object> x = args.atOrUndefined(isolate, 1);
883 : // 4. If y is not provided, let y be undefined.
884 3179 : Handle<Object> y = args.atOrUndefined(isolate, 2);
885 :
886 : // 5. Let X be ? ToString(x).
887 : Handle<String> string_x;
888 6358 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, string_x,
889 : Object::ToString(isolate, x));
890 : // 6. Let Y be ? ToString(y).
891 : Handle<String> string_y;
892 6358 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, string_y,
893 : Object::ToString(isolate, y));
894 :
895 : // 7. Return CompareStrings(collator, X, Y).
896 6358 : icu::Collator* icu_collator = collator->icu_collator()->raw();
897 3179 : CHECK_NOT_NULL(icu_collator);
898 6358 : return *Intl::CompareStrings(isolate, *icu_collator, string_x, string_y);
899 : }
900 :
901 : // ecma402 #sec-segment-iterator-prototype-breakType
902 191232 : BUILTIN(SegmentIteratorPrototypeBreakType) {
903 : const char* const method = "get %SegmentIteratorPrototype%.breakType";
904 : HandleScope scope(isolate);
905 :
906 95616 : CHECK_RECEIVER(JSSegmentIterator, segment_iterator, method);
907 95616 : return *segment_iterator->BreakType();
908 : }
909 :
910 : // ecma402 #sec-segment-iterator-prototype-following
911 108972 : BUILTIN(SegmentIteratorPrototypeFollowing) {
912 : const char* const method = "%SegmentIteratorPrototype%.following";
913 : HandleScope scope(isolate);
914 54891 : CHECK_RECEIVER(JSSegmentIterator, segment_iterator, method);
915 :
916 27108 : Handle<Object> from = args.atOrUndefined(isolate, 1);
917 :
918 : Maybe<bool> success =
919 27108 : JSSegmentIterator::Following(isolate, segment_iterator, from);
920 27135 : MAYBE_RETURN(success, ReadOnlyRoots(isolate).exception());
921 54162 : return *isolate->factory()->ToBoolean(success.FromJust());
922 : }
923 :
924 : // ecma402 #sec-segment-iterator-prototype-next
925 86004 : BUILTIN(SegmentIteratorPrototypeNext) {
926 : const char* const method = "%SegmentIteratorPrototype%.next";
927 : HandleScope scope(isolate);
928 43407 : CHECK_RECEIVER(JSSegmentIterator, segment_iterator, method);
929 :
930 42732 : RETURN_RESULT_OR_FAILURE(isolate,
931 : JSSegmentIterator::Next(isolate, segment_iterator));
932 : }
933 :
934 : // ecma402 #sec-segment-iterator-prototype-preceding
935 43380 : BUILTIN(SegmentIteratorPrototypePreceding) {
936 : const char* const method = "%SegmentIteratorPrototype%.preceding";
937 : HandleScope scope(isolate);
938 22095 : CHECK_RECEIVER(JSSegmentIterator, segment_iterator, method);
939 :
940 10710 : Handle<Object> from = args.atOrUndefined(isolate, 1);
941 :
942 : Maybe<bool> success =
943 10710 : JSSegmentIterator::Preceding(isolate, segment_iterator, from);
944 10755 : MAYBE_RETURN(success, ReadOnlyRoots(isolate).exception());
945 21330 : return *isolate->factory()->ToBoolean(success.FromJust());
946 : }
947 :
948 : // ecma402 #sec-segment-iterator-prototype-index
949 482868 : BUILTIN(SegmentIteratorPrototypeIndex) {
950 : const char* const method = "get %SegmentIteratorPrototype%.index";
951 : HandleScope scope(isolate);
952 :
953 241434 : CHECK_RECEIVER(JSSegmentIterator, segment_iterator, method);
954 241434 : return *JSSegmentIterator::Index(isolate, segment_iterator);
955 : }
956 :
957 5112 : BUILTIN(SegmenterConstructor) {
958 : HandleScope scope(isolate);
959 :
960 : return DisallowCallConstructor<JSSegmenter>(
961 : args, isolate, v8::Isolate::UseCounterFeature::kSegmenter,
962 2556 : "Intl.Segmenter");
963 : }
964 :
965 144 : BUILTIN(SegmenterSupportedLocalesOf) {
966 : HandleScope scope(isolate);
967 36 : Handle<Object> locales = args.atOrUndefined(isolate, 1);
968 36 : Handle<Object> options = args.atOrUndefined(isolate, 2);
969 :
970 108 : RETURN_RESULT_OR_FAILURE(
971 : isolate, Intl::SupportedLocalesOf(
972 : isolate, "Intl.Segmenter.supportedLocalesOf",
973 : JSSegmenter::GetAvailableLocales(), locales, options));
974 : }
975 :
976 2160 : BUILTIN(SegmenterPrototypeResolvedOptions) {
977 : HandleScope scope(isolate);
978 1080 : CHECK_RECEIVER(JSSegmenter, segmenter_holder,
979 : "Intl.Segmenter.prototype.resolvedOptions");
980 1080 : return *JSSegmenter::ResolvedOptions(isolate, segmenter_holder);
981 : }
982 :
983 : // ecma402 #sec-Intl.Segmenter.prototype.segment
984 17316 : BUILTIN(SegmenterPrototypeSegment) {
985 : HandleScope scope(isolate);
986 8658 : CHECK_RECEIVER(JSSegmenter, segmenter_holder,
987 : "Intl.Segmenter.prototype.segment");
988 4329 : Handle<Object> input_text = args.atOrUndefined(isolate, 1);
989 : // 3. Let string be ? ToString(string).
990 : Handle<String> text;
991 8667 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, text,
992 : Object::ToString(isolate, input_text));
993 :
994 : // 4. Return ? CreateSegmentIterator(segment, string).
995 17280 : RETURN_RESULT_OR_FAILURE(
996 : isolate,
997 : JSSegmentIterator::Create(
998 : isolate, segmenter_holder->icu_break_iterator()->raw()->clone(),
999 : segmenter_holder->granularity(), text));
1000 : }
1001 :
1002 920 : BUILTIN(V8BreakIteratorConstructor) {
1003 : HandleScope scope(isolate);
1004 :
1005 460 : return CallOrConstructConstructor<JSV8BreakIterator>(args, isolate);
1006 : }
1007 :
1008 288 : BUILTIN(V8BreakIteratorPrototypeResolvedOptions) {
1009 : HandleScope scope(isolate);
1010 144 : CHECK_RECEIVER(JSV8BreakIterator, break_iterator,
1011 : "Intl.v8BreakIterator.prototype.resolvedOptions");
1012 144 : return *JSV8BreakIterator::ResolvedOptions(isolate, break_iterator);
1013 : }
1014 :
1015 308 : BUILTIN(V8BreakIteratorPrototypeAdoptText) {
1016 : const char* const method = "get Intl.v8BreakIterator.prototype.adoptText";
1017 : HandleScope scope(isolate);
1018 :
1019 262 : CHECK_RECEIVER(JSV8BreakIterator, break_iterator, method);
1020 :
1021 82 : Handle<Object> bound_adopt_text(break_iterator->bound_adopt_text(), isolate);
1022 82 : if (!bound_adopt_text->IsUndefined(isolate)) {
1023 : DCHECK(bound_adopt_text->IsJSFunction());
1024 : return *bound_adopt_text;
1025 : }
1026 :
1027 : Handle<JSFunction> new_bound_adopt_text_function = CreateBoundFunction(
1028 41 : isolate, break_iterator, Builtins::kV8BreakIteratorInternalAdoptText, 1);
1029 82 : break_iterator->set_bound_adopt_text(*new_bound_adopt_text_function);
1030 41 : return *new_bound_adopt_text_function;
1031 : }
1032 :
1033 164 : BUILTIN(V8BreakIteratorInternalAdoptText) {
1034 : HandleScope scope(isolate);
1035 : Handle<Context> context = Handle<Context>(isolate->context(), isolate);
1036 :
1037 : Handle<JSV8BreakIterator> break_iterator = Handle<JSV8BreakIterator>(
1038 : JSV8BreakIterator::cast(context->get(
1039 : static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
1040 82 : isolate);
1041 :
1042 41 : Handle<Object> input_text = args.atOrUndefined(isolate, 1);
1043 : Handle<String> text;
1044 82 : ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, text,
1045 : Object::ToString(isolate, input_text));
1046 :
1047 41 : JSV8BreakIterator::AdoptText(isolate, break_iterator, text);
1048 41 : return ReadOnlyRoots(isolate).undefined_value();
1049 : }
1050 :
1051 288 : BUILTIN(V8BreakIteratorPrototypeFirst) {
1052 : const char* const method = "get Intl.v8BreakIterator.prototype.first";
1053 : HandleScope scope(isolate);
1054 :
1055 252 : CHECK_RECEIVER(JSV8BreakIterator, break_iterator, method);
1056 :
1057 72 : Handle<Object> bound_first(break_iterator->bound_first(), isolate);
1058 72 : if (!bound_first->IsUndefined(isolate)) {
1059 : DCHECK(bound_first->IsJSFunction());
1060 : return *bound_first;
1061 : }
1062 :
1063 : Handle<JSFunction> new_bound_first_function = CreateBoundFunction(
1064 36 : isolate, break_iterator, Builtins::kV8BreakIteratorInternalFirst, 0);
1065 72 : break_iterator->set_bound_first(*new_bound_first_function);
1066 36 : return *new_bound_first_function;
1067 : }
1068 :
1069 144 : BUILTIN(V8BreakIteratorInternalFirst) {
1070 : HandleScope scope(isolate);
1071 : Handle<Context> context = Handle<Context>(isolate->context(), isolate);
1072 :
1073 : Handle<JSV8BreakIterator> break_iterator = Handle<JSV8BreakIterator>(
1074 : JSV8BreakIterator::cast(context->get(
1075 : static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
1076 72 : isolate);
1077 :
1078 108 : return *JSV8BreakIterator::First(isolate, break_iterator);
1079 : }
1080 :
1081 1876 : BUILTIN(V8BreakIteratorPrototypeNext) {
1082 : const char* const method = "get Intl.v8BreakIterator.prototype.next";
1083 : HandleScope scope(isolate);
1084 :
1085 1073 : CHECK_RECEIVER(JSV8BreakIterator, break_iterator, method);
1086 :
1087 848 : Handle<Object> bound_next(break_iterator->bound_next(), isolate);
1088 848 : if (!bound_next->IsUndefined(isolate)) {
1089 : DCHECK(bound_next->IsJSFunction());
1090 : return *bound_next;
1091 : }
1092 :
1093 : Handle<JSFunction> new_bound_next_function = CreateBoundFunction(
1094 50 : isolate, break_iterator, Builtins::kV8BreakIteratorInternalNext, 0);
1095 100 : break_iterator->set_bound_next(*new_bound_next_function);
1096 50 : return *new_bound_next_function;
1097 : }
1098 :
1099 1660 : BUILTIN(V8BreakIteratorInternalNext) {
1100 : HandleScope scope(isolate);
1101 : Handle<Context> context = Handle<Context>(isolate->context(), isolate);
1102 :
1103 : Handle<JSV8BreakIterator> break_iterator = Handle<JSV8BreakIterator>(
1104 : JSV8BreakIterator::cast(context->get(
1105 : static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
1106 830 : isolate);
1107 1245 : return *JSV8BreakIterator::Next(isolate, break_iterator);
1108 : }
1109 :
1110 144 : BUILTIN(V8BreakIteratorPrototypeCurrent) {
1111 : const char* const method = "get Intl.v8BreakIterator.prototype.current";
1112 : HandleScope scope(isolate);
1113 :
1114 180 : CHECK_RECEIVER(JSV8BreakIterator, break_iterator, method);
1115 :
1116 0 : Handle<Object> bound_current(break_iterator->bound_current(), isolate);
1117 0 : if (!bound_current->IsUndefined(isolate)) {
1118 : DCHECK(bound_current->IsJSFunction());
1119 : return *bound_current;
1120 : }
1121 :
1122 : Handle<JSFunction> new_bound_current_function = CreateBoundFunction(
1123 0 : isolate, break_iterator, Builtins::kV8BreakIteratorInternalCurrent, 0);
1124 0 : break_iterator->set_bound_current(*new_bound_current_function);
1125 0 : return *new_bound_current_function;
1126 : }
1127 :
1128 0 : BUILTIN(V8BreakIteratorInternalCurrent) {
1129 : HandleScope scope(isolate);
1130 : Handle<Context> context = Handle<Context>(isolate->context(), isolate);
1131 :
1132 : Handle<JSV8BreakIterator> break_iterator = Handle<JSV8BreakIterator>(
1133 : JSV8BreakIterator::cast(context->get(
1134 : static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
1135 0 : isolate);
1136 0 : return *JSV8BreakIterator::Current(isolate, break_iterator);
1137 : }
1138 :
1139 1260 : BUILTIN(V8BreakIteratorPrototypeBreakType) {
1140 : const char* const method = "get Intl.v8BreakIterator.prototype.breakType";
1141 : HandleScope scope(isolate);
1142 :
1143 738 : CHECK_RECEIVER(JSV8BreakIterator, break_iterator, method);
1144 :
1145 558 : Handle<Object> bound_break_type(break_iterator->bound_break_type(), isolate);
1146 558 : if (!bound_break_type->IsUndefined(isolate)) {
1147 : DCHECK(bound_break_type->IsJSFunction());
1148 : return *bound_break_type;
1149 : }
1150 :
1151 : Handle<JSFunction> new_bound_break_type_function = CreateBoundFunction(
1152 18 : isolate, break_iterator, Builtins::kV8BreakIteratorInternalBreakType, 0);
1153 36 : break_iterator->set_bound_break_type(*new_bound_break_type_function);
1154 18 : return *new_bound_break_type_function;
1155 : }
1156 :
1157 1116 : BUILTIN(V8BreakIteratorInternalBreakType) {
1158 : HandleScope scope(isolate);
1159 : Handle<Context> context = Handle<Context>(isolate->context(), isolate);
1160 :
1161 : Handle<JSV8BreakIterator> break_iterator = Handle<JSV8BreakIterator>(
1162 : JSV8BreakIterator::cast(context->get(
1163 : static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
1164 558 : isolate);
1165 558 : return JSV8BreakIterator::BreakType(isolate, break_iterator);
1166 : }
1167 :
1168 : } // namespace internal
1169 183867 : } // namespace v8
|