diff --git a/moli-renderer-v8/src/script_vm/tests/webidl_fetch/byte_streams_and_observers.rs b/moli-renderer-v8/src/script_vm/tests/webidl_fetch/byte_streams_and_observers.rs index 2de1cc8dc0c..46e67eab887 100644 --- a/moli-renderer-v8/src/script_vm/tests/webidl_fetch/byte_streams_and_observers.rs +++ b/moli-renderer-v8/src/script_vm/tests/webidl_fetch/byte_streams_and_observers.rs @@ -2192,3 +2192,46 @@ fn intersection_observer_validates_thresholds_after_dictionary_conversion() { .expect("IntersectionObserver should separate conversion from threshold validation"); assert_eq!(result, "ok"); } + +#[test] +fn intersection_observer_margins_follow_css_token_syntax() { + let mut vm = new_storage_test_vm("https://intersection-observer-margin-tokens.test/"); + let result = vm + .eval( + r#" +(() => { + const check = (condition, label) => { if (!condition) throw new Error(label); }; + for (const member of ['rootMargin', 'scrollMargin']) { + for (const value of [0, '0', '+0', '-0', '0.0', '0e0', '1e-50', '1px 0', '0% 0 1px', + '\u00a0', '\u2003', '\u000b', '\u0085', '\u2028', '\u2029', + '()', '[]', '{}', ')', ']', '}']) { + let caught; + try { new IntersectionObserver(() => {}, {[member]: value}); } + catch (error) { caught = error; } + check(caught instanceof DOMException && caught.name === 'SyntaxError', + member + ': ' + JSON.stringify(value) + ' must throw SyntaxError'); + } + for (const value of ['', ' \t\r\n\f', '/**/', '/**/ /**/', '/* unclosed', ' /**/ \n /**/ ']) { + const observer = new IntersectionObserver(() => {}, {[member]: value}); + check(observer[member] === '0px 0px 0px 0px', + member + ': ' + JSON.stringify(value) + ' must normalize to zero margins'); + observer.disconnect(); + } + for (const [value, expected] of [ + ['1PX /* comment */ 2%', '1px 2% 1px 2%'], + ['1px/**/2%', '1px 2% 1px 2%'], + ['1\\70x', '1px 1px 1px 1px'], + ['1px 2% 3px 4%', '1px 2% 3px 4%'] + ]) { + const observer = new IntersectionObserver(() => {}, {[member]: value}); + check(observer[member] === expected, member + ': ' + JSON.stringify(value)); + observer.disconnect(); + } + } + return 'ok'; +})() +"#, + ) + .expect("IntersectionObserver margins should use CSS token syntax"); + assert_eq!(result, "ok"); +}