diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-01-29 18:54:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-29 18:54:23 +0100 |
commit | 161adfc51b750a7c8c62a898ea9948c2ad5b6cd9 (patch) | |
tree | 6d53db2a4acd30207372f665a3ba463e26db6fcf /cli/state.rs | |
parent | d14864c57cebbd1d5bc18b8a9e05e522eb9987b0 (diff) |
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
Diffstat (limited to 'cli/state.rs')
-rw-r--r-- | cli/state.rs | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/cli/state.rs b/cli/state.rs index b224451c5..c4835d6f5 100644 --- a/cli/state.rs +++ b/cli/state.rs @@ -1,4 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +use crate::compilers::TargetLib; use crate::deno_error::permission_denied; use crate::global_state::ThreadSafeGlobalState; use crate::global_timer::GlobalTimer; @@ -59,6 +60,7 @@ pub struct State { pub start_time: Instant, pub seeded_rng: Option<Mutex<StdRng>>, pub resource_table: Mutex<ResourceTable>, + pub target_lib: TargetLib, } impl Clone for ThreadSafeState { @@ -200,7 +202,7 @@ impl Loader for ThreadSafeState { let module_url_specified = module_specifier.to_string(); let fut = self .global_state - .fetch_compiled_module(module_specifier, maybe_referrer) + .fetch_compiled_module(module_specifier, maybe_referrer, self.target_lib) .map_ok(|compiled_module| deno_core::SourceCodeInfo { // Real module name, might be different from initial specifier // due to redirections. @@ -228,9 +230,9 @@ impl ThreadSafeState { (internal_channels, external_channels) } + /// If `shared_permission` is None then permissions from globa state are used. pub fn new( global_state: ThreadSafeGlobalState, - // If Some(perm), use perm. Else copy from global_state. shared_permissions: Option<Arc<Mutex<DenoPermissions>>>, main_module: Option<ModuleSpecifier>, internal_channels: WorkerChannels, @@ -267,6 +269,46 @@ impl ThreadSafeState { seeded_rng, resource_table: Mutex::new(ResourceTable::default()), + target_lib: TargetLib::Main, + }; + + Ok(ThreadSafeState(Arc::new(state))) + } + + /// If `shared_permission` is None then permissions from globa state are used. + pub fn new_for_worker( + global_state: ThreadSafeGlobalState, + shared_permissions: Option<Arc<Mutex<DenoPermissions>>>, + main_module: Option<ModuleSpecifier>, + internal_channels: WorkerChannels, + ) -> Result<Self, ErrBox> { + let seeded_rng = match global_state.flags.seed { + Some(seed) => Some(Mutex::new(StdRng::seed_from_u64(seed))), + None => None, + }; + + let permissions = if let Some(perm) = shared_permissions { + perm + } else { + Arc::new(Mutex::new(global_state.permissions.clone())) + }; + + let state = State { + global_state, + main_module, + permissions, + import_map: None, + worker_channels: internal_channels, + metrics: Metrics::default(), + global_timer: Mutex::new(GlobalTimer::new()), + workers: Mutex::new(HashMap::new()), + loading_workers: Mutex::new(HashMap::new()), + next_worker_id: AtomicUsize::new(0), + start_time: Instant::now(), + seeded_rng, + + resource_table: Mutex::new(ResourceTable::default()), + target_lib: TargetLib::Worker, }; Ok(ThreadSafeState(Arc::new(state))) |