summaryrefslogtreecommitdiff
path: root/dom/fetch
diff options
context:
space:
mode:
authorBrian Smith <brian@dbsoft.org>2023-09-28 19:51:09 -0500
committerBrian Smith <brian@dbsoft.org>2023-09-28 19:51:09 -0500
commit99c25d8e984905ef96990df66fea6bc12c310bbb (patch)
tree899a5aabf751212960ee6f683e65d7d95403f3f6 /dom/fetch
parent8a452389082e9b99cc14fd645daf3a40d310d9b1 (diff)
downloaduxp-99c25d8e984905ef96990df66fea6bc12c310bbb.tar.gz
Issue #1442 - Part 15 - Setting the correct global when ReadableStream.getReader() is called.
https://bugzilla.mozilla.org/show_bug.cgi?id=1128959
Diffstat (limited to 'dom/fetch')
-rw-r--r--dom/fetch/Fetch.cpp4
-rw-r--r--dom/fetch/FetchStreamReader.cpp16
2 files changed, 10 insertions, 10 deletions
diff --git a/dom/fetch/Fetch.cpp b/dom/fetch/Fetch.cpp
index 53ada9378b..dfc65c840e 100644
--- a/dom/fetch/Fetch.cpp
+++ b/dom/fetch/Fetch.cpp
@@ -1139,6 +1139,10 @@ FetchBody<Derived>::LockStream(JSContext* aCx,
JS::HandleObject aStream,
ErrorResult& aRv)
{
+ MOZ_ASSERT(JS::ReadableStreamGetMode(aStream) ==
+ JS::ReadableStreamMode::ExternalSource);
+
+ // This is native stream, creating a reader will not execute any JS code.
JS::Rooted<JSObject*> reader(aCx,
JS::ReadableStreamGetReader(aCx, aStream,
JS::ReadableStreamReaderMode::Default));
diff --git a/dom/fetch/FetchStreamReader.cpp b/dom/fetch/FetchStreamReader.cpp
index 98d2588a0e..5d9719a0c1 100644
--- a/dom/fetch/FetchStreamReader.cpp
+++ b/dom/fetch/FetchStreamReader.cpp
@@ -169,17 +169,13 @@ FetchStreamReader::OnOutputStreamReady(nsIAsyncOutputStream* aStream)
return WriteBuffer();
}
- AutoJSAPI jsapi;
- if (NS_WARN_IF(!jsapi.Init(mGlobal))) {
- CloseAndRelease(NS_ERROR_DOM_INVALID_STATE_ERR);
- return NS_ERROR_FAILURE;
- }
-
- JSContext* cx = jsapi.cx();
+ // TODO: We need to verify this is the correct global per the spec.
+ // See bug 1385890.
+ AutoEntryScript aes(mGlobal, "ReadableStreamReader.read", !mWorkerHolder);
- JS::Rooted<JSObject*> reader(cx, mReader);
- JS::Rooted<JSObject*> promise(cx,
- JS::ReadableStreamDefaultReaderRead(cx,
+ JS::Rooted<JSObject*> reader(aes.cx(), mReader);
+ JS::Rooted<JSObject*> promise(aes.cx(),
+ JS::ReadableStreamDefaultReaderRead(aes.cx(),
reader));
if (NS_WARN_IF(!promise)) {
// Let's close the stream.