summaryrefslogtreecommitdiff
path: root/core/runtime.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-11-21 15:56:14 +0100
committerGitHub <noreply@github.com>2020-11-21 15:56:14 +0100
commit04f4201f30b03f5afd183eb79cd3f9329a0426b7 (patch)
tree7c2e82d04a855e44465e94db18ef10bc05102340 /core/runtime.rs
parentcf7949db2feced61dfb4a7bc2a56ee72515394a3 (diff)
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".
Diffstat (limited to 'core/runtime.rs')
-rw-r--r--core/runtime.rs10
1 files changed, 9 insertions, 1 deletions
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<Box<JsErrorCreateFn>>,
+ /// Allows to map error type to a string "class" used to represent
+ /// error in JavaScript.
+ pub get_error_class_fn: Option<GetErrorClassFn>,
+
/// 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),