Skip to content

armgit / moli

Public Imported from GitHub
0

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

fix(v8): handle non-string function names

ldm02bead097731a
diff --git a/moli-renderer-v8/src/host/events.rs b/moli-renderer-v8/src/host/events.rs
index 1329e92b2..1f58c3af6 100644
--- a/moli-renderer-v8/src/host/events.rs
+++ b/moli-renderer-v8/src/host/events.rs
@@ -673,7 +673,9 @@ impl HostEventTargetRegistry {
scope: &mut v8::PinScope<'_, '_>,
listener: v8::Local<'_, v8::Function>,
) -> (String, i32, Option<String>, Option<u32>, Option<u32>) {
- let function_name = listener.get_name(scope).to_rust_string_lossy(scope);
+ let function_name = v8::Local::<v8::String>::try_from(listener.get_name(scope))
+ .map(|name| name.to_rust_string_lossy(scope))
+ .unwrap_or_default();
let script_id = listener.script_id();
let script_url = listener
.get_script_origin()
diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/events_selection_storage.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/events_selection_storage.rs
index 4ff383b30..ae429d04c 100644
--- a/moli-renderer-v8/src/script_vm/tests/browser_api/events_selection_storage.rs
+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/events_selection_storage.rs
@@ -939,6 +939,34 @@ fn event_dispatch_internal_flags_are_not_script_writable() {
);
}
+#[test]
+fn callable_proxy_event_listener_does_not_require_a_string_function_name() {
+ let mut vm = new_storage_test_vm("https://callable-proxy-event-listener.test/");
+
+ let result = vm
+ .eval(
+ r#"
+ (() => {
+ const target = document.createElement("div");
+ const calls = [];
+ const listener = new Proxy(function(event) {
+ calls.push(event.type);
+ }, {});
+
+ target.addEventListener("probe", listener);
+ target.dispatchEvent(new Event("probe"));
+ target.removeEventListener("probe", listener);
+ target.dispatchEvent(new Event("probe"));
+
+ return `${typeof listener}:${calls.join(",")}`;
+ })()
+ "#,
+ )
+ .expect("callable Proxy listener should register and dispatch");
+
+ assert_eq!(result, "function:probe");
+}
+
#[test]
fn document_level_scroll_blocking_listeners_default_to_passive() {
let mut vm = new_storage_test_vm("https://default-passive-events.test/");
diff --git a/vendor/v8-146.9.0/src/function.rs b/vendor/v8-146.9.0/src/function.rs
index be5f87d76..3b4a6f1a7 100644
--- a/vendor/v8-146.9.0/src/function.rs
+++ b/vendor/v8-146.9.0/src/function.rs
@@ -53,7 +53,7 @@ unsafe extern "C" {
argc: int,
argv: *const *const Value,
) -> *const Object;
- fn v8__Function__GetName(this: *const Function) -> *const String;
+ fn v8__Function__GetName(this: *const Function) -> *const Value;
fn v8__Function__SetName(this: *const Function, name: *const String);
fn v8__Function__GetScriptColumnNumber(this: *const Function) -> int;
fn v8__Function__GetScriptLineNumber(this: *const Function) -> int;
@@ -1012,7 +1012,7 @@ impl Function {
}
#[inline(always)]
- pub fn get_name<'s>(&self, scope: &PinScope<'s, '_>) -> Local<'s, String> {
+ pub fn get_name<'s>(&self, scope: &PinScope<'s, '_>) -> Local<'s, Value> {
unsafe { scope.cast_local(|_| v8__Function__GetName(self)).unwrap() }
}