Closed Bug 1736460 Opened 3 years ago Closed 3 years ago

Read_ReadRequest::ChunkSteps resolves with the wrong type.

Categories

(Core :: DOM: Streams, defect)

defect

Tracking

()

RESOLVED INVALID

People

(Reporter: mgaudet, Assigned: mgaudet)

References

(Blocks 1 open bug)

Details

Attachments

(2 obsolete files)

ReadableStreamDefaultReader's read WebIDL is specified as returning a Promise<ReadableStreamDefaultReadResult>.

Currently we do not do this, instead creating regular JS Objects. This turns out to be observable in response-stream-with-broken-then.any.js, where Object.prototype.then causes errors.

This may be fixable simply by removing the prototype from the object created in CreateValueDonePair, but we should have a clearer understanding of exactly what's involved in returning Promise<ReadableStreamDefaultReadResult>

Side note: Some archaeology:

This is a basic fix for response-stream-with-broken-then. What I'm not 100%
clear on is whether or not the fact that the IDL says we return a
Promise<ReadableStreamDefaultReadResult> means that we ought to do something
different / more binding typed?

Assignee: nobody → mgaudet
Status: NEW → ASSIGNED
Attachment #9246562 - Attachment is obsolete: true

So, the above patch has been abandoned. It would result in a user-visible, probably web-incompatible change where ReadableStreamDefaultReader.prototype.read would return an object with a null prototype.

The root cause of the problem is that the Streams specification is written as if we could easily resolve a promise with a dictionary value, avoiding all the messiness of resolving promises with objects, and having conversion from dictionary to object only occur at the WebIDL interface boundary. In reality, if we attempt to resolve a promise with a WebIDL dictionary value, we first convert that dictionary to an object, then resolve the promise.

In this case, rendering us vulnerable to the changes wrought by the special handling of the then property in the Promises specification (Steps 9-12) (thanks to Arai for pointing out the behaviour root).

I'm honestly not sure how to proceed here. From discussion about this issue on the Streams specification, it sounds like it's one of the few/only specs that uses Promises internally; but it seems like if more specs were written with Promises this could be a more pervasive issue: Any attempt to resolve a promise with an IDL type is vulnerable to this issue. It makes me feel as if the resolve path for IDL types needs specialization here, but I'm not sure where the lever ought to be applied.

Depends on: 1736622

(In reply to Matthew Gaudet (he/him) [:mgaudet] from comment #3)

The root cause of the problem is that the Streams specification is written as if we could easily resolve a promise with a dictionary value, avoiding all the messiness of resolving promises with objects, and having conversion from dictionary to object only occur at the WebIDL interface boundary. In reality, if we attempt to resolve a promise with a WebIDL dictionary value, we first convert that dictionary to an object, then resolve the promise.

This sounds like a spec issue. Or that the test is broken.

What part of the test fails? Or would it be possible to have a minimal testcase for this?

I ran into this on my local stack which is a bit ahead of whats in central, and so the linked test case needs Response. I'll try to to rescue the test case from Bug 1503324.

Regarding response-stream-with-broken-then.any.js, all sub-tests fail by allowing substitution.

The attached test case will fail on central, if the build is configured with --enable-dom-streams.

Attachment #9246739 - Attachment is obsolete: true
Attachment #9246739 - Attachment is obsolete: false

The severity field is not set for this bug.
:mgaudet, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(mgaudet)

So, this bug really only exists as part of the Fetch integration, so I have a fix that exists as part of the Fetch integration.

Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Flags: needinfo?(mgaudet)
Resolution: --- → INVALID
Attachment #9246739 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: