Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
fix(modules): report invalid import types as TypeError
ldm052e84d5fec8a
diff --git a/moli-module-script-tree/src/types.rs b/moli-module-script-tree/src/types.rsindex 44ee6ed5b..f78993866 100644--- a/moli-module-script-tree/src/types.rs+++ b/moli-module-script-tree/src/types.rs@@ -552,6 +552,7 @@ impl ModuleLoadError {#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]pub enum ModuleErrorConstructorKind {SyntaxError,+ TypeError,}#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]diff --git a/moli-renderer-v8/src/module_runtime/graph.rs b/moli-renderer-v8/src/module_runtime/graph.rsindex af76ccca8..6a28a08c4 100644--- a/moli-renderer-v8/src/module_runtime/graph.rs+++ b/moli-renderer-v8/src/module_runtime/graph.rs@@ -1327,6 +1327,7 @@ impl<O: NativeModuleTreeDocumentOwnerAdapter> module_tree::ModuleScriptTreeHostmodule_tree::ModuleLoadStage::Resolve,format!("{message} for import `{specifier}`"),)+ .with_error_constructor(module_tree::ModuleErrorConstructorKind::TypeError)},)?;if requested_phase == module_tree::ModuleImportPhase::Source@@ -1865,9 +1866,19 @@ fn local_graph(graph: module_tree::ModuleGraphHandle) -> ModuleGraphHandle {fn chromium_error(error: ModuleLoadError) -> module_tree::ModuleLoadError {let mut converted =module_tree::ModuleLoadError::new(chromium_load_stage(error.stage()), error.message());- if error.error_constructor() == Some(ScriptErrorConstructorKind::SyntaxError) {- converted =- converted.with_error_constructor(module_tree::ModuleErrorConstructorKind::SyntaxError);+ if let Some(constructor) = error.error_constructor() {+ let constructor = match constructor {+ ScriptErrorConstructorKind::SyntaxError => {+ module_tree::ModuleErrorConstructorKind::SyntaxError+ }+ ScriptErrorConstructorKind::TypeError => {+ module_tree::ModuleErrorConstructorKind::TypeError+ }+ ScriptErrorConstructorKind::Error+ | ScriptErrorConstructorKind::WebAssemblyCompileError+ | ScriptErrorConstructorKind::WebAssemblyLinkError => return converted,+ };+ converted = converted.with_error_constructor(constructor);}converted}@@ -1887,6 +1898,7 @@ fn local_error_constructor(module_tree::ModuleErrorConstructorKind::SyntaxError => {ScriptErrorConstructorKind::SyntaxError}+ module_tree::ModuleErrorConstructorKind::TypeError => ScriptErrorConstructorKind::TypeError,}}@@ -1985,6 +1997,7 @@ fn module_key_for_root(ModuleLoadStage::Resolve,format!("{message} for module `{}`", root.source_url),)+ .with_error_constructor(ScriptErrorConstructorKind::TypeError)})?;validate_source_phase_key(root.phase, &key, "module", root.source_url.as_str())?;Ok(key)@@ -3389,6 +3402,10 @@ import "./c.mjs";};assert_eq!(error.stage(), ModuleLoadStage::Resolve);+ assert_eq!(+ error.error_constructor(),+ Some(ScriptErrorConstructorKind::TypeError)+ );assert!(error.message()diff --git a/moli-renderer-v8/src/script_vm/native_module.rs b/moli-renderer-v8/src/script_vm/native_module.rsindex e93e76b80..03746eb7e 100644--- a/moli-renderer-v8/src/script_vm/native_module.rs+++ b/moli-renderer-v8/src/script_vm/native_module.rs@@ -4896,6 +4896,7 @@ fn script_error_value<'s>(ScriptErrorConstructorKind::SyntaxError => {Some(v8::Exception::syntax_error(scope, message))}+ ScriptErrorConstructorKind::TypeError => Some(v8::Exception::type_error(scope, message)),ScriptErrorConstructorKind::WebAssemblyCompileError => {captured_webassembly_error_constructor(scope,@@ -4923,6 +4924,7 @@ fn script_error_prototype<'s>(let error = match constructor_kind {ScriptErrorConstructorKind::Error => v8::Exception::error(scope, empty),ScriptErrorConstructorKind::SyntaxError => v8::Exception::syntax_error(scope, empty),+ ScriptErrorConstructorKind::TypeError => v8::Exception::type_error(scope, empty),ScriptErrorConstructorKind::WebAssemblyCompileError => {let constructor = captured_webassembly_error_constructor(scope,diff --git a/moli-renderer-v8/src/script_vm/script_event_body.rs b/moli-renderer-v8/src/script_vm/script_event_body.rsindex f21239261..34d28ea97 100644--- a/moli-renderer-v8/src/script_vm/script_event_body.rs+++ b/moli-renderer-v8/src/script_vm/script_event_body.rs@@ -143,6 +143,9 @@ fn window_script_failure_error_value<'s>(Some(crate::types::ScriptErrorConstructorKind::SyntaxError) => {v8::Exception::syntax_error(scope, message)}+ Some(crate::types::ScriptErrorConstructorKind::TypeError) => {+ v8::Exception::type_error(scope, message)+ }_ => v8::Exception::error(scope, message),})}diff --git a/moli-renderer-v8/src/types.rs b/moli-renderer-v8/src/types.rsindex d84e2c503..4b9df985e 100644--- a/moli-renderer-v8/src/types.rs+++ b/moli-renderer-v8/src/types.rs@@ -32,6 +32,7 @@ impl std::fmt::Display for DedicatedWorkerId {pub(crate) enum ScriptErrorConstructorKind {Error,SyntaxError,+ TypeError,WebAssemblyCompileError,WebAssemblyLinkError,}