summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-03-07 17:37:37 -0400
committerGitHub <noreply@github.com>2023-03-07 22:37:37 +0100
commitb32a6f8ad20e6e4b0cc24b8256c08192b4899844 (patch)
tree76201de6fe376b658b99228c8d2ca1618181ee57
parent0e3affcd5b932e1b1ecc37934a0625a0d4d0d62c (diff)
refactor(core): don't use Result in ExtensionBuilder::state (#18066)
There's no point for this API to expect result. If something fails it should result in a panic during build time to signal to embedder that setup is wrong.
-rw-r--r--cli/build.rs2
-rw-r--r--cli/lsp/tsc.rs1
-rw-r--r--cli/ops/bench.rs1
-rw-r--r--cli/ops/mod.rs1
-rw-r--r--cli/ops/testing.rs1
-rw-r--r--cli/tsc/mod.rs1
-rw-r--r--core/examples/schedule_task.rs2
-rw-r--r--core/extensions.rs11
-rw-r--r--core/runtime.rs6
-rw-r--r--ext/broadcast_channel/lib.rs1
-rw-r--r--ext/cache/lib.rs1
-rw-r--r--ext/crypto/lib.rs1
-rw-r--r--ext/fetch/lib.rs1
-rw-r--r--ext/ffi/lib.rs2
-rw-r--r--ext/flash/lib.rs1
-rw-r--r--ext/fs/lib.rs1
-rw-r--r--ext/io/lib.rs1
-rw-r--r--ext/napi/lib.rs1
-rw-r--r--ext/net/lib.rs1
-rw-r--r--ext/net/ops.rs1
-rw-r--r--ext/node/lib.rs1
-rw-r--r--ext/web/benches/encoding.rs1
-rw-r--r--ext/web/benches/timers_ops.rs1
-rw-r--r--ext/web/lib.rs1
-rw-r--r--ext/webgpu/lib.rs1
-rw-r--r--ext/webgpu/surface.rs1
-rw-r--r--ext/websocket/lib.rs1
-rw-r--r--ext/webstorage/lib.rs1
-rw-r--r--runtime/ops/os/mod.rs1
-rw-r--r--runtime/ops/runtime.rs1
-rw-r--r--runtime/ops/worker_host.rs2
-rw-r--r--runtime/web_worker.rs1
-rw-r--r--runtime/worker.rs1
33 files changed, 7 insertions, 45 deletions
diff --git a/cli/build.rs b/cli/build.rs
index c0a22ba12..21e702aed 100644
--- a/cli/build.rs
+++ b/cli/build.rs
@@ -269,8 +269,6 @@ mod ts {
state.put(op_crate_libs.clone());
state.put(build_libs.clone());
state.put(path_dts.clone());
-
- Ok(())
})
.build();
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs
index 2f66e2d2d..9a0c0dabe 100644
--- a/cli/lsp/tsc.rs
+++ b/cli/lsp/tsc.rs
@@ -2826,7 +2826,6 @@ fn init_extension(performance: Arc<Performance>) -> Extension {
Arc::new(StateSnapshot::default()),
performance.clone(),
));
- Ok(())
})
.build()
}
diff --git a/cli/ops/bench.rs b/cli/ops/bench.rs
index 2181a139c..513ecc0d1 100644
--- a/cli/ops/bench.rs
+++ b/cli/ops/bench.rs
@@ -38,7 +38,6 @@ pub fn init(
.state(move |state| {
state.put(sender.clone());
state.put(filter.clone());
- Ok(())
})
.build()
}
diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs
index c31a30531..53f74ad1f 100644
--- a/cli/ops/mod.rs
+++ b/cli/ops/mod.rs
@@ -18,7 +18,6 @@ fn init_proc_state(ps: ProcState) -> Extension {
.ops(vec![op_npm_process_state::decl()])
.state(move |state| {
state.put(ps.clone());
- Ok(())
})
.build()
}
diff --git a/cli/ops/testing.rs b/cli/ops/testing.rs
index e9d0acf41..9170e9400 100644
--- a/cli/ops/testing.rs
+++ b/cli/ops/testing.rs
@@ -44,7 +44,6 @@ pub fn init(
state.put(sender.clone());
state.put(fail_fast_tracker.clone());
state.put(filter.clone());
- Ok(())
})
.build()
}
diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs
index bdd11fd52..188bc0533 100644
--- a/cli/tsc/mod.rs
+++ b/cli/tsc/mod.rs
@@ -872,7 +872,6 @@ pub fn exec(request: Request) -> Result<Response, AnyError> {
root_map.clone(),
remapped_specifiers.clone(),
));
- Ok(())
})
.build()],
..Default::default()
diff --git a/core/examples/schedule_task.rs b/core/examples/schedule_task.rs
index 56c8f6dd6..42d00022d 100644
--- a/core/examples/schedule_task.rs
+++ b/core/examples/schedule_task.rs
@@ -34,8 +34,6 @@ fn main() {
let (tx, rx) = mpsc::unbounded::<Task>();
state.put(tx);
state.put(rx);
-
- Ok(())
})
.build();
diff --git a/core/extensions.rs b/core/extensions.rs
index ead1fa354..beddce4c7 100644
--- a/core/extensions.rs
+++ b/core/extensions.rs
@@ -42,7 +42,7 @@ pub struct ExtensionFileSource {
}
pub type OpFnRef = v8::FunctionCallback;
pub type OpMiddlewareFn = dyn Fn(OpDecl) -> OpDecl;
-pub type OpStateFn = dyn Fn(&mut OpState) -> Result<(), Error>;
+pub type OpStateFn = dyn Fn(&mut OpState);
pub type OpEventLoopFn = dyn Fn(Rc<RefCell<OpState>>, &mut Context) -> bool;
pub struct OpDecl {
@@ -147,10 +147,9 @@ impl Extension {
}
/// Allows setting up the initial op-state of an isolate at startup.
- pub fn init_state(&self, state: &mut OpState) -> Result<(), Error> {
- match &self.opstate_fn {
- Some(ofn) => ofn(state),
- None => Ok(()),
+ pub fn init_state(&self, state: &mut OpState) {
+ if let Some(op_fn) = &self.opstate_fn {
+ op_fn(state);
}
}
@@ -243,7 +242,7 @@ impl ExtensionBuilder {
pub fn state<F>(&mut self, opstate_fn: F) -> &mut Self
where
- F: Fn(&mut OpState) -> Result<(), Error> + 'static,
+ F: Fn(&mut OpState) + 'static,
{
self.state = Some(Box::new(opstate_fn));
self
diff --git a/core/runtime.rs b/core/runtime.rs
index 1d74c9ede..92e23873a 100644
--- a/core/runtime.rs
+++ b/core/runtime.rs
@@ -939,7 +939,7 @@ impl JsRuntime {
// Setup state
for e in extensions.iter_mut() {
// ops are already registered during in bindings::initialize_context();
- e.init_state(&mut op_state.borrow_mut())?;
+ e.init_state(&mut op_state.borrow_mut());
// Setup event-loop middleware
if let Some(middleware) = e.init_event_loop_middleware() {
@@ -957,7 +957,7 @@ impl JsRuntime {
// Setup state
for e in extensions.iter_mut() {
// ops are already registered during in bindings::initialize_context();
- e.init_state(&mut op_state.borrow_mut())?;
+ e.init_state(&mut op_state.borrow_mut());
// Setup event-loop middleware
if let Some(middleware) = e.init_event_loop_middleware() {
@@ -2887,7 +2887,6 @@ pub mod tests {
mode,
dispatch_count: dispatch_count2.clone(),
});
- Ok(())
})
.build();
let mut runtime = JsRuntime::new(RuntimeOptions {
@@ -4045,7 +4044,6 @@ assertEquals(1, notify_return_value);
.ops(vec![op_async_borrow::decl()])
.state(|state| {
state.put(InnerState(42));
- Ok(())
})
.build();
diff --git a/ext/broadcast_channel/lib.rs b/ext/broadcast_channel/lib.rs
index 85994bf97..cb8d31890 100644
--- a/ext/broadcast_channel/lib.rs
+++ b/ext/broadcast_channel/lib.rs
@@ -122,7 +122,6 @@ pub fn init<BC: BroadcastChannel + 'static>(
.state(move |state| {
state.put(bc.clone());
state.put(Unstable(unstable));
- Ok(())
})
.build()
}
diff --git a/ext/cache/lib.rs b/ext/cache/lib.rs
index b0efbca55..463ade94f 100644
--- a/ext/cache/lib.rs
+++ b/ext/cache/lib.rs
@@ -40,7 +40,6 @@ pub fn init<CA: Cache + 'static>(
if let Some(create_cache) = maybe_create_cache.clone() {
state.put(create_cache);
}
- Ok(())
})
.build()
}
diff --git a/ext/crypto/lib.rs b/ext/crypto/lib.rs
index 9d6017f39..6f456c9ee 100644
--- a/ext/crypto/lib.rs
+++ b/ext/crypto/lib.rs
@@ -111,7 +111,6 @@ pub fn init(maybe_seed: Option<u64>) -> Extension {
if let Some(seed) = maybe_seed {
state.put(StdRng::seed_from_u64(seed));
}
- Ok(())
})
.build()
}
diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs
index 766dabb62..f2a962539 100644
--- a/ext/fetch/lib.rs
+++ b/ext/fetch/lib.rs
@@ -124,7 +124,6 @@ where
)
.unwrap()
});
- Ok(())
})
.build()
}
diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs
index 38a5a7eb2..e9ce2ec2e 100644
--- a/ext/ffi/lib.rs
+++ b/ext/ffi/lib.rs
@@ -151,8 +151,6 @@ pub fn init<P: FfiPermissions + 'static>(unstable: bool) -> Extension {
async_work_receiver,
async_work_sender,
});
-
- Ok(())
})
.build()
}
diff --git a/ext/flash/lib.rs b/ext/flash/lib.rs
index 4ae064173..b50b7bb5c 100644
--- a/ext/flash/lib.rs
+++ b/ext/flash/lib.rs
@@ -1567,7 +1567,6 @@ pub fn init<P: FlashPermissions + 'static>(unstable: bool) -> Extension {
join_handles: HashMap::default(),
servers: HashMap::default(),
});
- Ok(())
})
.build()
}
diff --git a/ext/fs/lib.rs b/ext/fs/lib.rs
index 7551408a9..4b177a2bf 100644
--- a/ext/fs/lib.rs
+++ b/ext/fs/lib.rs
@@ -122,7 +122,6 @@ pub fn init<P: FsPermissions + 'static>(unstable: bool) -> Extension {
.esm(include_js_files!("30_fs.js",))
.state(move |state| {
state.put(UnstableChecker { unstable });
- Ok(())
})
.ops(vec![
op_open_sync::decl::<P>(),
diff --git a/ext/io/lib.rs b/ext/io/lib.rs
index f8dde139f..84d9d34a6 100644
--- a/ext/io/lib.rs
+++ b/ext/io/lib.rs
@@ -132,7 +132,6 @@ pub fn init(stdio: Stdio) -> Extension {
"stderr",
));
assert_eq!(rid, 2, "stderr must have ResourceId 2");
- Ok(())
})
.build()
}
diff --git a/ext/napi/lib.rs b/ext/napi/lib.rs
index 628ecd5a2..471ebfeab 100644
--- a/ext/napi/lib.rs
+++ b/ext/napi/lib.rs
@@ -578,7 +578,6 @@ pub fn init<P: NapiPermissions + 'static>() -> Extension {
env_cleanup_hooks: Rc::new(RefCell::new(vec![])),
tsfn_ref_counters: Arc::new(Mutex::new(vec![])),
});
- Ok(())
})
.build()
}
diff --git a/ext/net/lib.rs b/ext/net/lib.rs
index 0536f3233..5dc7823bc 100644
--- a/ext/net/lib.rs
+++ b/ext/net/lib.rs
@@ -96,7 +96,6 @@ pub fn init<P: NetPermissions + 'static>(
state.put(UnsafelyIgnoreCertificateErrors(
unsafely_ignore_certificate_errors.clone(),
));
- Ok(())
})
.build()
}
diff --git a/ext/net/ops.rs b/ext/net/ops.rs
index 737a46d8c..8ac08119a 100644
--- a/ext/net/ops.rs
+++ b/ext/net/ops.rs
@@ -910,7 +910,6 @@ mod tests {
.state(move |state| {
state.put(TestPermission {});
state.put(UnstableChecker { unstable: true });
- Ok(())
})
.build();
diff --git a/ext/node/lib.rs b/ext/node/lib.rs
index e1134bd03..411151f2f 100644
--- a/ext/node/lib.rs
+++ b/ext/node/lib.rs
@@ -383,7 +383,6 @@ pub fn init<P: NodePermissions + 'static>(
if let Some(npm_resolver) = maybe_npm_resolver.clone() {
state.put(npm_resolver);
}
- Ok(())
})
.build()
}
diff --git a/ext/web/benches/encoding.rs b/ext/web/benches/encoding.rs
index e9ef3a563..ffea2617e 100644
--- a/ext/web/benches/encoding.rs
+++ b/ext/web/benches/encoding.rs
@@ -40,7 +40,6 @@ fn setup() -> Vec<Extension> {
}])
.state(|state| {
state.put(Permissions {});
- Ok(())
})
.build(),
]
diff --git a/ext/web/benches/timers_ops.rs b/ext/web/benches/timers_ops.rs
index f177f7d83..8c700266a 100644
--- a/ext/web/benches/timers_ops.rs
+++ b/ext/web/benches/timers_ops.rs
@@ -38,7 +38,6 @@ fn setup() -> Vec<Extension> {
])
.state(|state| {
state.put(Permissions{});
- Ok(())
})
.build()
]
diff --git a/ext/web/lib.rs b/ext/web/lib.rs
index 76095810e..1af4cc29d 100644
--- a/ext/web/lib.rs
+++ b/ext/web/lib.rs
@@ -121,7 +121,6 @@ pub fn init<P: TimersPermission + 'static>(
state.put(Location(location));
}
state.put(StartTime::now());
- Ok(())
})
.build()
}
diff --git a/ext/webgpu/lib.rs b/ext/webgpu/lib.rs
index 68069c133..8e13a8050 100644
--- a/ext/webgpu/lib.rs
+++ b/ext/webgpu/lib.rs
@@ -127,7 +127,6 @@ pub fn init(unstable: bool) -> Extension {
// let unstable_checker = state.borrow::<super::UnstableChecker>();
// let unstable = unstable_checker.unstable;
state.put(Unstable(unstable));
- Ok(())
})
.build()
}
diff --git a/ext/webgpu/surface.rs b/ext/webgpu/surface.rs
index 8304427b9..d20d06bb1 100644
--- a/ext/webgpu/surface.rs
+++ b/ext/webgpu/surface.rs
@@ -30,7 +30,6 @@ pub fn init_surface(unstable: bool) -> Extension {
// let unstable_checker = state.borrow::<super::UnstableChecker>();
// let unstable = unstable_checker.unstable;
state.put(super::Unstable(unstable));
- Ok(())
})
.build()
}
diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs
index 0ae2ada63..4537c45e5 100644
--- a/ext/websocket/lib.rs
+++ b/ext/websocket/lib.rs
@@ -521,7 +521,6 @@ pub fn init<P: WebSocketPermissions + 'static>(
unsafely_ignore_certificate_errors.clone(),
));
state.put::<WsRootStore>(WsRootStore(root_cert_store.clone()));
- Ok(())
})
.build()
}
diff --git a/ext/webstorage/lib.rs b/ext/webstorage/lib.rs
index 5e534a122..98f1246d2 100644
--- a/ext/webstorage/lib.rs
+++ b/ext/webstorage/lib.rs
@@ -38,7 +38,6 @@ pub fn init(origin_storage_dir: Option<PathBuf>) -> Extension {
if let Some(origin_storage_dir) = &origin_storage_dir {
state.put(OriginStorageDir(origin_storage_dir.clone()));
}
- Ok(())
})
.build()
}
diff --git a/runtime/ops/os/mod.rs b/runtime/ops/os/mod.rs
index ac8ec541d..83ad8164f 100644
--- a/runtime/ops/os/mod.rs
+++ b/runtime/ops/os/mod.rs
@@ -45,7 +45,6 @@ pub fn init(exit_code: ExitCode) -> Extension {
init_ops(&mut builder)
.state(move |state| {
state.put::<ExitCode>(exit_code.clone());
- Ok(())
})
.build()
}
diff --git a/runtime/ops/runtime.rs b/runtime/ops/runtime.rs
index 22a481e77..5ce9966e0 100644
--- a/runtime/ops/runtime.rs
+++ b/runtime/ops/runtime.rs
@@ -12,7 +12,6 @@ pub fn init(main_module: ModuleSpecifier) -> Extension {
.ops(vec![op_main_module::decl()])
.state(move |state| {
state.put::<ModuleSpecifier>(main_module.clone());
- Ok(())
})
.build()
}
diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs
index 71009be8f..6007a3260 100644
--- a/runtime/ops/worker_host.rs
+++ b/runtime/ops/worker_host.rs
@@ -111,8 +111,6 @@ pub fn init(
let format_js_error_fn_holder =
FormatJsErrorFnHolder(format_js_error_fn.clone());
state.put::<FormatJsErrorFnHolder>(format_js_error_fn_holder);
-
- Ok(())
})
.ops(vec![
op_create_worker::decl(),
diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs
index cce69fabb..f07ecd27f 100644
--- a/runtime/web_worker.rs
+++ b/runtime/web_worker.rs
@@ -376,7 +376,6 @@ impl WebWorker {
state.put::<PermissionsContainer>(permissions.clone());
state.put(ops::UnstableChecker { unstable });
state.put(ops::TestingFeaturesEnabled(enable_testing_features));
- Ok(())
})
.build();
let create_cache = options.cache_storage_dir.map(|storage_dir| {
diff --git a/runtime/worker.rs b/runtime/worker.rs
index 1a6b6f2fc..c10f9f36e 100644
--- a/runtime/worker.rs
+++ b/runtime/worker.rs
@@ -206,7 +206,6 @@ impl MainWorker {
state.put::<PermissionsContainer>(permissions.clone());
state.put(ops::UnstableChecker { unstable });
state.put(ops::TestingFeaturesEnabled(enable_testing_features));
- Ok(())
})
.build();
let exit_code = ExitCode(Arc::new(AtomicI32::new(0)));