From 04f4201f30b03f5afd183eb79cd3f9329a0426b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 21 Nov 2020 15:56:14 +0100 Subject: refactor(corr): accept get_error_class_fn in RuntimeOptions (#8444) This commit adds "get_error_class_fn" field to "RuntimeOptions" struct in order to unify configuration of "JsRuntime". --- core/runtime.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/runtime.rs b/core/runtime.rs index e915571e0..7b63028cd 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -170,6 +170,10 @@ pub struct RuntimeOptions { /// is set to `JsError::create()`. pub js_error_create_fn: Option>, + /// Allows to map error type to a string "class" used to represent + /// error in JavaScript. + pub get_error_class_fn: Option, + /// Implementation of `ModuleLoader` which will be /// called when V8 requests to load ES modules. /// @@ -254,7 +258,11 @@ impl JsRuntime { let js_error_create_fn = options .js_error_create_fn .unwrap_or_else(|| Box::new(JsError::create)); - let op_state = OpState::default(); + let mut op_state = OpState::default(); + + if let Some(get_error_class_fn) = options.get_error_class_fn { + op_state.get_error_class_fn = get_error_class_fn; + } isolate.set_slot(Rc::new(RefCell::new(JsRuntimeState { global_context: Some(global_context), -- cgit v1.2.3