mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
Resolve worker specifiers relative to main module of host. (#2751)
This commit is contained in:
parent
520bdb6c31
commit
56a82e72d9
7 changed files with 21 additions and 11 deletions
16
cli/ops.rs
16
cli/ops.rs
|
@ -2095,9 +2095,21 @@ fn op_create_worker(
|
||||||
|
|
||||||
let parent_state = state.clone();
|
let parent_state = state.clone();
|
||||||
|
|
||||||
|
let mut module_specifier = ModuleSpecifier::resolve_url_or_path(specifier)?;
|
||||||
|
|
||||||
|
let mut child_argv = parent_state.argv.clone();
|
||||||
|
|
||||||
|
if !has_source_code {
|
||||||
|
if let Some(module) = state.main_module() {
|
||||||
|
module_specifier =
|
||||||
|
ModuleSpecifier::resolve_import(specifier, &module.to_string())?;
|
||||||
|
child_argv[1] = module_specifier.to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let child_state = ThreadSafeState::new(
|
let child_state = ThreadSafeState::new(
|
||||||
parent_state.flags.clone(),
|
parent_state.flags.clone(),
|
||||||
parent_state.argv.clone(),
|
child_argv,
|
||||||
op_selector_std,
|
op_selector_std,
|
||||||
parent_state.progress.clone(),
|
parent_state.progress.clone(),
|
||||||
include_deno_namespace,
|
include_deno_namespace,
|
||||||
|
@ -2134,8 +2146,6 @@ fn op_create_worker(
|
||||||
return ok_buf(exec_cb(worker));
|
return ok_buf(exec_cb(worker));
|
||||||
}
|
}
|
||||||
|
|
||||||
let module_specifier = ModuleSpecifier::resolve_url_or_path(specifier)?;
|
|
||||||
|
|
||||||
let op = worker
|
let op = worker
|
||||||
.execute_mod_async(&module_specifier, false)
|
.execute_mod_async(&module_specifier, false)
|
||||||
.and_then(move |()| Ok(exec_cb(worker)));
|
.and_then(move |()| Ok(exec_cb(worker)));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const jsWorker = new Worker("./tests/subdir/test_worker.js");
|
const jsWorker = new Worker("./subdir/test_worker.js");
|
||||||
const tsWorker = new Worker("./tests/subdir/test_worker.ts");
|
const tsWorker = new Worker("./subdir/test_worker.ts");
|
||||||
|
|
||||||
tsWorker.onmessage = (e): void => {
|
tsWorker.onmessage = (e): void => {
|
||||||
console.log("Received ts: " + e.data);
|
console.log("Received ts: " + e.data);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const w1 = new Worker("./tests/039_worker_deno_ns/has_ns.ts");
|
const w1 = new Worker("./039_worker_deno_ns/has_ns.ts");
|
||||||
const w2 = new Worker("./tests/039_worker_deno_ns/no_ns.ts", {
|
const w2 = new Worker("./039_worker_deno_ns/no_ns.ts", {
|
||||||
noDenoNamespace: true
|
noDenoNamespace: true
|
||||||
});
|
});
|
||||||
let w1MsgCount = 0;
|
let w1MsgCount = 0;
|
||||||
|
|
|
@ -2,7 +2,7 @@ onmessage = (msg): void => {
|
||||||
if (msg.data === "START") {
|
if (msg.data === "START") {
|
||||||
postMessage("has_ns.ts: is window.Deno available: " + !!window.Deno);
|
postMessage("has_ns.ts: is window.Deno available: " + !!window.Deno);
|
||||||
} else {
|
} else {
|
||||||
const worker = new Worker("./tests/039_worker_deno_ns/maybe_ns.ts");
|
const worker = new Worker("./maybe_ns.ts");
|
||||||
worker.onmessage = (msg): void => {
|
worker.onmessage = (msg): void => {
|
||||||
postMessage("[SPAWNED BY has_ns.ts] " + msg.data);
|
postMessage("[SPAWNED BY has_ns.ts] " + msg.data);
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@ onmessage = (msg): void => {
|
||||||
if (msg.data === "START") {
|
if (msg.data === "START") {
|
||||||
postMessage("no_ns.ts: is window.Deno available: " + !!window.Deno);
|
postMessage("no_ns.ts: is window.Deno available: " + !!window.Deno);
|
||||||
} else {
|
} else {
|
||||||
const worker = new Worker("./tests/039_worker_deno_ns/maybe_ns.ts");
|
const worker = new Worker("./maybe_ns.ts");
|
||||||
worker.onmessage = (msg): void => {
|
worker.onmessage = (msg): void => {
|
||||||
postMessage("[SPAWNED BY no_ns.ts] " + msg.data);
|
postMessage("[SPAWNED BY no_ns.ts] " + msg.data);
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,7 +39,7 @@ function handleAsyncMsgFromWorker(
|
||||||
async function main(): Promise<void> {
|
async function main(): Promise<void> {
|
||||||
const workers: Array<[Map<number, Resolvable<string>>, Worker]> = [];
|
const workers: Array<[Map<number, Resolvable<string>>, Worker]> = [];
|
||||||
for (var i = 1; i <= workerCount; ++i) {
|
for (var i = 1; i <= workerCount; ++i) {
|
||||||
const worker = new Worker("tests/subdir/bench_worker.ts");
|
const worker = new Worker("./subdir/bench_worker.ts");
|
||||||
const promise = new Promise(
|
const promise = new Promise(
|
||||||
(resolve): void => {
|
(resolve): void => {
|
||||||
worker.onmessage = (e): void => {
|
worker.onmessage = (e): void => {
|
||||||
|
|
|
@ -4,7 +4,7 @@ const workerCount = 50;
|
||||||
async function bench(): Promise<void> {
|
async function bench(): Promise<void> {
|
||||||
const workers: Worker[] = [];
|
const workers: Worker[] = [];
|
||||||
for (var i = 1; i <= workerCount; ++i) {
|
for (var i = 1; i <= workerCount; ++i) {
|
||||||
const worker = new Worker("tests/subdir/bench_worker.ts");
|
const worker = new Worker("./subdir/bench_worker.ts");
|
||||||
const promise = new Promise(
|
const promise = new Promise(
|
||||||
(resolve): void => {
|
(resolve): void => {
|
||||||
worker.onmessage = (e): void => {
|
worker.onmessage = (e): void => {
|
||||||
|
|
Loading…
Reference in a new issue