Closed Bug 1750634 Opened 2 years ago Closed 2 years ago

Write test for Streams global selection

Categories

(Core :: DOM: Streams, task, P3)

task

Tracking

()

RESOLVED FIXED
98 Branch
Tracking Status
firefox98 --- fixed

People

(Reporter: mgaudet, Assigned: mgaudet)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

This test had a fair amount of work put into it, it would be bad to lose it if it still provides value.

Hmm.

Some assumptions from this test may no longer be correct.

The test assumes that the following holds;

    otherGlobal = newGlobal({ wantGlobalProperties: ["ReadableStream"] });

    let OtherReadableStream = otherGlobal.ReadableStream;
    let ReadableStreamReader = new ReadableStream().getReader().constructor;
    let stream = new ReadableStream();
    let otherReader = OtherReadableStream.prototype.getReader.call(stream);

    Assert.equal(otherReader instanceof ReadableStreamReader, false, "because the global is different");

However, this isn't true in our current DOM streams implementation.

Pasting the following into Safari & Chrome, and we get varying results:

// I'm 99% sure creating a same origin iframe creates a new global, and so same as newGlobal above. 
var iframe = document.createElement("iframe")
iframe.src = window.location.href
document.body.append(iframe)
let ReadableStreamReader = new ReadableStream().getReader().constructor;
let OtherReadableStream = iframe.contentWindow.ReadableStream
let stream = new ReadableStream();
    let otherReader = OtherReadableStream.prototype.getReader.call(stream);

// False in Safari Firefox (with JS Streams) and
// True in Chrome and Firefox with DOM streams
console.log(otherReader instanceof ReadableStreamReader)

The reason this returns true in DOM Streams in firefox right now is that we borrow the parent of the given stream object when acquiring a reader. Since stream in this test case is from our current global, otherReader therefore is also from our current global.

I'm not sure how OtherReader.prototype.getReader.call(stream) switches globals in our current JS streams implementation; something I'm not understanding about .call?

Hmm. Ok. It looks like we're supposed to switch to the called function's realm during calling according to the JS Spec:

So I guess the question here is: Are WebIDL methods like ReadableStream.prototype.getReader ECMAScript Function Objects, or do they obey some other standard?

Olli: Is there a normal pattern to handle this I'm missing?

Flags: needinfo?(bugs)

Side note: Experimentally, I tried changing AcquireReadableStreamDefaultReader to instead create the reader with the incumbent global returned by GetIncumbentGlobal: no success.

(Given that there's disagreement on the web about what the correct behaviour is, I don't currently consider this a blocker to shipping)

It seems that the general expectation is that what we're currently doing for DOM streams is correct.

There will potentially be some followup work to clarify in the specification, but we can follow in testing the Chrome behaviour.

Flags: needinfo?(bugs)
Blocks: 1730584
No longer blocks: 1735656
Summary: Port test `readable-stream-global.js` from JS Streams implementation to xpcshell-test. → Write test for Streams global selection

(This will also hopefully be clarified and made explicit by https://github.com/whatwg/streams/issues/1213)

This test is based on the general structure of
js/src/tests/non262/ReadableStream/readable-stream-globals.js, however the
expectations have been commented and updated to match what we believe is
the correct WebIDL behaviour.

Not all the features of that test case have been ported over, as there's
some stuff around the handling of Symbol.species that we can test elsewhere,
and it attempts to test BYOB streams, which we have yet to implement.

Note: I tried to initially write this as an xpcshell test case using
Cu.sandbox; but I found that I wasn't geting global behaviour that matched
my expectations from testing on the web, hence why this was recreated as
a mochitest instead.

Assignee: nobody → mgaudet
Status: NEW → ASSIGNED
Attachment #9261600 - Attachment description: Bug 1750634 - Add a mochitest to verify global selection in Streams r?smaug → Bug 1750634 - Add WPT Test for Stream Object globals r?smaug
Pushed by mgaudet@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/00d4eefcf59b
Add WPT Test for Stream Object globals r=smaug,saschanaz
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/32649 for changes under testing/web-platform/tests
Upstream PR was closed without merging
Pushed by mgaudet@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/7b75650e5e0b
Add WPT Test for Stream Object globals r=smaug,saschanaz
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 98 Branch
Upstream PR merged by moz-wptsync-bot

Unfortunately it seems like the test never made it upstream. https://github.com/web-platform-tests/wpt/commit/da15929d2adb3cd7889264411c0df5a7fb0cc845

Flags: needinfo?(james)

I think what happened here is that the bot got confused by the backout being for multiple bugs, and so applied both that and this to upstream in the wrong order. https://github.com/web-platform-tests/wpt/pull/33274 reverts the backout.

Flags: needinfo?(james)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: