-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Consider not exposing ErrorEvent/PromiseRejectionEvent in ShadowRealms #7591
Comments
@domenic @Ms2ger @leobalter do you agree with @smaug---- about #7244? |
I'm not sure. I think it would generally be useful to expose ErrorEvent, so that people could fire ErrorEvents at their own custom EventTarget instances, in case application-specific errors occur. That seems nicer for developers than forcing them to use CustomEvent or Event-with-expandos for such cases. Directing promise rejections to custom EventTarget instances seems less likely to be useful, but not inconceivable. And I kind of feel like we should treat sync errors and promise rejections the same. So I lean toward including it, even though the browser will never fire it. But another consistent perspective would be to keep the number of Event subclasses exposed minimal, e.g. only Event and CustomEvent. |
I was able to review this internally with my team and we all agreed @domenic's feedback feels pretty solid. Please let me know if there is anything else I can provide from my end. |
I could vaguely see someone using ErrorEvent for something, but PromiseRejectionEvent rather unlikely. |
We discussed this topic today during the SES meeting, and we are in agreement with @domenic's position as well. @smaug---- with respect to |
I also want to re-iterate that no matter what, the incubator realm (or whatever the name is for the realm which holds the window as global), is not allowed to expose the error or promise objects from shadow realms, as that would violate the callable boundary. |
@caridy, I can totally understand exposing PromiseRejectionEvent once there is some API using it. But before that? We don't normally expose interfaces beforehand just in case some API later might use them. |
Has there been agreement about continuing to expose PromiseRejectionEvent and ErrorEvent? |
Ok, I dropped the ball on this one. Let me clarify my position. But first, keep in mind that now we have the semantics of error copying across realms well defined here: https://github.com/tc39/proposal-shadowrealm/blob/main/errors.md, this is important because it allows to think about errors as objects that can be copied from one realm to another at will. With that context, here is what I think:
Note: when an error is copied from a shadowRealm to the root realm, the type changes to TypeError, and the message is stitched together by the Host, but the stack reflects the whole stack, so logging and instrumentation of the errors should remain useful for developers out there. |
To be more specific: const s = new ShadowRealm()
const letItThrow = await s.importValue('./x.js', 'letItThrow');
try {
letItThrow();
} catch (e) {
// this is useful
} That should be equivalent to: const s = new ShadowRealm()
const letItReport = await s.importValue('./x.js', 'letItReport');
window.onerror = (message, source, lineno, colno, error) => {
// this is useful
console.error(`message: ${error.message}, lineno: ${lineno}` );
return true;
};
letItReport(); That does not violate any of the semantics described in the ShadowRealm proposal. |
The problem of promise rejections and the Unless you replaced the To avoid this complexity, I would recommend that both uncaught errors and unhandled rejections have a mechanism to be handled directly inside the ShadowRealm. That's why I suggested above a new |
HTML has a mechanism where if an error is uncaught inside a dedicated worker, it will be reported as an error in the worker's "parent", possibly propagating up the chain until you reach a non-dedicated worker agent (which usually is the window's main agent). The thrown exception is obviously not included in such error events (the There doesn't seem to be anything equivalent for unhandled promise rejections, but I wonder if it could be added as well. |
The main problem with unhandled rejections is the fact that the Another argument in favor of exposing the unhandled rejection events directly in the ShadowRealm is the likely impossibility for these events to be recreated inside the shadow realm by the code running in the root realm. Even if the program could identify which event is tied to a particular ShadowRealm, it is impossible for the program to derive the identity of the original promise inside the shadowrealm if the event is only triggered in the root realm. The only thing I can imagine is a unique symbol included on the event in addition to (or maybe in place of) the Of course as @andreubotella suggest, triggering the event in the shadow realm, and propagating to the root realm if unhandled may help. However the question arises then to what should happen inside the shadow realm to the original promise if the root realm adds a reaction to the representative promise. (aka would the rejection be become handled in the shadow realm, or not?) |
Few notes from today's discussion at SES: Errors Observed from within a ShadowRealm:
Errors observed from the incubator realm or root realm:
|
@smaug---- @annevk what do you guys think about the notes from last month? #7591 (comment) I'm leaning toward 2.a, I will like to know if that's possible with an ordinary global object. |
I like option 2.a personally. I don't like option 2.b at all, because it causes weird bifurcations in the platform. It does indeed open up a can of worms, regarding ordinary vs. not. We were already reaching a tricky state with the desire to add certain global methods and properties (e.g. Simple version, which was our plan until now IIUC:
Inherit directly from EventTarget:
Web platform usual pattern:
I worry that "Inherit directly from EventTarget" is a bad intermediate state. For example, you'd end up with So if we go down the 2.a route, I think "web platform usual pattern" is probably the way to go. /cc @yuki3 @syg as I know they were recently looking at some related parts of Blink/V8. |
yeah, I think it should be "web platform usual pattern". (And yes, 2b looks awkward.) |
I believe the only requirement 262 has on the ShadowRealm global is that it behaves like an ordinary unsealed object, aka that all properties be configurable, that the prototype can be set, and that changing any of those succeeds like for ordinary objects (including explicitly freezing the global object). |
I'm fine with "web platform usual pattern", and I think the rest of the champions will also agree with that approach. Again, the main goal was to get off the business of WindowProxy and unforgeable properties, and that proposal from @domenic does that. |
Only quibble I have is that both "realm" and "global" in the name seems odd, but overall it having a more solid Web IDL footing seems good. |
Exposing PromiseRejectionEvent in Shadow Realms doesn't make much sense, since the global isn't an EventTarget.
https://html.spec.whatwg.org/#unhandled-promise-rejections just doesn't work with that kind of globals.
And https://html.spec.whatwg.org/#report-the-exception doesn't really work either, again because the global isn't an EventTarget.
The text was updated successfully, but these errors were encountered: