deno.land / x / deno@v1.28.2 / runtime / worker_bootstrap.rs

worker_bootstrap.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
use deno_core::serde_json;use deno_core::serde_json::json;use deno_core::ModuleSpecifier;use std::thread;
use crate::colors;use crate::ops::runtime::ppid;
/// Common bootstrap options for MainWorker & WebWorker#[derive(Clone)]pub struct BootstrapOptions { /// Sets `Deno.args` in JS runtime. pub args: Vec<String>, pub cpu_count: usize, pub debug_flag: bool, pub enable_testing_features: bool, pub locale: String, pub location: Option<ModuleSpecifier>, /// Sets `Deno.noColor` in JS runtime. pub no_color: bool, pub is_tty: 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, pub user_agent: String, pub inspect: bool,}
impl Default for BootstrapOptions { fn default() -> Self { let cpu_count = thread::available_parallelism() .map(|p| p.get()) .unwrap_or(1);
let runtime_version = env!("CARGO_PKG_VERSION").into(); let user_agent = format!("Deno/{}", runtime_version);
Self { runtime_version, user_agent, cpu_count, no_color: !colors::use_color(), is_tty: colors::is_tty(), enable_testing_features: Default::default(), debug_flag: Default::default(), ts_version: Default::default(), locale: "en".to_string(), location: Default::default(), unstable: Default::default(), inspect: Default::default(), args: Default::default(), } }}
impl BootstrapOptions { pub fn as_json(&self) -> String { let payload = json!({ // Shared bootstrap args "args": self.args, "cpuCount": self.cpu_count, "debugFlag": self.debug_flag, "denoVersion": self.runtime_version, "locale": self.locale, "location": self.location, "noColor": self.no_color, "isTty": self.is_tty, "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(), "userAgent": self.user_agent, "inspectFlag": self.inspect, }); serde_json::to_string_pretty(&payload).unwrap() }}
deno

Version Info

Tagged at
a year ago