summaryrefslogtreecommitdiff
path: root/core/core_isolate.rs
diff options
context:
space:
mode:
authorGurwinder Singh <vargwin@gmail.com>2020-07-14 01:49:51 +0530
committerGitHub <noreply@github.com>2020-07-13 16:19:51 -0400
commitd51972377c1325076704d9faec2eee6f0e024496 (patch)
tree67c75b20d8e07ff356652c71a6c9e87cd36ab41f /core/core_isolate.rs
parent6af5149ea3d9b0accf7122073abbf852e355846f (diff)
refactor: Make OpDispatcher a trait (#6736)
Diffstat (limited to 'core/core_isolate.rs')
-rw-r--r--core/core_isolate.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/core/core_isolate.rs b/core/core_isolate.rs
index ffe75c00c..c9e718d2d 100644
--- a/core/core_isolate.rs
+++ b/core/core_isolate.rs
@@ -348,10 +348,11 @@ impl CoreIsolate {
/// corresponds to the second argument of Deno.core.dispatch().
///
/// Requires runtime to explicitly ask for op ids before using any of the ops.
- pub fn register_op<F>(&mut self, name: &str, op: F) -> OpId
- where
- F: Fn(&mut CoreIsolateState, &mut [ZeroCopyBuf]) -> Op + 'static,
- {
+ pub fn register_op(
+ &mut self,
+ name: &str,
+ op: impl OpDispatcher + 'static,
+ ) -> OpId {
let state_rc = Self::state(self);
let mut state = state_rc.borrow_mut();
state.op_registry.register(name, op)
@@ -466,7 +467,7 @@ impl CoreIsolateState {
/// Requires runtime to explicitly ask for op ids before using any of the ops.
pub fn register_op<F>(&mut self, name: &str, op: F) -> OpId
where
- F: Fn(&mut CoreIsolateState, &mut [ZeroCopyBuf]) -> Op + 'static,
+ F: OpDispatcher + 'static,
{
self.op_registry.register(name, op)
}
@@ -488,7 +489,7 @@ impl CoreIsolateState {
zero_copy_bufs: &mut [ZeroCopyBuf],
) -> Option<(OpId, Box<[u8]>)> {
let op = if let Some(dispatcher) = self.op_registry.get(op_id) {
- dispatcher(self, zero_copy_bufs)
+ dispatcher.dispatch(self, zero_copy_bufs)
} else {
let message =
v8::String::new(scope, &format!("Unknown op id: {}", op_id)).unwrap();