Skip to content

Commit

Permalink
[WeakRefs] Implement WeakRefs integration
Browse files Browse the repository at this point in the history
This uses the V8 API to register a clean up task that will execute
some time later at idle time.

The JavaScript spec is defined here:
https://tc39.es/proposal-weakrefs/

The HTML integration is defined here:
whatwg/html#4571

(Note that this CL doesn't implement ClearKeptObjects part of the
spec yet, a follow on CL will do that.)

TODO (before sumbitting this CL):
- Add tests

Bug: 1016767
Change-Id: I2db82dc9d037d1e3bc0ec8c192d5b06908161adc
  • Loading branch information
gsathya authored and chromium-wpt-export-bot committed Oct 30, 2019
1 parent 55b30ca commit 45a2d2c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
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>
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 */
}
};

0 comments on commit 45a2d2c

Please sign in to comment.