-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WeakRefs] Implement WeakRefs integration
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
1 parent
71aff5b
commit 3ec5dd8
Showing
5 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
spec: https://tc39.es/proposal-weakrefs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ | ||
} | ||
}; |