summaryrefslogtreecommitdiff
path: root/core/runtime.rs
diff options
context:
space:
mode:
Diffstat (limited to 'core/runtime.rs')
-rw-r--r--core/runtime.rs31
1 files changed, 20 insertions, 11 deletions
diff --git a/core/runtime.rs b/core/runtime.rs
index 643a4198d..d1b7db14c 100644
--- a/core/runtime.rs
+++ b/core/runtime.rs
@@ -1651,6 +1651,7 @@ pub mod tests {
futures::executor::block_on(lazy(move |cx| f(cx)));
}
+ #[derive(Copy, Clone)]
enum Mode {
Async,
AsyncZeroCopy(bool),
@@ -1661,7 +1662,7 @@ pub mod tests {
dispatch_count: Arc<AtomicUsize>,
}
- fn dispatch(rc_op_state: Rc<RefCell<OpState>>, payload: OpPayload) -> Op {
+ fn op_test(rc_op_state: Rc<RefCell<OpState>>, payload: OpPayload) -> Op {
let rc_op_state2 = rc_op_state.clone();
let op_state_ = rc_op_state2.borrow();
let test_state = op_state_.borrow::<TestState>();
@@ -1687,16 +1688,22 @@ pub mod tests {
fn setup(mode: Mode) -> (JsRuntime, Arc<AtomicUsize>) {
let dispatch_count = Arc::new(AtomicUsize::new(0));
- let mut runtime = JsRuntime::new(Default::default());
- let op_state = runtime.op_state();
- op_state.borrow_mut().put(TestState {
- mode,
- dispatch_count: dispatch_count.clone(),
+ let dispatch_count2 = dispatch_count.clone();
+ let ext = Extension::builder()
+ .ops(vec![("op_test", Box::new(op_test))])
+ .state(move |state| {
+ state.put(TestState {
+ mode,
+ dispatch_count: dispatch_count2.clone(),
+ });
+ Ok(())
+ })
+ .build();
+ let mut runtime = JsRuntime::new(RuntimeOptions {
+ extensions: vec![ext],
+ ..Default::default()
});
- runtime.register_op("op_test", dispatch);
- runtime.sync_ops_cache();
-
runtime
.execute_script(
"setup.js",
@@ -2029,12 +2036,14 @@ pub mod tests {
}
run_in_task(|cx| {
+ let ext = Extension::builder()
+ .ops(vec![("op_err", op_sync(op_err))])
+ .build();
let mut runtime = JsRuntime::new(RuntimeOptions {
+ extensions: vec![ext],
get_error_class_fn: Some(&get_error_class_name),
..Default::default()
});
- runtime.register_op("op_err", op_sync(op_err));
- runtime.sync_ops_cache();
runtime
.execute_script(
"error_builder_test.js",