mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -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:
parent
d41d3b8e2f
commit
dfc254cd57
4 changed files with 22 additions and 1 deletions
|
@ -46,6 +46,7 @@ let knownGlobals = [
|
|||
global.setTimeout,
|
||||
localStorage,
|
||||
location,
|
||||
name,
|
||||
navigator,
|
||||
onload,
|
||||
onunload,
|
||||
|
|
|
@ -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, "");
|
||||
});
|
||||
|
|
4
cli/tsc/dts/lib.deno.window.d.ts
vendored
4
cli/tsc/dts/lib.deno.window.d.ts
vendored
|
@ -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;
|
||||
|
|
|
@ -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),
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue