Commit f248584b authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[intl] Store resolveLocale on the context

This unblocks new feature work that require this operation from C++,
whilst the porting to C++ is underway.

Bug: v8:5751
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: Icb7f05bbea42ecfa1abc3cefb6d1bf8542ed921b
Reviewed-on: https://chromium-review.googlesource.com/1127082
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54265}
parent dd704218
......@@ -96,6 +96,7 @@ enum ContextLookupFlags {
V(PROMISE_FUNCTION_INDEX, JSFunction, promise_function) \
V(RANGE_ERROR_FUNCTION_INDEX, JSFunction, range_error_function) \
V(REFERENCE_ERROR_FUNCTION_INDEX, JSFunction, reference_error_function) \
V(RESOLVE_LOCALE_FUNCTION_INDEX, JSFunction, resolve_locale) \
V(SET_ADD_INDEX, JSFunction, set_add) \
V(SET_DELETE_INDEX, JSFunction, set_delete) \
V(SET_HAS_INDEX, JSFunction, set_has) \
......
......@@ -415,6 +415,9 @@ function resolveLocale(service, requestedLocales, options) {
return resolved;
}
%InstallToContext([
"resolve_locale", resolveLocale
]);
/**
* Look up the longest non-empty prefix of |locale| that is an element of
......
......@@ -1237,6 +1237,29 @@ MaybeHandle<JSReceiver> Intl::UnwrapReceiver(Isolate* isolate,
return Handle<JSReceiver>::cast(new_receiver);
}
// TODO(bstell): Convert this to C++ instead of calling out to the
// JS implementation.
MaybeHandle<JSObject> Intl::ResolveLocale(Isolate* isolate, const char* service,
Handle<Object> requestedLocales,
Handle<Object> options) {
Handle<String> service_str =
isolate->factory()->NewStringFromAsciiChecked(service);
Handle<JSFunction> resolve_locale_function = isolate->resolve_locale();
Handle<Object> result;
Handle<Object> undefined_value(ReadOnlyRoots(isolate).undefined_value(),
isolate);
Handle<Object> args[] = {service_str, requestedLocales, options};
ASSIGN_RETURN_ON_EXCEPTION(
isolate, result,
Execution::Call(isolate, resolve_locale_function, undefined_value,
arraysize(args), args),
JSObject);
return Handle<JSObject>::cast(result);
}
Maybe<bool> Intl::GetStringOption(Isolate* isolate, Handle<JSReceiver> options,
const char* property,
std::vector<const char*> values,
......
......@@ -201,12 +201,30 @@ class Intl {
// Returns the underlying Intl receiver for various methods which
// implement ECMA-402 v1 semantics for supporting initializing
// existing Intl objects.
static MaybeHandle<JSReceiver> UnwrapReceiver(
V8_WARN_UNUSED_RESULT static MaybeHandle<JSReceiver> UnwrapReceiver(
Isolate* isolate, Handle<JSReceiver> receiver,
Handle<JSFunction> constructor, Intl::Type type,
Handle<String> method_name /* TODO(gsathya): Make this char const* */,
bool check_legacy_constructor = false);
// The ResolveLocale abstract operation compares a BCP 47 language
// priority list requestedLocales against the locales in
// availableLocales and determines the best available language to
// meet the request. availableLocales, requestedLocales, and
// relevantExtensionKeys must be provided as List values, options
// and localeData as Records.
//
// #ecma402/sec-partitiondatetimepattern
//
// Returns a JSObject with two properties:
// (1) locale
// (2) extension
//
// To access either, use JSObject::GetDataProperty.
V8_WARN_UNUSED_RESULT static MaybeHandle<JSObject> ResolveLocale(
Isolate* isolate, const char* service, Handle<Object> requestedLocales,
Handle<Object> options);
// ECMA402 9.2.10. GetOption( options, property, type, values, fallback)
// ecma402/#sec-getoption
//
......
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