Skip to content

Commit

Permalink
[functions] Support IACVT-capture for function arguments
Browse files Browse the repository at this point in the history
Currently, if you attempt to pass e.g. var(--unknown) as a function
argument, the declaration containing the function call becomes
invalid at computed-value time (IACVT). The intended behavior is
instead that an argument "captures" these invalid states, and instead
falls back to its default value (or failing that, just becomes
<guaranteed-invalid>). This allows authors to pass a variable
which may or may not exist into a function, and actually act on that
information.

Fixed: 397919914
Bug: 325504770
Change-Id: I4ad474b29bdadddafc3780b5659916e7c73e46df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6288531
Commit-Queue: Anders Hartvoll Ruud <[email protected]>
Reviewed-by: Steinar H Gunderson <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1424415}
  • Loading branch information
andruud authored and chromium-wpt-export-bot committed Feb 25, 2025
1 parent d7fa260 commit 892b423
Showing 1 changed file with 111 additions and 14 deletions.
125 changes: 111 additions & 14 deletions css/css-mixins/dashed-function-eval.html
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,42 @@
</style>
</template>

<template data-name="Argument captures IACVT due to invalid var()">
<style>
@function --f(--x) {
result: var(--x, PASS);
}
#target {
--actual: --f(var(--unknown));
--expected: PASS;
}
</style>
</template>

<template data-name="Argument captures IACVT due to invalid var(), typed">
<style>
@function --f(--x <length>) {
result: var(--x, PASS);
}
#target {
--actual: --f(var(--unknown));
--expected: PASS;
}
</style>
</template>

<template data-name="Argument captures IACVT due to type mismatch">
<style>
@function --f(--x <length>) {
result: var(--x, PASS);
}
#target {
--actual: --f(red);
--expected: PASS;
}
</style>
</template>

<!-- Defaults -->

<template data-name="Single parameter with default value">
Expand Down Expand Up @@ -362,6 +398,42 @@
</style>
</template>

<template data-name="IACVT arguments are defaulted">
<style>
@function --f(--x: 1, --y, --z: 3) {
result: var(--x) var(--y) var(--z);
}
#target {
--actual: --f(var(--unknown), 2, var(--unknown));
--expected: 1 2 3;
}
</style>
</template>

<template data-name="IACVT arguments are defaulted, typed">
<style>
@function --f(--x <number>: 1, --y <number>, --z <number>: 3) {
result: var(--x) var(--y) var(--z);
}
#target {
--actual: --f(var(--unknown), 2, var(--unknown));
--expected: 1 2 3;
}
</style>
</template>

<template data-name="Arguments are defaulted on type mismatch">
<style>
@function --f(--x <number>: 1, --y <number>, --z <number>: 3) {
result: var(--x) var(--y) var(--z);
}
#target {
--actual: --f(red, 2, 360deg);
--expected: 1 2 3;
}
</style>
</template>

<!-- Locals -->

<template data-name="Unused local">
Expand Down Expand Up @@ -749,6 +821,45 @@
</style>
</template>

<template data-name="IACVT argument shadows outer scope">
<style>
@function --f(--x) {
result: var(--x, PASS);
}
#target {
--x: FAIL;
--actual: --f(var(--unknown));
--expected: PASS;
}
</style>
</template>

<template data-name="IACVT argument shadows outer scope, typed">
<style>
@function --f(--x <length>) {
result: var(--x, PASS);
}
#target {
--x: FAIL;
--actual: --f(var(--unknown));
--expected: PASS;
}
</style>
</template>

<template data-name="IACVT argument shadows outer scope, type mismatch">
<style>
@function --f(--x <length>) {
result: var(--x, PASS);
}
#target {
--x: FAIL;
--actual: --f(red);
--expected: PASS;
}
</style>
</template>

<!-- Invalid invocations -->

<template data-name="Missing only argument">
Expand All @@ -775,20 +886,6 @@
</style>
</template>

<template data-name="Unknown var() in argument makes declaration IACVT">
<!-- Note: In the future, this may be changed to instead trigger
the default for --x. -->
<style>
@function --f(--x:1px) {
result: var(--x);
}
#target {
--actual: --f(var(--unknown));
/* --expected: <guaranteed-invalid> */
}
</style>
</template>

<!--
{}-wrappers.
Expand Down

0 comments on commit 892b423

Please sign in to comment.