diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-05-03 17:30:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-03 17:30:41 +0200 |
commit | d21380728f7d16f1a5b7362b2e2b5c46ff8a8070 (patch) | |
tree | 190e3a83254cf1d4c36ec03d4ce688cf657d27c8 /core/runtime.rs | |
parent | 7bc03523d075ae4a5a508f9bdf59a1686f7bcdce (diff) |
fix(core): error registration could pollute constructors (#10422)
Co-authored-by: Luca Casonato <lucacasonato@yahoo.com>
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 { |