summaryrefslogtreecommitdiff
path: root/runtime/worker_bootstrap.rs
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/worker_bootstrap.rs')
-rw-r--r--runtime/worker_bootstrap.rs156
1 files changed, 131 insertions, 25 deletions
diff --git a/runtime/worker_bootstrap.rs b/runtime/worker_bootstrap.rs
index 12abceca6..09725122c 100644
--- a/runtime/worker_bootstrap.rs
+++ b/runtime/worker_bootstrap.rs
@@ -1,7 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
-use deno_core::serde_json;
-use deno_core::serde_json::json;
+use deno_core::v8;
use deno_core::ModuleSpecifier;
use std::thread;
@@ -58,28 +57,135 @@ impl Default for BootstrapOptions {
}
impl BootstrapOptions {
- pub fn as_json(&self) -> serde_json::Value {
- 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,
- })
+ pub fn as_v8<'s>(
+ &self,
+ scope: &mut v8::HandleScope<'s>,
+ ) -> v8::Local<'s, v8::Array> {
+ let array = v8::Array::new(scope, 17);
+
+ {
+ let args = v8::Array::new(scope, self.args.len() as i32);
+ for (idx, arg) in self.args.iter().enumerate() {
+ let arg_str = v8::String::new(scope, arg).unwrap();
+ args.set_index(scope, idx as u32, arg_str.into());
+ }
+ array.set_index(scope, 0, args.into());
+ }
+
+ {
+ let val = v8::Integer::new(scope, self.cpu_count as i32);
+ array.set_index(scope, 1, val.into());
+ }
+
+ {
+ let val = v8::Boolean::new(scope, self.debug_flag);
+ array.set_index(scope, 2, val.into());
+ }
+
+ {
+ let val = v8::String::new_from_one_byte(
+ scope,
+ self.runtime_version.as_bytes(),
+ v8::NewStringType::Internalized,
+ )
+ .unwrap();
+ array.set_index(scope, 3, val.into());
+ }
+
+ {
+ let val = v8::String::new_from_one_byte(
+ scope,
+ self.locale.as_bytes(),
+ v8::NewStringType::Normal,
+ )
+ .unwrap();
+ array.set_index(scope, 4, val.into());
+ }
+
+ {
+ let val: v8::Local<v8::Value> = if let Some(location) = &self.location {
+ v8::String::new(scope, location.as_str()).unwrap().into()
+ } else {
+ v8::undefined(scope).into()
+ };
+
+ array.set_index(scope, 5, val);
+ }
+
+ {
+ let val = v8::Boolean::new(scope, self.no_color);
+ array.set_index(scope, 6, val.into());
+ }
+
+ {
+ let val = v8::Boolean::new(scope, self.is_tty);
+ array.set_index(scope, 7, val.into());
+ }
+
+ {
+ let val = v8::String::new_from_one_byte(
+ scope,
+ self.ts_version.as_bytes(),
+ v8::NewStringType::Normal,
+ )
+ .unwrap();
+ array.set_index(scope, 8, val.into());
+ }
+
+ {
+ let val = v8::Boolean::new(scope, self.unstable);
+ array.set_index(scope, 9, val.into());
+ }
+
+ {
+ let val = v8::Integer::new(scope, std::process::id() as i32);
+ array.set_index(scope, 10, val.into());
+ }
+
+ {
+ let val = v8::Integer::new(scope, ppid() as i32);
+ array.set_index(scope, 11, val.into());
+ }
+
+ {
+ let val = v8::String::new_external_onebyte_static(
+ scope,
+ env!("TARGET").as_bytes(),
+ )
+ .unwrap();
+ array.set_index(scope, 12, val.into());
+ }
+
+ {
+ let val = v8::String::new_from_one_byte(
+ scope,
+ deno_core::v8_version().as_bytes(),
+ v8::NewStringType::Normal,
+ )
+ .unwrap();
+ array.set_index(scope, 13, val.into());
+ }
+
+ {
+ let val = v8::String::new_from_one_byte(
+ scope,
+ self.user_agent.as_bytes(),
+ v8::NewStringType::Normal,
+ )
+ .unwrap();
+ array.set_index(scope, 14, val.into());
+ }
+
+ {
+ let val = v8::Boolean::new(scope, self.inspect);
+ array.set_index(scope, 15, val.into());
+ }
+
+ {
+ let val = v8::Boolean::new(scope, self.enable_testing_features);
+ array.set_index(scope, 16, val.into());
+ }
+
+ array
}
}