-
Notifications
You must be signed in to change notification settings - Fork 67
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
Assert that the global object inside the Shadow Realm is ordinary. #413
Conversation
If this is something we can actually assert, that would work for me. In this case we should likely also assert that the object is extensible and that all own properties are configurable. I suppose the editor note for |
I don't think an assertion is the right tool here. Assertions are just editorial notes that explicitly state properties are an algorithm that are already true due to the algorithm itself. They are purely informative, and removing all assertions from the spec should not change its meaning. Instead, we should pass a boolean requireOrdinaryGlobal (or isShadowRealm) to InitializeHostDefinedRealm(), and replace step 12 with
By doing so we are actually requiring the host to create an ordinary object, rather than just asserting that it does without enforcing it, and we still allow the global to inherit from EventTarget. |
Actually, looking at the HTML integration this would be easier for layering:
Also, note that the current proposed HTML integration defines the ShadowRealm global to behave exactly like an ordinary object, but it's not an ordinary object. Specifically, the [[SetPrototypeOf]] implementation is exotic and defined at https://webidl.spec.whatwg.org/#platform-object-setprototypeof. It however happens to behave exactly as the ordinary one, because is global prototype chain mutable returns true. The reason this layering is simpler is because it's much easier for HTML to create a new object (for which it can use the WebIDL machinery) rather than to define new properties on an existing one. |
As I mentioned in #411, that's fine:
The spec deals in observable behaviors. An implementation is always free to deviate from the letter of the spec as long as JS programs can never observe the deviation.
How do you recommend we constrain hosts on only adding configurable properties to the global object? In general how do we enforce invariants on host hooks? |
By not putting the "Assert:" annotation in front of it 😛 Normally for host hooks we say "the host must do X, Y and Z" rather than not stating requirements on what the host can do and then assert that when we previously called into the host it did X, Y and Z. |
Fwiw, this is fixed in whatwg/webidl#1437 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, together with tc39/ecma262#3498. Note that when opening the PR in the ECMA-262 repo, the new requirement should be added to InitializeHostDefinedRealm
and not to HostInitializeShadowRealm
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides one minor correction, LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, LGTM with Mathieu's suggestion about "extensible"
Co-authored-by: Mathieu Hofman <[email protected]>
Thanks! |
@mhofman: please let me know if there's any requirements this doesn't capture.