forked from nodejs/node-chakracore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deps: fixing microtask behavior with multiple contexts
Initially we were handling microtasks per-context since our promise interface relies on per-library callbacks, but the v8 API actually deals with microtasks on a per-isolate level. This meant that we weren't properly firing microtasks / promise resolutions from contexts other than the currently active one. Now we also handle the microtask queue at the isolate level. PR-URL: nodejs#539 Reviewed-By: Kyle Farnung <kfarnung@microsoft.com> Reviewed-By: Hitesh Kanwathirtha <hiteshk@microsoft.com>
- Loading branch information
Showing
10 changed files
with
85 additions
and
44 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
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,32 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const vm = require('vm'); | ||
|
||
const responses = []; | ||
function saveResult(x) { | ||
responses.push(x); | ||
} | ||
|
||
const p1 = new Promise((resolve, reject) => resolve(1)); | ||
p1.then(saveResult).then(() => { saveResult(6); }); | ||
|
||
const p2 = new Promise((resolve, reject) => reject(2)); | ||
p2.catch(saveResult); | ||
|
||
const p5 = vm.runInNewContext(` | ||
const p3 = new Promise((resolve, reject) => resolve(3)).then(saveResult); | ||
p3.then(() => { saveResult(7); }); | ||
const p4 = new Promise((resolve, reject) => reject(4)).catch(saveResult); | ||
new Promise((resolve, reject) => resolve(5)); | ||
`, { saveResult }); | ||
p5.then(saveResult); | ||
|
||
// Note: using setImmediate here since that is a macrotask and will happen | ||
// after the microtask/promise queue is completely drained. | ||
setImmediate(() => { | ||
console.log(responses); | ||
assert.strictEqual(responses.length, 7); | ||
assert.deepStrictEqual(responses, [1, 2, 3, 4, 5, 6, 7]); | ||
}); |