summaryrefslogtreecommitdiff
path: root/test/parallel
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-11-24 00:34:36 +0100
committerAnna Henningsen <anna@addaleax.net>2019-11-29 02:17:12 +0100
commitfad952adbd8a2508d62c6df7ab20376d3898e228 (patch)
treea27475731ef2b778de617609574c1d11acec55fa /test/parallel
parentff48009fefcecedfee2c6ff1719e5be3f6969049 (diff)
downloadandroid-node-v8-fad952adbd8a2508d62c6df7ab20376d3898e228.tar.gz
android-node-v8-fad952adbd8a2508d62c6df7ab20376d3898e228.tar.bz2
android-node-v8-fad952adbd8a2508d62c6df7ab20376d3898e228.zip
src: use uv_async_t for WeakRefs
Schedule a task on the main event loop, similar to what the HTML spec recommends for browsers. Alternative to https://github.com/nodejs/node/pull/30198 PR-URL: https://github.com/nodejs/node/pull/30616 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'test/parallel')
-rw-r--r--test/parallel/test-finalization-group-error.js4
-rw-r--r--test/parallel/test-finalization-group-regular-gc.js25
2 files changed, 29 insertions, 0 deletions
diff --git a/test/parallel/test-finalization-group-error.js b/test/parallel/test-finalization-group-error.js
index 0754370f2d..0685811f55 100644
--- a/test/parallel/test-finalization-group-error.js
+++ b/test/parallel/test-finalization-group-error.js
@@ -18,6 +18,10 @@ setTimeout(() => {
name: 'Error',
message: 'test',
});
+
+ // Give the callbacks scheduled by global.gc() time to run, as the underlying
+ // uv_async_t is unref’ed.
+ setTimeout(() => {}, 200);
}, 200);
process.on('uncaughtException', common.mustCall());
diff --git a/test/parallel/test-finalization-group-regular-gc.js b/test/parallel/test-finalization-group-regular-gc.js
new file mode 100644
index 0000000000..7a4a4797ea
--- /dev/null
+++ b/test/parallel/test-finalization-group-regular-gc.js
@@ -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();
+});