Skip to content

Commit

Permalink
feat(runtime): allow passing extensions via Worker options (denoland#…
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronO committed Oct 8, 2021
1 parent 5f405bf commit 6b43e86
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ fn create_web_worker_callback(ps: ProcState) -> Arc<CreateWebWorkerCb> {
ts_version: version::TYPESCRIPT.to_string(),
unstable: ps.flags.unstable,
},
extensions: vec![],
unsafely_ignore_certificate_errors: ps
.flags
.unsafely_ignore_certificate_errors
Expand Down Expand Up @@ -216,6 +217,7 @@ pub fn create_main_worker(
ts_version: version::TYPESCRIPT.to_string(),
unstable: ps.flags.unstable,
},
extensions: vec![],
unsafely_ignore_certificate_errors: ps
.flags
.unsafely_ignore_certificate_errors
Expand Down
1 change: 1 addition & 0 deletions cli/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ pub async fn run(
ts_version: version::TYPESCRIPT.to_string(),
unstable: metadata.unstable,
},
extensions: vec![],
user_agent: version::get_user_agent(),
unsafely_ignore_certificate_errors: metadata
.unsafely_ignore_certificate_errors,
Expand Down
1 change: 1 addition & 0 deletions runtime/examples/hello_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async fn main() -> Result<(), AnyError> {
ts_version: "x".to_string(),
unstable: false,
},
extensions: vec![],
unsafely_ignore_certificate_errors: None,
root_cert_store: None,
user_agent: "hello_runtime".to_string(),
Expand Down
4 changes: 3 additions & 1 deletion runtime/web_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ pub struct WebWorker {

pub struct WebWorkerOptions {
pub bootstrap: BootstrapOptions,
pub extensions: Vec<Extension>,
pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
pub root_cert_store: Option<RootCertStore>,
pub user_agent: String,
Expand Down Expand Up @@ -297,7 +298,7 @@ impl WebWorker {
permissions: Permissions,
main_module: ModuleSpecifier,
worker_id: WorkerId,
options: WebWorkerOptions,
mut options: WebWorkerOptions,
) -> (Self, SendableWebWorkerHandle) {
// Permissions: many ops depend on this
let unstable = options.bootstrap.unstable;
Expand Down Expand Up @@ -377,6 +378,7 @@ impl WebWorker {
// Append exts
extensions.extend(runtime_exts);
extensions.extend(deno_ns_exts); // May be empty
extensions.extend(std::mem::take(&mut options.extensions));

let mut js_runtime = JsRuntime::new(RuntimeOptions {
module_loader: Some(options.module_loader.clone()),
Expand Down
7 changes: 5 additions & 2 deletions runtime/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct MainWorker {

pub struct WorkerOptions {
pub bootstrap: BootstrapOptions,
pub extensions: Vec<Extension>,
pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
pub root_cert_store: Option<RootCertStore>,
pub user_agent: String,
Expand Down Expand Up @@ -77,7 +78,7 @@ impl MainWorker {
pub fn from_options(
main_module: ModuleSpecifier,
permissions: Permissions,
options: WorkerOptions,
mut options: WorkerOptions,
) -> Self {
// Permissions: many ops depend on this
let unstable = options.bootstrap.unstable;
Expand All @@ -92,7 +93,7 @@ impl MainWorker {
.build();

// Internal modules
let extensions: Vec<Extension> = vec![
let mut extensions: Vec<Extension> = vec![
// Web APIs
deno_webidl::init(),
deno_console::init(),
Expand Down Expand Up @@ -146,6 +147,7 @@ impl MainWorker {
// Permissions ext (worker specific state)
perm_ext,
];
extensions.extend(std::mem::take(&mut options.extensions));

let mut js_runtime = JsRuntime::new(RuntimeOptions {
module_loader: Some(options.module_loader.clone()),
Expand Down Expand Up @@ -313,6 +315,7 @@ mod tests {
ts_version: "x".to_string(),
unstable: false,
},
extensions: vec![],
user_agent: "x".to_string(),
unsafely_ignore_certificate_errors: None,
root_cert_store: None,
Expand Down

0 comments on commit 6b43e86

Please sign in to comment.