-
-
Save mhofman/df7047ee89942038cbc4629c41b8c7e0 to your computer and use it in GitHub Desktop.
What realm does a promise `onResolve` belong to?
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
var red = $262.createRealm().global; | |
var blue = $262.createRealm().global; | |
var yellow = $262.createRealm().global; | |
var purple = $262.createRealm().global; | |
var thenResult = {}; | |
var finallyResult = {}; | |
var who = new Map(); | |
who.set(red.Function, "red"); | |
who.set(blue.Function, "blue"); | |
who.set(yellow.Function, "yellow"); | |
who.set(purple.Function, "purple"); | |
who.set(Function, "self"); | |
var blueThenFactory = blue.eval( | |
`(result) => (onThen, onCatch) => { result.onThen = onThen; result.onCatch = onCatch; }` | |
); | |
var purpleOnResolveBlueThenable = purple.eval( | |
`(then) => () => ({ then: then })` | |
)(blueThenFactory(thenResult)); | |
var redPromise = red.Promise.resolve(); | |
yellow.Promise.prototype.then.call(redPromise, purpleOnResolveBlueThenable); | |
var blueThenable = { then: blueThenFactory(finallyResult) }; | |
var purpleOnFinally = purple.eval(`() => {}`); | |
yellow.Promise.prototype.finally.call(blueThenable, purpleOnFinally); | |
print(who.size); | |
Promise.resolve() | |
.then(() => {}) | |
.then(() => { | |
print( | |
"then", | |
who.get(thenResult.onThen.constructor), | |
who.get(thenResult.onCatch.constructor) | |
); | |
print( | |
"finally", | |
who.get(finallyResult.onThen.constructor), | |
who.get(finallyResult.onCatch.constructor) | |
); | |
}); |
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
#### engine262 | |
5 | |
then red red | |
finally yellow yellow | |
#### JavaScriptCore | |
5 | |
then red red | |
finally yellow yellow | |
#### Moddable XS | |
1 | |
then self self | |
finally self self | |
#### SpiderMonkey | |
5 | |
then blue blue | |
finally yellow yellow | |
#### V8 | |
5 | |
then blue blue | |
finally yellow yellow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment