-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Should MessageEvent.port really be nullable? #1882
Comments
I suspect this dates back to before IDL could have sequences defaulting to empty sequence or something... At first glance, I see nothing preventing us from changing
and changing
@bakulf, any obvious problems with that? I think you last dealt with this stuff in Gecko... |
Per http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=4564 3/4 browsers have it as nullable. I don't really see the value in taking the longer path to compat instead of the shorter one... |
In Gecko, we can make it not nullable easily. No problem at all. |
@domenic Chrome had it nullable until fairly recently. What's the value of having this attribute / member nullable? |
I don't see any particular value in either behavior. I am just wary of churning the spec (e.g. Chrome developers being unhappy that they made spec compliance changes only to get them reversed) and in making 3 engines change instead of 1. |
Well, I do think there is value in having it not nullable. It is nicer for Web developers as they don't have to worry about event.ports being null and can always assume it is an array. I don't think nullable arrays are a nice pattern in general. I understand WebKit is the only one at this point not having it nullable and I will make it nullable in WebKit if people don't want to change the specification. However, doing this change makes me sad and I am hoping other engine developers would be willing to make this change, even if it is the longer path to interoperability, given that I think it would result in a nicer API. |
It's easy to agree that what @cdumez suggests would be nicer, it'd also allow for the CC @bashi who did the Blink change. |
I have never done a spec change but I guess there is a first time for everything :) |
Make MessageEvent.port non-nullable as having it be nullable does not bring value and it makes for a nicer API if it is always an array.
PR at #1883 |
…1882) Make MessageEvent's port attribute non-nullable as having it be nullable does not bring value and it makes for a nicer API if it is always an array. Also add [SameObject] IDL extended attribute to it.
…#1882) Make MessageEvent's ports attribute non-nullable as having it be nullable does not bring value and it makes for a nicer API if it is always an array. Also add [SameObject] IDL extended attribute to it.
Add test coverage for the MessageEvent constructor and check that MessageEvent's ports attribute is not nullable as per: - whatwg/html#1883 - whatwg/html#1882
Add test coverage for the MessageEvent constructor and check that MessageEvent's ports attribute is not nullable as per: - whatwg/html#1883 - whatwg/html#1882
No, because its value is not constant. |
Isn't it? This is on the MessageEvent. It just returns the value it was initialized to. |
Yes, but |
(I can claim no credit for noticing that, by the way; @smaug---- did.) |
…#1882) Make MessageEvent's ports attribute non-nullable as having it be nullable does not bring value and it makes for a nicer API if it is always an array.
Ugh, well no |
Add test coverage for the MessageEvent constructor and check that MessageEvent's ports attribute is not nullable as per: - whatwg/html#1883 - whatwg/html#1882 Also cover MessageEvent's initMessageEvent operation.
Add test coverage for the MessageEvent constructor and check that MessageEvent's ports attribute is not nullable as per: - whatwg/html#1883 - whatwg/html#1882 Also cover MessageEvent's initMessageEvent operation.
Add test coverage for the MessageEvent constructor and check that MessageEvent's ports attribute is not nullable as per: - whatwg/html#1883 - whatwg/html#1882 Also cover MessageEvent's initMessageEvent operation.
Add test coverage for the MessageEvent constructor and check that MessageEvent's ports attribute is not nullable as per: - whatwg/html#1883 - whatwg/html#1882 Also cover MessageEvent's initMessageEvent operation.
Add test coverage for the MessageEvent constructor and check that MessageEvent's ports attribute is not nullable as per: - whatwg/html#1883 - whatwg/html#1882 Also cover MessageEvent's initMessageEvent operation.
Test now available at https://w3c-test.org/html/webappapis/scripting/events/messageevent-constructor.html Filed https://crbug.com/654707 for myself and https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9293321/ for Edge, assuming @bakulf will handle Gecko. AFAICT, only Gecko already required all of the arguments for |
So MessageEvent is now inconsistent with ServiceWorkerMessageEvent. |
Note, ServiceWorkerMessageEvent has nullable .ports in Blink and Gecko |
Uh, there's also ExtendableMessageEvent: Not sure what to make of that, but leaving them inconsistent is no good. @cdumez, can you lobby to have the service worker spec changed? If it's more hassle than it's worth, we can always go back to nullable in HTML of course. |
Looks like @smaug---- already filed a bug against the Service Worker specification [1]. Let's see how this goes. |
FWIW, since service worker events have nullable .ports both in implementations and in the spec, and also since majority of implementations have nullable .ports also on MessageEvent, and since nullability doesn't really cause any harm (and makes even sense in window.postMessage case, IMO), perhaps we should just stick with nullable ports everywhere. |
Non-nullable is a lot nicer though and service workers is still relatively fresh (and should probably change a bit here, the duplication seems rather hairy). But yeah, churn is not great. |
@smaug---- what do you mean by "makes even sense in window.postMessage case". I thought that postMessage() always created a FrozenArray even if there are no ports? |
oh, I was wrong about window.postMessage. nm that. |
Ok, so I think this change was just totally useless change, but since there is now a patch for Gecko, I won't object. ServiceWorker stuff is still inconsistent with this. |
I think HTML being able to change it means SW can also change it.
Out of curiosity, I would like to be convinced about this though.
I'm also concerned about this. If HTML wants to stay with non-nullable, let me know. I think making them consistent would be the first choice. |
Basically, your code can assume it's an array. That's a lot better than first having to do a null-check. I think the question with respect to service workers is how we can reduce some of the duplication going on with respect to classes. |
Fair point.
Yeah, it'd be interesting to discuss if we can do better. Here's the discussion we'd had for your reference: w3c/ServiceWorker#669 I'll change the service worker's .ports conforming to HTML. |
Thanks @jungkees 👍 |
Done with SW: w3c/ServiceWorker@8538a55 Thanks. |
Closing this as OP is addressed. Further simplification is happening in #1944. |
Make MessageEvent's ports attribute non-nullable as having it be nullable does not bring value and it makes for a nicer API if it is always an array. Closes whatwg#1882.
Should MessageEvent.port really be nullable?
I don't understand why it is useful to have it be nullable and why its default value could not simply be an empty array.
This attribute is not nullable in WebKit and was not nullable in Blink until recently [1]. Thus, chances are it is web-compatible to have it not be nullable.
[1] https://chromium.googlesource.com/chromium/src/+/789b7be6bafd3d57fd747e0e8afe4218c7f025d7
The text was updated successfully, but these errors were encountered: