Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

fix(modules): classify caught native TypeError constructors

ldm013cb11c4acbe
diff --git a/moli-core/tests/scripts.rs b/moli-core/tests/scripts.rs
index 29f5a2d89..fc9d8296f 100644
--- a/moli-core/tests/scripts.rs
+++ b/moli-core/tests/scripts.rs
@@ -5373,7 +5373,7 @@ async fn module_wasm_js_cycle_reports_guard_without_crashing() -> Result<()> {
.await?;
assert_eq!(
diagnostic_global(&page, "moduleWasmJsCycleConstructor"),
- Some(&JsValueSnapshot::String("Error".to_owned())),
+ Some(&JsValueSnapshot::String("TypeError".to_owned())),
"message: {:?}",
diagnostic_global(&page, "moduleWasmJsCycleMessage")
);
diff --git a/moli-renderer-v8/src/script_vm/native_module.rs b/moli-renderer-v8/src/script_vm/native_module.rs
index 6490a27fa..62fa727c5 100644
--- a/moli-renderer-v8/src/script_vm/native_module.rs
+++ b/moli-renderer-v8/src/script_vm/native_module.rs
@@ -1104,6 +1104,7 @@ fn script_error_constructor_kind_from_value(
let prototype = object.get_prototype(scope)?;
for candidate in [
ScriptErrorConstructorKind::SyntaxError,
+ ScriptErrorConstructorKind::TypeError,
ScriptErrorConstructorKind::WebAssemblyCompileError,
ScriptErrorConstructorKind::WebAssemblyLinkError,
ScriptErrorConstructorKind::Error,
diff --git a/moli-renderer-v8/src/script_vm/native_module/tests.rs b/moli-renderer-v8/src/script_vm/native_module/tests.rs
index f46a73a16..a3fe6ea74 100644
--- a/moli-renderer-v8/src/script_vm/native_module/tests.rs
+++ b/moli-renderer-v8/src/script_vm/native_module/tests.rs
@@ -28,6 +28,7 @@ use crate::network::ResourceRequestClient;
use crate::script_vm::{ScriptVm, ScriptVmDefaultWorldBootstrap, StandaloneScriptVmHarness};
use crate::types::{
ModuleGraphFetchCompletion, ModuleGraphFetchOrdering, ModuleGraphFetchRequester,
+ ScriptErrorConstructorKind,
};
use crate::util::v8str;
use moli_fetch::FetchConfig;
@@ -1660,3 +1661,24 @@ fn wasm_compile_with_options_does_not_use_page_webassembly_constructor() {
"{message}"
);
}
+
+#[test]
+fn native_module_errors_classify_caught_v8_type_errors() {
+ ensure_v8();
+ let mut isolate = v8::Isolate::new(v8::CreateParams::default());
+ let scope = pin!(v8::HandleScope::new(&mut isolate));
+ let scope = &mut scope.init();
+ let context = v8::Context::new(scope, Default::default());
+ let scope = &mut v8::ContextScope::new(scope, context);
+ let try_catch = pin!(v8::TryCatch::new(scope));
+ let mut scope = try_catch.init();
+ let source = v8str(&scope, "null.missing");
+ let script = v8::Script::compile(&scope, source, None).expect("valid script");
+ assert!(crate::script_execution::execute_compiled_script(&mut scope, script).is_none());
+ let exception = scope.exception().expect("V8 should throw a TypeError");
+ let caught_constructor = super::script_error_constructor_kind_from_value(&mut scope, exception);
+ assert_eq!(
+ caught_constructor,
+ Some(ScriptErrorConstructorKind::TypeError)
+ );
+}