Repository: denoland/deno_core (rust)

Issue:
Migrate `get_error_class_fn` to `OpCtx`
The code paths that retrieve `get_error_class_fn` are currently `borrow`ing the `OpState` from a `RefCell` first. Let's move these to `OpCtx` directly (one copy of this function pointer per `OpCtx` so that we can simply read it as we need it.

This may impact both op and op2 code. If major changes are required to `op` code, let's leave the old copy of `get_error_class_fn` on OpState and get rid of it when we fully deprecate op1 

Pull request description:
refactor: move get_error_class_fn to OpCtx
Closes #51. `cargo test error` works in main repo.

Patch:
diff --git a/core/ops.rs b/core/ops.rs
index 1c5ab13..b4fe7bd 100644
--- a/core/ops.rs
+++ b/core/ops.rs
@@ -129,6 +129,7 @@ pub struct OpCtx {
   /// A stashed Isolate that ops can use in callbacks
   pub isolate: *mut Isolate,
   pub state: Rc<RefCell<OpState>>,
+  pub get_error_class_fn: GetErrorClassFn,
   pub decl: Rc<OpDecl>,
   pub fast_fn_c_info: Option<NonNull<v8::fast_api::CFunctionInfo>>,
   pub runtime_state: Weak<RefCell<JsRuntimeState>>,
@@ -145,6 +146,7 @@ impl OpCtx {
     decl: Rc<OpDecl>,
     state: Rc<RefCell<OpState>>,
     runtime_state: Weak<RefCell<JsRuntimeState>>,
+    get_error_class_fn: GetErrorClassFn,
   ) -> Self {
     let mut fast_fn_c_info = None;
 
@@ -170,6 +172,7 @@ impl OpCtx {
     OpCtx {
       id,
       state,
+      get_error_class_fn,
       runtime_state,
       decl,
       context_state,
@@ -209,7 +212,6 @@ impl OpCtx {
 /// Maintains the resources and ops inside a JS runtime.
 pub struct OpState {
   pub resource_table: ResourceTable,
-  pub get_error_class_fn: GetErrorClassFn,
   pub tracker: OpsTracker,
   pub last_fast_op_error: Option<AnyError>,
   pub(crate) gotham_state: GothamState,
@@ -220,7 +222,6 @@ impl OpState {
   pub fn new(ops_count: usize) -> OpState {
     OpState {
       resource_table: Default::default(),
-      get_error_class_fn: &|_| "Error",
       gotham_state: Default::default(),
       last_fast_op_error: None,
       tracker: OpsTracker::new(ops_count),
diff --git a/core/runtime/jsruntime.rs b/core/runtime/jsruntime.rs
index 10ed95c..83a738d 100644
--- a/core/runtime/jsruntime.rs
+++ b/core/runtime/jsruntime.rs
@@ -571,6 +571,7 @@ impl JsRuntime {
           Rc::new(decl),
           op_state.clone(),
           weak.clone(),
+          options.get_error_class_fn.unwrap_or(&|_| "Error"),
         )
       })
       .collect::<Vec<_>>()
@@ -800,6 +801,7 @@ impl JsRuntime {
             op_ctx.decl.clone(),
             op_ctx.state.clone(),
             op_ctx.runtime_state.clone(),
+            op_ctx.get_error_class_fn,
           )
         })
         .collect();
@@ -1062,10 +1064,6 @@ impl JsRuntime {
 
     let mut op_state = OpState::new(ops.len());
 
-    if let Some(get_error_class_fn) = options.get_error_class_fn {
-      op_state.get_error_class_fn = get_error_class_fn;
-    }
-
     // Setup state
     for e in &mut options.extensions {
       // ops are already registered during in bindings::initialize_context();
diff --git a/core/runtime/ops.rs b/core/runtime/ops.rs
index a245cfb..391a560 100644
--- a/core/runtime/ops.rs
+++ b/core/runtime/ops.rs
@@ -33,12 +33,9 @@ pub fn queue_fast_async_op<R: serde::Serialize + 'static>(
   promise_id: PromiseId,
   op: impl Future<Output = Result<R, Error>> + 'static,
 ) {
-  let get_class = {
-    let state = RefCell::borrow(&ctx.state);
-    state.tracker.track_async(ctx.id);
-    state.get_error_class_fn
-  };
-  let fut = op.map(|result| crate::_ops::to_op_result(get_class, result));
+  RefCell::borrow(&ctx.state).tracker.track_async(ctx.id);
+  let fut =
+    op.map(|result| crate::_ops::to_op_result(ctx.get_error_class_fn, result));
   ctx
     .context_state
     .borrow_mut()
@@ -51,13 +48,8 @@ pub fn map_async_op1<R: serde::Serialize + 'static>(
   ctx: &OpCtx,
   op: impl Future<Output = Result<R, Error>> + 'static,
 ) -> impl Future<Output = OpResult> {
-  let get_class = {
-    let state = RefCell::borrow(&ctx.state);
-    state.tracker.track_async(ctx.id);
-    state.get_error_class_fn
-  };
-
-  op.map(|res| crate::_ops::to_op_result(get_class, res))
+  RefCell::borrow(&ctx.state).tracker.track_async(ctx.id);
+  op.map(|res| crate::_ops::to_op_result(ctx.get_error_class_fn, res))
 }
 
 #[inline]
@@ -76,19 +68,15 @@ pub fn map_async_op3<R: serde::Serialize + 'static>(
   ctx: &OpCtx,
   op: Result<impl Future<Output = Result<R, Error>> + 'static, Error>,
 ) -> impl Future<Output = OpResult> {
-  let get_class = {
-    let state = RefCell::borrow(&ctx.state);
-    state.tracker.track_async(ctx.id);
-    state.get_error_class_fn
-  };
-
+  RefCell::borrow(&ctx.state).tracker.track_async(ctx.id);
   match op {
-    Err(err) => {
-      Either::Left(ready(OpResult::Err(OpError::new(get_class, err))))
-    }
-    Ok(fut) => {
-      Either::Right(fut.map(|res| crate::_ops::to_op_result(get_class, res)))
-    }
+    Err(err) => Either::Left(ready(OpResult::Err(OpError::new(
+      ctx.get_error_class_fn,
+      err,
+    )))),
+    Ok(fut) => Either::Right(
+      fut.map(|res| crate::_ops::to_op_result(ctx.get_error_class_fn, res)),
+    ),
   }
 }
 
@@ -97,16 +85,12 @@ pub fn map_async_op4<R: serde::Serialize + 'static>(
   ctx: &OpCtx,
   op: Result<impl Future<Output = R> + 'static, Error>,
 ) -> impl Future<Output = OpResult> {
-  let get_class = {
-    let state = RefCell::borrow(&ctx.state);
-    state.tracker.track_async(ctx.id);
-    state.get_error_class_fn
-  };
-
+  RefCell::borrow(&ctx.state).tracker.track_async(ctx.id);
   match op {
-    Err(err) => {
-      Either::Left(ready(OpResult::Err(OpError::new(get_class, err))))
-    }
+    Err(err) => Either::Left(ready(OpResult::Err(OpError::new(
+      ctx.get_error_class_fn,
+      err,
+    )))),
     Ok(fut) => Either::Right(fut.map(|r| OpResult::Ok(r.into()))),
   }
 }
@@ -222,7 +206,7 @@ pub fn map_async_op_fallible<R: 'static, E: Into<Error> + 'static>(
   ctx.state.borrow().tracker.track_async(id);
 
   if lazy {
-    let get_class = RefCell::borrow(&ctx.state).get_error_class_fn;
+    let get_class = ctx.get_error_class_fn;
     ctx.context_state.borrow_mut().pending_ops.spawn(op.map(
       move |r| match r {
         Ok(v) => (
@@ -252,7 +236,7 @@ pub fn map_async_op_fallible<R: 'static, E: Into<Error> + 'static>(
     }
   }
 
-  let get_class = RefCell::borrow(&ctx.state).get_error_class_fn;
+  let get_class = ctx.get_error_class_fn;
   ctx.context_state.borrow_mut().pending_ops.spawn(pinned.map(
     move |r| match r.2 {
       Ok(v) => (
diff --git a/ops/lib.rs b/ops/lib.rs
index 42ac026..efc5fc5 100644
--- a/ops/lib.rs
+++ b/ops/lib.rs
@@ -437,7 +437,7 @@ fn codegen_v8_sync(
       {
         let op_state = &mut std::cell::RefCell::borrow_mut(&ctx.state);
         if let Some(err) = op_state.last_fast_op_error.take() {
-          let exception = #core::error::to_v8_error(scope, op_state.get_error_class_fn, &err);
+          let exception = #core::error::to_v8_error(scope, ctx.get_error_class_fn, &err);
           scope.throw_exception(exception);
           return;
         }
@@ -791,7 +791,7 @@ fn codegen_sync_ret(
         #ok_block
       },
       Err(err) => {
-        let exception = #core::error::to_v8_error(scope, op_state.get_error_class_fn, &err);
+        let exception = #core::error::to_v8_error(scope, ctx.get_error_class_fn, &err);
         scope.throw_exception(exception);
       },
     };
diff --git a/ops/op2/dispatch_slow.rs b/ops/op2/dispatch_slow.rs
index f7e16aa..a0d18b3 100644
--- a/ops/op2/dispatch_slow.rs
+++ b/ops/op2/dispatch_slow.rs
@@ -723,10 +723,9 @@ pub(crate) fn throw_exception(
     #maybe_args
     #maybe_opctx
     let err = err.into();
-    let opstate = ::std::cell::RefCell::borrow(&*#opctx.state);
     let exception = #deno_core::error::to_v8_error(
       &mut #scope,
-      opstate.get_error_class_fn,
+      #opctx.get_error_class_fn,
       &err,
     );
     #scope.throw_exception(exception);


Test patch:
diff --git a/ops/op2/test_cases/async/async_arg_return_result.out b/ops/op2/test_cases/async/async_arg_return_result.out
index 264bf67..0004436 100644
--- a/ops/op2/test_cases/async/async_arg_return_result.out
+++ b/ops/op2/test_cases/async/async_arg_return_result.out
@@ -69,10 +69,9 @@ impl op_async {
                 }
                 Err(err) => {
                     let err = err.into();
-                    let opstate = ::std::cell::RefCell::borrow(&*opctx.state);
                     let exception = deno_core::error::to_v8_error(
                         &mut scope,
-                        opstate.get_error_class_fn,
+                        opctx.get_error_class_fn,
                         &err,
                     );
                     scope.throw_exception(exception);
diff --git a/ops/op2/test_cases/async/async_opstate.out b/ops/op2/test_cases/async/async_opstate.out
index 881af3e..5cc0152 100644
--- a/ops/op2/test_cases/async/async_opstate.out
+++ b/ops/op2/test_cases/async/async_opstate.out
@@ -57,10 +57,9 @@ impl op_async_opstate {
                 }
                 Err(err) => {
                     let err = err.into();
-                    let opstate = ::std::cell::RefCell::borrow(&*opctx.state);
                     let exception = deno_core::error::to_v8_error(
                         &mut scope,
-                        opstate.get_error_class_fn,
+                        opctx.get_error_class_fn,
                         &err,
                     );
                     scope.throw_exception(exception);
diff --git a/ops/op2/test_cases/async/async_result.out b/ops/op2/test_cases/async/async_result.out
index 1308061..8c8ee0c 100644
--- a/ops/op2/test_cases/async/async_result.out
+++ b/ops/op2/test_cases/async/async_result.out
@@ -53,10 +53,9 @@ impl op_async {
                 }
                 Err(err) => {
                     let err = err.into();
-                    let opstate = ::std::cell::RefCell::borrow(&*opctx.state);
                     let exception = deno_core::error::to_v8_error(
                         &mut scope,
-                        opstate.get_error_class_fn,
+                        opctx.get_error_class_fn,
                         &err,
                     );
                     scope.throw_exception(exception);
diff --git a/ops/op2/test_cases/async/async_result_impl.out b/ops/op2/test_cases/async/async_result_impl.out
index 64e8eac..727cf67 100644
--- a/ops/op2/test_cases/async/async_result_impl.out
+++ b/ops/op2/test_cases/async/async_result_impl.out
@@ -55,10 +55,9 @@ impl op_async_result_impl {
             Ok(result) => result,
             Err(err) => {
                 let err = err.into();
-                let opstate = ::std::cell::RefCell::borrow(&*opctx.state);
                 let exception = deno_core::error::to_v8_error(
                     &mut scope,
-                    opstate.get_error_class_fn,
+                    opctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
@@ -83,10 +82,9 @@ impl op_async_result_impl {
                 }
                 Err(err) => {
                     let err = err.into();
-                    let opstate = ::std::cell::RefCell::borrow(&*opctx.state);
                     let exception = deno_core::error::to_v8_error(
                         &mut scope,
-                        opstate.get_error_class_fn,
+                        opctx.get_error_class_fn,
                         &err,
                     );
                     scope.throw_exception(exception);
diff --git a/ops/op2/test_cases/async/async_result_smi.out b/ops/op2/test_cases/async/async_result_smi.out
index b49df43..b13822a 100644
--- a/ops/op2/test_cases/async/async_result_smi.out
+++ b/ops/op2/test_cases/async/async_result_smi.out
@@ -69,10 +69,9 @@ impl op_async {
                 }
                 Err(err) => {
                     let err = err.into();
-                    let opstate = ::std::cell::RefCell::borrow(&*opctx.state);
                     let exception = deno_core::error::to_v8_error(
                         &mut scope,
-                        opstate.get_error_class_fn,
+                        opctx.get_error_class_fn,
                         &err,
                     );
                     scope.throw_exception(exception);
diff --git a/ops/op2/test_cases/sync/bool_result.out b/ops/op2/test_cases/sync/bool_result.out
index 86bc513..79f476a 100644
--- a/ops/op2/test_cases/sync/bool_result.out
+++ b/ops/op2/test_cases/sync/bool_result.out
@@ -72,10 +72,9 @@ impl op_bool {
         if let Some(err) = unsafe { opctx.unsafely_take_last_error_for_ops_only() } {
             let mut scope = unsafe { deno_core::v8::CallbackScope::new(&*info) };
             let err = err.into();
-            let opstate = ::std::cell::RefCell::borrow(&*opctx.state);
             let exception = deno_core::error::to_v8_error(
                 &mut scope,
-                opstate.get_error_class_fn,
+                opctx.get_error_class_fn,
                 &err,
             );
             scope.throw_exception(exception);
@@ -93,10 +92,9 @@ impl op_bool {
             Err(err) => {
                 let mut scope = unsafe { deno_core::v8::CallbackScope::new(&*info) };
                 let err = err.into();
-                let opstate = ::std::cell::RefCell::borrow(&*opctx.state);
                 let exception = deno_core::error::to_v8_error(
                     &mut scope,
-                    opstate.get_error_class_fn,
+                    opctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
diff --git a/ops/op2/test_cases/sync/result_primitive.out b/ops/op2/test_cases/sync/result_primitive.out
index 8fd40c3..cf84857 100644
--- a/ops/op2/test_cases/sync/result_primitive.out
+++ b/ops/op2/test_cases/sync/result_primitive.out
@@ -71,10 +71,9 @@ impl op_u32_with_result {
                 &*info
             });
             let err = err.into();
-            let opstate = ::std::cell::RefCell::borrow(&*opctx.state);
             let exception = deno_core::error::to_v8_error(
                 &mut scope,
-                opstate.get_error_class_fn,
+                opctx.get_error_class_fn,
                 &err,
             );
             scope.throw_exception(exception);
@@ -91,10 +90,9 @@ impl op_u32_with_result {
                     &*info
                 });
                 let err = err.into();
-                let opstate = ::std::cell::RefCell::borrow(&*opctx.state);
                 let exception = deno_core::error::to_v8_error(
                     &mut scope,
-                    opstate.get_error_class_fn,
+                    opctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
diff --git a/ops/op2/test_cases/sync/result_scope.out b/ops/op2/test_cases/sync/result_scope.out
index e8db67c..97a92fd 100644
--- a/ops/op2/test_cases/sync/result_scope.out
+++ b/ops/op2/test_cases/sync/result_scope.out
@@ -44,10 +44,9 @@ impl op_void_with_result {
                         .value() as *const deno_core::_ops::OpCtx)
                 };
                 let err = err.into();
-                let opstate = ::std::cell::RefCell::borrow(&*opctx.state);
                 let exception = deno_core::error::to_v8_error(
                     &mut scope,
-                    opstate.get_error_class_fn,
+                    opctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
diff --git a/ops/op2/test_cases/sync/result_void.out b/ops/op2/test_cases/sync/result_void.out
index a767d48..38fadd2 100644
--- a/ops/op2/test_cases/sync/result_void.out
+++ b/ops/op2/test_cases/sync/result_void.out
@@ -71,10 +71,9 @@ impl op_void_with_result {
                 &*info
             });
             let err = err.into();
-            let opstate = ::std::cell::RefCell::borrow(&*opctx.state);
             let exception = deno_core::error::to_v8_error(
                 &mut scope,
-                opstate.get_error_class_fn,
+                opctx.get_error_class_fn,
                 &err,
             );
             scope.throw_exception(exception);
@@ -91,10 +90,9 @@ impl op_void_with_result {
                     &*info
                 });
                 let err = err.into();
-                let opstate = ::std::cell::RefCell::borrow(&*opctx.state);
                 let exception = deno_core::error::to_v8_error(
                     &mut scope,
-                    opstate.get_error_class_fn,
+                    opctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
diff --git a/ops/optimizer_tests/incompatible_1.out b/ops/optimizer_tests/incompatible_1.out
index ad74809..ce2fc90 100644
--- a/ops/optimizer_tests/incompatible_1.out
+++ b/ops/optimizer_tests/incompatible_1.out
@@ -74,7 +74,7 @@ impl op_sync_serialize_object_with_numbers_as_keys {
             Err(err) => {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
diff --git a/ops/optimizer_tests/op_blob_revoke_object_url.out b/ops/optimizer_tests/op_blob_revoke_object_url.out
index 529cc01..75c0c80 100644
--- a/ops/optimizer_tests/op_blob_revoke_object_url.out
+++ b/ops/optimizer_tests/op_blob_revoke_object_url.out
@@ -74,7 +74,7 @@ impl op_blob_revoke_object_url {
             Err(err) => {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
diff --git a/ops/optimizer_tests/op_print.out b/ops/optimizer_tests/op_print.out
index a108c2b..f7108d5 100644
--- a/ops/optimizer_tests/op_print.out
+++ b/ops/optimizer_tests/op_print.out
@@ -89,7 +89,7 @@ impl op_print {
             Err(err) => {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
diff --git a/ops/optimizer_tests/op_state_result.out b/ops/optimizer_tests/op_state_result.out
index 1078c52..b0ca7de 100644
--- a/ops/optimizer_tests/op_state_result.out
+++ b/ops/optimizer_tests/op_state_result.out
@@ -67,7 +67,7 @@ impl foo {
             if let Some(err) = op_state.last_fast_op_error.take() {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
@@ -110,7 +110,7 @@ impl foo {
             Err(err) => {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
diff --git a/ops/optimizer_tests/op_state_warning.out b/ops/optimizer_tests/op_state_warning.out
index 4393325..615048d 100644
--- a/ops/optimizer_tests/op_state_warning.out
+++ b/ops/optimizer_tests/op_state_warning.out
@@ -73,7 +73,7 @@ impl op_listen {
             if let Some(err) = op_state.last_fast_op_error.take() {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
@@ -101,7 +101,7 @@ impl op_listen {
             Err(err) => {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
diff --git a/ops/optimizer_tests/opstate_with_arity.out b/ops/optimizer_tests/opstate_with_arity.out
index b4e70a9..3e052b8 100644
--- a/ops/optimizer_tests/opstate_with_arity.out
+++ b/ops/optimizer_tests/opstate_with_arity.out
@@ -67,7 +67,7 @@ impl op_add_4 {
             if let Some(err) = op_state.last_fast_op_error.take() {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
@@ -128,7 +128,7 @@ impl op_add_4 {
             Err(err) => {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
diff --git a/ops/optimizer_tests/option_arg.out b/ops/optimizer_tests/option_arg.out
index 34cf33d..94ae14c 100644
--- a/ops/optimizer_tests/option_arg.out
+++ b/ops/optimizer_tests/option_arg.out
@@ -72,7 +72,7 @@ impl op_try_close {
             Err(err) => {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
diff --git a/ops/optimizer_tests/param_mut_binding_warning.out b/ops/optimizer_tests/param_mut_binding_warning.out
index 9a08f33..2357426 100644
--- a/ops/optimizer_tests/param_mut_binding_warning.out
+++ b/ops/optimizer_tests/param_mut_binding_warning.out
@@ -92,7 +92,7 @@ impl op_read_sync {
             Err(err) => {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
diff --git a/ops/optimizer_tests/strings_result.out b/ops/optimizer_tests/strings_result.out
index 4d836a5..e79e686 100644
--- a/ops/optimizer_tests/strings_result.out
+++ b/ops/optimizer_tests/strings_result.out
@@ -74,7 +74,7 @@ impl op_string_length {
             Err(err) => {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
diff --git a/ops/optimizer_tests/u64_result.out b/ops/optimizer_tests/u64_result.out
index 73cd698..93a6a81 100644
--- a/ops/optimizer_tests/u64_result.out
+++ b/ops/optimizer_tests/u64_result.out
@@ -75,7 +75,7 @@ impl op_bench_now {
             Err(err) => {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
diff --git a/ops/optimizer_tests/unit_result.out b/ops/optimizer_tests/unit_result.out
index 856840d..ce1f007 100644
--- a/ops/optimizer_tests/unit_result.out
+++ b/ops/optimizer_tests/unit_result.out
@@ -67,7 +67,7 @@ impl op_unit_result {
             if let Some(err) = op_state.last_fast_op_error.take() {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
@@ -82,7 +82,7 @@ impl op_unit_result {
             Err(err) => {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
diff --git a/ops/optimizer_tests/unit_result2.out b/ops/optimizer_tests/unit_result2.out
index 6d87096..f4e185c 100644
--- a/ops/optimizer_tests/unit_result2.out
+++ b/ops/optimizer_tests/unit_result2.out
@@ -74,7 +74,7 @@ impl op_set_nodelay {
             if let Some(err) = op_state.last_fast_op_error.take() {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);
@@ -115,7 +115,7 @@ impl op_set_nodelay {
             Err(err) => {
                 let exception = deno_core::error::to_v8_error(
                     scope,
-                    op_state.get_error_class_fn,
+                    ctx.get_error_class_fn,
                     &err,
                 );
                 scope.throw_exception(exception);