summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-10-09 00:12:59 +0200
committerGitHub <noreply@github.com>2023-10-08 22:12:59 +0000
commitdfc254cd57683f394f1b5fdca8c75200b2a9969d (patch)
tree25315d8183196486dbebae9d83dd7d2b00a65cec
parentd41d3b8e2f6079d806fb4bc4845b9ad681c20f00 (diff)
fix: define window.name (#20804)
Closes https://github.com/denoland/deno/issues/20750 This matches what browsers do: https://developer.mozilla.org/en-US/docs/Web/API/Window/name In the future we might want to change the behavior to actually update the process name, but that needs a bit of discussion regarding if it needs a permission flag (that would make polyfiling `process.title` setter really easy too).
-rw-r--r--cli/tests/node_compat/test/common/index.js1
-rw-r--r--cli/tests/unit/globals_test.ts14
-rw-r--r--cli/tsc/dts/lib.deno.window.d.ts4
-rw-r--r--runtime/js/99_main.js4
4 files changed, 22 insertions, 1 deletions
diff --git a/cli/tests/node_compat/test/common/index.js b/cli/tests/node_compat/test/common/index.js
index 0f6019746..f398108cd 100644
--- a/cli/tests/node_compat/test/common/index.js
+++ b/cli/tests/node_compat/test/common/index.js
@@ -46,6 +46,7 @@ let knownGlobals = [
global.setTimeout,
localStorage,
location,
+ name,
navigator,
onload,
onunload,
diff --git a/cli/tests/unit/globals_test.ts b/cli/tests/unit/globals_test.ts
index c63b28973..184b662a4 100644
--- a/cli/tests/unit/globals_test.ts
+++ b/cli/tests/unit/globals_test.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file no-window-prefix
-import { assert } from "./test_util.ts";
+import { assert, assertEquals } from "./test_util.ts";
Deno.test(function globalThisExists() {
assert(globalThis != null);
@@ -128,3 +128,15 @@ Deno.test(function webApiGlobalThis() {
assert(globalThis.CountQueuingStrategy !== null);
assert(globalThis.ByteLengthQueuingStrategy !== null);
});
+
+Deno.test(function windowNameIsDefined() {
+ assertEquals(typeof globalThis.name, "string");
+ assertEquals(name, "");
+ assertEquals(window.name, name);
+ name = "foobar";
+ assertEquals(window.name, "foobar");
+ assertEquals(name, "foobar");
+ name = "";
+ assertEquals(window.name, "");
+ assertEquals(name, "");
+});
diff --git a/cli/tsc/dts/lib.deno.window.d.ts b/cli/tsc/dts/lib.deno.window.d.ts
index 2edb2ce8f..58b57e52c 100644
--- a/cli/tsc/dts/lib.deno.window.d.ts
+++ b/cli/tsc/dts/lib.deno.window.d.ts
@@ -37,6 +37,7 @@ declare interface Window extends EventTarget {
localStorage: Storage;
sessionStorage: Storage;
caches: CacheStorage;
+ name: string;
addEventListener<K extends keyof WindowEventMap>(
type: K,
@@ -292,3 +293,6 @@ declare var Location: {
// The types there must first be split into window, worker and global types.
/** @category Web APIs */
declare var location: Location;
+
+/** @category Web APIs */
+declare var name: string;
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index d2a28838a..ccc61036a 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -489,6 +489,10 @@ function bootstrapMainRuntime(runtimeOptions) {
}
ObjectDefineProperties(globalThis, mainRuntimeGlobalProperties);
ObjectDefineProperties(globalThis, {
+ // TODO(bartlomieju): in the future we might want to change the
+ // behavior of setting `name` to actually update the process name.
+ // Empty string matches what browsers do.
+ name: util.writable(""),
close: util.writable(windowClose),
closed: util.getterOnly(() => windowIsClosing),
});