diff --git a/Cargo.lock b/Cargo.lock index 503436c6c13..bf25824abc8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5690,7 +5690,7 @@ dependencies = [ [[package]] name = "selectors" version = "0.41.0" -source = "git+https://github.com/lexmount/stylo?rev=ff564f4f1f632fd4565b116a46082b3be96c5af9#ff564f4f1f632fd4565b116a46082b3be96c5af9" +source = "git+https://github.com/lexmount/stylo?rev=b9ee834de357f32efeff0b1bce3e243253efb7b3#b9ee834de357f32efeff0b1bce3e243253efb7b3" dependencies = [ "bitflags", "cssparser", @@ -5820,7 +5820,7 @@ dependencies = [ [[package]] name = "servo_arc" version = "0.5.0" -source = "git+https://github.com/lexmount/stylo?rev=ff564f4f1f632fd4565b116a46082b3be96c5af9#ff564f4f1f632fd4565b116a46082b3be96c5af9" +source = "git+https://github.com/lexmount/stylo?rev=b9ee834de357f32efeff0b1bce3e243253efb7b3#b9ee834de357f32efeff0b1bce3e243253efb7b3" dependencies = [ "serde", "stable_deref_trait", @@ -6191,7 +6191,7 @@ dependencies = [ [[package]] name = "stylo" version = "0.22.0" -source = "git+https://github.com/lexmount/stylo?rev=ff564f4f1f632fd4565b116a46082b3be96c5af9#ff564f4f1f632fd4565b116a46082b3be96c5af9" +source = "git+https://github.com/lexmount/stylo?rev=b9ee834de357f32efeff0b1bce3e243253efb7b3#b9ee834de357f32efeff0b1bce3e243253efb7b3" dependencies = [ "app_units", "arrayvec", @@ -6247,7 +6247,7 @@ dependencies = [ [[package]] name = "stylo_atoms" version = "0.22.0" -source = "git+https://github.com/lexmount/stylo?rev=ff564f4f1f632fd4565b116a46082b3be96c5af9#ff564f4f1f632fd4565b116a46082b3be96c5af9" +source = "git+https://github.com/lexmount/stylo?rev=b9ee834de357f32efeff0b1bce3e243253efb7b3#b9ee834de357f32efeff0b1bce3e243253efb7b3" dependencies = [ "string_cache 0.11.0", "string_cache_codegen 0.11.2", @@ -6256,7 +6256,7 @@ dependencies = [ [[package]] name = "stylo_derive" version = "0.22.0" -source = "git+https://github.com/lexmount/stylo?rev=ff564f4f1f632fd4565b116a46082b3be96c5af9#ff564f4f1f632fd4565b116a46082b3be96c5af9" +source = "git+https://github.com/lexmount/stylo?rev=b9ee834de357f32efeff0b1bce3e243253efb7b3#b9ee834de357f32efeff0b1bce3e243253efb7b3" dependencies = [ "darling", "proc-macro2", @@ -6268,7 +6268,7 @@ dependencies = [ [[package]] name = "stylo_dom" version = "0.22.0" -source = "git+https://github.com/lexmount/stylo?rev=ff564f4f1f632fd4565b116a46082b3be96c5af9#ff564f4f1f632fd4565b116a46082b3be96c5af9" +source = "git+https://github.com/lexmount/stylo?rev=b9ee834de357f32efeff0b1bce3e243253efb7b3#b9ee834de357f32efeff0b1bce3e243253efb7b3" dependencies = [ "bitflags", "stylo_malloc_size_of", @@ -6277,7 +6277,7 @@ dependencies = [ [[package]] name = "stylo_malloc_size_of" version = "0.22.0" -source = "git+https://github.com/lexmount/stylo?rev=ff564f4f1f632fd4565b116a46082b3be96c5af9#ff564f4f1f632fd4565b116a46082b3be96c5af9" +source = "git+https://github.com/lexmount/stylo?rev=b9ee834de357f32efeff0b1bce3e243253efb7b3#b9ee834de357f32efeff0b1bce3e243253efb7b3" dependencies = [ "app_units", "cssparser", @@ -6295,7 +6295,7 @@ dependencies = [ [[package]] name = "stylo_static_prefs" version = "0.22.0" -source = "git+https://github.com/lexmount/stylo?rev=ff564f4f1f632fd4565b116a46082b3be96c5af9#ff564f4f1f632fd4565b116a46082b3be96c5af9" +source = "git+https://github.com/lexmount/stylo?rev=b9ee834de357f32efeff0b1bce3e243253efb7b3#b9ee834de357f32efeff0b1bce3e243253efb7b3" dependencies = [ "toml", ] @@ -6314,7 +6314,7 @@ dependencies = [ [[package]] name = "stylo_traits" version = "0.22.0" -source = "git+https://github.com/lexmount/stylo?rev=ff564f4f1f632fd4565b116a46082b3be96c5af9#ff564f4f1f632fd4565b116a46082b3be96c5af9" +source = "git+https://github.com/lexmount/stylo?rev=b9ee834de357f32efeff0b1bce3e243253efb7b3#b9ee834de357f32efeff0b1bce3e243253efb7b3" dependencies = [ "app_units", "bitflags", @@ -6624,7 +6624,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "to_shmem" version = "0.6.0" -source = "git+https://github.com/lexmount/stylo?rev=ff564f4f1f632fd4565b116a46082b3be96c5af9#ff564f4f1f632fd4565b116a46082b3be96c5af9" +source = "git+https://github.com/lexmount/stylo?rev=b9ee834de357f32efeff0b1bce3e243253efb7b3#b9ee834de357f32efeff0b1bce3e243253efb7b3" dependencies = [ "cssparser", "servo_arc", @@ -6637,7 +6637,7 @@ dependencies = [ [[package]] name = "to_shmem_derive" version = "0.2.0" -source = "git+https://github.com/lexmount/stylo?rev=ff564f4f1f632fd4565b116a46082b3be96c5af9#ff564f4f1f632fd4565b116a46082b3be96c5af9" +source = "git+https://github.com/lexmount/stylo?rev=b9ee834de357f32efeff0b1bce3e243253efb7b3#b9ee834de357f32efeff0b1bce3e243253efb7b3" dependencies = [ "darling", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 50193a750f6..9610134df3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -143,13 +143,13 @@ curl-sys = { path = "vendor/curl-sys-0.4.91" } cookie = { git = "https://github.com/ldm0/cookie-rs", branch = "priority" } v8 = { path = "vendor/v8-152.2.0" } deno_v8 = { path = "vendor/deno_v8-0.3.0" } -selectors = { git = "https://github.com/lexmount/stylo", rev = "ff564f4f1f632fd4565b116a46082b3be96c5af9" } -servo_arc = { git = "https://github.com/lexmount/stylo", rev = "ff564f4f1f632fd4565b116a46082b3be96c5af9" } -stylo = { git = "https://github.com/lexmount/stylo", rev = "ff564f4f1f632fd4565b116a46082b3be96c5af9" } -stylo_atoms = { git = "https://github.com/lexmount/stylo", rev = "ff564f4f1f632fd4565b116a46082b3be96c5af9" } -stylo_dom = { git = "https://github.com/lexmount/stylo", rev = "ff564f4f1f632fd4565b116a46082b3be96c5af9" } -stylo_static_prefs = { git = "https://github.com/lexmount/stylo", rev = "ff564f4f1f632fd4565b116a46082b3be96c5af9" } -stylo_traits = { git = "https://github.com/lexmount/stylo", rev = "ff564f4f1f632fd4565b116a46082b3be96c5af9" } +selectors = { git = "https://github.com/lexmount/stylo", rev = "b9ee834de357f32efeff0b1bce3e243253efb7b3" } +servo_arc = { git = "https://github.com/lexmount/stylo", rev = "b9ee834de357f32efeff0b1bce3e243253efb7b3" } +stylo = { git = "https://github.com/lexmount/stylo", rev = "b9ee834de357f32efeff0b1bce3e243253efb7b3" } +stylo_atoms = { git = "https://github.com/lexmount/stylo", rev = "b9ee834de357f32efeff0b1bce3e243253efb7b3" } +stylo_dom = { git = "https://github.com/lexmount/stylo", rev = "b9ee834de357f32efeff0b1bce3e243253efb7b3" } +stylo_static_prefs = { git = "https://github.com/lexmount/stylo", rev = "b9ee834de357f32efeff0b1bce3e243253efb7b3" } +stylo_traits = { git = "https://github.com/lexmount/stylo", rev = "b9ee834de357f32efeff0b1bce3e243253efb7b3" } svgtypes = { git = "https://github.com/lexmount/svgtypes", rev = "520374d714d69f8e2dc93c81a9d6be559ecde3ff" } # Preserve original SVG selector inputs and collect unclipped source geometry. usvg = { git = "https://github.com/lexmount/resvg", rev = "a137793a5749c27862b724eef60c4734526b14a0" } diff --git a/moli-renderer-v8/src/script_vm/tests/dom_xhr/cssom/extracted.rs b/moli-renderer-v8/src/script_vm/tests/dom_xhr/cssom/extracted.rs index ebb33e377f4..85895a1ffb5 100644 --- a/moli-renderer-v8/src/script_vm/tests/dom_xhr/cssom/extracted.rs +++ b/moli-renderer-v8/src/script_vm/tests/dom_xhr/cssom/extracted.rs @@ -1,5 +1,6 @@ use super::*; +mod attr_fallback; mod attr_invalidation; mod attr_security; mod css_text_and_detached; diff --git a/moli-renderer-v8/src/script_vm/tests/dom_xhr/cssom/extracted/attr_fallback.rs b/moli-renderer-v8/src/script_vm/tests/dom_xhr/cssom/extracted/attr_fallback.rs new file mode 100644 index 00000000000..23a76af0b28 --- /dev/null +++ b/moli-renderer-v8/src/script_vm/tests/dom_xhr/cssom/extracted/attr_fallback.rs @@ -0,0 +1,138 @@ +use super::*; + +#[test] +fn typed_attr_fallbacks_resolve_nested_references_and_preserve_cycles() { + let mut vm = new_storage_html_test_vm("https://typed-attr-fallback.test/page.html"); + let result = vm + .eval( + r#" +(() => { + let checks = 0; + const failures = []; + const equal = (actual, expected, label) => { + checks++; + if (actual !== expected) failures.push({label, actual, expected}); + }; + const attributes = { + 'data-number': '23', 'data-other': '31', 'data-present': '29', 'data-invalid': 'bad', + 'data-weight': '43', 'data-opacity': '0.5', 'data-length': '17px', 'data-color': 'blue', + 'data-gradient': 'linear-gradient(black, white)', + 'data-cycle': 'attr(data-cycle type(*))', 'data-dead-var': 'var(--dead)', + 'data-image': 'url(https://attr-fallback-resource.test/private.png)', + }; + const make = () => { + const element = document.createElement('div'); + for (const [name, value] of Object.entries(attributes)) element.setAttribute(name, value); + element.style.setProperty('--present', '29'); + element.style.setProperty('--dead', 'var(--dead)'); + document.body.appendChild(element); + return element; + }; + const value = (element, property, pseudo) => + getComputedStyle(element, pseudo).getPropertyValue(property); + const cases = [ + ['missing typed primary', 'z-index', 'attr(data-missing type(), attr(data-number type(), 5))', '23'], + ['invalid typed primary', 'z-index', 'attr(data-invalid type(), attr(data-number type(), 5))', '23'], + ['present typed primary', 'z-index', 'attr(data-present type(), attr(data-number type(), 5))', '29'], + ['number primary', 'z-index', 'attr(data-missing number, attr(data-number type(), 5))', '23'], + ['raw string primary', 'z-index', 'attr(data-missing raw-string, attr(data-number type(), 5))', '23'], + ['var fallback', 'z-index', 'var(--missing, attr(data-number type(), 5))', '23'], + ['env fallback', 'z-index', 'env(moli-unknown-environment, attr(data-number type(), 5))', '23'], + ['var and env fallbacks', 'z-index', 'var(--missing, env(moli-unknown-environment, attr(data-number type(), 5)))', '23'], + ['three attribute levels', 'z-index', 'attr(data-missing type(), attr(data-absent type(), attr(data-number type(), 5)))', '23'], + ['calc fallback', 'z-index', 'calc(attr(data-missing type(), attr(data-number type(), 5)) + 2)', '25'], + ['multiple fallback references', 'z-index', 'calc(var(--missing, attr(data-number type())) + env(moli-unknown-environment, attr(data-other type())))', '54'], + ['number type', 'font-weight', 'attr(data-missing type(), attr(data-weight type(), 5))', '43'], + ['opacity type', 'opacity', 'var(--missing, attr(data-opacity type(), 0))', '0.5'], + ['length type', 'margin-left', 'attr(data-missing type(), attr(data-length type(), 5px))', '17px'], + ['shorthand fallback', 'margin', 'var(--missing, attr(data-length type(), 5px))', '17px'], + ['color type', 'color', 'var(--missing, attr(data-color type(), red))', 'rgb(0, 0, 255)'], + ['image type', 'background-image', 'var(--missing, attr(data-gradient type(), none))', 'linear-gradient(rgb(0, 0, 0), rgb(255, 255, 255))'], + ['URL syntax stays invalid', 'z-index', 'attr(data-missing type(), attr(data-image type(), 5))', '5'], + ['unused var fallback', 'z-index', 'var(--present, attr(data-cycle type(), 5))', '29'], + ]; + for (const [label, property, expression, expected] of cases) { + const element = make(); + equal(CSS.supports(property, expression), true, label + ': declaration syntax'); + element.style.setProperty(property, expression); + equal(value(element, property === 'margin' ? 'margin-left' : property), expected, label); + element.remove(); + } + for (const [label, expression, expected] of [ + ['custom attr fallback', 'attr(data-missing type(), attr(data-number type(), 5))', '23'], + ['custom var fallback', 'var(--missing, attr(data-number type(), 5))', '23'], + ['custom env fallback', 'env(moli-unknown-environment, attr(data-number type(), 5))', '23'], + ['custom invalid fallback', 'attr(data-missing type(), attr(data-invalid type(), 7))', '7'], + ]) { + const element = make(); + element.style.setProperty('--probe', expression); + equal(value(element, '--probe'), expected, label); + element.remove(); + } + for (const [label, expression, expected] of [ + ['used attribute cycle', 'attr(data-missing type(), attr(data-cycle type(), 7))', '7'], + ['unused attribute cycle', 'attr(data-present type(), attr(data-cycle type(), 7))', '29'], + ['used cycle inside var fallback', 'var(--missing, attr(data-cycle type(), 7))', '7'], + ['invalid custom variable inside attribute', 'attr(data-missing type(), attr(data-dead-var type(), 7))', '7'], + ]) { + const element = make(); + element.style.zIndex = expression; + equal(value(element, 'z-index'), expected, label); + element.remove(); + } + for (const primary of ['data-missing', 'data-invalid', 'data-present']) { + const present = primary === 'data-present'; + const element = make(); + element.setAttribute('data-cycle', 'var(--loop)'); + element.style.setProperty('--loop', 'attr(' + primary + + ' type(), attr(data-cycle type(), 7))'); + element.style.zIndex = 'var(--loop, 11)'; + equal(value(element, '--loop'), present ? '29' : '', 'custom cycle: ' + primary); + equal(value(element, 'z-index'), present ? '29' : '11', 'custom cycle consumer: ' + primary); + element.remove(); + } + const parent = make(); + parent.style.fontSize = '10px'; + const relative = make(); + parent.appendChild(relative); + relative.setAttribute('data-relative', '2em'); + relative.style.fontSize = 'var(--missing, attr(data-relative type(), 7px))'; + equal(value(relative, 'font-size'), '20px', 'font-size fallback uses parent font'); + relative.setAttribute('data-relative', '3em'); + relative.style.fontSize = '10px'; + relative.style.lineHeight = 'var(--missing, attr(data-relative type(), 7px))'; + equal(value(relative, 'line-height'), '30px', 'line-height fallback uses computed font'); + + const dynamic = make(); + dynamic.style.zIndex = 'attr(data-missing type(), attr(data-number type(), 5))'; + equal(value(dynamic, 'z-index'), '23', 'fallback before mutation'); + dynamic.setAttribute('data-number', '31'); + equal(value(dynamic, 'z-index'), '31', 'fallback after mutation'); + dynamic.removeAttribute('data-number'); + equal(value(dynamic, 'z-index'), '5', 'fallback attribute removed'); + dynamic.setAttribute('data-number', '37'); + equal(value(dynamic, 'z-index'), '37', 'fallback attribute restored'); + + const sheet = document.createElement('style'); + sheet.textContent = '#typed-fallback-pseudo::before { content: "before"; color: var(--missing, attr(data-color type(), red)); }'; + document.head.appendChild(sheet); + const generated = make(); + generated.id = 'typed-fallback-pseudo'; + equal(value(generated, 'color', '::before'), 'rgb(0, 0, 255)', 'pseudo fallback initial value'); + generated.setAttribute('data-color', 'green'); + equal(value(generated, 'color', '::before'), 'rgb(0, 128, 0)', 'pseudo fallback attribute mutation'); + + const security = make(); + security.style.setProperty('--url-probe', 'var(--missing, attr(data-image type(*)))'); + equal(value(security, '--url-probe'), attributes['data-image'], 'unregistered universal fallback retains URL tokens'); + security.style.backgroundImage = 'var(--missing, attr(data-image type(*)))'; + equal(value(security, 'background-image'), 'none', 'fallback URL remains attr tainted'); + return JSON.stringify({checks, failures}); +})() +"#, + ) + .expect("typed attr fallback probe should evaluate"); + let result: serde_json::Value = serde_json::from_str(&result).unwrap(); + assert_eq!(result["checks"], 62, "{result}"); + assert_eq!(result["failures"], serde_json::json!([]), "{result}"); +}