2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2021-01-07 21:08:51 -05:00
|
|
|
|
2023-04-26 13:07:15 -04:00
|
|
|
use crate::args::get_root_cert_store;
|
2023-01-17 19:18:24 -05:00
|
|
|
use crate::args::CaData;
|
2023-04-26 13:07:15 -04:00
|
|
|
use crate::args::CacheSetting;
|
|
|
|
use crate::cache::DenoDir;
|
2020-11-30 14:35:12 -05:00
|
|
|
use crate::colors;
|
2021-09-13 00:19:23 -04:00
|
|
|
use crate::file_fetcher::get_source_from_data_url;
|
2023-04-26 13:07:15 -04:00
|
|
|
use crate::http_util::HttpClient;
|
|
|
|
use crate::npm::create_npm_fs_resolver;
|
|
|
|
use crate::npm::CliNpmRegistryApi;
|
|
|
|
use crate::npm::CliNpmResolver;
|
|
|
|
use crate::npm::NpmCache;
|
|
|
|
use crate::npm::NpmResolution;
|
2021-06-07 08:02:53 -04:00
|
|
|
use crate::ops;
|
2023-04-26 13:07:15 -04:00
|
|
|
use crate::util::progress_bar::ProgressBar;
|
|
|
|
use crate::util::progress_bar::ProgressBarStyle;
|
2023-01-24 23:03:03 -05:00
|
|
|
use crate::util::v8::construct_v8_flags;
|
2020-12-11 18:36:18 -05:00
|
|
|
use crate::version;
|
2023-02-15 11:30:54 -05:00
|
|
|
use crate::CliGraphResolver;
|
2021-11-16 09:02:28 -05:00
|
|
|
use deno_core::anyhow::Context;
|
2020-11-30 14:35:12 -05:00
|
|
|
use deno_core::error::type_error;
|
|
|
|
use deno_core::error::AnyError;
|
2023-03-19 18:32:54 -04:00
|
|
|
use deno_core::futures::task::LocalFutureObj;
|
2020-11-30 14:35:12 -05:00
|
|
|
use deno_core::futures::FutureExt;
|
2021-06-21 19:45:41 -04:00
|
|
|
use deno_core::located_script_name;
|
2021-01-04 18:15:52 -05:00
|
|
|
use deno_core::v8_set_flags;
|
2023-04-26 13:07:15 -04:00
|
|
|
use deno_core::CompiledWasmModuleStore;
|
2020-11-30 14:35:12 -05:00
|
|
|
use deno_core::ModuleLoader;
|
|
|
|
use deno_core::ModuleSpecifier;
|
2023-04-04 08:46:31 -04:00
|
|
|
use deno_core::ModuleType;
|
2023-01-10 08:35:44 -05:00
|
|
|
use deno_core::ResolutionKind;
|
2023-04-26 13:07:15 -04:00
|
|
|
use deno_core::SharedArrayBufferStore;
|
2022-02-24 08:28:00 -05:00
|
|
|
use deno_graph::source::Resolver;
|
2023-04-26 13:07:15 -04:00
|
|
|
use deno_runtime::deno_broadcast_channel::InMemoryBroadcastChannel;
|
|
|
|
use deno_runtime::deno_node;
|
|
|
|
use deno_runtime::deno_tls::rustls::RootCertStore;
|
|
|
|
use deno_runtime::deno_web::BlobStore;
|
2022-09-02 16:53:23 -04:00
|
|
|
use deno_runtime::fmt_errors::format_js_error;
|
2023-03-19 18:32:54 -04:00
|
|
|
use deno_runtime::ops::worker_host::CreateWebWorkerCb;
|
|
|
|
use deno_runtime::ops::worker_host::WorkerEventCb;
|
2020-12-13 13:45:53 -05:00
|
|
|
use deno_runtime::permissions::Permissions;
|
2023-01-07 11:25:34 -05:00
|
|
|
use deno_runtime::permissions::PermissionsContainer;
|
2023-03-19 18:32:54 -04:00
|
|
|
use deno_runtime::web_worker::WebWorker;
|
|
|
|
use deno_runtime::web_worker::WebWorkerOptions;
|
2020-12-13 13:45:53 -05:00
|
|
|
use deno_runtime::worker::MainWorker;
|
|
|
|
use deno_runtime::worker::WorkerOptions;
|
2021-10-05 16:41:14 -04:00
|
|
|
use deno_runtime::BootstrapOptions;
|
2022-02-24 08:28:00 -05:00
|
|
|
use import_map::parse_from_json;
|
2021-01-07 21:08:51 -05:00
|
|
|
use log::Level;
|
2020-11-30 14:35:12 -05:00
|
|
|
use std::pin::Pin;
|
|
|
|
use std::rc::Rc;
|
2020-12-11 12:49:26 -05:00
|
|
|
use std::sync::Arc;
|
2020-11-30 14:35:12 -05:00
|
|
|
|
2023-04-19 17:50:56 -04:00
|
|
|
mod binary;
|
2022-02-15 07:33:46 -05:00
|
|
|
|
2023-04-19 17:50:56 -04:00
|
|
|
pub use binary::extract_standalone;
|
|
|
|
pub use binary::is_standalone_binary;
|
|
|
|
pub use binary::DenoCompileBinaryWriter;
|
2022-02-15 07:33:46 -05:00
|
|
|
|
2023-04-19 17:50:56 -04:00
|
|
|
use self::binary::Metadata;
|
2021-01-04 18:15:52 -05:00
|
|
|
|
2023-03-19 18:32:54 -04:00
|
|
|
#[derive(Clone)]
|
2022-02-24 08:28:00 -05:00
|
|
|
struct EmbeddedModuleLoader {
|
2023-03-19 18:32:54 -04:00
|
|
|
eszip: Arc<eszip::EszipV2>,
|
|
|
|
maybe_import_map_resolver: Option<Arc<CliGraphResolver>>,
|
2022-02-24 08:28:00 -05:00
|
|
|
}
|
2020-11-30 14:35:12 -05:00
|
|
|
|
|
|
|
impl ModuleLoader for EmbeddedModuleLoader {
|
|
|
|
fn resolve(
|
|
|
|
&self,
|
|
|
|
specifier: &str,
|
2022-02-24 08:28:00 -05:00
|
|
|
referrer: &str,
|
2023-01-10 08:35:44 -05:00
|
|
|
_kind: ResolutionKind,
|
2020-11-30 14:35:12 -05:00
|
|
|
) -> Result<ModuleSpecifier, AnyError> {
|
2022-03-31 04:41:30 -04:00
|
|
|
// Try to follow redirects when resolving.
|
|
|
|
let referrer = match self.eszip.get_module(referrer) {
|
|
|
|
Some(eszip::Module { ref specifier, .. }) => {
|
2023-03-14 13:18:01 -04:00
|
|
|
ModuleSpecifier::parse(specifier)?
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
let cwd = std::env::current_dir().context("Unable to get CWD")?;
|
|
|
|
deno_core::resolve_url_or_path(referrer, &cwd)?
|
2022-03-31 04:41:30 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-03-15 17:46:36 -04:00
|
|
|
self
|
|
|
|
.maybe_import_map_resolver
|
|
|
|
.as_ref()
|
|
|
|
.map(|r| r.resolve(specifier, &referrer))
|
|
|
|
.unwrap_or_else(|| {
|
2022-02-24 08:28:00 -05:00
|
|
|
deno_core::resolve_import(specifier, referrer.as_str())
|
|
|
|
.map_err(|err| err.into())
|
2023-03-15 17:46:36 -04:00
|
|
|
})
|
2020-11-30 14:35:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn load(
|
|
|
|
&self,
|
|
|
|
module_specifier: &ModuleSpecifier,
|
2023-04-04 08:46:31 -04:00
|
|
|
_maybe_referrer: Option<&ModuleSpecifier>,
|
2020-11-30 14:35:12 -05:00
|
|
|
_is_dynamic: bool,
|
|
|
|
) -> Pin<Box<deno_core::ModuleSourceFuture>> {
|
2023-01-05 14:29:50 -05:00
|
|
|
let is_data_uri = get_source_from_data_url(module_specifier).ok();
|
2022-02-15 07:33:46 -05:00
|
|
|
let module = self
|
2022-02-24 08:28:00 -05:00
|
|
|
.eszip
|
2022-02-15 07:33:46 -05:00
|
|
|
.get_module(module_specifier.as_str())
|
|
|
|
.ok_or_else(|| type_error("Module not found"));
|
2023-04-04 08:46:31 -04:00
|
|
|
// TODO(mmastrac): This clone can probably be removed in the future if ModuleSpecifier is no longer a full-fledged URL
|
2023-01-05 14:29:50 -05:00
|
|
|
let module_specifier = module_specifier.clone();
|
2023-04-04 08:46:31 -04:00
|
|
|
|
2020-11-30 14:35:12 -05:00
|
|
|
async move {
|
2022-05-05 07:16:25 -04:00
|
|
|
if let Some((source, _)) = is_data_uri {
|
2023-04-04 08:46:31 -04:00
|
|
|
return Ok(deno_core::ModuleSource::new(
|
|
|
|
deno_core::ModuleType::JavaScript,
|
|
|
|
source.into(),
|
|
|
|
&module_specifier,
|
|
|
|
));
|
2020-11-30 14:35:12 -05:00
|
|
|
}
|
2021-06-05 10:24:17 -04:00
|
|
|
|
2022-02-15 07:33:46 -05:00
|
|
|
let module = module?;
|
2023-04-06 18:46:44 -04:00
|
|
|
let code = module.source().await.unwrap_or_default();
|
2022-02-15 07:33:46 -05:00
|
|
|
let code = std::str::from_utf8(&code)
|
|
|
|
.map_err(|_| type_error("Module source is not utf-8"))?
|
2023-04-04 08:46:31 -04:00
|
|
|
.to_owned()
|
|
|
|
.into();
|
2022-02-15 07:33:46 -05:00
|
|
|
|
2023-04-04 08:46:31 -04:00
|
|
|
Ok(deno_core::ModuleSource::new(
|
|
|
|
match module.kind {
|
|
|
|
eszip::ModuleKind::JavaScript => ModuleType::JavaScript,
|
|
|
|
eszip::ModuleKind::Json => ModuleType::Json,
|
2022-02-15 07:33:46 -05:00
|
|
|
},
|
2023-04-04 08:46:31 -04:00
|
|
|
code,
|
|
|
|
&module_specifier,
|
|
|
|
))
|
2020-11-30 14:35:12 -05:00
|
|
|
}
|
|
|
|
.boxed_local()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-19 18:32:54 -04:00
|
|
|
fn web_worker_callback() -> Arc<WorkerEventCb> {
|
|
|
|
Arc::new(|worker| {
|
|
|
|
let fut = async move { Ok(worker) };
|
|
|
|
LocalFutureObj::new(Box::new(fut))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-04-26 13:07:15 -04:00
|
|
|
struct SharedWorkerState {
|
|
|
|
npm_resolver: Arc<CliNpmResolver>,
|
|
|
|
root_cert_store: RootCertStore,
|
|
|
|
node_fs: Arc<dyn deno_node::NodeFs>,
|
|
|
|
blob_store: BlobStore,
|
|
|
|
broadcast_channel: InMemoryBroadcastChannel,
|
|
|
|
shared_array_buffer_store: SharedArrayBufferStore,
|
|
|
|
compiled_wasm_module_store: CompiledWasmModuleStore,
|
|
|
|
// options
|
|
|
|
argv: Vec<String>,
|
|
|
|
seed: Option<u64>,
|
|
|
|
unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
|
|
|
unstable: bool,
|
|
|
|
}
|
|
|
|
|
2023-03-19 18:32:54 -04:00
|
|
|
fn create_web_worker_callback(
|
2023-04-26 13:07:15 -04:00
|
|
|
shared: &Arc<SharedWorkerState>,
|
|
|
|
module_loader: &EmbeddedModuleLoader,
|
2023-03-19 18:32:54 -04:00
|
|
|
) -> Arc<CreateWebWorkerCb> {
|
2023-04-26 13:07:15 -04:00
|
|
|
let shared = shared.clone();
|
|
|
|
let module_loader = module_loader.clone();
|
2023-03-19 18:32:54 -04:00
|
|
|
Arc::new(move |args| {
|
|
|
|
let module_loader = Rc::new(module_loader.clone());
|
|
|
|
|
2023-04-26 13:07:15 -04:00
|
|
|
let create_web_worker_cb =
|
|
|
|
create_web_worker_callback(&shared, &module_loader);
|
2023-03-19 18:32:54 -04:00
|
|
|
let web_worker_cb = web_worker_callback();
|
|
|
|
|
|
|
|
let options = WebWorkerOptions {
|
|
|
|
bootstrap: BootstrapOptions {
|
2023-04-26 13:07:15 -04:00
|
|
|
args: shared.argv.clone(),
|
2023-03-19 18:32:54 -04:00
|
|
|
cpu_count: std::thread::available_parallelism()
|
|
|
|
.map(|p| p.get())
|
|
|
|
.unwrap_or(1),
|
2023-04-26 13:07:15 -04:00
|
|
|
debug_flag: false,
|
2023-03-19 18:32:54 -04:00
|
|
|
enable_testing_features: false,
|
|
|
|
locale: deno_core::v8::icu::get_language_tag(),
|
|
|
|
location: Some(args.main_module.clone()),
|
|
|
|
no_color: !colors::use_color(),
|
|
|
|
is_tty: colors::is_tty(),
|
2023-03-23 18:27:58 -04:00
|
|
|
runtime_version: version::deno().to_string(),
|
2023-03-19 18:32:54 -04:00
|
|
|
ts_version: version::TYPESCRIPT.to_string(),
|
2023-04-26 13:07:15 -04:00
|
|
|
unstable: shared.unstable,
|
2023-03-23 18:27:58 -04:00
|
|
|
user_agent: version::get_user_agent().to_string(),
|
2023-04-26 13:07:15 -04:00
|
|
|
inspect: false,
|
2023-03-19 18:32:54 -04:00
|
|
|
},
|
2023-04-26 13:07:15 -04:00
|
|
|
extensions: ops::cli_exts(shared.npm_resolver.clone()),
|
2023-03-19 18:32:54 -04:00
|
|
|
startup_snapshot: Some(crate::js::deno_isolate_init()),
|
2023-04-26 13:07:15 -04:00
|
|
|
unsafely_ignore_certificate_errors: shared
|
|
|
|
.unsafely_ignore_certificate_errors
|
2023-03-19 18:32:54 -04:00
|
|
|
.clone(),
|
2023-04-26 13:07:15 -04:00
|
|
|
root_cert_store: Some(shared.root_cert_store.clone()),
|
|
|
|
seed: shared.seed,
|
2023-03-19 18:32:54 -04:00
|
|
|
module_loader,
|
2023-04-26 13:07:15 -04:00
|
|
|
node_fs: Some(shared.node_fs.clone()),
|
2023-03-19 18:32:54 -04:00
|
|
|
npm_resolver: None, // not currently supported
|
|
|
|
create_web_worker_cb,
|
|
|
|
preload_module_cb: web_worker_cb.clone(),
|
|
|
|
pre_execute_module_cb: web_worker_cb,
|
|
|
|
format_js_error_fn: Some(Arc::new(format_js_error)),
|
|
|
|
source_map_getter: None,
|
|
|
|
worker_type: args.worker_type,
|
|
|
|
maybe_inspector_server: None,
|
|
|
|
get_error_class_fn: Some(&get_error_class_name),
|
2023-04-26 13:07:15 -04:00
|
|
|
blob_store: shared.blob_store.clone(),
|
|
|
|
broadcast_channel: shared.broadcast_channel.clone(),
|
|
|
|
shared_array_buffer_store: Some(shared.shared_array_buffer_store.clone()),
|
|
|
|
compiled_wasm_module_store: Some(
|
|
|
|
shared.compiled_wasm_module_store.clone(),
|
|
|
|
),
|
2023-03-19 18:32:54 -04:00
|
|
|
cache_storage_dir: None,
|
|
|
|
stdio: Default::default(),
|
|
|
|
};
|
|
|
|
|
|
|
|
WebWorker::bootstrap_from_options(
|
|
|
|
args.name,
|
|
|
|
args.permissions,
|
|
|
|
args.main_module,
|
|
|
|
args.worker_id,
|
|
|
|
options,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-07 21:08:51 -05:00
|
|
|
pub async fn run(
|
2022-02-15 07:33:46 -05:00
|
|
|
eszip: eszip::EszipV2,
|
2021-01-07 21:08:51 -05:00
|
|
|
metadata: Metadata,
|
|
|
|
) -> Result<(), AnyError> {
|
2022-02-15 07:33:46 -05:00
|
|
|
let main_module = &metadata.entrypoint;
|
2023-04-26 13:07:15 -04:00
|
|
|
let dir = DenoDir::new(None)?;
|
|
|
|
let root_cert_store = get_root_cert_store(
|
|
|
|
None,
|
|
|
|
metadata.ca_stores,
|
|
|
|
metadata.ca_data.map(CaData::Bytes),
|
|
|
|
)?;
|
|
|
|
let progress_bar = ProgressBar::new(ProgressBarStyle::TextOnly);
|
|
|
|
let http_client = HttpClient::new(
|
|
|
|
Some(root_cert_store.clone()),
|
|
|
|
metadata.unsafely_ignore_certificate_errors.clone(),
|
|
|
|
)?;
|
|
|
|
let npm_registry_url = CliNpmRegistryApi::default_url().to_owned();
|
|
|
|
let npm_cache = Arc::new(NpmCache::new(
|
|
|
|
dir.npm_folder_path(),
|
|
|
|
CacheSetting::Use,
|
|
|
|
http_client.clone(),
|
|
|
|
progress_bar.clone(),
|
|
|
|
));
|
|
|
|
let npm_api = Arc::new(CliNpmRegistryApi::new(
|
|
|
|
npm_registry_url.clone(),
|
|
|
|
npm_cache.clone(),
|
|
|
|
http_client.clone(),
|
|
|
|
progress_bar.clone(),
|
|
|
|
));
|
|
|
|
let node_fs = Arc::new(deno_node::RealFs);
|
|
|
|
let npm_resolution =
|
|
|
|
Arc::new(NpmResolution::from_serialized(npm_api.clone(), None, None));
|
|
|
|
let npm_fs_resolver = create_npm_fs_resolver(
|
|
|
|
node_fs.clone(),
|
|
|
|
npm_cache,
|
|
|
|
&progress_bar,
|
|
|
|
npm_registry_url,
|
|
|
|
npm_resolution.clone(),
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
let npm_resolver = Arc::new(CliNpmResolver::new(
|
|
|
|
npm_resolution.clone(),
|
|
|
|
npm_fs_resolver,
|
|
|
|
None,
|
|
|
|
));
|
|
|
|
|
|
|
|
let shared = Arc::new(SharedWorkerState {
|
|
|
|
npm_resolver,
|
|
|
|
root_cert_store,
|
|
|
|
node_fs,
|
|
|
|
blob_store: BlobStore::default(),
|
|
|
|
broadcast_channel: InMemoryBroadcastChannel::default(),
|
|
|
|
shared_array_buffer_store: SharedArrayBufferStore::default(),
|
|
|
|
compiled_wasm_module_store: CompiledWasmModuleStore::default(),
|
|
|
|
argv: metadata.argv,
|
|
|
|
seed: metadata.seed,
|
|
|
|
unsafely_ignore_certificate_errors: metadata
|
|
|
|
.unsafely_ignore_certificate_errors,
|
|
|
|
unstable: metadata.unstable,
|
|
|
|
});
|
|
|
|
|
2023-01-07 11:25:34 -05:00
|
|
|
let permissions = PermissionsContainer::new(Permissions::from_options(
|
|
|
|
&metadata.permissions,
|
|
|
|
)?);
|
2023-04-26 13:07:15 -04:00
|
|
|
let module_loader = EmbeddedModuleLoader {
|
2023-03-19 18:32:54 -04:00
|
|
|
eszip: Arc::new(eszip),
|
2022-02-24 08:28:00 -05:00
|
|
|
maybe_import_map_resolver: metadata.maybe_import_map.map(
|
|
|
|
|(base, source)| {
|
2023-03-19 18:32:54 -04:00
|
|
|
Arc::new(CliGraphResolver::new(
|
2023-02-15 11:30:54 -05:00
|
|
|
None,
|
|
|
|
Some(Arc::new(
|
|
|
|
parse_from_json(&base, &source).unwrap().import_map,
|
|
|
|
)),
|
2023-02-22 14:15:25 -05:00
|
|
|
false,
|
2023-04-26 13:07:15 -04:00
|
|
|
npm_api.clone(),
|
|
|
|
npm_resolution.clone(),
|
|
|
|
Default::default(),
|
2023-03-19 18:32:54 -04:00
|
|
|
))
|
2022-02-24 08:28:00 -05:00
|
|
|
},
|
|
|
|
),
|
2023-04-26 13:07:15 -04:00
|
|
|
};
|
|
|
|
let create_web_worker_cb =
|
|
|
|
create_web_worker_callback(&shared, &module_loader);
|
2023-03-19 18:32:54 -04:00
|
|
|
let web_worker_cb = web_worker_callback();
|
2020-12-11 12:49:26 -05:00
|
|
|
|
2023-01-24 23:03:03 -05:00
|
|
|
v8_set_flags(construct_v8_flags(&metadata.v8_flags, vec![]));
|
2021-01-07 21:08:51 -05:00
|
|
|
|
2020-12-11 12:49:26 -05:00
|
|
|
let options = WorkerOptions {
|
2021-10-05 16:41:14 -04:00
|
|
|
bootstrap: BootstrapOptions {
|
2023-04-26 13:07:15 -04:00
|
|
|
args: shared.argv.clone(),
|
2022-02-24 20:03:12 -05:00
|
|
|
cpu_count: std::thread::available_parallelism()
|
|
|
|
.map(|p| p.get())
|
|
|
|
.unwrap_or(1),
|
2023-03-15 17:46:36 -04:00
|
|
|
debug_flag: metadata
|
|
|
|
.log_level
|
|
|
|
.map(|l| l == Level::Debug)
|
|
|
|
.unwrap_or(false),
|
2021-10-05 16:41:14 -04:00
|
|
|
enable_testing_features: false,
|
2022-10-18 09:33:35 -04:00
|
|
|
locale: deno_core::v8::icu::get_language_tag(),
|
2021-10-05 16:41:14 -04:00
|
|
|
location: metadata.location,
|
|
|
|
no_color: !colors::use_color(),
|
2022-02-28 22:37:50 -05:00
|
|
|
is_tty: colors::is_tty(),
|
2023-03-23 18:27:58 -04:00
|
|
|
runtime_version: version::deno().to_string(),
|
2021-10-05 16:41:14 -04:00
|
|
|
ts_version: version::TYPESCRIPT.to_string(),
|
|
|
|
unstable: metadata.unstable,
|
2023-03-23 18:27:58 -04:00
|
|
|
user_agent: version::get_user_agent().to_string(),
|
2023-04-26 13:07:15 -04:00
|
|
|
inspect: false,
|
2021-10-05 16:41:14 -04:00
|
|
|
},
|
2023-04-26 13:07:15 -04:00
|
|
|
extensions: ops::cli_exts(shared.npm_resolver.clone()),
|
2022-11-21 08:36:26 -05:00
|
|
|
startup_snapshot: Some(crate::js::deno_isolate_init()),
|
2023-04-26 13:07:15 -04:00
|
|
|
unsafely_ignore_certificate_errors: shared
|
|
|
|
.unsafely_ignore_certificate_errors
|
|
|
|
.clone(),
|
|
|
|
root_cert_store: Some(shared.root_cert_store.clone()),
|
2021-01-07 21:08:51 -05:00
|
|
|
seed: metadata.seed,
|
2022-04-15 10:08:09 -04:00
|
|
|
source_map_getter: None,
|
2022-04-26 19:06:10 -04:00
|
|
|
format_js_error_fn: Some(Arc::new(format_js_error)),
|
2020-12-11 12:49:26 -05:00
|
|
|
create_web_worker_cb,
|
2022-08-16 21:00:35 -04:00
|
|
|
web_worker_preload_module_cb: web_worker_cb.clone(),
|
|
|
|
web_worker_pre_execute_module_cb: web_worker_cb,
|
2020-12-11 12:49:26 -05:00
|
|
|
maybe_inspector_server: None,
|
|
|
|
should_break_on_first_statement: false,
|
2022-12-12 09:33:30 -05:00
|
|
|
should_wait_for_inspector_session: false,
|
2023-04-26 13:07:15 -04:00
|
|
|
module_loader: Rc::new(module_loader),
|
|
|
|
node_fs: Some(shared.node_fs.clone()),
|
2022-08-20 11:31:33 -04:00
|
|
|
npm_resolver: None, // not currently supported
|
2021-01-07 21:08:51 -05:00
|
|
|
get_error_class_fn: Some(&get_error_class_name),
|
2022-09-28 08:11:12 -04:00
|
|
|
cache_storage_dir: None,
|
2021-05-27 01:23:12 -04:00
|
|
|
origin_storage_dir: None,
|
2023-04-26 13:07:15 -04:00
|
|
|
blob_store: shared.blob_store.clone(),
|
|
|
|
broadcast_channel: shared.broadcast_channel.clone(),
|
|
|
|
shared_array_buffer_store: Some(shared.shared_array_buffer_store.clone()),
|
|
|
|
compiled_wasm_module_store: Some(shared.compiled_wasm_module_store.clone()),
|
2022-04-26 19:00:04 -04:00
|
|
|
stdio: Default::default(),
|
2020-12-11 12:49:26 -05:00
|
|
|
};
|
2021-10-05 16:41:14 -04:00
|
|
|
let mut worker = MainWorker::bootstrap_from_options(
|
|
|
|
main_module.clone(),
|
|
|
|
permissions,
|
|
|
|
options,
|
|
|
|
);
|
2022-02-15 07:33:46 -05:00
|
|
|
worker.execute_main_module(main_module).await?;
|
2023-03-21 18:33:12 -04:00
|
|
|
worker.dispatch_load_event(located_script_name!())?;
|
2022-06-28 10:49:30 -04:00
|
|
|
|
|
|
|
loop {
|
|
|
|
worker.run_event_loop(false).await?;
|
2023-03-21 18:33:12 -04:00
|
|
|
if !worker.dispatch_beforeunload_event(located_script_name!())? {
|
2022-06-28 10:49:30 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-21 18:33:12 -04:00
|
|
|
worker.dispatch_unload_event(located_script_name!())?;
|
2021-01-07 21:08:51 -05:00
|
|
|
std::process::exit(0);
|
2020-11-30 14:35:12 -05:00
|
|
|
}
|
2021-01-04 18:15:52 -05:00
|
|
|
|
2021-01-07 21:08:51 -05:00
|
|
|
fn get_error_class_name(e: &AnyError) -> &'static str {
|
|
|
|
deno_runtime::errors::get_error_class_name(e).unwrap_or_else(|| {
|
2021-01-08 19:57:37 -05:00
|
|
|
panic!(
|
|
|
|
"Error '{}' contains boxed error of unsupported type:{}",
|
|
|
|
e,
|
2023-01-27 10:43:16 -05:00
|
|
|
e.chain().map(|e| format!("\n {e:?}")).collect::<String>()
|
2021-01-08 19:57:37 -05:00
|
|
|
);
|
2021-01-04 18:15:52 -05:00
|
|
|
})
|
|
|
|
}
|