-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Schedule a task on the main event loop, similar to what the HTML spec recommends for browsers. Alternative to #30198 PR-URL: #30616 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
- Loading branch information
1 parent
24f7335
commit 50b7f84
Showing
5 changed files
with
59 additions
and
6 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
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
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,25 @@ | ||
// Flags: --harmony-weak-refs | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
|
||
// Test that finalization callbacks do not crash when caused through a regular | ||
// GC (not global.gc()). | ||
|
||
const start = Date.now(); | ||
const g = new globalThis.FinalizationGroup(() => { | ||
const diff = Date.now() - start; | ||
assert(diff < 10000, `${diff} >= 10000`); | ||
}); | ||
g.register({}, 42); | ||
|
||
setImmediate(() => { | ||
const arr = []; | ||
// Build up enough memory usage to hopefully trigger a platform task but not | ||
// enough to trigger GC as an interrupt. | ||
while (arr.length < 1000000) arr.push([]); | ||
|
||
setTimeout(() => { | ||
g; // Keep reference alive. | ||
}, 200000).unref(); | ||
}); |