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.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/runtime/worker_bootstrap.rs b/runtime/worker_bootstrap.rs
index c019dae1a..ee3b81c62 100644
--- a/runtime/worker_bootstrap.rs
+++ b/runtime/worker_bootstrap.rs
@@ -4,10 +4,36 @@ use deno_core::v8;
use deno_core::ModuleSpecifier;
use serde::Serialize;
use std::cell::RefCell;
+use std::num::NonZeroU16;
use std::thread;
use deno_terminal::colors;
+/// The execution mode for this worker. Some modes may have implicit behaviour.
+#[derive(Copy, Clone)]
+#[repr(u8)]
+pub enum WorkerExecutionMode {
+ /// No special behaviour.
+ None,
+
+ /// Running in a worker.
+ Worker,
+ /// `deno run`
+ Run,
+ /// `deno repl`
+ Repl,
+ /// `deno eval`
+ Eval,
+ /// `deno test`
+ Test,
+ /// `deno bench`
+ Bench,
+ /// `deno serve`
+ Serve,
+ /// `deno jupyter`
+ Jupyter,
+}
+
/// The log level to use when printing diagnostic log messages, warnings,
/// or errors in the worker.
///
@@ -63,6 +89,10 @@ pub struct BootstrapOptions {
pub disable_deprecated_api_warning: bool,
pub verbose_deprecated_api_warning: bool,
pub future: bool,
+ pub mode: WorkerExecutionMode,
+ // Used by `deno serve`
+ pub serve_port: Option<NonZeroU16>,
+ pub serve_host: Option<String>,
}
impl Default for BootstrapOptions {
@@ -94,6 +124,9 @@ impl Default for BootstrapOptions {
disable_deprecated_api_warning: false,
verbose_deprecated_api_warning: false,
future: false,
+ mode: WorkerExecutionMode::None,
+ serve_port: Default::default(),
+ serve_host: Default::default(),
}
}
}
@@ -129,6 +162,12 @@ struct BootstrapV8<'a>(
bool,
// future
bool,
+ // mode
+ i32,
+ // serve port
+ u16,
+ // serve host
+ Option<&'a str>,
);
impl BootstrapOptions {
@@ -151,6 +190,9 @@ impl BootstrapOptions {
self.disable_deprecated_api_warning,
self.verbose_deprecated_api_warning,
self.future,
+ self.mode as u8 as _,
+ self.serve_port.map(|x| x.into()).unwrap_or_default(),
+ self.serve_host.as_deref(),
);
bootstrap.serialize(ser).unwrap()