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(html): reflect null body colors as empty strings
ldm0c577f54e323a
diff --git a/moli-renderer-v8/src/native_bridge/element/base_prototypes.rs b/moli-renderer-v8/src/native_bridge/element/base_prototypes.rsindex abd664cfd..826b8d577 100644--- a/moli-renderer-v8/src/native_bridge/element/base_prototypes.rs+++ b/moli-renderer-v8/src/native_bridge/element/base_prototypes.rs@@ -1167,7 +1167,7 @@ pub(super) struct HtmlBodyOrFrameSetEventHandlersPrototypeDeclaration {}#[derive(WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::HTMLBodyElement, enumerable)]+#[webapi(interface = web_api_interfaces::HTMLBodyElement, enumerable, receiver)]pub(super) struct HtmlBodyElementLegacyPrototypeDeclaration {#[webapi(accessor_property,diff --git a/moli-renderer-v8/src/native_bridge/element/global_attributes.rs b/moli-renderer-v8/src/native_bridge/element/global_attributes.rsindex 4c3ecf46b..a808d7c71 100644--- a/moli-renderer-v8/src/native_bridge/element/global_attributes.rs+++ b/moli-renderer-v8/src/native_bridge/element/global_attributes.rs@@ -16,7 +16,8 @@ use super::super::{use super::details_dialog::main_summary_child;use super::reflection::{DomStringReflection, ElementReflectionInterface, NullToEmptyDomStringReflection,- UnsignedLongReflection, UsvStringReflection, remove_reflected_attribute,+ UnsignedLongReflection, UsvStringReflection, element_reflection_receiver_or_throw,+ remove_reflected_attribute,};use super::{attribute_property_getter_from_object_or_detached,@@ -1081,7 +1082,7 @@ pub(in crate::native_bridge) fn node_sandbox_setter_function<'s>(rv.set_undefined();}-fn set_dom_string_treat_null_as_empty_on_object<'s>(+pub(super) fn set_dom_string_treat_null_as_empty_on_object<'s>(scope: &mut v8::PinScope<'s, '_>,object: v8::Local<'s, v8::Object>,attribute: &str,@@ -1089,6 +1090,9 @@ fn set_dom_string_treat_null_as_empty_on_object<'s>(owner: &'static str,property: &'static str,) {+ let Some((runtime_ptr, handle)) = element_reflection_receiver_or_throw(scope, object) else {+ return;+ };let options = webidl::StringOptions {treat_null_as_empty_string: true,};@@ -1104,10 +1108,6 @@ fn set_dom_string_treat_null_as_empty_on_object<'s>(return;}};- let Ok((runtime_ptr, handle)) = node_runtime_and_handle_from_object_or_detached(scope, object)- else {- return;- };set_reflected_attribute(scope, runtime_ptr, handle, attribute, &value);}diff --git a/moli-renderer-v8/src/native_bridge/element/html_elements/misc.rs b/moli-renderer-v8/src/native_bridge/element/html_elements/misc.rsindex 17b9950e6..0a23e2e5d 100644--- a/moli-renderer-v8/src/native_bridge/element/html_elements/misc.rs+++ b/moli-renderer-v8/src/native_bridge/element/html_elements/misc.rs@@ -1,3 +1,4 @@+use super::super::global_attributes::set_dom_string_treat_null_as_empty_on_object;use super::super::{attribute_property_getter_from_object_or_detached, element_attribute,html_element_getter_receiver, html_element_setter_receiver, property_dom_string_value,@@ -82,7 +83,8 @@ macro_rules! body_attr_reflection {$getter:ident,$setter:ident,$attr_name:expr,- $idl_name:expr $(,)?+ $idl_name:expr,+ $set_attribute:ident $(,)?) => {pub(in crate::native_bridge::element) fn $getter<'s>(scope: &mut v8::PinScope<'s, '_>,@@ -97,7 +99,7 @@ macro_rules! body_attr_reflection {args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'s, v8::Value>,) {- set_dom_string_attribute_property_on_object(+ $set_attribute(scope,args.this(),$attr_name,@@ -114,29 +116,34 @@ body_attr_reflection!(body_text_getter_function,body_text_setter_function,"text",- "text"+ "text",+ set_dom_string_treat_null_as_empty_on_object);body_attr_reflection!(body_link_getter_function,body_link_setter_function,"link",- "link"+ "link",+ set_dom_string_treat_null_as_empty_on_object);body_attr_reflection!(body_v_link_getter_function,body_v_link_setter_function,"vlink",- "vLink"+ "vLink",+ set_dom_string_treat_null_as_empty_on_object);body_attr_reflection!(body_a_link_getter_function,body_a_link_setter_function,"alink",- "aLink"+ "aLink",+ set_dom_string_treat_null_as_empty_on_object);body_attr_reflection!(body_background_getter_function,body_background_setter_function,"background",- "background"+ "background",+ set_dom_string_attribute_property_on_object);diff --git a/moli-renderer-v8/src/native_bridge/element/reflection.rs b/moli-renderer-v8/src/native_bridge/element/reflection.rsindex 150309bd3..82b95ecda 100644--- a/moli-renderer-v8/src/native_bridge/element/reflection.rs+++ b/moli-renderer-v8/src/native_bridge/element/reflection.rs@@ -1268,7 +1268,7 @@ pub(super) fn nullable_attribute_property_getter_from_object_or_detached<'s>(rv.set(value.into());}-fn element_reflection_receiver_or_throw<'s>(+pub(super) fn element_reflection_receiver_or_throw<'s>(scope: &mut v8::PinScope<'s, '_>,object: v8::Local<'s, v8::Object>,) -> Option<(*mut super::super::JsContextHost, DomHandle)> {diff --git a/moli-renderer-v8/src/script_vm/tests/dom_elements/detached/document_lifecycle_and_adoption.rs b/moli-renderer-v8/src/script_vm/tests/dom_elements/detached/document_lifecycle_and_adoption.rsindex 7677ec644..5fc2765e1 100644--- a/moli-renderer-v8/src/script_vm/tests/dom_elements/detached/document_lifecycle_and_adoption.rs+++ b/moli-renderer-v8/src/script_vm/tests/dom_elements/detached/document_lifecycle_and_adoption.rs@@ -792,3 +792,52 @@ fn detached_iframe_windows_do_not_change_document_visibility() {assert_eq!(result, "[]");}++#[test]+fn body_legacy_colors_treat_null_as_empty_before_reflection() {+ let mut vm = new_parsed_test_vm(+ "https://body-color-null-reflection.test/",+ "<!doctype html><body></body>",+ );+ let result = vm+ .eval(+ r#"+(() => {+ const assert = (condition, message) => {+ if (!condition) throw new Error(message);+ };+ const detachedDocument = document.implementation.createHTMLDocument("");+ for (const body of [document.body, document.createElement("body"), detachedDocument.body]) {+ for (const name of ["text", "link", "vLink", "aLink", "bgColor"]) {+ const attribute = name.toLowerCase();+ body[name] = null;+ assert(body[name] === "" && body.getAttribute(attribute) === "", `${name}: null`);+ body[name] = undefined;+ assert(body[name] === "undefined", `${name}: undefined`);+ let conversions = 0;+ body[name] = {toString() { conversions++; return "red"; }};+ assert(conversions === 1 && body.getAttribute(attribute) === "red", `${name}: conversion`);+ const failure = new Error("conversion failure");+ let caught;+ try { body[name] = {toString() {throw failure; }}; } catch (error) { caught = error; }+ assert(caught === failure && body[name] === "red", `${name}: exception`);+ const setter = Object.getOwnPropertyDescriptor(HTMLBodyElement.prototype, name).set;+ for (const invalid of [{}, document.createElement("div"), Object.create(body), new Proxy(body, {})]) {+ conversions = 0;+ caught = undefined;+ try {+ setter.call(invalid, {toString() {conversions++; return "blue"; }});+ } catch (error) { caught = error; }+ assert(caught instanceof TypeError && conversions === 0, `${name}: receiver before conversion`);+ }+ }+ body.background = null;+ assert(body.getAttribute("background") === "null", "background uses ordinary DOMString conversion");+ }+ return "ok";+})()+"#,+ )+ .expect("legacy body colors should preserve WebIDL conversion semantics");+ assert_eq!(result, "ok");+}