diff --git a/src/builtins/builtins-bigint.cc b/src/builtins/builtins-bigint.cc index 1201ce9730..c414d6db64 100644 --- a/src/builtins/builtins-bigint.cc +++ b/src/builtins/builtins-bigint.cc @@ -125,26 +125,24 @@ Object BigIntToStringImpl(Handle receiver, Handle radix, BUILTIN(BigIntPrototypeToLocaleString) { HandleScope scope(isolate); + const char* method = "BigInt.prototype.toLocaleString"; #ifdef V8_INTL_SUPPORT if (FLAG_harmony_intl_bigint) { // 1. Let x be ? thisBigIntValue(this value). Handle x; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate, x, - ThisBigIntValue(isolate, args.receiver(), - "BigInt.prototype.toLocaleString")); + isolate, x, ThisBigIntValue(isolate, args.receiver(), method)); RETURN_RESULT_OR_FAILURE( isolate, Intl::NumberToLocaleString(isolate, x, args.atOrUndefined(isolate, 1), - args.atOrUndefined(isolate, 2))); + args.atOrUndefined(isolate, 2), method)); } // Fallbacks to old toString implemention if flag is off or no // V8_INTL_SUPPORT #endif // V8_INTL_SUPPORT Handle radix = isolate->factory()->undefined_value(); - return BigIntToStringImpl(args.receiver(), radix, isolate, - "BigInt.prototype.toLocaleString"); + return BigIntToStringImpl(args.receiver(), radix, isolate, method); } BUILTIN(BigIntPrototypeToString) { diff --git a/src/builtins/builtins-date.cc b/src/builtins/builtins-date.cc index c3e7601832..258b1022da 100644 --- a/src/builtins/builtins-date.cc +++ b/src/builtins/builtins-date.cc @@ -854,16 +854,18 @@ BUILTIN(DatePrototypeToLocaleDateString) { isolate->CountUsage(v8::Isolate::UseCounterFeature::kDateToLocaleDateString); - CHECK_RECEIVER(JSDate, date, "Date.prototype.toLocaleDateString"); + const char* method = "Date.prototype.toLocaleDateString"; + CHECK_RECEIVER(JSDate, date, method); RETURN_RESULT_OR_FAILURE( isolate, JSDateTimeFormat::ToLocaleDateTime( isolate, - date, // date - args.atOrUndefined(isolate, 1), // locales - args.atOrUndefined(isolate, 2), // options - JSDateTimeFormat::RequiredOption::kDate, // required - JSDateTimeFormat::DefaultsOption::kDate)); // defaults + date, // date + args.atOrUndefined(isolate, 1), // locales + args.atOrUndefined(isolate, 2), // options + JSDateTimeFormat::RequiredOption::kDate, // required + JSDateTimeFormat::DefaultsOption::kDate, // defaults + method)); // method } // ecma402 #sup-date.prototype.tolocalestring @@ -872,16 +874,18 @@ BUILTIN(DatePrototypeToLocaleString) { isolate->CountUsage(v8::Isolate::UseCounterFeature::kDateToLocaleString); - CHECK_RECEIVER(JSDate, date, "Date.prototype.toLocaleString"); + const char* method = "Date.prototype.toLocaleString"; + CHECK_RECEIVER(JSDate, date, method); RETURN_RESULT_OR_FAILURE( isolate, JSDateTimeFormat::ToLocaleDateTime( isolate, - date, // date - args.atOrUndefined(isolate, 1), // locales - args.atOrUndefined(isolate, 2), // options - JSDateTimeFormat::RequiredOption::kAny, // required - JSDateTimeFormat::DefaultsOption::kAll)); // defaults + date, // date + args.atOrUndefined(isolate, 1), // locales + args.atOrUndefined(isolate, 2), // options + JSDateTimeFormat::RequiredOption::kAny, // required + JSDateTimeFormat::DefaultsOption::kAll, // defaults + method)); // method } // ecma402 #sup-date.prototype.tolocaletimestring @@ -890,16 +894,18 @@ BUILTIN(DatePrototypeToLocaleTimeString) { isolate->CountUsage(v8::Isolate::UseCounterFeature::kDateToLocaleTimeString); - CHECK_RECEIVER(JSDate, date, "Date.prototype.toLocaleTimeString"); + const char* method = "Date.prototype.toLocaleTimeString"; + CHECK_RECEIVER(JSDate, date, method); RETURN_RESULT_OR_FAILURE( isolate, JSDateTimeFormat::ToLocaleDateTime( isolate, - date, // date - args.atOrUndefined(isolate, 1), // locales - args.atOrUndefined(isolate, 2), // options - JSDateTimeFormat::RequiredOption::kTime, // required - JSDateTimeFormat::DefaultsOption::kTime)); // defaults + date, // date + args.atOrUndefined(isolate, 1), // locales + args.atOrUndefined(isolate, 2), // options + JSDateTimeFormat::RequiredOption::kTime, // required + JSDateTimeFormat::DefaultsOption::kTime, // defaults + method)); // method } #endif // V8_INTL_SUPPORT diff --git a/src/builtins/builtins-intl.cc b/src/builtins/builtins-intl.cc index ff8e96f4f5..22bd065783 100644 --- a/src/builtins/builtins-intl.cc +++ b/src/builtins/builtins-intl.cc @@ -282,8 +282,8 @@ Object LegacyFormatConstructor(BuiltinArguments args, Isolate* isolate, // 3. Perform ? Initialize(Format, locales, options). Handle format; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, format, - T::New(isolate, map, locales, options)); + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate, format, T::New(isolate, map, locales, options, method)); // 4. Let this be the this value. Handle receiver = args.receiver(); @@ -367,7 +367,8 @@ Object DisallowCallConstructor(BuiltinArguments args, Isolate* isolate, * Common code shared by Collator and V8BreakIterator */ template -Object CallOrConstructConstructor(BuiltinArguments args, Isolate* isolate) { +Object CallOrConstructConstructor(BuiltinArguments args, Isolate* isolate, + const char* method) { Handle new_target; if (args.new_target()->IsUndefined(isolate)) { @@ -386,7 +387,8 @@ Object CallOrConstructConstructor(BuiltinArguments args, Isolate* isolate) { ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, map, JSFunction::GetDerivedMap(isolate, target, new_target)); - RETURN_RESULT_OR_FAILURE(isolate, T::New(isolate, map, locales, options)); + RETURN_RESULT_OR_FAILURE(isolate, + T::New(isolate, map, locales, options, method)); } } // namespace @@ -884,7 +886,7 @@ BUILTIN(CollatorConstructor) { isolate->CountUsage(v8::Isolate::UseCounterFeature::kCollator); - return CallOrConstructConstructor(args, isolate); + return CallOrConstructConstructor(args, isolate, "Intl.Collator"); } BUILTIN(CollatorPrototypeResolvedOptions) { @@ -1069,7 +1071,8 @@ BUILTIN(SegmenterPrototypeSegment) { BUILTIN(V8BreakIteratorConstructor) { HandleScope scope(isolate); - return CallOrConstructConstructor(args, isolate); + return CallOrConstructConstructor(args, isolate, + "Intl.v8BreakIterator"); } BUILTIN(V8BreakIteratorPrototypeResolvedOptions) { diff --git a/src/builtins/builtins-number.cc b/src/builtins/builtins-number.cc index d2fb0ff74c..49e7ff27b8 100644 --- a/src/builtins/builtins-number.cc +++ b/src/builtins/builtins-number.cc @@ -111,6 +111,7 @@ BUILTIN(NumberPrototypeToFixed) { // ES6 section 20.1.3.4 Number.prototype.toLocaleString ( [ r1 [ , r2 ] ] ) BUILTIN(NumberPrototypeToLocaleString) { HandleScope scope(isolate); + const char* method = "Number.prototype.toLocaleString"; isolate->CountUsage(v8::Isolate::UseCounterFeature::kNumberToLocaleString); @@ -123,17 +124,17 @@ BUILTIN(NumberPrototypeToLocaleString) { // 1. Let x be ? thisNumberValue(this value) if (!value->IsNumber()) { THROW_NEW_ERROR_RETURN_FAILURE( - isolate, NewTypeError(MessageTemplate::kNotGeneric, - isolate->factory()->NewStringFromAsciiChecked( - "Number.prototype.toLocaleString"), - isolate->factory()->Number_string())); + isolate, + NewTypeError(MessageTemplate::kNotGeneric, + isolate->factory()->NewStringFromAsciiChecked(method), + isolate->factory()->Number_string())); } #ifdef V8_INTL_SUPPORT RETURN_RESULT_OR_FAILURE( isolate, Intl::NumberToLocaleString(isolate, value, args.atOrUndefined(isolate, 1), - args.atOrUndefined(isolate, 2))); + args.atOrUndefined(isolate, 2), method)); #else // Turn the {value} into a String. return *isolate->factory()->NumberToString(value); diff --git a/src/builtins/builtins-string.cc b/src/builtins/builtins-string.cc index 04a96c7e46..ba2346d661 100644 --- a/src/builtins/builtins-string.cc +++ b/src/builtins/builtins-string.cc @@ -136,20 +136,21 @@ BUILTIN(StringPrototypeLocaleCompare) { HandleScope handle_scope(isolate); isolate->CountUsage(v8::Isolate::UseCounterFeature::kStringLocaleCompare); + const char* method = "String.prototype.localeCompare"; #ifdef V8_INTL_SUPPORT - TO_THIS_STRING(str1, "String.prototype.localeCompare"); + TO_THIS_STRING(str1, method); Handle str2; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, str2, Object::ToString(isolate, args.atOrUndefined(isolate, 1))); RETURN_RESULT_OR_FAILURE( - isolate, Intl::StringLocaleCompare(isolate, str1, str2, - args.atOrUndefined(isolate, 2), - args.atOrUndefined(isolate, 3))); + isolate, Intl::StringLocaleCompare( + isolate, str1, str2, args.atOrUndefined(isolate, 2), + args.atOrUndefined(isolate, 3), method)); #else DCHECK_EQ(2, args.length()); - TO_THIS_STRING(str1, "String.prototype.localeCompare"); + TO_THIS_STRING(str1, method); Handle str2; ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, str2, Object::ToString(isolate, args.at(1))); diff --git a/src/objects/intl-objects.cc b/src/objects/intl-objects.cc index cbc7c5d47b..d3081b575b 100644 --- a/src/objects/intl-objects.cc +++ b/src/objects/intl-objects.cc @@ -177,12 +177,13 @@ const UChar* GetUCharBufferFromFlat(const String::FlatContent& flat, template MaybeHandle New(Isolate* isolate, Handle constructor, - Handle locales, Handle options) { + Handle locales, Handle options, + const char* method) { Handle map; ASSIGN_RETURN_ON_EXCEPTION( isolate, map, JSFunction::GetDerivedMap(isolate, constructor, constructor), T); - return T::New(isolate, map, locales, options); + return T::New(isolate, map, locales, options, method); } } // namespace @@ -995,11 +996,9 @@ MaybeHandle Intl::StringLocaleConvertCase(Isolate* isolate, } } -MaybeHandle Intl::StringLocaleCompare(Isolate* isolate, - Handle string1, - Handle string2, - Handle locales, - Handle options) { +MaybeHandle Intl::StringLocaleCompare( + Isolate* isolate, Handle string1, Handle string2, + Handle locales, Handle options, const char* method) { // We only cache the instance when both locales and options are undefined, // as that is the only case when the specified side-effects of examining // those arguments are unobservable. @@ -1025,7 +1024,7 @@ MaybeHandle Intl::StringLocaleCompare(Isolate* isolate, Handle collator; ASSIGN_RETURN_ON_EXCEPTION( isolate, collator, - New(isolate, constructor, locales, options), Object); + New(isolate, constructor, locales, options, method), Object); if (can_cache) { isolate->set_icu_object_in_cache( Isolate::ICUObjectCacheType::kDefaultCollator, @@ -1084,7 +1083,8 @@ Handle Intl::CompareStrings(Isolate* isolate, MaybeHandle Intl::NumberToLocaleString(Isolate* isolate, Handle num, Handle locales, - Handle options) { + Handle options, + const char* method) { Handle numeric_obj; if (FLAG_harmony_intl_bigint) { ASSIGN_RETURN_ON_EXCEPTION(isolate, numeric_obj, @@ -1119,7 +1119,8 @@ MaybeHandle Intl::NumberToLocaleString(Isolate* isolate, // 2. Let numberFormat be ? Construct(%NumberFormat%, « locales, options »). ASSIGN_RETURN_ON_EXCEPTION( isolate, number_format, - New(isolate, constructor, locales, options), String); + New(isolate, constructor, locales, options, method), + String); if (can_cache) { isolate->set_icu_object_in_cache( diff --git a/src/objects/intl-objects.h b/src/objects/intl-objects.h index 4d4d3245fd..ac2040e282 100644 --- a/src/objects/intl-objects.h +++ b/src/objects/intl-objects.h @@ -164,7 +164,7 @@ class Intl { V8_WARN_UNUSED_RESULT static MaybeHandle StringLocaleCompare( Isolate* isolate, Handle s1, Handle s2, - Handle locales, Handle options); + Handle locales, Handle options, const char* method); V8_WARN_UNUSED_RESULT static Handle CompareStrings( Isolate* isolate, const icu::Collator& collator, Handle s1, @@ -173,7 +173,7 @@ class Intl { // ecma402/#sup-properties-of-the-number-prototype-object V8_WARN_UNUSED_RESULT static MaybeHandle NumberToLocaleString( Isolate* isolate, Handle num, Handle locales, - Handle options); + Handle options, const char* method); // ecma402/#sec-setnfdigitoptions struct NumberFormatDigitOptions { diff --git a/src/objects/js-break-iterator.cc b/src/objects/js-break-iterator.cc index 31ed3f8611..1a9d096411 100644 --- a/src/objects/js-break-iterator.cc +++ b/src/objects/js-break-iterator.cc @@ -17,7 +17,7 @@ namespace internal { MaybeHandle JSV8BreakIterator::New( Isolate* isolate, Handle map, Handle locales, - Handle options_obj) { + Handle options_obj, const char* service) { Factory* factory = isolate->factory(); // 1. Let requestedLocales be ? CanonicalizeLocaleList(locales). @@ -31,15 +31,14 @@ MaybeHandle JSV8BreakIterator::New( if (options_obj->IsUndefined(isolate)) { options = factory->NewJSObjectWithNullProto(); } else { - ASSIGN_RETURN_ON_EXCEPTION( - isolate, options, - Object::ToObject(isolate, options_obj, "Intl.JSV8BreakIterator"), - JSV8BreakIterator); + ASSIGN_RETURN_ON_EXCEPTION(isolate, options, + Object::ToObject(isolate, options_obj, service), + JSV8BreakIterator); } // Extract locale string Maybe maybe_locale_matcher = - Intl::GetLocaleMatcher(isolate, options, "Intl.JSV8BreakIterator"); + Intl::GetLocaleMatcher(isolate, options, service); MAYBE_RETURN(maybe_locale_matcher, MaybeHandle()); Intl::MatcherOption matcher = maybe_locale_matcher.FromJust(); @@ -49,7 +48,7 @@ MaybeHandle JSV8BreakIterator::New( // Extract type from options Maybe maybe_type = Intl::GetStringOption( - isolate, options, "type", "Intl.v8BreakIterator", + isolate, options, "type", service, {"word", "character", "sentence", "line"}, {Type::WORD, Type::CHARACTER, Type::SENTENCE, Type::LINE}, Type::WORD); MAYBE_RETURN(maybe_type, MaybeHandle()); diff --git a/src/objects/js-break-iterator.h b/src/objects/js-break-iterator.h index 4b40192c81..2b0209632e 100644 --- a/src/objects/js-break-iterator.h +++ b/src/objects/js-break-iterator.h @@ -31,7 +31,7 @@ class JSV8BreakIterator : public JSObject { public: V8_WARN_UNUSED_RESULT static MaybeHandle New( Isolate* isolate, Handle map, Handle input_locales, - Handle input_options); + Handle input_options, const char* service); static Handle ResolvedOptions( Isolate* isolate, Handle break_iterator); diff --git a/src/objects/js-collator.cc b/src/objects/js-collator.cc index 0413e2acd1..39178b3acf 100644 --- a/src/objects/js-collator.cc +++ b/src/objects/js-collator.cc @@ -243,7 +243,8 @@ void SetCaseFirstOption(icu::Collator* icu_collator, // static MaybeHandle JSCollator::New(Isolate* isolate, Handle map, Handle locales, - Handle options_obj) { + Handle options_obj, + const char* service) { // 1. Let requestedLocales be ? CanonicalizeLocaleList(locales). Maybe> maybe_requested_locales = Intl::CanonicalizeLocaleList(isolate, locales); @@ -258,9 +259,9 @@ MaybeHandle JSCollator::New(Isolate* isolate, Handle map, } else { // 3. Else // 3. a. Let options be ? ToObject(options). - ASSIGN_RETURN_ON_EXCEPTION( - isolate, options_obj, - Object::ToObject(isolate, options_obj, "Intl.Collator"), JSCollator); + ASSIGN_RETURN_ON_EXCEPTION(isolate, options_obj, + Object::ToObject(isolate, options_obj, service), + JSCollator); } // At this point, options_obj can either be a JSObject or a JSProxy only. @@ -269,7 +270,7 @@ MaybeHandle JSCollator::New(Isolate* isolate, Handle map, // 4. Let usage be ? GetOption(options, "usage", "string", « "sort", // "search" », "sort"). Maybe maybe_usage = Intl::GetStringOption( - isolate, options, "usage", "Intl.Collator", {"sort", "search"}, + isolate, options, "usage", service, {"sort", "search"}, {Usage::SORT, Usage::SEARCH}, Usage::SORT); MAYBE_RETURN(maybe_usage, MaybeHandle()); Usage usage = maybe_usage.FromJust(); @@ -278,7 +279,7 @@ MaybeHandle JSCollator::New(Isolate* isolate, Handle map, // « "lookup", "best fit" », "best fit"). // 10. Set opt.[[localeMatcher]] to matcher. Maybe maybe_locale_matcher = - Intl::GetLocaleMatcher(isolate, options, "Intl.Collator"); + Intl::GetLocaleMatcher(isolate, options, service); MAYBE_RETURN(maybe_locale_matcher, MaybeHandle()); Intl::MatcherOption matcher = maybe_locale_matcher.FromJust(); @@ -293,14 +294,14 @@ MaybeHandle JSCollator::New(Isolate* isolate, Handle map, // // 13. Set opt.[[kn]] to numeric. bool numeric; - Maybe found_numeric = Intl::GetBoolOption(isolate, options, "numeric", - "Intl.Collator", &numeric); + Maybe found_numeric = + Intl::GetBoolOption(isolate, options, "numeric", service, &numeric); MAYBE_RETURN(found_numeric, MaybeHandle()); // 14. Let caseFirst be ? GetOption(options, "caseFirst", "string", // « "upper", "lower", "false" », undefined). Maybe maybe_case_first = - Intl::GetCaseFirst(isolate, options, "Intl.Collator"); + Intl::GetCaseFirst(isolate, options, service); MAYBE_RETURN(maybe_case_first, MaybeHandle()); Intl::CaseFirst case_first = maybe_case_first.FromJust(); @@ -411,7 +412,7 @@ MaybeHandle JSCollator::New(Isolate* isolate, Handle map, // 24. Let sensitivity be ? GetOption(options, "sensitivity", // "string", « "base", "accent", "case", "variant" », undefined). Maybe maybe_sensitivity = Intl::GetStringOption( - isolate, options, "sensitivity", "Intl.Collator", + isolate, options, "sensitivity", service, {"base", "accent", "case", "variant"}, {Sensitivity::kBase, Sensitivity::kAccent, Sensitivity::kCase, Sensitivity::kVariant}, @@ -451,9 +452,8 @@ MaybeHandle JSCollator::New(Isolate* isolate, Handle map, // 27.Let ignorePunctuation be ? GetOption(options, // "ignorePunctuation", "boolean", undefined, false). bool ignore_punctuation; - Maybe found_ignore_punctuation = - Intl::GetBoolOption(isolate, options, "ignorePunctuation", - "Intl.Collator", &ignore_punctuation); + Maybe found_ignore_punctuation = Intl::GetBoolOption( + isolate, options, "ignorePunctuation", service, &ignore_punctuation); MAYBE_RETURN(found_ignore_punctuation, MaybeHandle()); // 28. Set collator.[[IgnorePunctuation]] to ignorePunctuation. diff --git a/src/objects/js-collator.h b/src/objects/js-collator.h index e9114afeb1..ab029e64a3 100644 --- a/src/objects/js-collator.h +++ b/src/objects/js-collator.h @@ -34,7 +34,7 @@ class JSCollator : public JSObject { // ecma402/#sec-initializecollator V8_WARN_UNUSED_RESULT static MaybeHandle New( Isolate* isolate, Handle map, Handle locales, - Handle options); + Handle options, const char* service); // ecma402/#sec-intl.collator.prototype.resolvedoptions static Handle ResolvedOptions(Isolate* isolate, diff --git a/src/objects/js-date-time-format.cc b/src/objects/js-date-time-format.cc index b8380b40e6..1ee7f2056b 100644 --- a/src/objects/js-date-time-format.cc +++ b/src/objects/js-date-time-format.cc @@ -641,7 +641,8 @@ Isolate::ICUObjectCacheType ConvertToCacheType( MaybeHandle JSDateTimeFormat::ToLocaleDateTime( Isolate* isolate, Handle date, Handle locales, - Handle options, RequiredOption required, DefaultsOption defaults) { + Handle options, RequiredOption required, DefaultsOption defaults, + const char* method) { Isolate::ICUObjectCacheType cache_type = ConvertToCacheType(defaults); Factory* factory = isolate->factory(); @@ -691,7 +692,8 @@ MaybeHandle JSDateTimeFormat::ToLocaleDateTime( Handle date_time_format; ASSIGN_RETURN_ON_EXCEPTION( isolate, date_time_format, - JSDateTimeFormat::New(isolate, map, locales, internal_options), String); + JSDateTimeFormat::New(isolate, map, locales, internal_options, method), + String); if (can_cache) { isolate->set_icu_object_in_cache( @@ -1215,7 +1217,7 @@ enum FormatMatcherOption { kBestFit, kBasic }; // ecma402/#sec-initializedatetimeformat MaybeHandle JSDateTimeFormat::New( Isolate* isolate, Handle map, Handle locales, - Handle input_options) { + Handle input_options, const char* service) { Factory* factory = isolate->factory(); // 1. Let requestedLocales be ? CanonicalizeLocaleList(locales). Maybe> maybe_requested_locales = @@ -1265,21 +1267,21 @@ MaybeHandle JSDateTimeFormat::New( } Maybe maybe_locale_matcher = - Intl::GetLocaleMatcher(isolate, options, "Intl.DateTimeFormat"); + Intl::GetLocaleMatcher(isolate, options, service); MAYBE_RETURN(maybe_locale_matcher, MaybeHandle()); Intl::MatcherOption locale_matcher = maybe_locale_matcher.FromJust(); // 6. Let hour12 be ? GetOption(options, "hour12", "boolean", undefined, // undefined). bool hour12; - Maybe maybe_get_hour12 = Intl::GetBoolOption( - isolate, options, "hour12", "Intl.DateTimeFormat", &hour12); + Maybe maybe_get_hour12 = + Intl::GetBoolOption(isolate, options, "hour12", service, &hour12); MAYBE_RETURN(maybe_get_hour12, Handle()); // 7. Let hourCycle be ? GetOption(options, "hourCycle", "string", « "h11", // "h12", "h23", "h24" », undefined). Maybe maybe_hour_cycle = - Intl::GetHourCycle(isolate, options, "Intl.DateTimeFormat"); + Intl::GetHourCycle(isolate, options, service); MAYBE_RETURN(maybe_hour_cycle, MaybeHandle()); Intl::HourCycle hour_cycle = maybe_hour_cycle.FromJust(); @@ -1321,9 +1323,8 @@ MaybeHandle JSDateTimeFormat::New( // 17. Let timeZone be ? Get(options, "timeZone"). const std::vector empty_values; std::unique_ptr timezone = nullptr; - Maybe maybe_timezone = - Intl::GetStringOption(isolate, options, "timeZone", empty_values, - "Intl.DateTimeFormat", &timezone); + Maybe maybe_timezone = Intl::GetStringOption( + isolate, options, "timeZone", empty_values, service, &timezone); MAYBE_RETURN(maybe_timezone, Handle()); std::unique_ptr tz = CreateTimeZone(isolate, timezone.get()); @@ -1413,7 +1414,7 @@ MaybeHandle JSDateTimeFormat::New( // "full", "long", "medium", "short" », undefined). Maybe maybe_date_style = Intl::GetStringOption( - isolate, options, "dateStyle", "Intl.DateTimeFormat", + isolate, options, "dateStyle", service, {"full", "long", "medium", "short"}, {DateTimeStyle::kFull, DateTimeStyle::kLong, DateTimeStyle::kMedium, DateTimeStyle::kShort}, @@ -1427,7 +1428,7 @@ MaybeHandle JSDateTimeFormat::New( // "full", "long", "medium", "short" »). Maybe maybe_time_style = Intl::GetStringOption( - isolate, options, "timeStyle", "Intl.DateTimeFormat", + isolate, options, "timeStyle", service, {"full", "long", "medium", "short"}, {DateTimeStyle::kFull, DateTimeStyle::kLong, DateTimeStyle::kMedium, DateTimeStyle::kShort}, @@ -1455,9 +1456,9 @@ MaybeHandle JSDateTimeFormat::New( // i. Let prop be the name given in the Property column of the row. // ii. Let value be ? GetOption(options, prop, "string", « the strings // given in the Values column of the row », undefined). - Maybe maybe_get_option = Intl::GetStringOption( - isolate, options, item.property.c_str(), item.allowed_values, - "Intl.DateTimeFormat", &input); + Maybe maybe_get_option = + Intl::GetStringOption(isolate, options, item.property.c_str(), + item.allowed_values, service, &input); MAYBE_RETURN(maybe_get_option, Handle()); if (maybe_get_option.FromJust()) { if (item.property == "hour") { @@ -1486,8 +1487,7 @@ MaybeHandle JSDateTimeFormat::New( // « "basic", "best fit" », "best fit"). Maybe maybe_format_matcher = Intl::GetStringOption( - isolate, options, "formatMatcher", "Intl.DateTimeFormat", - {"best fit", "basic"}, + isolate, options, "formatMatcher", service, {"best fit", "basic"}, {FormatMatcherOption::kBestFit, FormatMatcherOption::kBasic}, FormatMatcherOption::kBestFit); MAYBE_RETURN(maybe_format_matcher, MaybeHandle()); diff --git a/src/objects/js-date-time-format.h b/src/objects/js-date-time-format.h index f4a8ccc8f5..6d4fd920aa 100644 --- a/src/objects/js-date-time-format.h +++ b/src/objects/js-date-time-format.h @@ -34,7 +34,7 @@ class JSDateTimeFormat : public JSObject { public: V8_WARN_UNUSED_RESULT static MaybeHandle New( Isolate* isolate, Handle map, Handle locales, - Handle options); + Handle options, const char* service); V8_WARN_UNUSED_RESULT static MaybeHandle ResolvedOptions( Isolate* isolate, Handle date_time_format); @@ -82,7 +82,8 @@ class JSDateTimeFormat : public JSObject { V8_WARN_UNUSED_RESULT static MaybeHandle ToLocaleDateTime( Isolate* isolate, Handle date, Handle locales, - Handle options, RequiredOption required, DefaultsOption defaults); + Handle options, RequiredOption required, DefaultsOption defaults, + const char* method); V8_EXPORT_PRIVATE static const std::set& GetAvailableLocales(); diff --git a/src/objects/js-number-format.cc b/src/objects/js-number-format.cc index ff564975d6..b149fa60a1 100644 --- a/src/objects/js-number-format.cc +++ b/src/objects/js-number-format.cc @@ -837,7 +837,8 @@ MaybeHandle JSNumberFormat::UnwrapNumberFormat( MaybeHandle JSNumberFormat::New(Isolate* isolate, Handle map, Handle locales, - Handle options_obj) { + Handle options_obj, + const char* service) { Factory* factory = isolate->factory(); // 1. Let requestedLocales be ? CanonicalizeLocaleList(locales). @@ -854,10 +855,9 @@ MaybeHandle JSNumberFormat::New(Isolate* isolate, } else { // 3. Else // 3. a. Let options be ? ToObject(options). - ASSIGN_RETURN_ON_EXCEPTION( - isolate, options_obj, - Object::ToObject(isolate, options_obj, "Intl.NumberFormat"), - JSNumberFormat); + ASSIGN_RETURN_ON_EXCEPTION(isolate, options_obj, + Object::ToObject(isolate, options_obj, service), + JSNumberFormat); } // At this point, options_obj can either be a JSObject or a JSProxy only. @@ -868,7 +868,7 @@ MaybeHandle JSNumberFormat::New(Isolate* isolate, // "lookup", "best fit" », "best fit"). // 6. Set opt.[[localeMatcher]] to matcher. Maybe maybe_locale_matcher = - Intl::GetLocaleMatcher(isolate, options, "Intl.NumberFormat"); + Intl::GetLocaleMatcher(isolate, options, service); MAYBE_RETURN(maybe_locale_matcher, MaybeHandle()); Intl::MatcherOption matcher = maybe_locale_matcher.FromJust(); @@ -914,7 +914,6 @@ MaybeHandle JSNumberFormat::New(Isolate* isolate, // 12. Let style be ? GetOption(options, "style", "string", « "decimal", // "percent", "currency" », "decimal"). - const char* service = "Intl.NumberFormat"; std::vector style_str_values({"decimal", "percent", "currency"}); std::vector style_enum_values( @@ -1035,7 +1034,7 @@ MaybeHandle JSNumberFormat::New(Isolate* isolate, THROW_NEW_ERROR( isolate, NewTypeError(MessageTemplate::kInvalidUnit, - factory->NewStringFromStaticChars("Intl.NumberFormat"), + factory->NewStringFromAsciiChecked(service), factory->empty_string()), JSNumberFormat); } @@ -1047,10 +1046,9 @@ MaybeHandle JSNumberFormat::New(Isolate* isolate, if (maybe_wellformed.IsNothing()) { THROW_NEW_ERROR( isolate, - NewRangeError( - MessageTemplate::kInvalidUnit, - factory->NewStringFromStaticChars("Intl.NumberFormat"), - factory->NewStringFromAsciiChecked(unit.c_str())), + NewRangeError(MessageTemplate::kInvalidUnit, + factory->NewStringFromAsciiChecked(service), + factory->NewStringFromAsciiChecked(unit.c_str())), JSNumberFormat); } std::pair unit_pair = diff --git a/src/objects/js-number-format.h b/src/objects/js-number-format.h index 2979ab10f4..f9a4b729ba 100644 --- a/src/objects/js-number-format.h +++ b/src/objects/js-number-format.h @@ -36,7 +36,7 @@ class JSNumberFormat : public JSObject { // ecma402/#sec-initializenumberformat V8_WARN_UNUSED_RESULT static MaybeHandle New( Isolate* isolate, Handle map, Handle locales, - Handle options); + Handle options, const char* service); // ecma402/#sec-unwrapnumberformat V8_WARN_UNUSED_RESULT static MaybeHandle UnwrapNumberFormat( diff --git a/test/intl/assert.js b/test/intl/assert.js index a6367a8cf2..ae1646cc02 100644 --- a/test/intl/assert.js +++ b/test/intl/assert.js @@ -157,7 +157,7 @@ function assertThrows(code, type_opt, cause_opt) { assertInstanceof(e, type_opt); } if (arguments.length >= 3) { - assertEquals(cause_opt, e.type, 'thrown exception type mismatch'); + assertEquals(cause_opt, e.message, 'thrown exception type mismatch'); } // Success. return; diff --git a/test/intl/regress-1799396.js b/test/intl/regress-1799396.js new file mode 100644 index 0000000000..fc51d632f9 --- /dev/null +++ b/test/intl/regress-1799396.js @@ -0,0 +1,51 @@ +// Copyright 2019 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Number, BigInt and Intl.NumberFormat +assertThrows( + "new Intl.NumberFormat('en', { style: 'unit', unit: 'son'});", + RangeError, + "Invalid unit argument for Intl.NumberFormat() 'son'"); + +assertThrows( + "123n.toLocaleString('en', { style: 'unit', unit: 'son'});", + RangeError, + "Invalid unit argument for BigInt.prototype.toLocaleString() 'son'"); + +assertThrows( + "Math.PI.toLocaleString('en', { style: 'unit', unit: 'son'});", + RangeError, + "Invalid unit argument for Number.prototype.toLocaleString() 'son'"); + +// String and Intl.Collator +assertThrows( + "new Intl.Collator('en', { usage: 'mom'});", + RangeError, + "Value mom out of range for Intl.Collator options property usage"); + +assertThrows( + "'abc'.localeCompare('efg', 'en', { usage: 'mom'});", + RangeError, + "Value mom out of range for String.prototype.localeCompare options property usage"); + +// Date and Intl.DateTimeFormat +assertThrows( + "new Intl.DateTimeFormat('en', { hour: 'dad'});", + RangeError, + "Value dad out of range for Intl.DateTimeFormat options property hour"); + +assertThrows( + "(new Date).toLocaleDateString('en', { hour: 'dad'});", + RangeError, + "Value dad out of range for Date.prototype.toLocaleDateString options property hour"); + +assertThrows( + "(new Date).toLocaleString('en', { hour: 'dad'});", + RangeError, + "Value dad out of range for Date.prototype.toLocaleString options property hour"); + +assertThrows( + "(new Date).toLocaleTimeString('en', { hour: 'dad'});", + RangeError, + "Value dad out of range for Date.prototype.toLocaleTimeString options property hour");