diff options
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/examples/hello_runtime.rs | 1 | ||||
| -rw-r--r-- | runtime/js/11_workers.js | 12 | ||||
| -rw-r--r-- | runtime/js/99_main.js | 22 | ||||
| -rw-r--r-- | runtime/js/README.md | 2 | ||||
| -rw-r--r-- | runtime/web_worker.rs | 3 | ||||
| -rw-r--r-- | runtime/worker.rs | 3 |
6 files changed, 41 insertions, 2 deletions
diff --git a/runtime/examples/hello_runtime.rs b/runtime/examples/hello_runtime.rs index c93bbc90b..829b2d36c 100644 --- a/runtime/examples/hello_runtime.rs +++ b/runtime/examples/hello_runtime.rs @@ -39,6 +39,7 @@ async fn main() -> Result<(), AnyError> { ts_version: "x".to_string(), no_color: false, get_error_class_fn: Some(&get_error_class_name), + location: None, }; let js_path = diff --git a/runtime/js/11_workers.js b/runtime/js/11_workers.js index 4989cd4b5..57f420728 100644 --- a/runtime/js/11_workers.js +++ b/runtime/js/11_workers.js @@ -3,6 +3,7 @@ ((window) => { const core = window.Deno.core; const { Window } = window.__bootstrap.globalInterfaces; + const { getLocationHref } = window.__bootstrap.location; const { log, pathFromURL } = window.__bootstrap.util; const { defineEventHandler } = window.__bootstrap.webUtil; const build = window.__bootstrap.build.build; @@ -127,6 +128,7 @@ constructor(specifier, options = {}) { super(); + specifier = String(specifier); const { deno = {}, name = "unknown", @@ -177,6 +179,16 @@ const hasSourceCode = false; const sourceCode = decoder.decode(new Uint8Array()); + if ( + specifier.startsWith("./") || specifier.startsWith("../") || + specifier.startsWith("/") || type == "classic" + ) { + const baseUrl = getLocationHref(); + if (baseUrl != null) { + specifier = new URL(specifier, baseUrl).href; + } + } + const { id } = createWorker( specifier, hasSourceCode, diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index f38d51936..284bef48c 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -9,6 +9,7 @@ delete Object.prototype.__proto__; const util = window.__bootstrap.util; const eventTarget = window.__bootstrap.eventTarget; const globalInterfaces = window.__bootstrap.globalInterfaces; + const location = window.__bootstrap.location; const dispatchMinimal = window.__bootstrap.dispatchMinimal; const build = window.__bootstrap.build; const version = window.__bootstrap.version; @@ -196,6 +197,8 @@ delete Object.prototype.__proto__; // https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope const windowOrWorkerGlobalScope = { + Location: location.locationConstructorDescriptor, + location: location.locationDescriptor, Blob: util.nonEnumerable(fetch.Blob), ByteLengthQueuingStrategy: util.nonEnumerable( streams.ByteLengthQueuingStrategy, @@ -290,7 +293,19 @@ delete Object.prototype.__proto__; defineEventHandler(window, "unload", null); runtimeStart(runtimeOptions); - const { args, noColor, pid, ppid, unstableFlag } = runtimeOptions; + const { + args, + location: locationHref, + noColor, + pid, + ppid, + unstableFlag, + } = runtimeOptions; + + if (locationHref != null) { + location.setLocationHref(locationHref); + fetch.setBaseUrl(locationHref); + } registerErrors(); @@ -349,8 +364,11 @@ delete Object.prototype.__proto__; runtimeOptions, internalName ?? name, ); - const { unstableFlag, pid, noColor, args } = runtimeOptions; + const { unstableFlag, pid, noColor, args, location: locationHref } = + runtimeOptions; + location.setLocationHref(locationHref); + fetch.setBaseUrl(locationHref); registerErrors(); const finalDenoNs = { diff --git a/runtime/js/README.md b/runtime/js/README.md index b17fa22e5..7e3fe4345 100644 --- a/runtime/js/README.md +++ b/runtime/js/README.md @@ -38,6 +38,8 @@ Some Web APIs are using ops under the hood, eg. `console`, `performance`. [Body](https://developer.mozilla.org/en-US/docs/Web/API/Body) and [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers): modern Promise-based HTTP Request API. +- [location](https://developer.mozilla.org/en-US/docs/Web/API/Window/location) + and [Location](https://developer.mozilla.org/en-US/docs/Web/API/Location). - [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData): access to a `multipart/form-data` serialization. - [Performance](https://developer.mozilla.org/en-US/docs/Web/API/Performance): diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 313c71177..3a1f5316c 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -130,6 +130,7 @@ pub struct WebWorker { terminate_rx: mpsc::Receiver<()>, handle: WebWorkerHandle, pub use_deno_namespace: bool, + pub main_module: ModuleSpecifier, } pub struct WebWorkerOptions { @@ -197,6 +198,7 @@ impl WebWorker { terminate_rx, handle, use_deno_namespace: options.use_deno_namespace, + main_module: main_module.clone(), }; { @@ -286,6 +288,7 @@ impl WebWorker { "tsVersion": options.ts_version, "unstableFlag": options.unstable, "v8Version": deno_core::v8_version(), + "location": self.main_module, }); let runtime_options_str = diff --git a/runtime/worker.rs b/runtime/worker.rs index 9326d632e..6ebb2fb36 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -63,6 +63,7 @@ pub struct WorkerOptions { /// Sets `Deno.noColor` in JS runtime. pub no_color: bool, pub get_error_class_fn: Option<GetErrorClassFn>, + pub location: Option<Url>, } impl MainWorker { @@ -179,6 +180,7 @@ impl MainWorker { "tsVersion": options.ts_version, "unstableFlag": options.unstable, "v8Version": deno_core::v8_version(), + "location": options.location, }); let script = format!( @@ -282,6 +284,7 @@ mod tests { ts_version: "x".to_string(), no_color: true, get_error_class_fn: None, + location: None, }; MainWorker::from_options(main_module, permissions, &options) |
