Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lint.whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ CONSOLE: resources/check-layout-th.js
CONSOLE: resources/chromium/*
CONSOLE: resources/idlharness.js
CONSOLE: streams/resources/test-utils.js
CONSOLE: weakrefs/resources/test-utils.js
CONSOLE: service-workers/service-worker/resources/navigation-redirect-other-origin.html
CONSOLE: service-workers/service-worker/navigation-redirect.https.html
CONSOLE: service-workers/service-worker/resources/clients-get-other-origin.html
Expand Down
1 change: 1 addition & 0 deletions weakrefs/META.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spec: https://tc39.es/proposal-weakrefs/
32 changes: 32 additions & 0 deletions weakrefs/finalization-group-basic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="module">
import garbageCollect from './resources/test-utils.js';

async_test(function() {
let called = false;

const callback = this.step_func(function(iter) {
const values = [...iter];
assert_equals(values[0], 'holdings',
'holdings should be initialized correctly');
this.done();
});

const fg = new FinalizationGroup(callback);

(function() {
let x = {};
fg.register(x, 'holdings');
x = null;
})();

assert_false(called, 'finalizer should not be called in the same turn');

garbageCollect();

assert_false(called, 'finalizer should not be called in the same turn');

}, `FinalizationGroup registers an object and calls finalizer`);
</script>
32 changes: 32 additions & 0 deletions weakrefs/finalization-group-cleanupSome-basic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="module">
import garbageCollect from './resources/test-utils.js';

test(function() {
let called = false;
function callback(iter) {
called = true;
const values = [...iter];
assert_equals(values[0], 'holdings',
'holdings should be initialized correctly');
};

const fg = new FinalizationGroup(callback);

(function() {
let x = {};
fg.register(x, 'holdings');
x = null;
})();

assert_false(called, 'finalizer should not be called yet');

garbageCollect();

fg.cleanupSome();
assert_true(called, 'finalizer should be called');

}, `FinalizationGroup.cleanupSome calls finalizer in same turn`);
</script>
31 changes: 31 additions & 0 deletions weakrefs/finalization-group-error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="module">
import garbageCollect from './resources/test-utils.js';

setup({allow_uncaught_exception : true});

async_test(function() {
window.onerror = this.step_func(function(msg, source, lineno, colno, e) {
assert_equals(e.message, 'weakrefs are awesome',
'Correct exception is thrown');
this.done();
});

function callback(iter) {
[...iter];
throw new Error('weakrefs are awesome');
};

const fg = new FinalizationGroup(callback);

(function() {
let x = {};
fg.register(x, 'holdings');
x = null;
})();

garbageCollect();
}, `finalizer callback exceptions are reported to error handler`);
</script>
16 changes: 16 additions & 0 deletions weakrefs/resources/test-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default function() {
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
self.gc();
} else if (self.GCController) {
// Present in some WebKit development environments
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 */
}
};