mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -05:00
BREAKING: remove window.location and self.location (#5034)
This commit removes "location" global available on "window", "globalThis" and "self".
This commit is contained in:
parent
5d3c49082f
commit
6661e7e287
13 changed files with 4 additions and 155 deletions
63
cli/js/lib.deno.shared_globals.d.ts
vendored
63
cli/js/lib.deno.shared_globals.d.ts
vendored
|
@ -192,7 +192,6 @@ declare function clearInterval(id?: number): void;
|
|||
declare function queueMicrotask(func: Function): void;
|
||||
|
||||
declare var console: Console;
|
||||
declare var location: Location;
|
||||
|
||||
declare function addEventListener(
|
||||
type: string,
|
||||
|
@ -440,68 +439,6 @@ declare class DOMException extends Error {
|
|||
readonly message: string;
|
||||
}
|
||||
|
||||
/** The location (URL) of the object it is linked to. Changes done on it are
|
||||
* reflected on the object it relates to. Both the Document and Window
|
||||
* interface have such a linked Location, accessible via Document.location and
|
||||
* Window.location respectively. */
|
||||
declare interface Location {
|
||||
/** Returns a DOMStringList object listing the origins of the ancestor
|
||||
* browsing contexts, from the parent browsing context to the top-level
|
||||
* browsing context. */
|
||||
readonly ancestorOrigins: DOMStringList;
|
||||
/** Returns the Location object's URL's fragment (includes leading "#" if
|
||||
* non-empty).
|
||||
*
|
||||
* Can be set, to navigate to the same URL with a changed fragment (ignores
|
||||
* leading "#"). */
|
||||
hash: string;
|
||||
/** Returns the Location object's URL's host and port (if different from the
|
||||
* default port for the scheme).
|
||||
*
|
||||
* Can be set, to navigate to the same URL with a changed host and port. */
|
||||
host: string;
|
||||
/** Returns the Location object's URL's host.
|
||||
*
|
||||
* Can be set, to navigate to the same URL with a changed host. */
|
||||
hostname: string;
|
||||
/** Returns the Location object's URL.
|
||||
*
|
||||
* Can be set, to navigate to the given URL. */
|
||||
href: string;
|
||||
toString(): string;
|
||||
/** Returns the Location object's URL's origin. */
|
||||
readonly origin: string;
|
||||
/** Returns the Location object's URL's path.
|
||||
*
|
||||
* Can be set, to navigate to the same URL with a changed path. */
|
||||
pathname: string;
|
||||
/** Returns the Location object's URL's port.
|
||||
*
|
||||
* Can be set, to navigate to the same URL with a changed port. */
|
||||
port: string;
|
||||
/** Returns the Location object's URL's scheme.
|
||||
*
|
||||
* Can be set, to navigate to the same URL with a changed scheme. */
|
||||
protocol: string;
|
||||
/** Returns the Location object's URL's query (includes leading "?" if
|
||||
* non-empty).
|
||||
*
|
||||
* Can be set, to navigate to the same URL with a changed query (ignores
|
||||
* leading "?"). */
|
||||
search: string;
|
||||
/**
|
||||
* Navigates to the given URL.
|
||||
*/
|
||||
assign(url: string): void;
|
||||
/**
|
||||
* Reloads the current page.
|
||||
*/
|
||||
reload(): void;
|
||||
/** Removes the current page from the session history and navigates to the
|
||||
* given URL. */
|
||||
replace(url: string): void;
|
||||
}
|
||||
|
||||
type BufferSource = ArrayBufferView | ArrayBuffer;
|
||||
type BlobPart = BufferSource | Blob | string;
|
||||
|
||||
|
|
1
cli/js/lib.deno.window.d.ts
vendored
1
cli/js/lib.deno.window.d.ts
vendored
|
@ -12,7 +12,6 @@ declare interface Window extends EventTarget {
|
|||
readonly self: Window & typeof globalThis;
|
||||
onload: ((this: Window, ev: Event) => any) | null;
|
||||
onunload: ((this: Window, ev: Event) => any) | null;
|
||||
location: Location;
|
||||
crypto: Crypto;
|
||||
close: () => void;
|
||||
readonly closed: boolean;
|
||||
|
|
1
cli/js/lib.deno.worker.d.ts
vendored
1
cli/js/lib.deno.worker.d.ts
vendored
|
@ -11,7 +11,6 @@ declare interface DedicatedWorkerGlobalScope {
|
|||
self: DedicatedWorkerGlobalScope & typeof globalThis;
|
||||
onmessage: (e: MessageEvent) => void;
|
||||
onmessageerror: (e: MessageEvent) => void;
|
||||
location: Location;
|
||||
onerror: undefined | typeof onerror;
|
||||
name: typeof __workerMain.name;
|
||||
close: typeof __workerMain.close;
|
||||
|
|
|
@ -7,7 +7,6 @@ export interface Start {
|
|||
cwd: string;
|
||||
debugFlag: boolean;
|
||||
denoVersion: string;
|
||||
location: string; // Absolute URL.
|
||||
noColor: boolean;
|
||||
pid: number;
|
||||
repl: boolean;
|
||||
|
|
|
@ -24,7 +24,6 @@ import { unstableMethods, unstableProperties } from "./globals_unstable.ts";
|
|||
import { internalObject, internalSymbol } from "./internals.ts";
|
||||
import { setSignals } from "./signals.ts";
|
||||
import { replLoop } from "./repl.ts";
|
||||
import { LocationImpl } from "./web/location.ts";
|
||||
import { setTimeout } from "./web/timers.ts";
|
||||
import * as runtime from "./runtime.ts";
|
||||
import { log, immutableDefine } from "./util.ts";
|
||||
|
@ -98,19 +97,7 @@ export function bootstrapMainRuntime(): void {
|
|||
}
|
||||
});
|
||||
|
||||
const {
|
||||
args,
|
||||
cwd,
|
||||
location,
|
||||
noColor,
|
||||
pid,
|
||||
repl,
|
||||
unstableFlag,
|
||||
} = runtime.start();
|
||||
|
||||
const location_ = new LocationImpl(location);
|
||||
immutableDefine(globalThis, "location", location_);
|
||||
Object.freeze(globalThis.location);
|
||||
const { args, cwd, noColor, pid, repl, unstableFlag } = runtime.start();
|
||||
|
||||
Object.defineProperties(denoNs, {
|
||||
pid: readOnly(pid),
|
||||
|
|
|
@ -21,7 +21,6 @@ import { unstableMethods, unstableProperties } from "./globals_unstable.ts";
|
|||
import * as denoNs from "./deno.ts";
|
||||
import * as denoUnstableNs from "./deno_unstable.ts";
|
||||
import * as webWorkerOps from "./ops/web_worker.ts";
|
||||
import { LocationImpl } from "./web/location.ts";
|
||||
import { log, assert, immutableDefine } from "./util.ts";
|
||||
import { MessageEvent, ErrorEvent } from "./web/workers.ts";
|
||||
import { TextEncoder } from "./web/text_encoding.ts";
|
||||
|
@ -138,14 +137,10 @@ export function bootstrapWorkerRuntime(
|
|||
Object.defineProperties(globalThis, eventTargetProperties);
|
||||
Object.defineProperties(globalThis, { name: readOnly(name) });
|
||||
setEventTargetData(globalThis);
|
||||
const { location, unstableFlag, pid, noColor, args } = runtime.start(
|
||||
const { unstableFlag, pid, noColor, args } = runtime.start(
|
||||
internalName ?? name
|
||||
);
|
||||
|
||||
const location_ = new LocationImpl(location);
|
||||
immutableDefine(globalThis, "location", location_);
|
||||
Object.freeze(globalThis.location);
|
||||
|
||||
if (unstableFlag) {
|
||||
Object.defineProperties(globalThis, unstableMethods);
|
||||
Object.defineProperties(globalThis, unstableProperties);
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { unitTest, assert } from "./test_util.ts";
|
||||
|
||||
unitTest(function locationBasic(): void {
|
||||
// location example: file:///Users/rld/src/deno/js/unit_tests.ts
|
||||
assert(window.location.toString().endsWith("unit_test_runner.ts"));
|
||||
});
|
|
@ -33,7 +33,6 @@ import "./headers_test.ts";
|
|||
import "./internals_test.ts";
|
||||
import "./io_test.ts";
|
||||
import "./link_test.ts";
|
||||
import "./location_test.ts";
|
||||
import "./make_temp_test.ts";
|
||||
import "./metrics_test.ts";
|
||||
import "./dom_iterable_test.ts";
|
||||
|
|
|
@ -31,11 +31,6 @@ Some of the Web APIs are using ops under the hood, eg. `console`, `performance`.
|
|||
Promise-based HTTP Request API
|
||||
- [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData): access
|
||||
to a `multipart/form-data` serialization
|
||||
- [Location](https://developer.mozilla.org/en-US/docs/Web/API/Location): parsing
|
||||
the current script's URL
|
||||
- **Implementation notes:** the `globalThis.location` object cannot be
|
||||
manipulated using `assign()`, `reload()` and `replace()` methods. They are
|
||||
not implemented.
|
||||
- [Performance](https://developer.mozilla.org/en-US/docs/Web/API/Performance):
|
||||
retrieving current time with a high precision
|
||||
- [setTimeout](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout),
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { notImplemented } from "../util.ts";
|
||||
import { getDOMStringList } from "./dom_util.ts";
|
||||
|
||||
export class LocationImpl implements Location {
|
||||
#url: URL;
|
||||
|
||||
constructor(url: string) {
|
||||
const u = new URL(url);
|
||||
this.#url = u;
|
||||
this.hash = u.hash;
|
||||
this.host = u.host;
|
||||
this.href = u.href;
|
||||
this.hostname = u.hostname;
|
||||
this.origin = u.protocol + "//" + u.host;
|
||||
this.pathname = u.pathname;
|
||||
this.protocol = u.protocol;
|
||||
this.port = u.port;
|
||||
this.search = u.search;
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return this.#url.toString();
|
||||
}
|
||||
|
||||
readonly ancestorOrigins: DOMStringList = getDOMStringList([]);
|
||||
hash: string;
|
||||
host: string;
|
||||
hostname: string;
|
||||
href: string;
|
||||
readonly origin: string;
|
||||
pathname: string;
|
||||
port: string;
|
||||
protocol: string;
|
||||
search: string;
|
||||
assign(_url: string): void {
|
||||
throw notImplemented();
|
||||
}
|
||||
reload(): void {
|
||||
throw notImplemented();
|
||||
}
|
||||
replace(_url: string): void {
|
||||
throw notImplemented();
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the `window.location` at runtime.
|
||||
* @internal */
|
||||
export function setLocation(url: string): void {
|
||||
globalThis.location = new LocationImpl(url);
|
||||
Object.freeze(globalThis.location);
|
||||
}
|
|
@ -405,7 +405,7 @@ export class URLImpl implements URL {
|
|||
|
||||
// TODO(kevinkassimo): implement MediaSource version in the future.
|
||||
static createObjectURL(b: Blob): string {
|
||||
const origin = globalThis.location.origin || "http://deno-opaque-origin";
|
||||
const origin = "http://deno-opaque-origin";
|
||||
const key = `blob:${origin}/${generateUUID()}`;
|
||||
blobURLMap.set(key, b);
|
||||
return key;
|
||||
|
|
|
@ -28,7 +28,6 @@ fn op_start(
|
|||
"cwd": &env::current_dir().unwrap(),
|
||||
"debugFlag": gs.flags.log_level.map_or(false, |l| l == log::Level::Debug),
|
||||
"denoVersion": version::DENO,
|
||||
"location": state.main_module.to_string(),
|
||||
"noColor": !colors::use_color(),
|
||||
"pid": std::process::id(),
|
||||
"repl": gs.flags.subcommand == DenoSubcommand::Repl,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
if (window.location.toString() == import.meta.url) {
|
||||
if (import.meta.main) {
|
||||
console.log("main");
|
||||
} else {
|
||||
console.log("import.meta.url", import.meta.url);
|
||||
console.log("window.location", window.location.toString());
|
||||
throw Error("not main");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue