Commit 141ddce1 authored by Anders Hartvoll Ruud's avatar Anders Hartvoll Ruud Committed by aborovova@mozilla.com
Browse files

Bug 1966770 [wpt PR 52577] - Make var() and attr() short-circuiting,

Automatic update from web-platform-tests
Make var() and attr() short-circuiting

Following the resolution in Issue 11500, all substitution functions
should be short-circuiting. This CL implements this for var()
and attr(), behind the flag CSSShortCircuitVarAttr.

Note that env() already has the desired behavior, and therefore
no change is needed for env().

https://github.com/w3c/csswg-drafts/issues/11500

Bug: 397690639
Change-Id: If71326bc52a55524ecfd4d439d30ac09bf22fea3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6530122
Reviewed-by: default avatarMunira Tursunova <moonira@google.com>
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1460882}

--

wpt-commits: 649319c229a6037ad25250a4f006bf605e986e81
wpt-pr: 52577

Differential Revision: https://phabricator.services.mozilla.com/D250638
parent 05f15170
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -40,12 +40,12 @@
  </style>
</template>

<template data-name="Local with self-cycle in fallback">
<template data-name="Local with self-cycle in unused fallback">
  <style>
    @function --f() {
      --y: FAIL;
      --y: PASS;
      --x: var(--y, var(--x));
      result: var(--x, PASS);
      result: var(--x, FAIL);
    }
    #target {
      --actual: --f();
+4 −4
Original line number Diff line number Diff line
@@ -82,13 +82,13 @@
  </style>
</template>

<template data-name="attr() cycle through fallback in local">
<template data-name="attr() cycle through unused fallback in local">
  <style>
    @function --f() {
      --valid: valid;
      --valid: PASS;
      --x: var(--valid, attr(data-x type(*)));
      --y: attr(data-x type(*), PASS);
      result: var(--y, PASS);
      --y: attr(data-x type(*), FAIL);
      result: var(--y, FAIL);
    }
    #target {
      --x: FAIL1;
+8 −5
Original line number Diff line number Diff line
@@ -96,18 +96,21 @@
  attrElem.style.setProperty('--x', null);
  attrElem.removeAttribute('data-bar');

  /* Cycle in fallback */
  test_attr_cycle('--y', 'attr(data-foo type(*), var(--y))', '3');
  test_attr_cycle('--y', 'attr(data-foo type(*), attr(data-foo))', '3');
  /* Cycle in unused fallbacks */
  test_attr_no_cycle('--y', 'attr(data-foo type(*), var(--y))', '3', '3');
  test_attr_no_cycle('--y', 'attr(data-foo type(*), attr(data-foo))', '3', '3');

  attrElem.style.setProperty('--x', 'var(--y)');
  test_attr_cycle('--y', 'attr(data-foo type(*), var(--x))', '3');
  test_attr_no_cycle('--y', 'attr(data-foo type(*), var(--x))', '3', '3');
  attrElem.style.setProperty('--x', null);

  attrElem.setAttribute('data-bar', 'attr(data-foo type(*))');
  test_attr_cycle('--y', 'attr(data-foo type(*), attr(data-bar type(*)))', '3');
  test_attr_no_cycle('--y', 'attr(data-foo type(*), attr(data-bar type(*)))', '3', '3');
  attrElem.removeAttribute('data-bar');

  /* Cycle in fallback */
  test_attr_cycle('--y', 'attr(data-unknown type(*), var(--y))', '3');

  /* No cycle, use raw CSS string without substitution */
  attrElem.setAttribute('data-bar', 'var(--y)');
  test_attr_no_cycle('--y', 'attr(data-foo type(<string>))', 'attr(data-bar type(<string>))', '');
+1 −1
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@
  test_if(`if(style(--x: attr(data-foo, var(--y))): true_value;
          else: false_value)`,
        [['--x', '"30px"'], ['--y', 'var(--y)']],
        'false_value');
        'true_value');

  // self cycle in unused condition
  test_if(`if(style(--x: 0): value1; style(--prop): value2)`,
+9 −3
Original line number Diff line number Diff line
@@ -377,6 +377,9 @@
    'Cycle with deeper secondary cycle');


  // If we cared about cycles in unused fallbacks,
  // then --a/--b/--c would be in a cycle in this case:
  //
  //            ┌───┐
  //            │ x │
  //            └───┘
@@ -404,6 +407,9 @@
  //         │  ┌───┐  │
  //         └▶ │ y │ ◀┘
  //            └───┘
  //
  // However, as of https://github.com/w3c/csswg-drafts/issues/11500,
  // we no longer care about such cycles.
  test_cycles(
    [
      '--x:var(--a, valid)',
@@ -412,8 +418,8 @@
      '--c:var(--y, var(--a, cycle))',
      '--y:valid'
    ],
    ['--a', '--b', '--c'],
    ['--x', '--y'],
    'Cycle via fallback');
    [], // Nothing is invalid.
    ['--a', '--b', '--c', '--x', '--y'],
    'Cycle in unused fallback');

</script>
Loading