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(svg): brand filter and marker getters and retain owner identity
ldm03fc2e28f7d5e
diff --git a/moli-renderer-v8/src/context_bootstrap/svg_runtime/bindings.rs b/moli-renderer-v8/src/context_bootstrap/svg_runtime/bindings.rsindex eebb206eb..9c7906668 100644--- a/moli-renderer-v8/src/context_bootstrap/svg_runtime/bindings.rs+++ b/moli-renderer-v8/src/context_bootstrap/svg_runtime/bindings.rs@@ -1746,7 +1746,7 @@ struct SvgClipPathElementPrototypeAccessorsDeclaration {}#[derive(WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::SVGFilterElement, enumerable)]+#[webapi(interface = web_api_interfaces::SVGFilterElement, enumerable, receiver)]struct SvgFilterElementPrototypeAccessorsDeclaration {#[webapi(accessor_property = "x", getter = svg_filter_animated_length_getter, data = callback_data_index_value(scope, 0))]x: (),@@ -2076,7 +2076,7 @@ struct SvgGraphicsBoxElementPrototypeAccessorsDeclaration {}#[derive(WebApiFunctionTemplate)]-#[webapi(interface = web_api_interfaces::SVGMarkerElement, enumerable)]+#[webapi(interface = web_api_interfaces::SVGMarkerElement, enumerable, receiver)]struct SvgMarkerElementPrototypeAccessorsDeclaration {#[webapi(accessor_property = "refX", getter = svg_marker_animated_length_getter, data = callback_data_index_value(scope, 0))]ref_x: (),diff --git a/moli-renderer-v8/src/context_bootstrap/svg_runtime/callbacks.rs b/moli-renderer-v8/src/context_bootstrap/svg_runtime/callbacks.rsindex 2b57da172..55576f037 100644--- a/moli-renderer-v8/src/context_bootstrap/svg_runtime/callbacks.rs+++ b/moli-renderer-v8/src/context_bootstrap/svg_runtime/callbacks.rs@@ -632,6 +632,14 @@ fn svg_animated_length_attribute_getter<'s>(name: &'static str,initial_value: &'static str,) {+ let Some(owner) = moli_webapi_declare::web_api_object_target(scope, owner) else {+ return;+ };+ let Some(context) = owner.get_creation_context(scope) else {+ return;+ };+ // Registered native Proxies share their target's cache and producer realm.+ let scope = &mut v8::ContextScope::new(scope, context);let slot = svg_animated_length_attribute_slot(name);if let Some(value) = get_private_value(scope, owner, slot) {if let Ok(object) = v8::Local::<v8::Object>::try_from(value) {@@ -688,10 +696,16 @@ pub(super) fn svg_marker_orient_angle_getter<'s>(args: v8::FunctionCallbackArguments<'s>,mut rv: v8::ReturnValue<'_, v8::Value>,) {- let owner = args.this();+ let Some(owner) = moli_webapi_declare::web_api_object_target(scope, args.this()) else {+ return;+ };if svg_marker_runtime_and_handle(scope, owner, "orientAngle").is_none() {return;}+ let Some(context) = owner.get_creation_context(scope) else {+ return;+ };+ let scope = &mut v8::ContextScope::new(scope, context);if let Some(value) = get_private_value(scope, owner, SVG_MARKER_ORIENT_ANGLE_SLOT) {if let Ok(animated) = v8::Local::<v8::Object>::try_from(value) {sync_svg_animated_angle_from_owner_attribute(scope, animated, owner, "orient");@@ -956,7 +970,13 @@ pub(super) fn svg_element_animated_enumeration_getter<'s>(rv.set_undefined();return;};- let holder = args.this();+ let Some(holder) = moli_webapi_declare::web_api_object_target(scope, args.this()) else {+ return;+ };+ let Some(context) = holder.get_creation_context(scope) else {+ return;+ };+ let scope = &mut v8::ContextScope::new(scope, context);if let Some(value) = get_private_value(scope, holder, property.cache_slot) {if let Ok(animated) = v8::Local::<v8::Object>::try_from(value) {sync_svg_animated_enumeration_from_owner_attribute(scope, animated);diff --git a/moli-renderer-v8/src/script_vm/tests/svg_filter_interfaces.rs b/moli-renderer-v8/src/script_vm/tests/svg_filter_interfaces.rsindex 9b8eaefba..4cc8208b8 100644--- a/moli-renderer-v8/src/script_vm/tests/svg_filter_interfaces.rs+++ b/moli-renderer-v8/src/script_vm/tests/svg_filter_interfaces.rs@@ -46,3 +46,86 @@ fn svg_filter_interfaces_preserve_native_inheritance_and_realm_contracts() {return true;})()"#).unwrap(), "true");}++#[test]+fn svg_filter_and_marker_getters_validate_native_receivers() {+ let mut vm =+ new_storage_page_task_executor_test_vm("https://svg-filter-marker-receivers.test/");+ vm.eval("document.body.innerHTML = '<iframe></iframe>'")+ .unwrap();+ vm.eval(include_str!("svg_filter_marker_receivers.js"))+ .unwrap();+ assert_eq!(vm.eval("__uiEventResults.complete").unwrap(), "true");+ assert_eq!(vm.eval("__uiEventResults.total").unwrap(), "1872");+ assert_eq!(+ vm.eval("JSON.stringify(__uiEventResults.checks.filter(row => !row.passed))")+ .unwrap(),+ "[]"+ );+}++#[test]+fn svg_filter_and_marker_getters_accept_registered_native_proxies() {+ let mut vm = new_storage_page_task_executor_test_vm("https://svg-filter-marker-proxies.test/");+ vm.eval(+ r#"+ document.body.innerHTML = '<iframe></iframe>';+ globalThis.childWindow = document.querySelector('iframe').contentWindow;+ globalThis.foreignFilter = childWindow.document.createElementNS('http://www.w3.org/2000/svg', 'filter');+ globalThis.foreignMarker = childWindow.document.createElementNS('http://www.w3.org/2000/svg', 'marker');+ "#,+ )+ .unwrap();+ let context_ptr = &vm.page_default_context as *const _;+ vm.with_context_scope_by_ptr_and_checkpoint_for_test(context_ptr, |scope, _| {+ let global = scope.get_current_context().global(scope);+ for (name, proxy_name) in [+ ("foreignFilter", "nativeFilterProxy"),+ ("foreignMarker", "nativeMarkerProxy"),+ ] {+ let key = crate::util::v8str(scope, name);+ let object = global.get(scope, key.into()).unwrap();+ let object = v8::Local::<v8::Object>::try_from(object).unwrap();+ let handler = crate::util::new_null_prototype_object(scope);+ let proxy = v8::Proxy::new(scope, object, handler).unwrap();+ moli_webapi_declare::register_web_api_proxy(scope, proxy).unwrap();+ let key = crate::util::v8str(scope, proxy_name);+ assert_eq!(+ global.create_data_property(scope, key.into(), proxy.into()),+ Some(true)+ );+ }+ Ok(())+ })+ .unwrap();+ assert_eq!(+ vm.eval(+ r#"(() => {+ for (const [name, element, native, properties] of [+ ['SVGFilterElement', foreignFilter, nativeFilterProxy, ['x','y','width','height','filterUnits','primitiveUnits']],+ ['SVGMarkerElement', foreignMarker, nativeMarkerProxy, ['refX','refY','markerWidth','markerHeight','markerUnits','orientType','orientAngle']],+ ]) {+ let traps = 0;+ const author = new Proxy(native, {get() {traps++;throw 42;}, getPrototypeOf() {traps++;throw 42;}});+ const revoked = Proxy.revocable(native, {}); revoked.revoke();+ for (const property of properties) {+ const getter = Object.getOwnPropertyDescriptor(window[name].prototype, property).get;+ const value = getter.call(native);+ if (value !== element[property] || value !== getter.call(element) ||+ Object.getPrototypeOf(value) !== childWindow[value.constructor.name].prototype) {+ throw Error(name + '.' + property + ' native proxy state/realm');+ }+ for (const receiver of [author, revoked.proxy, Object.create(native)]) {+ let error;+ try {getter.call(receiver);} catch (caught) {error = caught;}+ if (!(error instanceof TypeError) || traps !== 0) throw Error(property + ' author proxy accepted');+ }+ }+ }+ return true;+ })()"#,+ )+ .unwrap(),+ "true"+ );+}diff --git a/moli-renderer-v8/src/script_vm/tests/svg_filter_marker_receivers.js b/moli-renderer-v8/src/script_vm/tests/svg_filter_marker_receivers.jsnew file mode 100644index 000000000..70fda0b2b--- /dev/null+++ b/moli-renderer-v8/src/script_vm/tests/svg_filter_marker_receivers.js@@ -0,0 +1,87 @@+(() => {+ const checks = [];+ const check = (name, callback) => {+ try { checks.push({name, passed: callback() === true}); }+ catch (error) { checks.push({name, passed: false, error: String(error)}); }+ };+ const invoke = (getter, receiver) => Reflect.apply(getter, receiver, []);+ const typeError = (getter, receiver, realm) => {+ try { invoke(getter, receiver); }+ catch (error) { return error instanceof realm.TypeError; }+ return false;+ };+ const ns = 'http://www.w3.org/2000/svg';+ const child = document.querySelector('iframe').contentWindow;+ const definitions = [+ ['filter', 'SVGFilterElement', [+ ['x', 'SVGAnimatedLength'], ['y', 'SVGAnimatedLength'],+ ['width', 'SVGAnimatedLength'], ['height', 'SVGAnimatedLength'],+ ['filterUnits', 'SVGAnimatedEnumeration'], ['primitiveUnits', 'SVGAnimatedEnumeration'],+ ]],+ ['marker', 'SVGMarkerElement', [+ ['refX', 'SVGAnimatedLength'], ['refY', 'SVGAnimatedLength'],+ ['markerWidth', 'SVGAnimatedLength'], ['markerHeight', 'SVGAnimatedLength'],+ ['markerUnits', 'SVGAnimatedEnumeration'], ['orientType', 'SVGAnimatedEnumeration'],+ ['orientAngle', 'SVGAnimatedAngle'],+ ]],+ ];+ for (const [world, realm] of [['main', globalThis], ['child', child]]) {+ for (const [documentKind, doc] of [+ ['live', realm.document],+ ['windowless-html', realm.document.implementation.createHTMLDocument('')],+ ['windowless-xml', new realm.DOMParser().parseFromString('<root/>', 'application/xml')],+ ]) {+ for (const [tag, name, properties] of definitions) {+ const proto = realm[name].prototype;+ const make = () => doc.createElementNS(ns, tag);+ for (const [property, type] of properties) {+ const prefix = `${world}/${documentKind}/${tag}/${property}`;+ const descriptor = Object.getOwnPropertyDescriptor(proto, property);+ const getter = descriptor.get;+ const real = make();+ const value = real[property];+ check(prefix + '/readonly-descriptor', () => typeof getter === 'function' &&+ descriptor.set === undefined && descriptor.enumerable && descriptor.configurable);+ check(prefix + '/function-realm', () => Object.getPrototypeOf(getter) === realm.Function.prototype);+ check(prefix + '/valid-native-receiver', () => invoke(getter, real) === value && value instanceof realm[type]);+ check(prefix + '/stable-tear-off', () => invoke(getter, real) === invoke(getter, real));+ check(prefix + '/clone', () => invoke(getter, real.cloneNode(false)) instanceof realm[type]);+ check(prefix + '/import', () => invoke(getter, doc.importNode(real, false)) instanceof realm[type]);+ check(prefix + '/bypass-author-property', () => {+ const element = make(), original = element[property]; let reads = 0;+ Object.defineProperty(element, property, {get() { reads++; throw 42; }});+ return invoke(getter, element) === original && reads === 0;+ });+ const other = realm === globalThis ? child : globalThis;+ const foreign = Object.getOwnPropertyDescriptor(other[name].prototype, property).get;+ check(prefix + '/borrowed-foreign-getter', () => invoke(foreign, real) === value);+ check(prefix + '/foreign-error-realm', () => typeError(foreign, {}, other));+ const revoked = Proxy.revocable(real, {}); revoked.revoke();+ let traps = 0;+ const author = new Proxy(real, {+ get() { traps++; throw 42; },+ getPrototypeOf() { traps++; throw 42; },+ has() { traps++; throw 42; },+ });+ const wrong = doc.createElementNS(ns, tag === 'filter' ? 'marker' : 'filter');+ Object.setPrototypeOf(wrong, proto);+ for (const [label, receiver] of [+ ['undefined', undefined], ['null', null], ['boolean', true], ['number', 42],+ ['symbol', Symbol('receiver')], ['plain', {}], ['interface-prototype', proto],+ ['forged-prototype', Object.create(proto)], ['inherit-real', Object.create(real)],+ ['author-proxy', author], ['revoked-proxy', revoked.proxy],+ ['wrong-svg', doc.createElementNS(ns, tag === 'filter' ? 'marker' : 'filter')],+ ['html-namespace', doc.createElementNS('http://www.w3.org/1999/xhtml', tag)],+ ['prototype-swapped-wrong-svg', wrong],+ ]) {+ check(prefix + '/receiver/' + label, () => typeError(getter, receiver, realm) && traps === 0);+ }+ check(prefix + '/retained-value-after-invalid-calls', () => real[property] === value);+ }+ }+ }+ }+ globalThis.__uiEventResults = {complete: true, total: checks.length,+ passed: checks.filter(row => row.passed).length, checks};+ return true;+})()