mirror of
https://github.com/denoland/deno.git
synced 2024-12-26 09:10:40 -05:00
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.
This commit is contained in:
parent
ec69d8c8ab
commit
3e16c3fe36
33 changed files with 7 additions and 45 deletions
|
@ -269,8 +269,6 @@ mod ts {
|
|||
state.put(op_crate_libs.clone());
|
||||
state.put(build_libs.clone());
|
||||
state.put(path_dts.clone());
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.build();
|
||||
|
||||
|
|
|
@ -2826,7 +2826,6 @@ fn init_extension(performance: Arc<Performance>) -> Extension {
|
|||
Arc::new(StateSnapshot::default()),
|
||||
performance.clone(),
|
||||
));
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
|
|
@ -38,7 +38,6 @@ pub fn init(
|
|||
.state(move |state| {
|
||||
state.put(sender.clone());
|
||||
state.put(filter.clone());
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@ pub fn init(
|
|||
state.put(sender.clone());
|
||||
state.put(fail_fast_tracker.clone());
|
||||
state.put(filter.clone());
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
|
|
@ -872,7 +872,6 @@ pub fn exec(request: Request) -> Result<Response, AnyError> {
|
|||
root_map.clone(),
|
||||
remapped_specifiers.clone(),
|
||||
));
|
||||
Ok(())
|
||||
})
|
||||
.build()],
|
||||
..Default::default()
|
||||
|
|
|
@ -34,8 +34,6 @@ fn main() {
|
|||
let (tx, rx) = mpsc::unbounded::<Task>();
|
||||
state.put(tx);
|
||||
state.put(rx);
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.build();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -122,7 +122,6 @@ pub fn init<BC: BroadcastChannel + 'static>(
|
|||
.state(move |state| {
|
||||
state.put(bc.clone());
|
||||
state.put(Unstable(unstable));
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
|
1
ext/cache/lib.rs
vendored
1
ext/cache/lib.rs
vendored
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -124,7 +124,6 @@ where
|
|||
)
|
||||
.unwrap()
|
||||
});
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
|
|
@ -151,8 +151,6 @@ pub fn init<P: FfiPermissions + 'static>(unstable: bool) -> Extension {
|
|||
async_work_receiver,
|
||||
async_work_sender,
|
||||
});
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
|
|
@ -1567,7 +1567,6 @@ pub fn init<P: FlashPermissions + 'static>(unstable: bool) -> Extension {
|
|||
join_handles: HashMap::default(),
|
||||
servers: HashMap::default(),
|
||||
});
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
|
|
@ -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>(),
|
||||
|
|
|
@ -132,7 +132,6 @@ pub fn init(stdio: Stdio) -> Extension {
|
|||
"stderr",
|
||||
));
|
||||
assert_eq!(rid, 2, "stderr must have ResourceId 2");
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -96,7 +96,6 @@ pub fn init<P: NetPermissions + 'static>(
|
|||
state.put(UnsafelyIgnoreCertificateErrors(
|
||||
unsafely_ignore_certificate_errors.clone(),
|
||||
));
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
|
|
@ -910,7 +910,6 @@ mod tests {
|
|||
.state(move |state| {
|
||||
state.put(TestPermission {});
|
||||
state.put(UnstableChecker { unstable: true });
|
||||
Ok(())
|
||||
})
|
||||
.build();
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ fn setup() -> Vec<Extension> {
|
|||
}])
|
||||
.state(|state| {
|
||||
state.put(Permissions {});
|
||||
Ok(())
|
||||
})
|
||||
.build(),
|
||||
]
|
||||
|
|
|
@ -38,7 +38,6 @@ fn setup() -> Vec<Extension> {
|
|||
])
|
||||
.state(|state| {
|
||||
state.put(Permissions{});
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
]
|
||||
|
|
|
@ -121,7 +121,6 @@ pub fn init<P: TimersPermission + 'static>(
|
|||
state.put(Location(location));
|
||||
}
|
||||
state.put(StartTime::now());
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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| {
|
||||
|
|
|
@ -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)));
|
||||
|
|
Loading…
Reference in a new issue