1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

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).
This commit is contained in:
Bartek Iwańczuk 2023-10-09 00:12:59 +02:00 committed by GitHub
parent d41d3b8e2f
commit dfc254cd57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 1 deletions

View file

@ -46,6 +46,7 @@ let knownGlobals = [
global.setTimeout,
localStorage,
location,
name,
navigator,
onload,
onunload,

View file

@ -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, "");
});

View file

@ -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;

View file

@ -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),
});