From d21380728f7d16f1a5b7362b2e2b5c46ff8a8070 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Mon, 3 May 2021 17:30:41 +0200 Subject: fix(core): error registration could pollute constructors (#10422) Co-authored-by: Luca Casonato --- core/runtime.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'core/runtime.rs') 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; @@ -1768,6 +1770,39 @@ pub mod tests { }); } + #[test] + fn test_error_builder() { + fn op_err( + _: &mut OpState, + _: (), + _: Option, + ) -> 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 = { -- cgit v1.2.3