From 161adfc51b750a7c8c62a898ea9948c2ad5b6cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 29 Jan 2020 18:54:23 +0100 Subject: workers: proper TS libs, more spec-compliant APIs (#3812) * split lib.deno_main.d.ts into: - lib.deno.shared_globals.d.ts - lib.deno.window.d.ts - lib.deno.worker.d.ts * remove no longer used libs: - lib.deno_main.d.ts - lib.deno_worker.d.ts * change module loading to use proper TS library for compilation * align to Worker API spec: - Worker.terminate() - self.close() - self.name --- cli/ops/worker_host.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'cli/ops') diff --git a/cli/ops/worker_host.rs b/cli/ops/worker_host.rs index 976c32219..a1509d2f7 100644 --- a/cli/ops/worker_host.rs +++ b/cli/ops/worker_host.rs @@ -4,7 +4,6 @@ use crate::deno_error::bad_resource; use crate::deno_error::js_check; use crate::deno_error::DenoError; use crate::deno_error::ErrorKind; -use crate::deno_error::GetErrorKind; use crate::fmt_errors::JSError; use crate::ops::json_op; use crate::startup_data; @@ -60,6 +59,7 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] struct CreateWorkerArgs { + name: Option, specifier: String, has_source_code: bool, source_code: String, @@ -89,23 +89,28 @@ fn op_create_worker( } let (int, ext) = ThreadSafeState::create_channels(); - let child_state = ThreadSafeState::new( + let child_state = ThreadSafeState::new_for_worker( state.global_state.clone(), Some(parent_state.permissions.clone()), // by default share with parent Some(module_specifier.clone()), int, )?; + let worker_name = if let Some(name) = args.name { + name + } else { + // TODO(bartlomieju): change it to something more descriptive + format!("USER-WORKER-{}", specifier) + }; + // TODO: add a new option to make child worker not sharing permissions // with parent (aka .clone(), requests from child won't reflect in parent) - // TODO(bartlomieju): get it from "name" argument when creating worker - let name = format!("USER-WORKER-{}", specifier); let mut worker = WebWorker::new( - name.to_string(), + worker_name.to_string(), startup_data::deno_isolate_init(), child_state, ext, ); - let script = format!("bootstrapWorkerRuntime(\"{}\")", name); + let script = format!("bootstrapWorkerRuntime(\"{}\")", worker_name); js_check(worker.execute(&script)); js_check(worker.execute("runWorkerMessageLoop()")); @@ -158,6 +163,8 @@ impl Future for WorkerPollFuture { } fn serialize_worker_result(result: Result<(), ErrBox>) -> Value { + use crate::deno_error::GetErrorKind; + if let Err(error) = result { match error.kind() { ErrorKind::JSError => { -- cgit v1.2.3