1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

feat(runtime): allow passing extensions via Worker options (#12362)

This commit is contained in:
Aaron O'Mullan 2021-10-08 17:03:49 +02:00 committed by GitHub
parent 5f405bf114
commit 6b43e862fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 3 deletions

View file

@ -127,6 +127,7 @@ fn create_web_worker_callback(ps: ProcState) -> Arc<CreateWebWorkerCb> {
ts_version: version::TYPESCRIPT.to_string(), ts_version: version::TYPESCRIPT.to_string(),
unstable: ps.flags.unstable, unstable: ps.flags.unstable,
}, },
extensions: vec![],
unsafely_ignore_certificate_errors: ps unsafely_ignore_certificate_errors: ps
.flags .flags
.unsafely_ignore_certificate_errors .unsafely_ignore_certificate_errors
@ -216,6 +217,7 @@ pub fn create_main_worker(
ts_version: version::TYPESCRIPT.to_string(), ts_version: version::TYPESCRIPT.to_string(),
unstable: ps.flags.unstable, unstable: ps.flags.unstable,
}, },
extensions: vec![],
unsafely_ignore_certificate_errors: ps unsafely_ignore_certificate_errors: ps
.flags .flags
.unsafely_ignore_certificate_errors .unsafely_ignore_certificate_errors

View file

@ -241,6 +241,7 @@ pub async fn run(
ts_version: version::TYPESCRIPT.to_string(), ts_version: version::TYPESCRIPT.to_string(),
unstable: metadata.unstable, unstable: metadata.unstable,
}, },
extensions: vec![],
user_agent: version::get_user_agent(), user_agent: version::get_user_agent(),
unsafely_ignore_certificate_errors: metadata unsafely_ignore_certificate_errors: metadata
.unsafely_ignore_certificate_errors, .unsafely_ignore_certificate_errors,

View file

@ -36,6 +36,7 @@ async fn main() -> Result<(), AnyError> {
ts_version: "x".to_string(), ts_version: "x".to_string(),
unstable: false, unstable: false,
}, },
extensions: vec![],
unsafely_ignore_certificate_errors: None, unsafely_ignore_certificate_errors: None,
root_cert_store: None, root_cert_store: None,
user_agent: "hello_runtime".to_string(), user_agent: "hello_runtime".to_string(),

View file

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

View file

@ -44,6 +44,7 @@ pub struct MainWorker {
pub struct WorkerOptions { pub struct WorkerOptions {
pub bootstrap: BootstrapOptions, pub bootstrap: BootstrapOptions,
pub extensions: Vec<Extension>,
pub unsafely_ignore_certificate_errors: Option<Vec<String>>, pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
pub root_cert_store: Option<RootCertStore>, pub root_cert_store: Option<RootCertStore>,
pub user_agent: String, pub user_agent: String,
@ -77,7 +78,7 @@ impl MainWorker {
pub fn from_options( pub fn from_options(
main_module: ModuleSpecifier, main_module: ModuleSpecifier,
permissions: Permissions, permissions: Permissions,
options: WorkerOptions, mut options: WorkerOptions,
) -> Self { ) -> Self {
// Permissions: many ops depend on this // Permissions: many ops depend on this
let unstable = options.bootstrap.unstable; let unstable = options.bootstrap.unstable;
@ -92,7 +93,7 @@ impl MainWorker {
.build(); .build();
// Internal modules // Internal modules
let extensions: Vec<Extension> = vec![ let mut extensions: Vec<Extension> = vec![
// Web APIs // Web APIs
deno_webidl::init(), deno_webidl::init(),
deno_console::init(), deno_console::init(),
@ -146,6 +147,7 @@ impl MainWorker {
// Permissions ext (worker specific state) // Permissions ext (worker specific state)
perm_ext, perm_ext,
]; ];
extensions.extend(std::mem::take(&mut options.extensions));
let mut js_runtime = JsRuntime::new(RuntimeOptions { let mut js_runtime = JsRuntime::new(RuntimeOptions {
module_loader: Some(options.module_loader.clone()), module_loader: Some(options.module_loader.clone()),
@ -313,6 +315,7 @@ mod tests {
ts_version: "x".to_string(), ts_version: "x".to_string(),
unstable: false, unstable: false,
}, },
extensions: vec![],
user_agent: "x".to_string(), user_agent: "x".to_string(),
unsafely_ignore_certificate_errors: None, unsafely_ignore_certificate_errors: None,
root_cert_store: None, root_cert_store: None,