Skip to content

armgit / moli

Public Imported from GitHub
0

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

fix(svg): expose unit and spread-method enumeration constants

ldm02ac735781b62
diff --git a/moli-renderer-v8/src/context_bootstrap/runtime_state.rs b/moli-renderer-v8/src/context_bootstrap/runtime_state.rs
index b1a84af0f..32c90bcbc 100644
--- a/moli-renderer-v8/src/context_bootstrap/runtime_state.rs
+++ b/moli-renderer-v8/src/context_bootstrap/runtime_state.rs
@@ -1728,6 +1728,7 @@ pub(crate) fn finish_context_bootstrap(
("SVGNumberList", "SVGNumberList"),
("SVGAnimatedNumberList", "SVGAnimatedNumberList"),
("SVGAnimatedEnumeration", "SVGAnimatedEnumeration"),
+ ("SVGUnitTypes", "SVGUnitTypes"),
("SVGAnimatedTransformList", "SVGAnimatedTransformList"),
("SVGTransformList", "SVGTransformList"),
("SVGTransform", "SVGTransform"),
diff --git a/moli-renderer-v8/src/context_bootstrap/specs/registry.rs b/moli-renderer-v8/src/context_bootstrap/specs/registry.rs
index 19634ac72..dc0f583b5 100644
--- a/moli-renderer-v8/src/context_bootstrap/specs/registry.rs
+++ b/moli-renderer-v8/src/context_bootstrap/specs/registry.rs
@@ -120,6 +120,10 @@ const CONSTRUCTOR_SPECS_BEFORE_STREAMS: &[ConstructorSpec] = &[
interface: web_api_interfaces::SVGAnimatedEnumeration::DESCRIPTOR,
kind: ConstructorKind::Illegal,
},
+ ConstructorSpec {
+ interface: web_api_interfaces::SVGUnitTypes::DESCRIPTOR,
+ kind: ConstructorKind::Illegal,
+ },
ConstructorSpec {
interface: web_api_interfaces::SVGAnimatedTransformList::DESCRIPTOR,
kind: ConstructorKind::Illegal,
diff --git a/moli-renderer-v8/src/context_bootstrap/svg_runtime/bindings.rs b/moli-renderer-v8/src/context_bootstrap/svg_runtime/bindings.rs
index c3060c7ed..1c08bf98d 100644
--- a/moli-renderer-v8/src/context_bootstrap/svg_runtime/bindings.rs
+++ b/moli-renderer-v8/src/context_bootstrap/svg_runtime/bindings.rs
@@ -433,6 +433,53 @@ struct SvgTextContentElementTemplateMethodsDeclaration {
select_sub_string: (),
}
+#[derive(WebApiFunctionTemplate)]
+#[webapi(interface = web_api_interfaces::SVGUnitTypes, enumerable)]
+struct SvgUnitTypesTemplateConstantsDeclaration {
+ #[webapi(constant = "SVG_UNIT_TYPE_UNKNOWN", value = SVG_UNIT_TYPE_UNKNOWN)]
+ unknown: (),
+
+ #[webapi(
+ constant = "SVG_UNIT_TYPE_USERSPACEONUSE",
+ value = SVG_UNIT_TYPE_USER_SPACE_ON_USE
+ )]
+ user_space_on_use: (),
+
+ #[webapi(
+ constant = "SVG_UNIT_TYPE_OBJECTBOUNDINGBOX",
+ value = SVG_UNIT_TYPE_OBJECT_BOUNDING_BOX
+ )]
+ object_bounding_box: (),
+}
+
+#[derive(WebApiFunctionTemplate)]
+#[webapi(interface = web_api_interfaces::SVGGradientElement, enumerable)]
+struct SvgGradientElementTemplateConstantsDeclaration {
+ #[webapi(
+ constant = "SVG_SPREADMETHOD_UNKNOWN",
+ value = SVG_SPREAD_METHOD_UNKNOWN
+ )]
+ spread_method_unknown: (),
+
+ #[webapi(
+ constant = "SVG_SPREADMETHOD_PAD",
+ value = SVG_SPREAD_METHOD_PAD
+ )]
+ spread_method_pad: (),
+
+ #[webapi(
+ constant = "SVG_SPREADMETHOD_REFLECT",
+ value = SVG_SPREAD_METHOD_REFLECT
+ )]
+ spread_method_reflect: (),
+
+ #[webapi(
+ constant = "SVG_SPREADMETHOD_REPEAT",
+ value = SVG_SPREAD_METHOD_REPEAT
+ )]
+ spread_method_repeat: (),
+}
+
#[derive(WebApiFunctionTemplate)]
#[webapi(interface = web_api_interfaces::SVGSVGElement, enumerable)]
struct SvgSvgElementTemplateMethodsDeclaration {
@@ -966,6 +1013,24 @@ pub(super) fn install_svg_animated_enumeration_bindings<'s>(
SvgAnimatedEnumerationTemplateAccessorsDeclaration::initialize_prototype_template(scope, proto);
}
+pub(super) fn install_svg_unit_types_bindings<'s>(
+ scope: &mut v8::PinScope<'s, '_, ()>,
+ template: v8::Local<'s, v8::FunctionTemplate>,
+) {
+ let prototype = template.prototype_template(scope);
+ SvgUnitTypesTemplateConstantsDeclaration::initialize_template(scope, template);
+ SvgUnitTypesTemplateConstantsDeclaration::initialize_prototype_template(scope, prototype);
+}
+
+pub(super) fn install_svg_gradient_element_bindings<'s>(
+ scope: &mut v8::PinScope<'s, '_, ()>,
+ template: v8::Local<'s, v8::FunctionTemplate>,
+) {
+ let prototype = template.prototype_template(scope);
+ SvgGradientElementTemplateConstantsDeclaration::initialize_template(scope, template);
+ SvgGradientElementTemplateConstantsDeclaration::initialize_prototype_template(scope, prototype);
+}
+
pub(super) fn install_svg_value_list_bindings<'s>(
scope: &mut v8::PinScope<'s, '_, ()>,
template: v8::Local<'s, v8::FunctionTemplate>,
diff --git a/moli-renderer-v8/src/context_bootstrap/svg_runtime/mod.rs b/moli-renderer-v8/src/context_bootstrap/svg_runtime/mod.rs
index 75b9b3ed6..63d786c49 100644
--- a/moli-renderer-v8/src/context_bootstrap/svg_runtime/mod.rs
+++ b/moli-renderer-v8/src/context_bootstrap/svg_runtime/mod.rs
@@ -240,6 +240,15 @@ const SVG_LENGTH_ADJUST_UNKNOWN: u32 = 0;
const SVG_LENGTH_ADJUST_SPACING: u32 = 1;
const SVG_LENGTH_ADJUST_SPACING_AND_GLYPHS: u32 = 2;
+const SVG_UNIT_TYPE_UNKNOWN: u32 = 0;
+const SVG_UNIT_TYPE_USER_SPACE_ON_USE: u32 = 1;
+const SVG_UNIT_TYPE_OBJECT_BOUNDING_BOX: u32 = 2;
+
+const SVG_SPREAD_METHOD_UNKNOWN: u32 = 0;
+const SVG_SPREAD_METHOD_PAD: u32 = 1;
+const SVG_SPREAD_METHOD_REFLECT: u32 = 2;
+const SVG_SPREAD_METHOD_REPEAT: u32 = 3;
+
pub(in crate::context_bootstrap) fn install_svg_template_bindings<'s>(
scope: &mut v8::PinScope<'s, '_, ()>,
template: v8::Local<'s, v8::FunctionTemplate>,
@@ -260,6 +269,8 @@ pub(in crate::context_bootstrap) fn install_svg_template_bindings<'s>(
"SVGAnimatedNumberList" => {
bindings::install_svg_animated_number_list_bindings(scope, template)
}
+ "SVGUnitTypes" => bindings::install_svg_unit_types_bindings(scope, template),
+ "SVGGradientElement" => bindings::install_svg_gradient_element_bindings(scope, template),
"SVGAnimatedEnumeration" => {
bindings::install_svg_animated_enumeration_bindings(scope, template)
}
diff --git a/moli-renderer-v8/src/script_vm/tests/dom_elements/live_document/geometry_and_svg.rs b/moli-renderer-v8/src/script_vm/tests/dom_elements/live_document/geometry_and_svg.rs
index ac9a199a6..1b2553246 100644
--- a/moli-renderer-v8/src/script_vm/tests/dom_elements/live_document/geometry_and_svg.rs
+++ b/moli-renderer-v8/src/script_vm/tests/dom_elements/live_document/geometry_and_svg.rs
@@ -1,5 +1,36 @@
use super::*;
+#[test]
+fn svg_enumeration_constants_have_webidl_descriptors() {
+ let mut vm = new_storage_test_vm("https://svg-enumeration-constants.test/");
+ let result = vm.eval(r#"
+(() => {
+ const assert = (condition, message) => { if (!condition) throw new Error(message); };
+ const groups = [
+ [SVGUnitTypes, [["SVG_UNIT_TYPE_UNKNOWN", 0], ["SVG_UNIT_TYPE_USERSPACEONUSE", 1], ["SVG_UNIT_TYPE_OBJECTBOUNDINGBOX", 2]]],
+ [SVGGradientElement, [["SVG_SPREADMETHOD_UNKNOWN", 0], ["SVG_SPREADMETHOD_PAD", 1], ["SVG_SPREADMETHOD_REFLECT", 2], ["SVG_SPREADMETHOD_REPEAT", 3]]],
+ ];
+ for (const [constructor, constants] of groups) {
+ for (const owner of [constructor, constructor.prototype]) {
+ for (const [name, value] of constants) {
+ const descriptor = Object.getOwnPropertyDescriptor(owner, name);
+ assert(descriptor && descriptor.value === value, name + " value");
+ assert(descriptor.enumerable && !descriptor.configurable && !descriptor.writable, name + " descriptor");
+ }
+ }
+ let caught;
+ try { new constructor(); } catch (error) { caught = error; }
+ assert(caught instanceof TypeError, constructor.name + " illegal constructor");
+ }
+ const gradient = document.createElementNS("http://www.w3.org/2000/svg", "linearGradient");
+ assert(gradient.SVG_SPREADMETHOD_REPEAT === 3, "gradient inherits constants");
+ assert(SVGLinearGradientElement.SVG_SPREADMETHOD_REPEAT === 3, "constructor inherits constants");
+ return "ok";
+})()
+"#).expect("SVG enumeration constants should use WebIDL descriptors");
+ assert_eq!(result, "ok");
+}
+
#[test]
fn svg_specialized_accessors_live_on_owner_prototypes() {
let mut vm = new_parsed_test_vm(
diff --git a/moli-renderer-v8/src/web_api_interfaces.rs b/moli-renderer-v8/src/web_api_interfaces.rs
index bdecde040..b06bba0a1 100644
--- a/moli-renderer-v8/src/web_api_interfaces.rs
+++ b/moli-renderer-v8/src/web_api_interfaces.rs
@@ -366,6 +366,7 @@ interfaces! {
Response;
SVGAElement: SVGGraphicsElement;
SVGAnimatedEnumeration;
+ SVGUnitTypes;
SVGAnimatedLength;
SVGAnimatedLengthList;
SVGAnimatedNumber;