summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/01_core.js9
-rw-r--r--ext/web/02_timers.js4
-rw-r--r--runtime/js/99_main.js6
3 files changed, 18 insertions, 1 deletions
diff --git a/core/01_core.js b/core/01_core.js
index 13aa17c7e..d4a6508cb 100644
--- a/core/01_core.js
+++ b/core/01_core.js
@@ -187,7 +187,16 @@
const cb = macrotaskCallbacks[i];
while (true) {
const res = cb();
+
+ // If callback returned `undefined` then it has no work to do, we don't
+ // need to perform microtask checkpoint.
+ if (res === undefined) {
+ break;
+ }
+
ops.op_run_microtasks();
+ // If callback returned `true` then it has no more work to do, stop
+ // calling it then.
if (res === true) {
break;
}
diff --git a/ext/web/02_timers.js b/ext/web/02_timers.js
index 19ebfaa0e..27e2e953d 100644
--- a/ext/web/02_timers.js
+++ b/ext/web/02_timers.js
@@ -54,8 +54,10 @@ const timerTasks = [];
let timerNestingLevel = 0;
function handleTimerMacrotask() {
+ // We have no work to do, tell the runtime that we don't
+ // need to perform microtask checkpoint.
if (timerTasks.length === 0) {
- return true;
+ return undefined;
}
const task = ArrayPrototypeShift(timerTasks);
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index 8fd9a6bd9..511368141 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -351,6 +351,12 @@ function promiseRejectCallback(type, promise, reason) {
}
function promiseRejectMacrotaskCallback() {
+ // We have no work to do, tell the runtime that we don't
+ // need to perform microtask checkpoint.
+ if (pendingRejections.length === 0) {
+ return undefined;
+ }
+
while (pendingRejections.length > 0) {
const promise = ArrayPrototypeShift(pendingRejections);
const hasPendingException = ops.op_has_pending_promise_rejection(