summaryrefslogtreecommitdiff
path: root/runtime/ops
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-11-12 20:52:59 -0800
committerGitHub <noreply@github.com>2023-11-13 04:52:59 +0000
commit1ef617e8f3d48098e69e222b6eb6fe981aeca1c3 (patch)
tree8ab4fab5b5b248d51575e874f240c16fba4ae268 /runtime/ops
parent39223f709bcb86069f3aa8eab7a4be80304128e6 (diff)
perf: lazy bootstrap options - first pass (#21164)
Move most runtime options to be lazily loaded. Constant options will be covered in a different PR. Towards https://github.com/denoland/deno/issues/21133
Diffstat (limited to 'runtime/ops')
-rw-r--r--runtime/ops/bootstrap.rs61
-rw-r--r--runtime/ops/mod.rs1
2 files changed, 62 insertions, 0 deletions
diff --git a/runtime/ops/bootstrap.rs b/runtime/ops/bootstrap.rs
new file mode 100644
index 000000000..1b86a7509
--- /dev/null
+++ b/runtime/ops/bootstrap.rs
@@ -0,0 +1,61 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
+use deno_core::op2;
+use deno_core::OpState;
+
+use crate::BootstrapOptions;
+
+deno_core::extension!(
+ deno_bootstrap,
+ ops = [
+ op_bootstrap_args,
+ op_bootstrap_pid,
+ op_bootstrap_numcpus,
+ op_bootstrap_user_agent,
+ op_bootstrap_language,
+ op_bootstrap_log_level,
+ op_bootstrap_no_color,
+ ],
+);
+
+#[op2]
+#[serde]
+pub fn op_bootstrap_args(state: &mut OpState) -> Vec<String> {
+ state.borrow::<BootstrapOptions>().args.clone()
+}
+
+#[op2(fast)]
+#[smi]
+pub fn op_bootstrap_pid() -> u32 {
+ std::process::id()
+}
+
+#[op2(fast)]
+#[smi]
+pub fn op_bootstrap_numcpus(state: &mut OpState) -> u32 {
+ state.borrow::<BootstrapOptions>().cpu_count as u32
+}
+
+#[op2]
+#[string]
+pub fn op_bootstrap_user_agent(state: &mut OpState) -> String {
+ state.borrow::<BootstrapOptions>().user_agent.clone()
+}
+
+#[op2]
+#[string]
+pub fn op_bootstrap_language(state: &mut OpState) -> String {
+ state.borrow::<BootstrapOptions>().locale.clone()
+}
+
+#[op2(fast)]
+#[smi]
+pub fn op_bootstrap_log_level(state: &mut OpState) -> i32 {
+ state.borrow::<BootstrapOptions>().log_level as i32
+}
+
+#[op2(fast)]
+pub fn op_bootstrap_no_color(state: &mut OpState) -> bool {
+ let options = state.borrow::<BootstrapOptions>();
+ options.no_color || !options.is_tty
+}
diff --git a/runtime/ops/mod.rs b/runtime/ops/mod.rs
index bafa6c571..0d285a808 100644
--- a/runtime/ops/mod.rs
+++ b/runtime/ops/mod.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+pub mod bootstrap;
pub mod fs_events;
pub mod http;
pub mod os;