diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-10-05 22:41:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-05 22:41:14 +0200 |
commit | 678a881f63ee8e3b86d4dc539234a78c94cc9c1e (patch) | |
tree | 312c72895dca58d360e5d932e72f47f0fcb54be9 /runtime/worker_bootstrap.rs | |
parent | 77a00ce1fb4ae2523e22b9b84ae09a0200502e38 (diff) |
refactor(runtime): Worker bootstrap options (#12299)
Diffstat (limited to 'runtime/worker_bootstrap.rs')
-rw-r--r-- | runtime/worker_bootstrap.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/runtime/worker_bootstrap.rs b/runtime/worker_bootstrap.rs new file mode 100644 index 000000000..9bd519d73 --- /dev/null +++ b/runtime/worker_bootstrap.rs @@ -0,0 +1,48 @@ +use crate::ops::runtime::ppid; +use deno_core::serde_json; +use deno_core::serde_json::json; +use deno_core::ModuleSpecifier; + +/// Common bootstrap options for MainWorker & WebWorker +#[derive(Clone)] +pub struct BootstrapOptions { + /// Sets `Deno.args` in JS runtime. + pub args: Vec<String>, + pub apply_source_maps: bool, + pub cpu_count: usize, + pub debug_flag: bool, + pub enable_testing_features: bool, + pub location: Option<ModuleSpecifier>, + /// Sets `Deno.noColor` in JS runtime. + pub no_color: bool, + /// Sets `Deno.version.deno` in JS runtime. + pub runtime_version: String, + /// Sets `Deno.version.typescript` in JS runtime. + pub ts_version: String, + pub unstable: bool, +} + +impl BootstrapOptions { + pub fn as_json(&self) -> String { + let payload = json!({ + // Shared bootstrap args + "args": self.args, + "applySourceMaps": self.apply_source_maps, + "cpuCount": self.cpu_count, + "debugFlag": self.debug_flag, + "denoVersion": self.runtime_version, + "location": self.location, + "noColor": self.no_color, + "tsVersion": self.ts_version, + "unstableFlag": self.unstable, + // Web worker only + "enableTestingFeaturesFlag": self.enable_testing_features, + // Env values + "pid": std::process::id(), + "ppid": ppid(), + "target": env!("TARGET"), + "v8Version": deno_core::v8_version(), + }); + serde_json::to_string_pretty(&payload).unwrap() + } +} |