-
Notifications
You must be signed in to change notification settings - Fork 464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test Promise thenable's onResolve realm #3356
Comments
This is not equivalent to the test proposed in #2910, right? This test seem to use the realm of the The equivalent would be: var other = $262.createRealm().global;
var otherThen = other.eval('() => {}');
var onThen, onCatch;
Promise.prototype.then.call({
then(onThen_, onCatch_) {
onThen= onThen_;
onCatch= onCatch_;
}
}, otherThen);
assert.sameValue(thenFinally.constructor, onFinally.constructor);
assert.sameValue(catchFinally.constructor, onFinally.constructor); Which is highlighting what I don't understand. I believe it wouldn't be a concern to use the realm of the |
Yes, but not quite. The only way to access the synthetic functions in Promise.resolve().then(() => {
return {
then(onThen) {
// onThen is a synthetic function. What realm does it belong to?
}
};
}); The only way to test, then, is to check if the realm of |
So one thing I still don't understand is why isn't the realm of |
There's a lot of history in:
Essentially, if we used |
Thanks for the links, still going through them. From a quick read, this sound like an HTML specific decision to not process enqueued promise jobs under some circumstances, which ends up affecting the specified scoping of JavaScript promises. Feels weird to me to have dynamic scoping wart in JS for this. Afaik there are other issues with detached iframes, like Naïve question, why can't promises in the queue of a detached document be rejected? Would that actually not be web compatible since it seems currently the behavior of some browsers is to hang? |
It's a security invariant, too. Imagine you were able to grab the global
Easing the integration for our most important consumer is important.
|
Right, dynamic scoping is a security issue, and I don't see how the current approach satisfies that invariant. I wrote the following test: https://gist.github.com/mhofman/df7047ee89942038cbc4629c41b8c7e0 First, implementations seem inconsistent, so I don't think we should claim the current behavior is beyond repair. The way I see it, the truly sane value for any of those is The least bad of those is probably
Thankfully |
I don't see how the Consider instead https://output.jsbin.com/hidozel/quiet. In this case, we have an unexpected difference between |
Sure, but neither example calls
What is the difference? I'm seeing the following in the console in Chrome 96:
Regardless, I'm not arguing for a difference between the two. I'm arguing that they should both behave the same, but that if a thenable is involved, that the user code's thenable is not able to get access to a function constructor they wouldn't have had access to otherwise. In the example I gave, I believe it should all print |
I think we do have a web compatibility issue though I would have to look more deeply about which browser has it right -- there may be pressure to align with sm/chrome if there is a major library that relies on this behavior (hopefully unlikely) so we may have to follow web reality in that case -- otherwise this might be a correction issue. Without looking deeply i think SM/chrome might be correct so that may not be an issue? It looks like we are missing a test for this on promise.then as justin pointed out. I think we are in agreement that we likely need to align on this. |
Also thank you mhofman for the test, that was interesting to read. |
From a conceptual point of view, I think JSC is closer to being correct, as it's the creator of the adopting promise which creates the callback function in its own realm and gives them to the thenable. However what the implication is on dying realms and existing code, I'm not sure. It's likely some Chrome/Firefox specific programs would be impacted if the realm of the adopting promise was used instead of the realm of the thenable's |
At present, I disagree, both regarding that the answer here should be red or yellow. I believe chrome and firefox have the intended behaviour, but maybe i spent too much time looking at it. The binding is explicit to the blue realm, that it should change to the red or yellow realm seems odd and exposes multiple realms when there should only be one. However, I am on break starting today. I will pick this thread up again once i am back from winter break. |
My opinion derives from what a userland library implementing While I find that surprising as form of dynamic scoping, it does indeed not reveal functions from another realm to blue's Enjoy the break! |
Re: #2910, I'm not able to find a similar test that checks the realm of the
onResolve
/onReject
when using a cross realm thenable:I believe this was part of tc39/ecma262#1597?
The text was updated successfully, but these errors were encountered: