Skip to content

Commit d944b8a

Browse files
andruudmoz-wptsync-bot
authored andcommitted
Bug 1950096 [wpt PR 50907] - [functions] Let parameter defaults reference other parameters, a=testonly
Automatic update from web-platform-tests [functions] Let parameter defaults reference other parameters Per "evaluate a custom function" [1], the default value of a parameter may "see" other parameters, e.g. @function --f(--x, --y:var(--x)). Before this CL, that var(--x) would resolve in the outer scope, but now it's supposed to resolve against the actual argument value passed for --x. At the same time, default values should not have access to the actual *locals* of the function body, meaning that they resolve in some gray area *between* the outer scope and inner scope. In this CL, that "gray area" is implemented by using a disposable FunctionContext with the unresolved defaults set as the unresolved locals. This is convenient, because we get all the needed "dependency handling" (including cycle detection) for free. Since various things now need to parse against a type (arguments, defaults, and the 'result' descriptor), and because these various things differ in how they are represented (some CSSVariableData, some StringView), this CL aligns all of those things to use CSSVariableData, and adjusts ResolveFunctionExpression accordingly. This would be needed anyway, to actually transport various tainting information, though that is not explicit handled/tested in this CL. Finally, note that there is a drive-by fix in this CL: the "already applied" branch of ApplyLocalVariables now actually skips the work if it's already applied. This should ideally have a performance test, which is tracked as a follow-up task (Issue 397164440). [1] https://drafts.csswg.org/css-mixins-1/#evaluate-a-custom-function Fixed: 397459622 Bug: 325504770, 397164440 Change-Id: Ic705209d25f4bee6149f2397bda78e1224b16901 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6276516 Commit-Queue: Anders Hartvoll Ruud <[email protected]> Reviewed-by: Steinar H Gunderson <[email protected]> Cr-Commit-Position: refs/heads/main@{#1423855} -- wpt-commits: b5045d03a5a6963f8af68d403e24bb325f2ce2e6 wpt-pr: 50907
1 parent 7b86ff4 commit d944b8a

File tree

2 files changed

+127
-5
lines changed

2 files changed

+127
-5
lines changed

testing/web-platform/tests/css/css-mixins/dashed-function-cycles.tentative.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,31 @@
307307
</style>
308308
</template>
309309

310+
<template data-name="Function in a cycle with its own default">
311+
<style>
312+
@function --f(--x, --y: --f(13px)) {
313+
result: 10px;
314+
}
315+
#target {
316+
--tmp: --f(42px);
317+
--actual: var(--tmp, PASS);
318+
--expected: PASS;
319+
}
320+
</style>
321+
</template>
322+
323+
<template data-name="Cyclic defaults">
324+
<style>
325+
@function --f(--x, --y: var(--z), --z: var(--y)) {
326+
result: var(--x, FAIL) var(--y, PASS-y) var(--z, PASS-z);
327+
}
328+
#target {
329+
--actual: --f(42px);
330+
--expected: 42px PASS-y PASS-z;
331+
}
332+
</style>
333+
</template>
334+
310335
<script>
311336
test_all_templates();
312337
</script>

testing/web-platform/tests/css/css-mixins/dashed-function-eval.html

Lines changed: 102 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,63 @@
305305
</style>
306306
</template>
307307

308+
<template data-name="Default referencing another parameter">
309+
<style>
310+
@function --f(--x, --y: var(--x)) {
311+
result: var(--x) var(--y);
312+
}
313+
#target {
314+
--x: FAIL;
315+
--y: FAIL;
316+
--actual: --f(5px);
317+
--expected: 5px 5px;
318+
}
319+
</style>
320+
</template>
321+
322+
<template data-name="Default referencing another parameter, local interference">
323+
<style>
324+
@function --f(--x, --y: var(--x)) {
325+
--x: 17px;
326+
result: var(--x) var(--y);
327+
}
328+
#target {
329+
--x: FAIL;
330+
--y: FAIL;
331+
--actual: --f(5px);
332+
--expected: 17px 5px;
333+
}
334+
</style>
335+
</template>
336+
337+
<template data-name="Default referencing another defaulted parameter">
338+
<style>
339+
@function --f(--x: 5px, --y: var(--x)) {
340+
result: var(--x) var(--y);
341+
}
342+
#target {
343+
--x: FAIL;
344+
--y: FAIL;
345+
--actual: --f();
346+
--expected: 5px 5px;
347+
}
348+
</style>
349+
</template>
350+
351+
<template data-name="Typed default with reference">
352+
<style>
353+
@function --f(--x: 5px, --y <length>: calc(var(--x) + 1px)) {
354+
result: var(--x) var(--y);
355+
}
356+
#target {
357+
--x: FAIL;
358+
--y: FAIL;
359+
--actual: --f();
360+
--expected: 5px 6px;
361+
}
362+
</style>
363+
</template>
364+
308365
<!-- Locals -->
309366

310367
<template data-name="Unused local">
@@ -420,11 +477,6 @@
420477
</style>
421478
</template>
422479

423-
<!--
424-
TODO(andruud): Add more tests for dynamic scoping when Issue 10954
425-
resolves: https://github.com/w3c/csswg-drafts/issues/10954
426-
-->
427-
428480
<template data-name="Substitute local from outer scope">
429481
<style>
430482
@function --f() {
@@ -623,6 +675,51 @@
623675
</style>
624676
</template>
625677

678+
<template data-name="Inner function call should see resolved outer locals">
679+
<style>
680+
@function --a() {
681+
--x: --b();
682+
--y: var(--px);
683+
result: var(--x);
684+
}
685+
686+
@function --b() {
687+
result: var(--y, FAIL);
688+
}
689+
#target {
690+
--px: 10px;
691+
--actual: --a();
692+
--expected: 10px;
693+
}
694+
</style>
695+
</template>
696+
697+
<!--
698+
This the same test as the one above, but the *values* of --x and --y
699+
are flipped, as are the references to those vars. If there is a bug
700+
related to this behavior, it may be masked by "lucky" ordering of items
701+
in a hash backing. Testing both ways ensures that at least one test
702+
fails.
703+
-->
704+
<template data-name="Inner function call should see resolved outer locals (reverse)">
705+
<style>
706+
@function --a() {
707+
--x: var(--px);
708+
--y: --b();
709+
result: var(--y);
710+
}
711+
712+
@function --b() {
713+
result: var(--x, FAIL);
714+
}
715+
#target {
716+
--px: 10px;
717+
--actual: --a();
718+
--expected: 10px;
719+
}
720+
</style>
721+
</template>
722+
626723
<!-- Shadowing -->
627724

628725
<template data-name="Parameter shadows custom property">

0 commit comments

Comments
 (0)