From 87acad9d29437346b964aad222ab7b45cffb2a80 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 19 Aug 2024 18:51:45 +0200 Subject: [PATCH] deps: V8: cherry-pick e74d0f437fcd Original commit message: [api] add v8::Isolate::GetDefaultLocale() This allows embedders to query the default locale used by Intl APIs. This information is already available to user land via Intl?.Collator().resolvedOptions().locale, the issue with this is that it's a lot slower and requires dynamic access to Intl API, which is subject to patching and prototype pollution so it's not as reliable for embedders than having a V8 API to query the default locale directly. Refs: https://github.com/nodejs/node/pull/54279 Change-Id: I5a1823993c9ae79f8f61f54c6464daf882a09ba3 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5772938 Reviewed-by: Leszek Swirski Commit-Queue: Joyee Cheung Cr-Commit-Position: refs/heads/main@{#95678} Refs: https://github.com/v8/v8/commit/e74d0f437fcd385e312bfd33c369515c91048478 PR-URL: https://github.com/nodejs/node/pull/54279 Reviewed-By: Ben Noordhuis Reviewed-By: Matteo Collina Reviewed-By: Ethan Arrowood Reviewed-By: Jiawen Geng Reviewed-By: Chengzhong Wu Reviewed-By: James M Snell --- common.gypi | 2 +- deps/v8/include/v8-isolate.h | 7 +++++++ deps/v8/src/api/api.cc | 11 +++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/common.gypi b/common.gypi index 207b98c9b6f36a..a97e77860e151f 100644 --- a/common.gypi +++ b/common.gypi @@ -36,7 +36,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.18', + 'v8_embedder_string': '-node.19', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/include/v8-isolate.h b/deps/v8/include/v8-isolate.h index 585b513fac446a..8f3326812918e5 100644 --- a/deps/v8/include/v8-isolate.h +++ b/deps/v8/include/v8-isolate.h @@ -9,6 +9,7 @@ #include #include +#include #include #include "cppgc/common.h" @@ -1711,6 +1712,12 @@ class V8_EXPORT Isolate { */ void LocaleConfigurationChangeNotification(); + /** + * Returns the default locale in a string if Intl support is enabled. + * Otherwise returns an empty string. + */ + std::string GetDefaultLocale(); + Isolate() = delete; ~Isolate() = delete; Isolate(const Isolate&) = delete; diff --git a/deps/v8/src/api/api.cc b/deps/v8/src/api/api.cc index 28f0389258cc95..2dd476dda34f1c 100644 --- a/deps/v8/src/api/api.cc +++ b/deps/v8/src/api/api.cc @@ -10577,6 +10577,17 @@ void v8::Isolate::LocaleConfigurationChangeNotification() { #endif // V8_INTL_SUPPORT } +std::string Isolate::GetDefaultLocale() { + i::Isolate* i_isolate = reinterpret_cast(this); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + +#ifdef V8_INTL_SUPPORT + return i_isolate->DefaultLocale(); +#else + return std::string(); +#endif +} + #if defined(V8_OS_WIN) && defined(V8_ENABLE_ETW_STACK_WALKING) void Isolate::SetFilterETWSessionByURLCallback( FilterETWSessionByURLCallback callback) {