From df188190488fbbce9a66dbfb4e26347357903811 Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Tue, 12 Dec 2017 15:01:13 -0800 Subject: [PATCH] Fix Platform.localeName by setting _Platform._localeClosure (#4450) --- lib/ui/dart_runtime_hooks.cc | 18 +++++++++++------- lib/ui/hooks.dart | 6 ++++++ runtime/dart_vm_entry_points.txt | 2 ++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/ui/dart_runtime_hooks.cc b/lib/ui/dart_runtime_hooks.cc index 2339297abe7fd..edd51245b05db 100644 --- a/lib/ui/dart_runtime_hooks.cc +++ b/lib/ui/dart_runtime_hooks.cc @@ -112,16 +112,20 @@ static void InitDartAsync(Dart_Handle builtin_library, &schedule_microtask)); } -static void InitDartIO(const std::string& script_uri) { +static void InitDartIO(Dart_Handle builtin_library, + const std::string& script_uri) { + Dart_Handle io_lib = Dart_LookupLibrary(ToDart("dart:io")); + DART_CHECK_VALID(io_lib); + Dart_Handle platform_type = + Dart_GetType(io_lib, ToDart("_Platform"), 0, nullptr); + DART_CHECK_VALID(platform_type); if (!script_uri.empty()) { - Dart_Handle io_lib = Dart_LookupLibrary(ToDart("dart:io")); - DART_CHECK_VALID(io_lib); - Dart_Handle platform_type = - Dart_GetType(io_lib, ToDart("_Platform"), 0, nullptr); - DART_CHECK_VALID(platform_type); DART_CHECK_VALID(Dart_SetField(platform_type, ToDart("_nativeScript"), ToDart(script_uri))); } + Dart_Handle locale_closure = GetClosure(builtin_library, "_getLocaleClosure"); + DART_CHECK_VALID( + Dart_SetField(platform_type, ToDart("_localeClosure"), locale_closure)); } void DartRuntimeHooks::Install(IsolateType isolate_type, @@ -131,7 +135,7 @@ void DartRuntimeHooks::Install(IsolateType isolate_type, InitDartInternal(builtin, isolate_type); InitDartCore(builtin, script_uri); InitDartAsync(builtin, isolate_type); - InitDartIO(script_uri); + InitDartIO(builtin, script_uri); } // Implementation of native functions which are used for some diff --git a/lib/ui/hooks.dart b/lib/ui/hooks.dart index ed201c8c50d0b..9de206dac3866 100644 --- a/lib/ui/hooks.dart +++ b/lib/ui/hooks.dart @@ -39,6 +39,12 @@ void _updateWindowMetrics(double devicePixelRatio, _invoke(window.onMetricsChanged, window._onMetricsChangedZone); } +typedef String LocaleClosure(); + +String _localeClosure() => window._locale.toString(); + +LocaleClosure _getLocaleClosure() => _localeClosure; + void _updateLocale(String languageCode, String countryCode) { window._locale = new Locale(languageCode, countryCode); _invoke(window.onLocaleChanged, window._onLocaleChangedZone); diff --git a/runtime/dart_vm_entry_points.txt b/runtime/dart_vm_entry_points.txt index 3b02081c82945..5be14f22ceeaa 100644 --- a/runtime/dart_vm_entry_points.txt +++ b/runtime/dart_vm_entry_points.txt @@ -1,6 +1,7 @@ dart:_internal,::,_printClosure dart:async,::,_setScheduleImmediateClosure dart:io,::,_setupHooks +dart:io,_Platform,_localeClosure dart:io,_Platform,set:_nativeScript dart:isolate,::,_getIsolateScheduleImmediateClosure dart:isolate,::,_setupHooks @@ -12,6 +13,7 @@ dart:ui,::,_dispatchSemanticsAction dart:ui,::,_drawFrame dart:ui,::,_getGetBaseURLClosure dart:ui,::,_baseURL +dart:ui,::,_getLocaleClosure dart:ui,::,_getMainClosure dart:ui,::,_getPrintClosure dart:ui,::,_getScheduleMicrotaskClosure