Commit 89efdfcf authored by Shu-yu Guo's avatar Shu-yu Guo Committed by Commit Bot

[weakrefs] Add FinalizationRegistry web tests

Bug: chromium:1016767, v8:8179
Change-Id: I14d0aa2c0f458156cb03bb09d1f1175c21086659
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2145160Reviewed-by: default avatarDomenic Denicola <domenic@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759294}
parent 27c72c0d
......@@ -2273,6 +2273,11 @@ crbug.com/1052717 external/wpt/css/css-text/line-break/line-break-strict-hyphens
crbug.com/922618 external/wpt/html/semantics/document-metadata/the-link-element/link-multiple-error-events.html [ Timeout ]
crbug.com/922618 external/wpt/html/semantics/document-metadata/the-link-element/link-multiple-load-events.html [ Timeout ]
# WeakRefs are under development and run in a virtual test suite
crbug.com/1016767 js/weakrefs/finalization-registry-basic.html [ Skip ]
crbug.com/1016767 js/weakrefs/finalization-registry-microtasks.html [ Skip ]
crbug.com/1016767 js/weakrefs/finalization-registry-onerror.html [ Skip ]
# Sheriff 2020-02-06
# Flaking on Linux Leak
crbug.com/1049599 [ Linux ] virtual/threaded-prefer-compositing/fast/scrolling/events/overscroll-event-fired-to-element-with-overscroll-behavior.html [ Pass Failure Timeout ]
......
......@@ -731,5 +731,10 @@
"prefix": "trust-tokens",
"bases": [ "external/wpt/trust-tokens/end-to-end", "http/tests/loading/trust-tokens" ],
"args": [ "--enable-features=TrustTokens" ]
},
{
"prefix": "weakrefs",
"bases": [ "js/weakrefs" ],
"args": [ "--js-flags=--harmony-weak-refs" ]
}
]
spec: https://tc39.es/proposal-weakrefs/
JS WeakRefs Tests README
These tests are currently Chrome and V8-specific. They pass because of the
exposed gc() function, which forces a major GC synchronously and forces
collection of the unreachable `garbage` binding in the tests.
Moving these tests to WPT is blocked on [a cross-browser way to trigger GC in
the test harness](https://github.com/web-platform-tests/wpt/issues/7899).
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script type="module">
async_test(t => {
let called = false;
const callback = t.step_func_done(function(holdings) {
called = true;
assert_equals(holdings, 'holdings',
'holdings should be initialized correctly');
});
const fr = new FinalizationRegistry(callback);
// The following is an IIFE to ensure that garbage becomes unreachable after
// the function returns.
(function() {
let garbage = {};
fr.register(garbage, 'holdings');
garbage = null;
})();
assert_false(called, 'finalizer should not be called in the same turn');
gc();
assert_false(called, 'finalizer should not be called in the same turn');
}, 'FinalizationRegistry registers an object and calls finalizer');
</script>
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script type="module">
async_test(t => {
let last_task_that_ran = "";
let num_microtasks_that_ran = 0;
const callback = () => {
last_task_that_ran = 'finalizer';
Promise.resolve().then(t.step_func(function() {
assert_equals(last_task_that_ran, 'finalizer');
last_task_that_ran = 'microtask';
// The two FinalizationRegistries below run their finalizers in two
// separate tasks. Those tasks should be each followed by a microtask
// checkpoint, thus the counter here.
if (++num_microtasks_that_ran == 2) t.done();
}));
};
const fr1 = new FinalizationRegistry(callback);
const fr2 = new FinalizationRegistry(callback);
(function() {
let garbage = {};
fr1.register(garbage, 'holdings1');
fr2.register(garbage, 'holdings2');
garbage = null;
})();
gc();
}, 'FinalizationRegistry finalizers have a microtask checkpoint on completion');
</script>
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script type="module">
setup({allow_uncaught_exception: true });
async_test(t => {
window.onerror = t.step_func_done(function(msg, source, lineno, colno, e) {
assert_equals(e.message, 'weakrefs are awesome',
'Correct exception is thrown');
});
function callback(holdings) {
throw new Error('weakrefs are awesome');
}
const fr = new FinalizationRegistry(callback);
(function() {
let garbage = {};
fr.register(garbage, 'holdings');
garbage = null;
})();
gc();
}, 'FinalizationRegistry callback exceptions are reported to error handler');
</script>
Tests HTML integration of the WeakRef and FinalizationRegistry features rely on
V8's GC behavior to pass.
This virtual test suite will be removed once WeakRefs ship in V8.
https://bugs.chromium.org/p/chromium/issues/detail?id=1016767
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment