Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
shvaikalesh authored Aug 8, 2022
1 parent b91acab commit 5fdf998
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<title>Target element of ElementsInternals is held strongly and doesn't get GCed if there are no other references</title>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/garbage-collect.js"></script>

<script>
customElements.define("x-foo", class extends HTMLElement {});

promise_test(async t => {
const elementInternals = [];

for (let i = 0; i < 1e5; i++) {
const targetElement = document.createElement("x-foo");
targetElement.attachShadow({ mode: "open" });
elementInternals.push(targetElement.attachInternals());
}

await maybeGarbageCollectAsync();
await new Promise(r => t.step_timeout(r, 100));

const allShadowRootsAreAlive = elementInternals.every(eI => eI.shadowRoot instanceof ShadowRoot);
assert_true(allShadowRootsAreAlive);
});
</script>
19 changes: 19 additions & 0 deletions custom-elements/resources/garbage-collect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
async function maybeGarbageCollectAsync() {
if (typeof TestUtils !== 'undefined' && TestUtils.gc) {
await TestUtils.gc();
} else if (self.gc) {
// Use --expose_gc for V8 (and Node.js)
// to pass this flag at chrome launch use: --js-flags="--expose-gc"
// Exposed in SpiderMonkey shell as well
await self.gc();
} else if (self.GCController) {
// Present in some WebKit development environments
await GCController.collect();
} else {
/* eslint-disable no-console */
console.warn('Tests are running without the ability to do manual ' +
'garbage collection. They will still work, but ' +
'coverage will be suboptimal.');
/* eslint-enable no-console */
}
}
1 change: 1 addition & 0 deletions lint.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ PRINT STATEMENT: webdriver/tests/support/helpers.py

# semi-legitimate use of console.*
CONSOLE: console/*
CONSOLE: custom-elements/resources/garbage-collect.js
CONSOLE: js/builtins/weakrefs/resources/maybe-garbage-collect.js
CONSOLE: resources/check-layout-th.js
CONSOLE: resources/chromium/*
Expand Down

0 comments on commit 5fdf998

Please sign in to comment.