diff options
Diffstat (limited to 'core/runtime.rs')
-rw-r--r-- | core/runtime.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/core/runtime.rs b/core/runtime.rs index 547f6aa23..af1280373 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -1521,7 +1521,9 @@ impl JsRuntime { #[cfg(test)] pub mod tests { use super::*; + use crate::error::custom_error; use crate::modules::ModuleSourceFuture; + use crate::op_sync; use futures::future::lazy; use futures::FutureExt; use std::io; @@ -1769,6 +1771,39 @@ pub mod tests { } #[test] + fn test_error_builder() { + fn op_err( + _: &mut OpState, + _: (), + _: Option<ZeroCopyBuf>, + ) -> Result<(), AnyError> { + Err(custom_error("DOMExceptionOperationError", "abc")) + } + + pub fn get_error_class_name(_: &AnyError) -> &'static str { + "DOMExceptionOperationError" + } + + run_in_task(|mut cx| { + let mut runtime = JsRuntime::new(RuntimeOptions { + 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( + "error_builder_test.js", + include_str!("error_builder_test.js"), + ) + .unwrap(); + if let Poll::Ready(Err(_)) = runtime.poll_event_loop(&mut cx) { + unreachable!(); + } + }); + } + + #[test] fn will_snapshot() { let snapshot = { let mut runtime = JsRuntime::new(RuntimeOptions { |