diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/dts/lib.deno.window.d.ts | 2 | ||||
-rw-r--r-- | cli/dts/lib.deno.worker.d.ts | 2 | ||||
-rw-r--r-- | cli/standalone.rs | 1 | ||||
-rw-r--r-- | cli/tests/integration/run_tests.rs | 53 | ||||
-rw-r--r-- | cli/tests/testdata/navigator_language.ts | 1 | ||||
-rw-r--r-- | cli/tests/testdata/navigator_languages.ts | 1 | ||||
-rw-r--r-- | cli/worker.rs | 2 |
7 files changed, 62 insertions, 0 deletions
diff --git a/cli/dts/lib.deno.window.d.ts b/cli/dts/lib.deno.window.d.ts index 77204fcbd..4ce288a4d 100644 --- a/cli/dts/lib.deno.window.d.ts +++ b/cli/dts/lib.deno.window.d.ts @@ -97,6 +97,8 @@ declare class Navigator { readonly gpu: GPU; readonly hardwareConcurrency: number; readonly userAgent: string; + readonly language: string; + readonly languages: string[]; } /** @category Web APIs */ diff --git a/cli/dts/lib.deno.worker.d.ts b/cli/dts/lib.deno.worker.d.ts index 10a771807..d274d4c05 100644 --- a/cli/dts/lib.deno.worker.d.ts +++ b/cli/dts/lib.deno.worker.d.ts @@ -61,6 +61,8 @@ declare class WorkerNavigator { readonly gpu: GPU; readonly hardwareConcurrency: number; readonly userAgent: string; + readonly language: string; + readonly languages: string[]; } /** @category Web APIs */ diff --git a/cli/standalone.rs b/cli/standalone.rs index 0c454ce77..528c55f1c 100644 --- a/cli/standalone.rs +++ b/cli/standalone.rs @@ -276,6 +276,7 @@ pub async fn run( .unwrap_or(1), debug_flag: metadata.log_level.map_or(false, |l| l == Level::Debug), enable_testing_features: false, + locale: deno_core::v8::icu::get_language_tag(), location: metadata.location, no_color: !colors::use_color(), is_tty: colors::is_tty(), diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index 004acb469..156940185 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -2377,6 +2377,59 @@ itest!(eval_context_throw_dom_exception { output: "run/eval_context_throw_dom_exception.js.out", }); +#[test] +#[cfg(unix)] +fn navigator_language_unix() { + let (res, _) = util::run_and_collect_output( + true, + "run navigator_language.ts", + None, + Some(vec![("LC_ALL".to_owned(), "pl_PL".to_owned())]), + false, + ); + assert_eq!(res, "pl-PL\n") +} + +#[test] +fn navigator_language() { + let (res, _) = util::run_and_collect_output( + true, + "run navigator_language.ts", + None, + None, + false, + ); + assert!(!res.is_empty()) +} + +#[test] +#[cfg(unix)] +fn navigator_languages_unix() { + let (res, _) = util::run_and_collect_output( + true, + "run navigator_languages.ts", + None, + Some(vec![ + ("LC_ALL".to_owned(), "pl_PL".to_owned()), + ("NO_COLOR".to_owned(), "1".to_owned()), + ]), + false, + ); + assert_eq!(res, "[ \"pl-PL\" ]\n") +} + +#[test] +fn navigator_languages() { + let (res, _) = util::run_and_collect_output( + true, + "run navigator_languages.ts", + None, + None, + false, + ); + assert!(!res.is_empty()) +} + /// Regression test for https://github.com/denoland/deno/issues/12740. #[test] fn issue12740() { diff --git a/cli/tests/testdata/navigator_language.ts b/cli/tests/testdata/navigator_language.ts new file mode 100644 index 000000000..1cdbc2fe6 --- /dev/null +++ b/cli/tests/testdata/navigator_language.ts @@ -0,0 +1 @@ +console.log(navigator.language); diff --git a/cli/tests/testdata/navigator_languages.ts b/cli/tests/testdata/navigator_languages.ts new file mode 100644 index 000000000..41dece950 --- /dev/null +++ b/cli/tests/testdata/navigator_languages.ts @@ -0,0 +1 @@ +console.log(navigator.languages); diff --git a/cli/worker.rs b/cli/worker.rs index 581d4f90f..10fe5b36f 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -418,6 +418,7 @@ pub async fn create_main_worker( .log_level() .map_or(false, |l| l == log::Level::Debug), enable_testing_features: ps.options.enable_testing_features(), + locale: deno_core::v8::icu::get_language_tag(), location: ps.options.location_flag().map(ToOwned::to_owned), no_color: !colors::use_color(), is_tty: colors::is_tty(), @@ -534,6 +535,7 @@ fn create_web_worker_callback( .log_level() .map_or(false, |l| l == log::Level::Debug), enable_testing_features: ps.options.enable_testing_features(), + locale: deno_core::v8::icu::get_language_tag(), location: Some(args.main_module.clone()), no_color: !colors::use_color(), is_tty: colors::is_tty(), |