-
Notifications
You must be signed in to change notification settings - Fork 161
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
Timing differences on start promise on WritableStream #1298
Comments
In general it's a bad idea to use const promise = Promise.resolve();
promise.then = doSomethingCustom; into "normal" promises. This is why throughout the web platform we use |
Yes, Blink is failing to follow the standard here. I filed https://bugs.chromium.org/p/chromium/issues/detail?id=1493934 against Blink but changing the standard might also be an option. When writing Streams tests I have always tried to avoid counting ticks, but if this is an important interoperability issue then we'll have to start. |
Thanks, Domenic! While we are at it: the IDL has Promise conversion rule which requires creating a new promise, but when I tested with the following snippet, it seems nobody at all cares for that: new WritableStream({
write() {
console.log('write')
const promise = Promise.resolve();
promise.then = () => console.log('then');
return promise;
}
}).getWriter().write() The log in the reference impl: write then I guess everyone is not following the Web IDL spec here. I can file an issue, but I want to double check my understanding is correct that the reference impl works right and everyone else is wrong. Am I correct here? (A little bit more context: the write callback returns a Promise so the JS promise should go through the conversion rule.) |
I am pretty sure the reference implementation is following the Web IDL spec and is correct. That said, it sounds like we have multiple implementations disobeying the Web IDL spec. Not just for Streams, probably, but also for other parts of the web platform. Although I gave a reason above why converting is generally good, it might not be worth the churn. We could just change Web IDL. I would mildly prefer aligning with the current Web IDL spec, but I would not be the one doing the work, so I'd like to see more discussion from implementers. |
I'm going to try to align our implementation to the WebIDL spec in https://bugzilla.mozilla.org/show_bug.cgi?id=1860083. |
One case were this is a bit weird is for |
Ah yep, that's weird. I guess we should just change that to |
As discovered in whatwg/streams#1298 (comment), Promise<T> is actually not an appropriate type for it.
As discovered in whatwg/streams#1298 (comment), Promise<T> is actually not an appropriate type for it.
Editorial: remove closing tags on the dir attribute table Helps with whatwg#9832. Editorial: remove closing tags on the dir attribute table Helps with whatwg#9832. Editorial: Remove old FinishDynamicImport reference Restore early return for history.go(0) This accidentally was lost in 0a97a81. Editorial: add enumerated attribute table for draggable Helps with whatwg#9832. Editorial: add enumerated attribute table for form/autocomplete Helps with whatwg#9832. Fix PromiseRejectionEvent's promise attribute As discovered in whatwg/streams#1298 (comment), Promise<T> is actually not an appropriate type for it. Navigation API: add navigation.activation Closes whatwg#9760. Editorial: remove closing tags on the dir attribute table Helps with whatwg#9832. Editorial: remove closing tags on the dir attribute table Helps with whatwg#9832. Editorial: remove closing tags on the dir attribute table Helps with whatwg#9832. Editorial: remove closing tags on the dir attribute table Helps with whatwg#9832. Editorial: remove closing tags on the dir attribute table Helps with whatwg#9832. Editorial: remove closing tags on the dir attribute table Helps with whatwg#9832. Editorial: remove closing tags on the dir attribute table Helps with whatwg#9832. Editorial: remove closing tags on the dir attribute table Helps with whatwg#9832.
What is the issue with the Streams Standard?
I was investigating further on #1296 and found that this snippet emits different logs on different implementations:
UnderlyingSinkStartCallback returns
any
, so the IDL promise conversion doesn't happen here, and thusstartResult
of step 15 becomes the raw JS promise. Then step 16 wraps it with a new promise via "a promise resolved with" algorithm, and thus it takes two rounds for the listener ofstartPromise
to be called.Promise.resolve().then()
only takes one round, so the result here should bepromise write
, as the reference impl shows.Instead, WebKit and Blink somehow effectively uses
Promise.resolve()
on the return value of startPromise: https://bugzilla.mozilla.org/show_bug.cgi?id=1859853#c1I think we need a discussion as the implementations are divided here. I guess the spec ended up with "a promise resolved with" wrapper steps as that's what Web IDL does, but is there a real point to wrap
startResult
that way? What bad thing happens when we just usePromise.resolve()
as WebKit/Blink/Node.js do?The text was updated successfully, but these errors were encountered: