1
0
Fork 0
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:
Bartek Iwańczuk 2023-03-07 17:37:37 -04:00 committed by Yoshiya Hinosawa
parent ec69d8c8ab
commit 3e16c3fe36
33 changed files with 7 additions and 45 deletions

View file

@ -269,8 +269,6 @@ mod ts {
state.put(op_crate_libs.clone());
state.put(build_libs.clone());
state.put(path_dts.clone());
Ok(())
})
.build();

View file

@ -2826,7 +2826,6 @@ fn init_extension(performance: Arc<Performance>) -> Extension {
Arc::new(StateSnapshot::default()),
performance.clone(),
));
Ok(())
})
.build()
}

View file

@ -38,7 +38,6 @@ pub fn init(
.state(move |state| {
state.put(sender.clone());
state.put(filter.clone());
Ok(())
})
.build()
}

View file

@ -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()
}

View file

@ -44,7 +44,6 @@ pub fn init(
state.put(sender.clone());
state.put(fail_fast_tracker.clone());
state.put(filter.clone());
Ok(())
})
.build()
}

View file

@ -872,7 +872,6 @@ pub fn exec(request: Request) -> Result<Response, AnyError> {
root_map.clone(),
remapped_specifiers.clone(),
));
Ok(())
})
.build()],
..Default::default()

View file

@ -34,8 +34,6 @@ fn main() {
let (tx, rx) = mpsc::unbounded::<Task>();
state.put(tx);
state.put(rx);
Ok(())
})
.build();

View file

@ -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

View file

@ -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();

View file

@ -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
View file

@ -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()
}

View file

@ -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()
}

View file

@ -124,7 +124,6 @@ where
)
.unwrap()
});
Ok(())
})
.build()
}

View file

@ -151,8 +151,6 @@ pub fn init<P: FfiPermissions + 'static>(unstable: bool) -> Extension {
async_work_receiver,
async_work_sender,
});
Ok(())
})
.build()
}

View file

@ -1567,7 +1567,6 @@ pub fn init<P: FlashPermissions + 'static>(unstable: bool) -> Extension {
join_handles: HashMap::default(),
servers: HashMap::default(),
});
Ok(())
})
.build()
}

View file

@ -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>(),

View file

@ -132,7 +132,6 @@ pub fn init(stdio: Stdio) -> Extension {
"stderr",
));
assert_eq!(rid, 2, "stderr must have ResourceId 2");
Ok(())
})
.build()
}

View file

@ -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()
}

View file

@ -96,7 +96,6 @@ pub fn init<P: NetPermissions + 'static>(
state.put(UnsafelyIgnoreCertificateErrors(
unsafely_ignore_certificate_errors.clone(),
));
Ok(())
})
.build()
}

View file

@ -910,7 +910,6 @@ mod tests {
.state(move |state| {
state.put(TestPermission {});
state.put(UnstableChecker { unstable: true });
Ok(())
})
.build();

View file

@ -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()
}

View file

@ -40,7 +40,6 @@ fn setup() -> Vec<Extension> {
}])
.state(|state| {
state.put(Permissions {});
Ok(())
})
.build(),
]

View file

@ -38,7 +38,6 @@ fn setup() -> Vec<Extension> {
])
.state(|state| {
state.put(Permissions{});
Ok(())
})
.build()
]

View file

@ -121,7 +121,6 @@ pub fn init<P: TimersPermission + 'static>(
state.put(Location(location));
}
state.put(StartTime::now());
Ok(())
})
.build()
}

View file

@ -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()
}

View file

@ -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()
}

View file

@ -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()
}

View file

@ -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()
}

View file

@ -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()
}

View file

@ -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()
}

View file

@ -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(),

View file

@ -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| {

View file

@ -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)));