diff options
author | Luca Matei Pintilie <lucafulger@gmail.com> | 2022-10-18 15:33:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-18 15:33:35 +0200 |
commit | 1a0c7edebacc76a70e57dfd494e24420fa77b56b (patch) | |
tree | afa26f8db4dd121f548e19f92f84c1da589708c4 /runtime | |
parent | 23bb0abc230bd796e60bb8e22ccc39aef5629158 (diff) |
feat: introduce navigator.language (#12322)
Link to the spec:
https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-language-dev
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/examples/hello_runtime.rs | 1 | ||||
-rw-r--r-- | runtime/js/99_main.js | 36 | ||||
-rw-r--r-- | runtime/worker.rs | 1 | ||||
-rw-r--r-- | runtime/worker_bootstrap.rs | 3 |
4 files changed, 40 insertions, 1 deletions
diff --git a/runtime/examples/hello_runtime.rs b/runtime/examples/hello_runtime.rs index b4a8d8201..1f3610789 100644 --- a/runtime/examples/hello_runtime.rs +++ b/runtime/examples/hello_runtime.rs @@ -32,6 +32,7 @@ async fn main() -> Result<(), AnyError> { cpu_count: 1, debug_flag: false, enable_testing_features: false, + locale: deno_core::v8::icu::get_language_tag(), location: None, no_color: false, is_tty: false, diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 0a65cadee..a123fc24f 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -335,7 +335,7 @@ delete Intl.v8BreakIterator; const navigator = webidl.createBranded(Navigator); - let numCpus, userAgent; + let numCpus, userAgent, language; ObjectDefineProperties(Navigator.prototype, { gpu: { @@ -362,6 +362,22 @@ delete Intl.v8BreakIterator; return userAgent; }, }, + language: { + configurable: true, + enumerable: true, + get() { + webidl.assertBranded(this, NavigatorPrototype); + return language; + }, + }, + languages: { + configurable: true, + enumerable: true, + get() { + webidl.assertBranded(this, NavigatorPrototype); + return [language]; + }, + }, }); const NavigatorPrototype = Navigator.prototype; @@ -393,6 +409,22 @@ delete Intl.v8BreakIterator; webidl.assertBranded(this, WorkerNavigatorPrototype); return numCpus; }, + language: { + configurable: true, + enumerable: true, + get() { + webidl.assertBranded(this, WorkerNavigatorPrototype); + return language; + }, + }, + languages: { + configurable: true, + enumerable: true, + get() { + webidl.assertBranded(this, WorkerNavigatorPrototype); + return [language]; + }, + }, }, }); const WorkerNavigatorPrototype = WorkerNavigator.prototype; @@ -705,6 +737,7 @@ delete Intl.v8BreakIterator; numCpus = runtimeOptions.cpuCount; userAgent = runtimeOptions.userAgent; + language = runtimeOptions.locale; const internalSymbol = Symbol("Deno.internal"); @@ -793,6 +826,7 @@ delete Intl.v8BreakIterator; location.setLocationHref(runtimeOptions.location); numCpus = runtimeOptions.cpuCount; + language = runtimeOptions.locale; globalThis.pollForMessages = pollForMessages; diff --git a/runtime/worker.rs b/runtime/worker.rs index 36833da32..61cdfb94e 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -549,6 +549,7 @@ mod tests { cpu_count: 1, debug_flag: false, enable_testing_features: false, + locale: deno_core::v8::icu::get_language_tag(), location: None, no_color: true, is_tty: false, diff --git a/runtime/worker_bootstrap.rs b/runtime/worker_bootstrap.rs index 8af78c21a..07b093e44 100644 --- a/runtime/worker_bootstrap.rs +++ b/runtime/worker_bootstrap.rs @@ -16,6 +16,7 @@ pub struct BootstrapOptions { pub cpu_count: usize, pub debug_flag: bool, pub enable_testing_features: bool, + pub locale: String, pub location: Option<ModuleSpecifier>, /// Sets `Deno.noColor` in JS runtime. pub no_color: bool, @@ -47,6 +48,7 @@ impl Default for BootstrapOptions { enable_testing_features: Default::default(), debug_flag: Default::default(), ts_version: Default::default(), + locale: "en-EN".to_string(), location: Default::default(), unstable: Default::default(), inspect: Default::default(), @@ -63,6 +65,7 @@ impl BootstrapOptions { "cpuCount": self.cpu_count, "debugFlag": self.debug_flag, "denoVersion": self.runtime_version, + "locale": self.locale, "location": self.location, "noColor": self.no_color, "isTty": self.is_tty, |