Commit 6b3fde42 authored by Brian Stell's avatar Brian Stell Committed by Commit Bot

Replace the JS version of supportedLocalesOf with the C++ version.

Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: I5f6adec8857398f82598295e86d2559c96363647

Bug: v8:7955, v8:7869, v8:5751
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: I5f6adec8857398f82598295e86d2559c96363647
Reviewed-on: https://chromium-review.googlesource.com/1184046
Commit-Queue: Brian Stell <bstell@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55434}
parent 9563acd3
......@@ -2895,6 +2895,10 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
native_context()->set_intl_date_time_format_function(
*date_time_format_constructor);
SimpleInstallFunction(
isolate(), date_time_format_constructor, "supportedLocalesOf",
Builtins::kDateTimeFormatSupportedLocalesOf, 1, false);
Handle<JSObject> prototype(
JSObject::cast(date_time_format_constructor->prototype()), isolate_);
......@@ -2927,6 +2931,10 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
native_context()->set_intl_number_format_function(
*number_format_constructor);
SimpleInstallFunction(
isolate(), number_format_constructor, "supportedLocalesOf",
Builtins::kNumberFormatSupportedLocalesOf, 1, false);
Handle<JSObject> prototype(
JSObject::cast(number_format_constructor->prototype()), isolate_);
......@@ -2960,6 +2968,10 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
InstallWithIntrinsicDefaultProto(isolate_, collator_constructor,
Context::INTL_COLLATOR_FUNCTION_INDEX);
SimpleInstallFunction(isolate(), collator_constructor,
"supportedLocalesOf",
Builtins::kCollatorSupportedLocalesOf, 1, false);
Handle<JSObject> prototype(
JSObject::cast(collator_constructor->prototype()), isolate_);
......@@ -2989,6 +3001,10 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
native_context()->set_intl_v8_break_iterator_function(
*v8_break_iterator_constructor);
SimpleInstallFunction(
isolate(), v8_break_iterator_constructor, "supportedLocalesOf",
Builtins::kv8BreakIteratorSupportedLocalesOf, 1, false);
Handle<JSObject> prototype(
JSObject::cast(v8_break_iterator_constructor->prototype()), isolate_);
......@@ -3021,6 +3037,10 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
isolate_, plural_rules_constructor,
Context::INTL_PLURAL_RULES_FUNCTION_INDEX);
SimpleInstallFunction(isolate(), plural_rules_constructor,
"supportedLocalesOf",
Builtins::kPluralRulesSupportedLocalesOf, 1, false);
Handle<JSObject> prototype(
JSObject::cast(plural_rules_constructor->prototype()), isolate_);
......@@ -4687,6 +4707,10 @@ void Genesis::InitializeGlobal_harmony_intl_relative_time_format() {
relative_time_format_fun->shared()->set_length(0);
relative_time_format_fun->shared()->DontAdaptArguments();
SimpleInstallFunction(
isolate(), relative_time_format_fun, "supportedLocalesOf",
Builtins::kRelativeTimeFormatSupportedLocalesOf, 1, false);
// Setup %RelativeTimeFormatPrototype%.
Handle<JSObject> prototype(
JSObject::cast(relative_time_format_fun->instance_prototype()),
......
......@@ -1327,6 +1327,10 @@ namespace internal {
#define BUILTIN_LIST_INTL(CPP, TFJ, TFS) \
/* ecma402 #sec-intl.collator */ \
CPP(CollatorConstructor) \
/* ecma402 #sec-intl.v8breakiterator.supportedlocalesof */ \
CPP(v8BreakIteratorSupportedLocalesOf) \
/* ecma402 #sec-intl.collator.supportedlocalesof */ \
CPP(CollatorSupportedLocalesOf) \
TFS(StringToLowerCaseIntl, kString) \
/* ES #sec-string.prototype.tolowercase */ \
TFJ(StringPrototypeToLowerCaseIntl, 0, kReceiver) \
......@@ -1368,16 +1372,24 @@ namespace internal {
CPP(LocalePrototypeMinimize) \
/* ecma402 #sec-number-format-functions */ \
CPP(NumberFormatInternalFormatNumber) \
/* ecma402 #sec-intl.numberformat.supportedlocalesof */ \
CPP(NumberFormatSupportedLocalesOf) \
/* ecma402 #sec-intl.numberformat.prototype.format */ \
CPP(NumberFormatPrototypeFormatNumber) \
/* ecma402 #sec-datetime-format-functions */ \
CPP(DateTimeFormatInternalFormat) \
/* ecma402 #sec-intl.datetimeformat.supportedlocalesof */ \
CPP(DateTimeFormatSupportedLocalesOf) \
/* ecma402 #sec-intl.datetimeformat.prototype.format */ \
CPP(DateTimeFormatPrototypeFormat) \
/* ecma402 #sec-intl.pluralrules */ \
CPP(PluralRulesConstructor) \
/* ecma402 #sec-intl.pluralrules.supportedlocalesof */ \
CPP(PluralRulesSupportedLocalesOf) \
/* ecma402 #sec-intl.RelativeTimeFormat.constructor */ \
CPP(RelativeTimeFormatConstructor) \
/* ecma402 #sec-intl.RelativeTimeFormat.supportedlocalesof */ \
CPP(RelativeTimeFormatSupportedLocalesOf) \
/* ecma402 #sec-intl.RelativeTimeFormat.prototype.resolvedOptions */ \
CPP(RelativeTimeFormatPrototypeResolvedOptions) \
/* ecma402 #sec-intl.RelativeTimeFormat.prototype.format */ \
......
......@@ -346,8 +346,38 @@ MaybeHandle<Object> FormatDateToParts(Isolate* isolate, icu::DateFormat* format,
return result;
}
MaybeHandle<JSObject> SupportedLocalesOfCommon(Isolate* isolate,
const char* service_in,
BuiltinArguments args) {
Factory* factory = isolate->factory();
Handle<String> service = factory->NewStringFromAsciiChecked(service_in);
Handle<Object> locales = args.atOrUndefined(isolate, 1);
Handle<Object> options = args.atOrUndefined(isolate, 2);
MaybeHandle<JSObject> result =
Intl::SupportedLocalesOf(isolate, service, locales, options);
Handle<JSObject> elements;
ASSIGN_RETURN_ON_EXCEPTION(isolate, elements, result, JSObject);
return elements;
}
} // namespace
BUILTIN(v8BreakIteratorSupportedLocalesOf) {
HandleScope scope(isolate);
// 1. If NewTarget is defined, throw a TypeError exception.
if (!args.new_target()->IsUndefined(isolate)) { // [[Call]]
THROW_NEW_ERROR_RETURN_FAILURE(
isolate,
NewTypeError(MessageTemplate::kOrdinaryFunctionCalledAsConstructor,
isolate->factory()->NewStringFromStaticChars(
"Intl.v8BreakIterator")));
}
RETURN_RESULT_OR_FAILURE(
isolate, SupportedLocalesOfCommon(isolate, "breakiterator", args));
}
// Flattens a list of possibly-overlapping "regions" to a list of
// non-overlapping "parts". At least one of the input regions must span the
// entire space of possible indexes. The regions parameter will sorted in-place
......@@ -438,6 +468,12 @@ std::vector<NumberFormatSpan> FlattenRegionsToParts(
return out_parts;
}
BUILTIN(NumberFormatSupportedLocalesOf) {
HandleScope scope(isolate);
RETURN_RESULT_OR_FAILURE(
isolate, SupportedLocalesOfCommon(isolate, "numberformat", args));
}
BUILTIN(NumberFormatPrototypeFormatToParts) {
const char* const method = "Intl.NumberFormat.prototype.formatToParts";
HandleScope handle_scope(isolate);
......@@ -468,6 +504,12 @@ BUILTIN(NumberFormatPrototypeFormatToParts) {
isolate, FormatNumberToParts(isolate, number_format, x->Number()));
}
BUILTIN(DateTimeFormatSupportedLocalesOf) {
HandleScope scope(isolate);
RETURN_RESULT_OR_FAILURE(
isolate, SupportedLocalesOfCommon(isolate, "dateformat", args));
}
BUILTIN(DateTimeFormatPrototypeFormatToParts) {
const char* const method = "Intl.DateTimeFormat.prototype.formatToParts";
HandleScope handle_scope(isolate);
......@@ -966,6 +1008,12 @@ MaybeHandle<Object> RelativeTimeFormatPrototypeFormatCommon(
} // namespace
BUILTIN(RelativeTimeFormatSupportedLocalesOf) {
HandleScope scope(isolate);
RETURN_RESULT_OR_FAILURE(
isolate, SupportedLocalesOfCommon(isolate, "relativetimeformat", args));
}
BUILTIN(RelativeTimeFormatPrototypeFormat) {
HandleScope scope(isolate);
// 1. Let relativeTimeFormat be the this value.
......@@ -1163,6 +1211,12 @@ BUILTIN(PluralRulesConstructor) {
locales, options));
}
BUILTIN(PluralRulesSupportedLocalesOf) {
HandleScope scope(isolate);
RETURN_RESULT_OR_FAILURE(
isolate, SupportedLocalesOfCommon(isolate, "pluralrules", args));
}
BUILTIN(CollatorConstructor) {
HandleScope scope(isolate);
Handle<JSReceiver> new_target;
......@@ -1193,6 +1247,12 @@ BUILTIN(CollatorConstructor) {
isolate, collator, locales, options));
}
BUILTIN(CollatorSupportedLocalesOf) {
HandleScope scope(isolate);
RETURN_RESULT_OR_FAILURE(isolate,
SupportedLocalesOfCommon(isolate, "collator", args));
}
BUILTIN(CollatorPrototypeCompare) {
const char* const method = "get Intl.Collator.prototype.compare";
HandleScope scope(isolate);
......
......@@ -638,20 +638,6 @@ DEFINE_METHOD(
);
/**
* Returns the subset of the given locale list for which this locale list
* has a matching (possibly fallback) locale. Locales appear in the same
* order in the returned list as in the input list.
* Options are optional parameter.
*/
DEFINE_METHOD(
GlobalIntlCollator,
supportedLocalesOf(locales) {
return %SupportedLocalesOf('collator', locales, arguments[1]);
}
);
DEFINE_METHOD(
GlobalIntlPluralRules.prototype,
resolvedOptions() {
......@@ -659,13 +645,6 @@ DEFINE_METHOD(
}
);
DEFINE_METHOD(
GlobalIntlPluralRules,
supportedLocalesOf(locales) {
return %SupportedLocalesOf('pluralrules', locales, arguments[1]);
}
);
DEFINE_METHOD(
GlobalIntlPluralRules.prototype,
select(value) {
......@@ -857,19 +836,6 @@ DEFINE_METHOD(
);
/**
* Returns the subset of the given locale list for which this locale list
* has a matching (possibly fallback) locale. Locales appear in the same
* order in the returned list as in the input list.
* Options are optional parameter.
*/
DEFINE_METHOD(
GlobalIntlNumberFormat,
supportedLocalesOf(locales) {
return %SupportedLocalesOf('numberformat', locales, arguments[1]);
}
);
/**
* Returns a string that matches LDML representation of the options object.
*/
......@@ -1221,20 +1187,6 @@ DEFINE_METHOD(
);
/**
* Returns the subset of the given locale list for which this locale list
* has a matching (possibly fallback) locale. Locales appear in the same
* order in the returned list as in the input list.
* Options are optional parameter.
*/
DEFINE_METHOD(
GlobalIntlDateTimeFormat,
supportedLocalesOf(locales) {
return %SupportedLocalesOf('dateformat', locales, arguments[1]);
}
);
/**
* Returns canonical Area/Location(/Location) name, or throws an exception
* if the zone name is invalid IANA name.
......@@ -1357,24 +1309,6 @@ DEFINE_METHOD(
);
/**
* Returns the subset of the given locale list for which this locale list
* has a matching (possibly fallback) locale. Locales appear in the same
* order in the returned list as in the input list.
* Options are optional parameter.
*/
DEFINE_METHOD(
GlobalIntlv8BreakIterator,
supportedLocalesOf(locales) {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
}
return %SupportedLocalesOf('breakiterator', locales, arguments[1]);
}
);
/**
* Returns index of the first break in the string and moves current pointer.
*/
......
......@@ -2440,9 +2440,12 @@ MaybeHandle<JSObject> SupportedLocales(
}
} // namespace
// ECMA 402 10.2.2 Intl.Collator.supportedLocalesOf
// ECMA 402 Intl.*.supportedLocalesOf
// https://tc39.github.io/ecma402/#sec-intl.collator.supportedlocalesof
// of Intl::SupportedLocalesOf thru JS
// https://tc39.github.io/ecma402/#sec-intl.numberformat.supportedlocalesof
// https://tc39.github.io/ecma402/#sec-intl.datetimeformat.supportedlocalesof
// https://tc39.github.io/ecma402/#sec-intl.pluralrules.supportedlocalesof
// http://tc39.github.io/proposal-intl-relative-time/#sec-Intl.RelativeTimeFormat.supportedLocalesOf
MaybeHandle<JSObject> Intl::SupportedLocalesOf(Isolate* isolate,
Handle<String> service,
Handle<Object> locales_in,
......
......@@ -526,18 +526,5 @@ RUNTIME_FUNCTION(Runtime_IntlUnwrapReceiver) {
check_legacy_constructor));
}
RUNTIME_FUNCTION(Runtime_SupportedLocalesOf) {
HandleScope scope(isolate);
DCHECK_EQ(args.length(), 3);
CONVERT_ARG_HANDLE_CHECKED(String, service, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, locales, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, options, 2);
RETURN_RESULT_OR_FAILURE(
isolate, Intl::SupportedLocalesOf(isolate, service, locales, options));
}
} // namespace internal
} // namespace v8
......@@ -228,7 +228,6 @@ namespace internal {
F(ToLocaleDateTime, 6, 1) \
F(StringToLowerCaseIntl, 1, 1) \
F(StringToUpperCaseIntl, 1, 1) \
F(SupportedLocalesOf, 3, 1) \
// End of macro.
#else
#define FOR_EACH_INTRINSIC_INTL(F)
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Test that supportedLocalesOf is not a constructor.
var iterator = new Intl.v8BreakIterator();
assertThrows(() => new Intl.v8BreakIterator.supportedLocalesOf(), TypeError);
......@@ -465,12 +465,6 @@
'intl402/Locale/prototype/toStringTag/toStringTag': [FAIL],
'intl402/Locale/prototype/toStringTag/toString': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=7869
'intl402/RelativeTimeFormat/constructor/supportedLocalesOf/branding': [FAIL],
'intl402/RelativeTimeFormat/constructor/supportedLocalesOf/length': [FAIL],
'intl402/RelativeTimeFormat/constructor/supportedLocalesOf/name': [FAIL],
'intl402/RelativeTimeFormat/constructor/supportedLocalesOf/prop-desc': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=7993
'intl402/RelativeTimeFormat/prototype/toStringTag/toStringTag': [FAIL],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment