Bug 1757241 - Remove !MOZ_DOM_STREAMS code from most files r=smaug

I've also tested to verify that JS Streams remains enabled in the JS Shell package

Differential Revision: https://phabricator.services.mozilla.com/D142620
This commit is contained in:
Matthew Gaudet 2022-04-13 18:57:48 +00:00
Родитель 43f30fd551
Коммит d07e459e7b
30 изменённых файлов: 26 добавлений и 1119 удалений

Просмотреть файл

@ -9,10 +9,8 @@
#include "mozilla/CycleCollectedJSContext.h"
#include "mozilla/dom/AutoEntryScript.h"
#include "mozilla/dom/DOMException.h"
#ifdef MOZ_DOM_STREAMS
# include "mozilla/dom/ReadableStream.h"
# include "mozilla/dom/ReadableByteStreamController.h"
#endif
#include "mozilla/dom/ReadableStream.h"
#include "mozilla/dom/ReadableByteStreamController.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/dom/WorkerPrivate.h"
@ -59,13 +57,6 @@ void BodyStreamHolder::StoreBodyStream(BodyStream* aBodyStream) {
mBodyStream = aBodyStream;
}
#ifndef MOZ_DOM_STREAMS
void BodyStreamHolder::ForgetBodyStream() {
MOZ_ASSERT_IF(mStreamCreated, mBodyStream);
mBodyStream = nullptr;
}
#endif
// BodyStream
// ---------------------------------------------------------------------------
@ -138,26 +129,11 @@ void BodyStream::Create(JSContext* aCx, BodyStreamHolder* aStreamHolder,
stream->mWorkerRef = std::move(workerRef);
}
#ifdef MOZ_DOM_STREAMS
RefPtr<ReadableStream> body =
ReadableStream::Create(aCx, aGlobal, aStreamHolder, aRv);
if (aRv.Failed()) {
return;
}
#else
aRv.MightThrowJSException();
JS::Rooted<JSObject*> body(aCx, JS::NewReadableExternalSourceStreamObject(
aCx, stream, aStreamHolder));
if (!body) {
aRv.StealExceptionFromJSContext(aCx);
return;
}
// This will be released in BodyStream::FinalizeCallback(). We are
// guaranteed the jsapi will call FinalizeCallback when ReadableStream
// js object is finalized.
NS_ADDREF(stream.get());
#endif
cleanup.release();
@ -169,7 +145,6 @@ void BodyStream::Create(JSContext* aCx, BodyStreamHolder* aStreamHolder,
#endif
}
#ifdef MOZ_DOM_STREAMS
// UnderlyingSource.pull, implemented for BodyStream.
already_AddRefed<Promise> BodyStream::PullCallback(
JSContext* aCx, ReadableStreamController& aController, ErrorResult& aRv) {
@ -177,9 +152,9 @@ already_AddRefed<Promise> BodyStream::PullCallback(
ReadableStream* stream = aController.AsByte()->Stream();
MOZ_ASSERT(stream);
# if MOZ_DIAGNOSTIC_ASSERT_ENABLED
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
MOZ_DIAGNOSTIC_ASSERT(stream->Disturbed());
# endif
#endif
AssertIsOnOwningThread();
@ -244,90 +219,12 @@ already_AddRefed<Promise> BodyStream::PullCallback(
// All good.
return resolvedWithUndefinedPromise.forget();
}
#else
void BodyStream::requestData(JSContext* aCx, JS::HandleObject aStream,
size_t aDesiredSize) {
# if MOZ_DIAGNOSTIC_ASSERT_ENABLED
bool disturbed;
if (!JS::ReadableStreamIsDisturbed(aCx, aStream, &disturbed)) {
JS_ClearPendingException(aCx);
} else {
MOZ_DIAGNOSTIC_ASSERT(disturbed);
}
# endif
AssertIsOnOwningThread();
MutexSingleWriterAutoLock lock(mMutex);
MOZ_DIAGNOSTIC_ASSERT(mState == eInitializing || mState == eWaiting ||
mState == eChecking || mState == eReading);
if (mState == eReading) {
// We are already reading data.
return;
}
if (mState == eChecking) {
// If we are looking for more data, there is nothing else we should do:
// let's move this checking operation in a reading.
MOZ_ASSERT(mInputStream);
mState = eReading;
return;
}
if (mState == eInitializing) {
// The stream has been used for the first time.
mStreamHolder->MarkAsRead();
}
mState = eReading;
if (!mInputStream) {
// This is the first use of the stream. Let's convert the
// mOriginalInputStream into an nsIAsyncInputStream.
MOZ_ASSERT(mOriginalInputStream);
nsCOMPtr<nsIAsyncInputStream> asyncStream;
nsresult rv = NS_MakeAsyncNonBlockingInputStream(
mOriginalInputStream.forget(), getter_AddRefs(asyncStream));
if (NS_WARN_IF(NS_FAILED(rv))) {
ErrorPropagation(aCx, lock, aStream, rv);
return;
}
mInputStream = asyncStream;
mOriginalInputStream = nullptr;
}
MOZ_DIAGNOSTIC_ASSERT(mInputStream);
MOZ_DIAGNOSTIC_ASSERT(!mOriginalInputStream);
nsresult rv = mInputStream->AsyncWait(this, 0, 0, mOwningEventTarget);
if (NS_WARN_IF(NS_FAILED(rv))) {
ErrorPropagation(aCx, lock, aStream, rv);
return;
}
// All good.
}
#endif
#ifdef MOZ_DOM_STREAMS
void BodyStream::WriteIntoReadRequestBuffer(JSContext* aCx,
ReadableStream* aStream,
JS::Handle<JSObject*> aChunk,
uint32_t aLength,
uint32_t* aByteWritten) {
#else
// This is passed the buffer directly: It is the responsibility of the
// caller to ensure the buffer handling is GC Safe.
void BodyStream::writeIntoReadRequestBuffer(JSContext* aCx,
JS::HandleObject aStream,
JS::Handle<JSObject*> aChunk,
size_t aLength,
size_t* aByteWritten) {
#endif
MOZ_DIAGNOSTIC_ASSERT(aChunk);
MOZ_DIAGNOSTIC_ASSERT(aByteWritten);
@ -379,7 +276,6 @@ void BodyStream::writeIntoReadRequestBuffer(JSContext* aCx,
// All good.
}
#ifdef MOZ_DOM_STREAMS
// UnderlyingSource.cancel callback, implmented for BodyStream.
already_AddRefed<Promise> BodyStream::CancelCallback(
JSContext* aCx, const Optional<JS::Handle<JS::Value>>& aReason,
@ -412,35 +308,7 @@ already_AddRefed<Promise> BodyStream::CancelCallback(
return promise.forget();
}
#else
JS::Value BodyStream::cancel(JSContext* aCx, JS::HandleObject aStream,
JS::HandleValue aReason) {
AssertIsOnOwningThread();
if (mState == eInitializing) {
// The stream has been used for the first time.
mStreamHolder->MarkAsRead();
}
if (mInputStream) {
mInputStream->CloseWithStatus(NS_BASE_STREAM_CLOSED);
}
// It could be that we don't have mInputStream yet, but we still have the
// original stream. We need to close that too.
if (mOriginalInputStream) {
MOZ_ASSERT(!mInputStream);
mOriginalInputStream->Close();
}
ReleaseObjects();
return JS::UndefinedValue();
}
void BodyStream::onClosed(JSContext* aCx, JS::HandleObject aStream) {}
#endif
#ifdef MOZ_DOM_STREAMS
// Non-standard UnderlyingSource.error callback.
void BodyStream::ErrorCallback() {
mMutex.AssertOnWritingThread();
@ -456,35 +324,6 @@ void BodyStream::ErrorCallback() {
ReleaseObjects();
}
#else
void BodyStream::onErrored(JSContext* aCx, JS::HandleObject aStream,
JS::HandleValue aReason) {
AssertIsOnOwningThread();
if (mState == eInitializing) {
// The stream has been used for the first time.
mStreamHolder->MarkAsRead();
}
if (mInputStream) {
mInputStream->CloseWithStatus(NS_BASE_STREAM_CLOSED);
}
ReleaseObjects();
}
#endif
#ifndef MOZ_DOM_STREAMS
void BodyStream::finalize() {
// This can be called in any thread.
// This takes ownership of the ref created in BodyStream::Create().
RefPtr<BodyStream> stream = dont_AddRef(this);
stream->ReleaseObjects();
}
#endif
BodyStream::BodyStream(nsIGlobalObject* aGlobal,
BodyStreamHolder* aStreamHolder,
@ -499,15 +338,9 @@ BodyStream::BodyStream(nsIGlobalObject* aGlobal,
MOZ_DIAGNOSTIC_ASSERT(aStreamHolder);
}
#ifdef MOZ_DOM_STREAMS
void BodyStream::ErrorPropagation(JSContext* aCx,
const MutexSingleWriterAutoLock& aProofOfLock,
ReadableStream* aStream, nsresult aError) {
#else
void BodyStream::ErrorPropagation(JSContext* aCx,
const MutexSingleWriterAutoLock& aProofOfLock,
JS::HandleObject aStream, nsresult aError) {
#endif
mMutex.AssertOnWritingThread();
mMutex.AssertCurrentThreadOwns();
@ -534,22 +367,17 @@ void BodyStream::ErrorPropagation(JSContext* aCx,
{
MutexSingleWriterAutoUnlock unlock(mMutex);
#ifdef MOZ_DOM_STREAMS
// Don't re-error an already errored stream.
if (aStream->State() == ReadableStream::ReaderState::Readable) {
IgnoredErrorResult rv;
ReadableStreamError(aCx, aStream, errorValue, rv);
NS_WARNING_ASSERTION(!rv.Failed(), "Failed to error BodyStream");
}
#else
JS::ReadableStreamError(aCx, aStream, errorValue);
#endif
}
ReleaseObjects(aProofOfLock);
}
#ifdef MOZ_DOM_STREAMS
void BodyStream::EnqueueChunkWithSizeIntoStream(JSContext* aCx,
ReadableStream* aStream,
uint64_t aAvailableData,
@ -594,7 +422,6 @@ void BodyStream::EnqueueChunkWithSizeIntoStream(JSContext* aCx,
return;
}
}
#endif
// thread-safety doesn't handle emplace well
NS_IMETHODIMP
@ -624,19 +451,10 @@ BodyStream::OnInputStreamReady(nsIAsyncInputStream* aStream)
MOZ_DIAGNOSTIC_ASSERT(mState == eReading || mState == eChecking);
JSContext* cx = aes.cx();
#ifdef MOZ_DOM_STREAMS
ReadableStream* stream = mStreamHolder->GetReadableStreamBody();
if (!stream) {
return NS_ERROR_FAILURE;
}
#else
JSObject* streamObj = mStreamHolder->GetReadableStreamBody();
if (!streamObj) {
return NS_ERROR_FAILURE;
}
JS::Rooted<JSObject*> stream(cx, streamObj);
#endif
uint64_t size = 0;
nsresult rv = mInputStream->Available(&size);
@ -663,7 +481,6 @@ BodyStream::OnInputStreamReady(nsIAsyncInputStream* aStream)
// Release the mutex before the call below (which could execute JS), as well
// as before the microtask checkpoint queued up above occurs.
lock.reset();
#ifdef MOZ_DOM_STREAMS
ErrorResult errorResult;
EnqueueChunkWithSizeIntoStream(cx, stream, size, errorResult);
errorResult.WouldReportJSException();
@ -672,9 +489,6 @@ BodyStream::OnInputStreamReady(nsIAsyncInputStream* aStream)
ErrorPropagation(cx, *lock, stream, errorResult.StealNSResult());
return NS_OK;
}
#else
Unused << JS::ReadableStreamUpdateDataAvailableFromSource(cx, stream, size);
#endif
// The previous call can execute JS (even up to running a nested event
// loop), so |mState| can't be asserted to have any particular value, even
@ -683,7 +497,6 @@ BodyStream::OnInputStreamReady(nsIAsyncInputStream* aStream)
return NS_OK;
}
#ifdef MOZ_DOM_STREAMS
/* static */
nsresult BodyStream::RetrieveInputStream(BodyStreamHolder* aStream,
nsIInputStream** aInputStream) {
@ -706,29 +519,6 @@ nsresult BodyStream::RetrieveInputStream(BodyStreamHolder* aStream,
inputStream.forget(aInputStream);
return NS_OK;
}
#else
/* static */
nsresult BodyStream::RetrieveInputStream(
JS::ReadableStreamUnderlyingSource* aUnderlyingReadableStreamSource,
nsIInputStream** aInputStream) {
MOZ_ASSERT(aUnderlyingReadableStreamSource);
MOZ_ASSERT(aInputStream);
RefPtr<BodyStream> stream =
static_cast<BodyStream*>(aUnderlyingReadableStreamSource);
stream->AssertIsOnOwningThread();
// if mOriginalInputStream is null, the reading already started. We don't want
// to expose the internal inputStream.
if (NS_WARN_IF(!stream->mOriginalInputStream)) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
nsCOMPtr<nsIInputStream> inputStream = stream->mOriginalInputStream;
inputStream.forget(aInputStream);
return NS_OK;
}
#endif
void BodyStream::Close() {
AssertIsOnOwningThread();
@ -744,7 +534,6 @@ void BodyStream::Close() {
ReleaseObjects(lock);
return;
}
#ifdef MOZ_DOM_STREAMS
ReadableStream* stream = mStreamHolder->GetReadableStreamBody();
if (stream) {
JSContext* cx = jsapi.cx();
@ -752,19 +541,8 @@ void BodyStream::Close() {
} else {
ReleaseObjects(lock);
}
#else
JSObject* streamObj = mStreamHolder->GetReadableStreamBody();
if (streamObj) {
JSContext* cx = jsapi.cx();
JS::Rooted<JSObject*> stream(cx, streamObj);
CloseAndReleaseObjects(cx, lock, stream);
} else {
ReleaseObjects(lock);
}
#endif
}
#ifdef MOZ_DOM_STREAMS
void BodyStream::CloseAndReleaseObjects(
JSContext* aCx, const MutexSingleWriterAutoLock& aProofOfLock,
ReadableStream* aStream) {
@ -782,26 +560,6 @@ void BodyStream::CloseAndReleaseObjects(
NS_WARNING_ASSERTION(!rv.Failed(), "Failed to Close Stream");
}
}
#else
void BodyStream::CloseAndReleaseObjects(
JSContext* aCx, const MutexSingleWriterAutoLock& aProofOfLock,
JS::HandleObject aStream) {
AssertIsOnOwningThread();
mMutex.AssertCurrentThreadOwns();
MOZ_DIAGNOSTIC_ASSERT(mState != eClosed);
ReleaseObjects(aProofOfLock);
MutexSingleWriterAutoUnlock unlock(mMutex);
bool readable;
if (!JS::ReadableStreamIsReadable(aCx, aStream, &readable)) {
return;
}
if (readable) {
JS::ReadableStreamClose(aCx, aStream);
}
}
#endif
void BodyStream::ReleaseObjects() {
MutexSingleWriterAutoLock lock(mMutex);
@ -847,23 +605,14 @@ void BodyStream::ReleaseObjects(const MutexSingleWriterAutoLock& aProofOfLock) {
}
}
#ifdef MOZ_DOM_STREAMS
ReadableStream* stream = mStreamHolder->GetReadableStreamBody();
if (stream) {
stream->ReleaseObjects();
}
#else
JSObject* streamObj = mStreamHolder->GetReadableStreamBody();
if (streamObj) {
// Let's inform the JSEngine that we are going to be released.
JS::ReadableStreamReleaseCCObject(streamObj);
}
#endif
mWorkerRef = nullptr;
mGlobal = nullptr;
#ifdef MOZ_DOM_STREAMS
// Since calling ForgetBodyStream can cause our current ref count to drop to
// zero, which would be bad, because this means we'd be destroying the mutex
// which aProofOfLock is holding; instead, we do this later by creating an
@ -877,9 +626,6 @@ void BodyStream::ReleaseObjects(const MutexSingleWriterAutoLock& aProofOfLock) {
// This is cancelable because if a worker cancels this, we're still fine
// as the lambda will be successfully destroyed.
}));
#else
mStreamHolder->ForgetBodyStream();
#endif
mStreamHolder->NullifyStream();
mStreamHolder = nullptr;
}

Просмотреть файл

@ -10,10 +10,8 @@
#include "jsapi.h"
#include "js/Stream.h"
#include "mozilla/AlreadyAddRefed.h"
#ifdef MOZ_DOM_STREAMS
# include "mozilla/dom/ByteStreamHelpers.h"
# include "mozilla/dom/BindingDeclarations.h"
#endif
#include "mozilla/dom/ByteStreamHelpers.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "nsIAsyncInputStream.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIObserver.h"
@ -34,9 +32,7 @@ namespace dom {
class BodyStream;
class WeakWorkerRef;
class ReadableStream;
#ifdef MOZ_DOM_STREAMS
class ReadableStreamController;
#endif
class BodyStreamUnderlyingSourceAlgorithms;
@ -55,36 +51,21 @@ class BodyStreamHolder : public nsISupports {
virtual void MarkAsRead() = 0;
#ifndef MOZ_DOM_STREAMS
virtual void SetReadableStreamBody(JSObject* aBody) = 0;
virtual JSObject* GetReadableStreamBody() = 0;
#else
virtual void SetReadableStreamBody(ReadableStream* aBody) = 0;
virtual ReadableStream* GetReadableStreamBody() = 0;
#endif
protected:
virtual ~BodyStreamHolder() = default;
private:
void StoreBodyStream(BodyStream* aBodyStream);
#ifdef MOZ_DOM_STREAMS
already_AddRefed<BodyStream> TakeBodyStream() {
MOZ_ASSERT_IF(mStreamCreated, mBodyStream);
return mBodyStream.forget();
}
#else
void ForgetBodyStream();
#endif
BodyStream* GetBodyStream() { return mBodyStream; }
#ifdef MOZ_DOM_STREAMS
RefPtr<BodyStream> mBodyStream;
#else
// Raw pointer because BodyStream keeps BodyStreamHolder alive and it
// nullifies this stream before being released.
BodyStream* mBodyStream;
#endif
#ifdef DEBUG
bool mStreamCreated = false;
@ -94,12 +75,7 @@ class BodyStreamHolder : public nsISupports {
class BodyStream final : public nsIInputStreamCallback,
public nsIObserver,
public nsSupportsWeakReference,
public SingleWriterLockOwner
#ifndef MOZ_DOM_STREAMS
,
private JS::ReadableStreamUnderlyingSource
#endif
{
public SingleWriterLockOwner {
friend class BodyStreamHolder;
public:
@ -124,14 +100,8 @@ class BodyStream final : public nsIInputStreamCallback,
#endif
}
#ifdef MOZ_DOM_STREAMS
static nsresult RetrieveInputStream(BodyStreamHolder* aStream,
nsIInputStream** aInputStream);
#else
static nsresult RetrieveInputStream(
JS::ReadableStreamUnderlyingSource* aUnderlyingReadableStreamSource,
nsIInputStream** aInputStream);
#endif
private:
BodyStream(nsIGlobalObject* aGlobal, BodyStreamHolder* aStreamHolder,
@ -144,7 +114,6 @@ class BodyStream final : public nsIInputStreamCallback,
void AssertIsOnOwningThread() const {}
#endif
#ifdef MOZ_DOM_STREAMS
public:
// Cancel Callback
already_AddRefed<Promise> CancelCallback(
@ -178,33 +147,6 @@ class BodyStream final : public nsIInputStreamCallback,
MOZ_CAN_RUN_SCRIPT_BOUNDARY void CloseAndReleaseObjects(
JSContext* aCx, const MutexSingleWriterAutoLock& aProofOfLock,
ReadableStream* aStream) REQUIRES(mMutex);
#else
void requestData(JSContext* aCx, JS::HandleObject aStream,
size_t aDesiredSize) override;
void writeIntoReadRequestBuffer(JSContext* aCx, JS::HandleObject aStream,
JS::Handle<JSObject*> aChunk, size_t aLength,
size_t* aBytesWritten) override;
JS::Value cancel(JSContext* aCx, JS::HandleObject aStream,
JS::HandleValue aReason) override REQUIRES(mMutex);
void onClosed(JSContext* aCx, JS::HandleObject aStream) override;
void onErrored(JSContext* aCx, JS::HandleObject aStream,
JS::HandleValue aReason) override REQUIRES(mMutex);
void finalize() override;
void ErrorPropagation(JSContext* aCx,
const MutexSingleWriterAutoLock& aProofOfLock,
JS::HandleObject aStream, nsresult aRv)
REQUIRES(mMutex);
void CloseAndReleaseObjects(JSContext* aCx,
const MutexSingleWriterAutoLock& aProofOfLock,
JS::HandleObject aStream) REQUIRES(mMutex);
#endif
class WorkerShutdown;

Просмотреть файл

@ -134,10 +134,8 @@ void nsIGlobalObject::UnlinkObjectsInGlobal() {
mReportRecords.Clear();
mReportingObservers.Clear();
#ifdef MOZ_DOM_STREAMS
mCountQueuingStrategySizeFunction = nullptr;
mByteLengthQueuingStrategySizeFunction = nullptr;
#endif
}
void nsIGlobalObject::TraverseObjectsInGlobal(
@ -153,10 +151,8 @@ void nsIGlobalObject::TraverseObjectsInGlobal(
nsIGlobalObject* tmp = this;
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReportRecords)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReportingObservers)
#ifdef MOZ_DOM_STREAMS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCountQueuingStrategySizeFunction)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mByteLengthQueuingStrategySizeFunction)
#endif
}
void nsIGlobalObject::AddEventTargetObject(DOMEventTargetHelper* aObject) {
@ -357,7 +353,6 @@ void nsIGlobalObject::RemoveReportRecords() {
}
}
#ifdef MOZ_DOM_STREAMS
already_AddRefed<mozilla::dom::Function>
nsIGlobalObject::GetCountQueuingStrategySizeFunction() {
return do_AddRef(mCountQueuingStrategySizeFunction);
@ -377,7 +372,6 @@ void nsIGlobalObject::SetByteLengthQueuingStrategySizeFunction(
mozilla::dom::Function* aFunction) {
mByteLengthQueuingStrategySizeFunction = aFunction;
}
#endif
bool nsIGlobalObject::ShouldResistFingerprinting() const {
return nsContentUtils::ShouldResistFingerprinting();

Просмотреть файл

@ -223,7 +223,6 @@ class nsIGlobalObject : public nsISupports,
void RemoveReportRecords();
#ifdef MOZ_DOM_STREAMS
// https://streams.spec.whatwg.org/#count-queuing-strategy-size-function
// This function is set once by CountQueuingStrategy::GetSize.
already_AddRefed<mozilla::dom::Function>
@ -234,7 +233,6 @@ class nsIGlobalObject : public nsISupports,
GetByteLengthQueuingStrategySizeFunction();
void SetByteLengthQueuingStrategySizeFunction(
mozilla::dom::Function* aFunction);
#endif
/**
* Check whether we should avoid leaking distinguishing information to JS/CSS.
@ -273,13 +271,11 @@ class nsIGlobalObject : public nsISupports,
nsTArray<RefPtr<mozilla::dom::ReportingObserver>> mReportingObservers;
nsTArray<RefPtr<mozilla::dom::Report>> mReportRecords;
#ifdef MOZ_DOM_STREAMS
// https://streams.spec.whatwg.org/#count-queuing-strategy-size-function
RefPtr<mozilla::dom::Function> mCountQueuingStrategySizeFunction;
// https://streams.spec.whatwg.org/#byte-length-queuing-strategy-size-function
RefPtr<mozilla::dom::Function> mByteLengthQueuingStrategySizeFunction;
#endif
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIGlobalObject, NS_IGLOBALOBJECT_IID)

Просмотреть файл

@ -1,30 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_ReadableStream_h
#define mozilla_dom_ReadableStream_h
#ifdef MOZ_DOM_STREAMS
# error "This shouldn't have been included"
#else
# include "js/experimental/TypedData.h"
# include "mozilla/dom/SpiderMonkeyInterface.h"
namespace mozilla {
namespace dom {
class ReadableStream : public SpiderMonkeyInterfaceObjectStorage {
public:
inline bool Init(JSObject* obj) {
MOZ_ASSERT(!inited());
mImplObj = mWrappedObj = js::UnwrapReadableStream(obj);
return inited();
}
};
} // namespace dom
} // namespace mozilla
#endif
#endif /* mozilla_dom_ReadableStream_h */

Просмотреть файл

@ -59,10 +59,6 @@ EXPORTS.mozilla.dom += [
"XrayExpandoClass.h",
]
if not CONFIG["MOZ_DOM_STREAMS"]:
EXPORTS.mozilla.dom += [
"ReadableStream.h",
]
# Generated bindings reference *Binding.h, not mozilla/dom/*Binding.h. And,
# since we generate exported bindings directly to $(DIST)/include, we need

Просмотреть файл

@ -31,6 +31,7 @@
#include "mozilla/dom/Headers.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/PromiseWorkerProxy.h"
#include "mozilla/dom/ReadableStreamDefaultReader.h"
#include "mozilla/dom/RemoteWorkerChild.h"
#include "mozilla/dom/Request.h"
#include "mozilla/dom/Response.h"
@ -48,15 +49,10 @@
#include "mozilla/dom/WorkerRunnable.h"
#include "mozilla/dom/WorkerScope.h"
#ifdef MOZ_DOM_STREAMS
# include "mozilla/dom/ReadableStreamDefaultReader.h"
#endif
namespace mozilla::dom {
namespace {
#ifdef MOZ_DOM_STREAMS
void AbortStream(JSContext* aCx, ReadableStream* aReadableStream,
ErrorResult& aRv) {
if (aReadableStream->State() != ReadableStream::ReaderState::Readable) {
@ -72,34 +68,6 @@ void AbortStream(JSContext* aCx, ReadableStream* aReadableStream,
ReadableStreamError(aCx, aReadableStream, value, aRv);
}
#else
void AbortStream(JSContext* aCx, JS::Handle<JSObject*> aStream,
ErrorResult& aRv) {
aRv.MightThrowJSException();
bool isReadable;
if (!JS::ReadableStreamIsReadable(aCx, aStream, &isReadable)) {
aRv.StealExceptionFromJSContext(aCx);
return;
}
if (!isReadable) {
return;
}
RefPtr<DOMException> e = DOMException::Create(NS_ERROR_DOM_ABORT_ERR);
JS::Rooted<JS::Value> value(aCx);
if (!GetOrCreateDOMReflector(aCx, e, &value)) {
return;
}
if (!JS::ReadableStreamError(aCx, aStream, value)) {
aRv.StealExceptionFromJSContext(aCx);
}
}
#endif
} // namespace
class AbortSignalMainThread final : public AbortSignalImpl {
@ -1133,27 +1101,7 @@ bool FetchBody<Derived>::GetBodyUsed(ErrorResult& aRv) const {
// If this stream is disturbed, return true.
if (mReadableStreamBody) {
#ifdef MOZ_DOM_STREAMS
return mReadableStreamBody->Disturbed();
#else
aRv.MightThrowJSException();
AutoJSAPI jsapi;
if (!jsapi.Init(mOwner)) {
aRv.Throw(NS_ERROR_FAILURE);
return true;
}
JSContext* cx = jsapi.cx();
JS::Rooted<JSObject*> body(cx, mReadableStreamBody);
bool disturbed;
if (!JS::ReadableStreamIsDisturbed(cx, body, &disturbed)) {
aRv.StealExceptionFromJSContext(cx);
return false;
}
return disturbed;
#endif
}
return false;
@ -1189,40 +1137,6 @@ void FetchBody<Derived>::SetBodyUsed(JSContext* aCx, ErrorResult& aRv) {
mBodyUsed = true;
#ifndef MOZ_DOM_STREAMS
// If we already have a ReadableStreamBody and it has been created by DOM, we
// have to lock it now because it can have been shared with other objects.
if (mReadableStreamBody) {
aRv.MightThrowJSException();
JSAutoRealm ar(aCx, mOwner->GetGlobalJSObject());
JS::Rooted<JSObject*> readableStreamObj(aCx, mReadableStreamBody);
JS::ReadableStreamMode mode;
if (!JS::ReadableStreamGetMode(aCx, readableStreamObj, &mode)) {
aRv.StealExceptionFromJSContext(aCx);
return;
}
if (mode == JS::ReadableStreamMode::ExternalSource) {
LockStream(aCx, readableStreamObj, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
} else {
// If this is not a native ReadableStream, let's activate the
// FetchStreamReader.
MOZ_ASSERT(mFetchStreamReader);
JS::Rooted<JSObject*> reader(aCx);
mFetchStreamReader->StartConsuming(aCx, readableStreamObj, &reader, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
mReadableStreamReader = reader;
}
}
#else
// If we already have a ReadableStreamBody and it has been created by DOM, we
// have to lock it now because it can have been shared with other objects.
if (mReadableStreamBody) {
@ -1244,7 +1158,6 @@ void FetchBody<Derived>::SetBodyUsed(JSContext* aCx, ErrorResult& aRv) {
mReadableStreamReader = reader.forget();
}
}
#endif
}
template void FetchBody<Request>::SetBodyUsed(JSContext* aCx, ErrorResult& aRv);
@ -1384,38 +1297,6 @@ template const nsAString& FetchBody<Response>::BodyLocalPath() const;
template const nsAString& FetchBody<EmptyBody>::BodyLocalPath() const;
#ifndef MOZ_DOM_STREAMS
template <class Derived>
void FetchBody<Derived>::SetReadableStreamBody(JSContext* aCx,
JSObject* aBody) {
MOZ_ASSERT(!mReadableStreamBody);
MOZ_ASSERT(aBody);
mReadableStreamBody = aBody;
RefPtr<AbortSignalImpl> signalImpl = DerivedClass()->GetSignalImpl();
if (!signalImpl) {
return;
}
bool aborted = signalImpl->Aborted();
if (aborted) {
JS::Rooted<JSObject*> body(aCx, mReadableStreamBody);
IgnoredErrorResult result;
AbortStream(aCx, body, result);
if (NS_WARN_IF(result.Failed())) {
return;
}
} else if (!IsFollowing()) {
Follow(signalImpl);
}
}
template void FetchBody<Request>::SetReadableStreamBody(JSContext* aCx,
JSObject* aBody);
template void FetchBody<Response>::SetReadableStreamBody(JSContext* aCx,
JSObject* aBody);
#else
template <class Derived>
void FetchBody<Derived>::SetReadableStreamBody(JSContext* aCx,
ReadableStream* aBody) {
@ -1445,70 +1326,7 @@ template void FetchBody<Request>::SetReadableStreamBody(JSContext* aCx,
template void FetchBody<Response>::SetReadableStreamBody(JSContext* aCx,
ReadableStream* aBody);
#endif
#ifndef MOZ_DOM_STREAMS
template <class Derived>
void FetchBody<Derived>::GetBody(JSContext* aCx,
JS::MutableHandle<JSObject*> aBodyOut,
ErrorResult& aRv) {
if (mReadableStreamBody) {
aBodyOut.set(mReadableStreamBody);
return;
}
nsCOMPtr<nsIInputStream> inputStream;
DerivedClass()->GetBody(getter_AddRefs(inputStream));
if (!inputStream) {
aBodyOut.set(nullptr);
return;
}
BodyStream::Create(aCx, this, DerivedClass()->GetParentObject(), inputStream,
aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
MOZ_ASSERT(mReadableStreamBody);
JS::Rooted<JSObject*> body(aCx, mReadableStreamBody);
// If the body has been already consumed, we lock the stream.
bool bodyUsed = GetBodyUsed(aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
if (bodyUsed) {
LockStream(aCx, body, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
}
RefPtr<AbortSignalImpl> signalImpl = DerivedClass()->GetSignalImpl();
if (signalImpl) {
if (signalImpl->Aborted()) {
AbortStream(aCx, body, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
} else if (!IsFollowing()) {
Follow(signalImpl);
}
}
aBodyOut.set(mReadableStreamBody);
}
template void FetchBody<Request>::GetBody(JSContext* aCx,
JS::MutableHandle<JSObject*> aMessage,
ErrorResult& aRv);
template void FetchBody<Response>::GetBody(
JSContext* aCx, JS::MutableHandle<JSObject*> aMessage, ErrorResult& aRv);
#else
template <class Derived>
already_AddRefed<ReadableStream> FetchBody<Derived>::GetBody(JSContext* aCx,
ErrorResult& aRv) {
@ -1567,9 +1385,6 @@ template already_AddRefed<ReadableStream> FetchBody<Request>::GetBody(
template already_AddRefed<ReadableStream> FetchBody<Response>::GetBody(
JSContext* aCx, ErrorResult& aRv);
#endif
#ifdef MOZ_DOM_STREAMS
template <class Derived>
void FetchBody<Derived>::LockStream(JSContext* aCx, ReadableStream* aStream,
ErrorResult& aRv) {
@ -1590,107 +1405,6 @@ template void FetchBody<Request>::LockStream(JSContext* aCx,
template void FetchBody<Response>::LockStream(JSContext* aCx,
ReadableStream* aStream,
ErrorResult& aRv);
#else
template <class Derived>
void FetchBody<Derived>::LockStream(JSContext* aCx, JS::HandleObject aStream,
ErrorResult& aRv) {
aRv.MightThrowJSException();
# if DEBUG
JS::ReadableStreamMode streamMode;
if (!JS::ReadableStreamGetMode(aCx, aStream, &streamMode)) {
aRv.StealExceptionFromJSContext(aCx);
return;
}
MOZ_ASSERT(streamMode == JS::ReadableStreamMode::ExternalSource);
# endif // DEBUG
// 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));
if (!reader) {
aRv.StealExceptionFromJSContext(aCx);
return;
}
mReadableStreamReader = reader;
}
template void FetchBody<Request>::LockStream(JSContext* aCx,
JS::HandleObject aStream,
ErrorResult& aRv);
template void FetchBody<Response>::LockStream(JSContext* aCx,
JS::HandleObject aStream,
ErrorResult& aRv);
#endif
#ifndef MOZ_DOM_STREAMS
template <class Derived>
void FetchBody<Derived>::MaybeTeeReadableStreamBody(
JSContext* aCx, JS::MutableHandle<JSObject*> aBodyOut,
FetchStreamReader** aStreamReader, nsIInputStream** aInputStream,
ErrorResult& aRv) {
MOZ_DIAGNOSTIC_ASSERT(aStreamReader);
MOZ_DIAGNOSTIC_ASSERT(aInputStream);
MOZ_DIAGNOSTIC_ASSERT(!CheckBodyUsed());
aBodyOut.set(nullptr);
*aStreamReader = nullptr;
*aInputStream = nullptr;
if (!mReadableStreamBody) {
return;
}
aRv.MightThrowJSException();
JSAutoRealm ar(aCx, mOwner->GetGlobalJSObject());
JS::Rooted<JSObject*> stream(aCx, mReadableStreamBody);
// If this is a ReadableStream with an external source, this has been
// generated by a Fetch. In this case, Fetch will be able to recreate it
// again when GetBody() is called.
JS::ReadableStreamMode streamMode;
if (!JS::ReadableStreamGetMode(aCx, stream, &streamMode)) {
aRv.StealExceptionFromJSContext(aCx);
return;
}
if (streamMode == JS::ReadableStreamMode::ExternalSource) {
aBodyOut.set(nullptr);
return;
}
JS::Rooted<JSObject*> branch1(aCx);
JS::Rooted<JSObject*> branch2(aCx);
if (!JS::ReadableStreamTee(aCx, stream, &branch1, &branch2)) {
aRv.StealExceptionFromJSContext(aCx);
return;
}
mReadableStreamBody = branch1;
aBodyOut.set(branch2);
aRv = FetchStreamReader::Create(aCx, mOwner, aStreamReader, aInputStream);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
}
template void FetchBody<Request>::MaybeTeeReadableStreamBody(
JSContext* aCx, JS::MutableHandle<JSObject*> aMessage,
FetchStreamReader** aStreamReader, nsIInputStream** aInputStream,
ErrorResult& aRv);
template void FetchBody<Response>::MaybeTeeReadableStreamBody(
JSContext* aCx, JS::MutableHandle<JSObject*> aMessage,
FetchStreamReader** aStreamReader, nsIInputStream** aInputStream,
ErrorResult& aRv);
#else
template <class Derived>
void FetchBody<Derived>::MaybeTeeReadableStreamBody(
@ -1741,7 +1455,6 @@ template void FetchBody<Response>::MaybeTeeReadableStreamBody(
JSContext* aCx, ReadableStream** aBodyOut,
FetchStreamReader** aStreamReader, nsIInputStream** aInputStream,
ErrorResult& aRv);
#endif
template <class Derived>
void FetchBody<Derived>::RunAbortAlgorithm() {
@ -1756,11 +1469,7 @@ void FetchBody<Derived>::RunAbortAlgorithm() {
JSContext* cx = jsapi.cx();
#ifdef MOZ_DOM_STREAMS
RefPtr<ReadableStream> body(mReadableStreamBody);
#else
JS::Rooted<JSObject*> body(cx, mReadableStreamBody);
#endif
IgnoredErrorResult result;
AbortStream(cx, body, result);
}
@ -1778,10 +1487,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(EmptyBody, FetchBody<EmptyBody>)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAbortSignalImpl)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFetchStreamReader)
#ifdef MOZ_DOM_STREAMS
NS_IMPL_CYCLE_COLLECTION_UNLINK(mReadableStreamBody)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mReadableStreamReader)
#endif
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(EmptyBody,
@ -1789,10 +1496,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(EmptyBody,
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAbortSignalImpl)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFetchStreamReader)
#ifdef MOZ_DOM_STREAMS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReadableStreamBody)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReadableStreamReader)
#endif
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(EmptyBody, FetchBody<EmptyBody>)

Просмотреть файл

@ -19,10 +19,8 @@
#include "mozilla/dom/BodyStream.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/FetchStreamReader.h"
#ifdef MOZ_DOM_STREAMS
# include "mozilla/dom/ReadableStream.h"
# include "mozilla/dom/ReadableStreamDefaultReaderBinding.h"
#endif
#include "mozilla/dom/ReadableStream.h"
#include "mozilla/dom/ReadableStreamDefaultReaderBinding.h"
#include "mozilla/dom/RequestBinding.h"
#include "mozilla/dom/workerinternals/RuntimeService.h"
@ -164,19 +162,13 @@ class FetchBody : public BodyStreamHolder, public AbortFollower {
return ConsumeBody(aCx, BodyConsumer::CONSUME_TEXT, aRv);
}
#ifdef MOZ_DOM_STREAMS
already_AddRefed<ReadableStream> GetBody(JSContext* aCx, ErrorResult& aRv);
#else
void GetBody(JSContext* aCx, JS::MutableHandle<JSObject*> aBodyOut,
ErrorResult& aRv);
#endif
void GetMimeType(nsACString& aMimeType);
const nsACString& BodyBlobURISpec() const;
const nsAString& BodyLocalPath() const;
#ifdef MOZ_DOM_STREAMS
// If the body contains a ReadableStream body object, this method produces a
// tee() of it.
//
@ -188,15 +180,6 @@ class FetchBody : public BodyStreamHolder, public AbortFollower {
FetchStreamReader** aStreamReader,
nsIInputStream** aInputStream,
ErrorResult& aRv);
#else
// If the body contains a ReadableStream body object, this method produces a
// tee() of it.
void MaybeTeeReadableStreamBody(JSContext* aCx,
JS::MutableHandle<JSObject*> aBodyOut,
FetchStreamReader** aStreamReader,
nsIInputStream** aInputStream,
ErrorResult& aRv);
#endif
// Utility public methods accessed by various runnables.
@ -229,19 +212,12 @@ class FetchBody : public BodyStreamHolder, public AbortFollower {
mFetchStreamReader = nullptr;
}
#ifndef MOZ_DOM_STREAMS
void SetReadableStreamBody(JSObject* aBody) override {
mReadableStreamBody = aBody;
}
JSObject* GetReadableStreamBody() override { return mReadableStreamBody; }
#else
void SetReadableStreamBody(ReadableStream* aBody) override {
mReadableStreamBody = aBody;
}
ReadableStream* GetReadableStreamBody() override {
return mReadableStreamBody;
}
#endif
void MarkAsRead() override { mBodyUsed = true; }
@ -259,7 +235,6 @@ class FetchBody : public BodyStreamHolder, public AbortFollower {
protected:
nsCOMPtr<nsIGlobalObject> mOwner;
#ifdef MOZ_DOM_STREAMS
// This is the ReadableStream exposed to content. It's underlying source is a
// BodyStream object. This needs to be traversed by subclasses.
RefPtr<ReadableStream> mReadableStreamBody;
@ -267,36 +242,20 @@ class FetchBody : public BodyStreamHolder, public AbortFollower {
// This is the Reader used to retrieve data from the body. This needs to be
// traversed by subclasses.
RefPtr<ReadableStreamDefaultReader> mReadableStreamReader;
#else
// This is the ReadableStream exposed to content. It's underlying source is a
// BodyStream object.
JS::Heap<JSObject*> mReadableStreamBody;
// This is the Reader used to retrieve data from the body.
JS::Heap<JSObject*> mReadableStreamReader;
#endif
RefPtr<FetchStreamReader> mFetchStreamReader;
explicit FetchBody(nsIGlobalObject* aOwner);
virtual ~FetchBody();
#ifdef MOZ_DOM_STREAMS
void SetReadableStreamBody(JSContext* aCx, ReadableStream* aBody);
#else
void SetReadableStreamBody(JSContext* aCx, JSObject* aBody);
#endif
private:
Derived* DerivedClass() const {
return static_cast<Derived*>(const_cast<FetchBody*>(this));
}
#ifdef MOZ_DOM_STREAMS
void LockStream(JSContext* aCx, ReadableStream* aStream, ErrorResult& aRv);
#else
void LockStream(JSContext* aCx, JS::HandleObject aStream, ErrorResult& aRv);
#endif
void AssertIsOnTargetThread() {
MOZ_ASSERT(NS_IsMainThread() == !GetCurrentThreadWorkerPrivate());

Просмотреть файл

@ -13,11 +13,9 @@
#include "mozilla/dom/DOMException.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/PromiseBinding.h"
#ifdef MOZ_DOM_STREAMS
# include "mozilla/dom/ReadableStream.h"
# include "mozilla/dom/ReadableStreamDefaultController.h"
# include "mozilla/dom/ReadableStreamDefaultReader.h"
#endif
#include "mozilla/dom/ReadableStream.h"
#include "mozilla/dom/ReadableStreamDefaultController.h"
#include "mozilla/dom/ReadableStreamDefaultReader.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/dom/WorkerRef.h"
#include "mozilla/HoldDropJSObjects.h"
@ -39,24 +37,15 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(FetchStreamReader)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(FetchStreamReader)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal)
#ifdef MOZ_DOM_STREAMS
NS_IMPL_CYCLE_COLLECTION_UNLINK(mReader)
#else
tmp->mReader = nullptr;
#endif
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(FetchStreamReader)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal)
#ifdef MOZ_DOM_STREAMS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReader)
#endif
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(FetchStreamReader)
#ifndef MOZ_DOM_STREAMS
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mReader)
#endif
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FetchStreamReader)
@ -153,7 +142,6 @@ void FetchStreamReader::CloseAndRelease(JSContext* aCx, nsresult aStatus) {
JS::Rooted<JS::Value> errorValue(aCx);
if (ToJSValue(aCx, error, &errorValue)) {
#ifdef MOZ_DOM_STREAMS
IgnoredErrorResult ignoredError;
// It's currently safe to cancel an already closed reader because, per the
// comments in ReadableStream::cancel() conveying the spec, step 2 of
@ -163,14 +151,6 @@ void FetchStreamReader::CloseAndRelease(JSContext* aCx, nsresult aStatus) {
MOZ_KnownLive(mReader)->Cancel(aCx, errorValue, ignoredError);
NS_WARNING_ASSERTION(!ignoredError.Failed(),
"Failed to cancel stream during close and release");
#else
JS::Rooted<JSObject*> reader(aCx, mReader);
// It's currently safe to cancel an already closed reader because, per the
// comments in ReadableStream::cancel() conveying the spec, step 2 of
// 3.4.3 that specified ReadableStreamCancel is: If stream.[[state]] is
// "closed", return a new promise resolved with undefined.
JS::ReadableStreamReaderCancel(aCx, reader, errorValue);
#endif
}
// We don't want to propagate exceptions during the cleanup.
@ -192,7 +172,6 @@ void FetchStreamReader::CloseAndRelease(JSContext* aCx, nsresult aStatus) {
mBuffer.Clear();
}
#ifdef MOZ_DOM_STREAMS
void FetchStreamReader::StartConsuming(JSContext* aCx, ReadableStream* aStream,
ReadableStreamDefaultReader** aReader,
ErrorResult& aRv) {
@ -215,42 +194,6 @@ void FetchStreamReader::StartConsuming(JSContext* aCx, ReadableStream* aStream,
}
}
#else
void FetchStreamReader::StartConsuming(JSContext* aCx, JS::HandleObject aStream,
JS::MutableHandle<JSObject*> aReader,
ErrorResult& aRv) {
MOZ_DIAGNOSTIC_ASSERT(!mReader);
MOZ_DIAGNOSTIC_ASSERT(aStream);
aRv.MightThrowJSException();
// Here, by spec, we can pick any global we want. Just to avoid extra
// cross-compartment steps, we want to create the reader in the same
// compartment of the owning Fetch Body object.
// The same global will be used to retrieve data from this reader.
JSAutoRealm ar(aCx, mGlobal->GetGlobalJSObject());
JS::Rooted<JSObject*> reader(
aCx, JS::ReadableStreamGetReader(aCx, aStream,
JS::ReadableStreamReaderMode::Default));
if (!reader) {
aRv.StealExceptionFromJSContext(aCx);
CloseAndRelease(aCx, NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
mReader = reader;
aReader.set(reader);
aRv = mPipeOut->AsyncWait(this, 0, 0, mOwningEventTarget);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
}
#endif
#ifdef MOZ_DOM_STREAMS
struct FetchReadRequest : public ReadRequest {
public:
NS_DECL_ISUPPORTS_INHERITED
@ -285,7 +228,6 @@ NS_IMPL_ADDREF_INHERITED(FetchReadRequest, ReadRequest)
NS_IMPL_RELEASE_INHERITED(FetchReadRequest, ReadRequest)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FetchReadRequest)
NS_INTERFACE_MAP_END_INHERITING(ReadRequest)
#endif
// nsIOutputStreamCallback interface
MOZ_CAN_RUN_SCRIPT_BOUNDARY
@ -309,7 +251,6 @@ FetchStreamReader::OnOutputStreamReady(nsIAsyncOutputStream* aStream) {
// Response's one.
AutoEntryScript aes(mGlobal, "ReadableStreamReader.read", !mWorkerRef);
#ifdef MOZ_DOM_STREAMS
IgnoredErrorResult rv;
// https://fetch.spec.whatwg.org/#incrementally-read-loop
@ -325,31 +266,9 @@ FetchStreamReader::OnOutputStreamReady(nsIAsyncOutputStream* aStream) {
return NS_ERROR_FAILURE;
}
#else
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.
CloseAndRelease(aes.cx(), NS_ERROR_DOM_INVALID_STATE_ERR);
return NS_ERROR_FAILURE;
}
RefPtr<Promise> domPromise = Promise::CreateFromExisting(mGlobal, promise);
if (NS_WARN_IF(!domPromise)) {
// Let's close the stream.
CloseAndRelease(aes.cx(), NS_ERROR_DOM_INVALID_STATE_ERR);
return NS_ERROR_FAILURE;
}
// Let's wait.
domPromise->AppendNativeHandler(this);
#endif
return NS_OK;
}
#ifdef MOZ_DOM_STREAMS
void FetchStreamReader::ChunkSteps(JSContext* aCx, JS::Handle<JS::Value> aChunk,
ErrorResult& aRv) {
// This roughly implements the chunk steps from
@ -394,72 +313,6 @@ void FetchStreamReader::ErrorSteps(JSContext* aCx, JS::Handle<JS::Value> aError,
CloseAndRelease(aCx, NS_ERROR_FAILURE);
}
#else
void FetchStreamReader::ResolvedCallback(JSContext* aCx,
JS::Handle<JS::Value> aValue,
ErrorResult& aRv) {
if (mStreamClosed) {
return;
}
// This promise should be resolved with { done: boolean, value: something },
// "value" is interesting only if done is false.
// We don't want to play with JS api, let's WebIDL bindings doing it for us.
// FetchReadableStreamReadDataDone is a dictionary with just a boolean, if the
// parsing succeeded, we can proceed with the parsing of the "value", which it
// must be a Uint8Array.
FetchReadableStreamReadDataDone valueDone;
if (!valueDone.Init(aCx, aValue)) {
JS_ClearPendingException(aCx);
CloseAndRelease(aCx, NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
if (valueDone.mDone) {
// Stream is completed.
CloseAndRelease(aCx, NS_BASE_STREAM_CLOSED);
return;
}
RootedDictionary<FetchReadableStreamReadDataArray> value(aCx);
if (!value.Init(aCx, aValue) || !value.mValue.WasPassed()) {
JS_ClearPendingException(aCx);
CloseAndRelease(aCx, NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
Uint8Array& array = value.mValue.Value();
array.ComputeState();
uint32_t len = array.Length();
if (len == 0) {
// If there is nothing to read, let's do another reading.
OnOutputStreamReady(mPipeOut);
return;
}
MOZ_DIAGNOSTIC_ASSERT(mBuffer.IsEmpty());
// Let's take a copy of the data.
if (!mBuffer.AppendElements(array.Data(), len, fallible)) {
CloseAndRelease(aCx, NS_ERROR_OUT_OF_MEMORY);
return;
}
mBufferOffset = 0;
mBufferRemaining = len;
nsresult rv = WriteBuffer();
if (NS_FAILED(rv)) {
// DOMException only understands errors from domerr.msg, so we normalize to
// identifying an abort if the write fails.
CloseAndRelease(aCx, NS_ERROR_DOM_ABORT_ERR);
}
}
#endif
nsresult FetchStreamReader::WriteBuffer() {
MOZ_ASSERT(!mBuffer.IsEmpty());
@ -496,15 +349,6 @@ nsresult FetchStreamReader::WriteBuffer() {
return NS_OK;
}
#ifndef MOZ_DOM_STREAMS
void FetchStreamReader::RejectedCallback(JSContext* aCx,
JS::Handle<JS::Value> aValue,
ErrorResult& aRv) {
ReportErrorToConsole(aCx, aValue);
CloseAndRelease(aCx, NS_ERROR_FAILURE);
}
#endif
void FetchStreamReader::ReportErrorToConsole(JSContext* aCx,
JS::Handle<JS::Value> aValue) {
nsCString sourceSpec;

Просмотреть файл

@ -22,12 +22,7 @@ class ReadableStream;
class ReadableStreamDefaultReader;
class WeakWorkerRef;
class FetchStreamReader final : public nsIOutputStreamCallback
#ifndef MOZ_DOM_STREAMS
,
public PromiseNativeHandler
#endif
{
class FetchStreamReader final : public nsIOutputStreamCallback {
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(
@ -40,18 +35,10 @@ class FetchStreamReader final : public nsIOutputStreamCallback
FetchStreamReader** aStreamReader,
nsIInputStream** aInputStream);
#ifdef MOZ_DOM_STREAMS
void ChunkSteps(JSContext* aCx, JS::Handle<JS::Value> aChunk,
ErrorResult& aRv);
void ErrorSteps(JSContext* aCx, JS::Handle<JS::Value> aError,
ErrorResult& aRv);
#else
void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
ErrorResult& aRv) override;
void RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
ErrorResult& aRv) override;
#endif
// Idempotently close the output stream and null out all state. If aCx is
// provided, the reader will also be canceled. aStatus must be a DOM error
@ -64,13 +51,8 @@ class FetchStreamReader final : public nsIOutputStreamCallback
MOZ_CAN_RUN_SCRIPT_BOUNDARY
void CloseAndRelease(JSContext* aCx, nsresult aStatus);
#ifdef MOZ_DOM_STREAMS
void StartConsuming(JSContext* aCx, ReadableStream* aStream,
ReadableStreamDefaultReader** aReader, ErrorResult& aRv);
#else
void StartConsuming(JSContext* aCx, JS::HandleObject aStream,
JS::MutableHandle<JSObject*> aReader, ErrorResult& aRv);
#endif
private:
explicit FetchStreamReader(nsIGlobalObject* aGlobal);
@ -87,11 +69,7 @@ class FetchStreamReader final : public nsIOutputStreamCallback
RefPtr<WeakWorkerRef> mWorkerRef;
#ifdef MOZ_DOM_STREAMS
RefPtr<ReadableStreamDefaultReader> mReader;
#else
JS::Heap<JSObject*> mReader;
#endif
nsTArray<uint8_t> mBuffer;
uint32_t mBufferRemaining;

Просмотреть файл

@ -23,9 +23,7 @@
#include "mozilla/ipc/PBackgroundSharedTypes.h"
#include "mozilla/Unused.h"
#ifdef MOZ_DOM_STREAMS
# include "mozilla/dom/ReadableStreamDefaultReader.h"
#endif
#include "mozilla/dom/ReadableStreamDefaultReader.h"
namespace mozilla::dom {
@ -35,10 +33,8 @@ NS_IMPL_RELEASE_INHERITED(Request, FetchBody<Request>)
NS_IMPL_CYCLE_COLLECTION_CLASS(Request)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(Request, FetchBody<Request>)
#ifdef MOZ_DOM_STREAMS
NS_IMPL_CYCLE_COLLECTION_UNLINK(mReadableStreamBody)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mReadableStreamReader)
#endif
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mHeaders)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSignal)
@ -46,21 +42,14 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(Request, FetchBody<Request>)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(Request, FetchBody<Request>)
#ifdef MOZ_DOM_STREAMS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReadableStreamBody)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReadableStreamReader)
#endif
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mHeaders)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSignal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(Request, FetchBody<Request>)
#ifndef MOZ_DOM_STREAMS
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mReadableStreamBody)
MOZ_DIAGNOSTIC_ASSERT(!tmp->mReadableStreamReader);
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mReadableStreamReader)
#endif
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_TRACE_END

Просмотреть файл

@ -28,9 +28,7 @@
#include "FetchStreamReader.h"
#include "InternalResponse.h"
#ifdef MOZ_DOM_STREAMS
# include "mozilla/dom/ReadableStreamDefaultReader.h"
#endif
#include "mozilla/dom/ReadableStreamDefaultReader.h"
namespace mozilla::dom {
@ -44,13 +42,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(Response, FetchBody<Response>)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mHeaders)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSignalImpl)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFetchStreamReader)
#ifdef MOZ_DOM_STREAMS
NS_IMPL_CYCLE_COLLECTION_UNLINK(mReadableStreamBody)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mReadableStreamReader)
#else
tmp->mReadableStreamBody = nullptr;
tmp->mReadableStreamReader = nullptr;
#endif
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
@ -59,17 +52,11 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(Response, FetchBody<Response>)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mHeaders)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSignalImpl)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFetchStreamReader)
#ifdef MOZ_DOM_STREAMS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReadableStreamBody)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReadableStreamReader)
#endif
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(Response, FetchBody<Response>)
#ifndef MOZ_DOM_STREAMS
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mReadableStreamBody)
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mReadableStreamReader)
#endif
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_TRACE_END
@ -293,7 +280,6 @@ already_AddRefed<Response> Response::Constructor(
const fetch::ResponseBodyInit& body = aBody.Value();
if (body.IsReadableStream()) {
JSContext* cx = aGlobal.Context();
#ifdef MOZ_DOM_STREAMS
aRv.MightThrowJSException();
ReadableStream& readableStream = body.GetAsReadableStream();
@ -318,58 +304,6 @@ already_AddRefed<Response> Response::Constructor(
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
#else
aRv.MightThrowJSException();
const ReadableStream& readableStream = body.GetAsReadableStream();
JS::Rooted<JSObject*> readableStreamObj(cx, readableStream.Obj());
bool disturbed;
bool locked;
if (!JS::ReadableStreamIsDisturbed(cx, readableStreamObj, &disturbed) ||
!JS::ReadableStreamIsLocked(cx, readableStreamObj, &locked)) {
aRv.StealExceptionFromJSContext(cx);
return nullptr;
}
if (disturbed || locked) {
aRv.ThrowTypeError<MSG_FETCH_BODY_CONSUMED_ERROR>();
return nullptr;
}
r->SetReadableStreamBody(cx, readableStreamObj);
JS::ReadableStreamMode streamMode;
if (!JS::ReadableStreamGetMode(cx, readableStreamObj, &streamMode)) {
aRv.StealExceptionFromJSContext(cx);
return nullptr;
}
if (streamMode == JS::ReadableStreamMode::ExternalSource) {
// If this is a DOM generated ReadableStream, we can extract the
// inputStream directly.
JS::ReadableStreamUnderlyingSource* underlyingSource = nullptr;
if (!JS::ReadableStreamGetExternalUnderlyingSource(
cx, readableStreamObj, &underlyingSource)) {
aRv.StealExceptionFromJSContext(cx);
return nullptr;
}
MOZ_ASSERT(underlyingSource);
aRv = BodyStream::RetrieveInputStream(underlyingSource,
getter_AddRefs(bodyStream));
// The releasing of the external source is needed in order to avoid an
// extra stream lock.
if (!JS::ReadableStreamReleaseExternalUnderlyingSource(
cx, readableStreamObj)) {
aRv.StealExceptionFromJSContext(cx);
return nullptr;
}
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
#endif
} else {
// If this is a JS-created ReadableStream, let's create a
// FetchStreamReader.
@ -417,27 +351,7 @@ already_AddRefed<Response> Response::Clone(JSContext* aCx, ErrorResult& aRv) {
}
if (!bodyUsed && mReadableStreamBody) {
#ifdef MOZ_DOM_STREAMS
bool locked = mReadableStreamBody->Locked();
#else
aRv.MightThrowJSException();
AutoJSAPI jsapi;
if (!jsapi.Init(mOwner)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
JSContext* cx = jsapi.cx();
JS::Rooted<JSObject*> body(cx, mReadableStreamBody);
bool locked;
// We just need to check the 'locked' state because GetBodyUsed() already
// checked the 'disturbed' state.
if (!JS::ReadableStreamIsLocked(cx, body, &locked)) {
aRv.StealExceptionFromJSContext(cx);
return nullptr;
}
#endif
bodyUsed = locked;
}
@ -449,16 +363,10 @@ already_AddRefed<Response> Response::Clone(JSContext* aCx, ErrorResult& aRv) {
RefPtr<FetchStreamReader> streamReader;
nsCOMPtr<nsIInputStream> inputStream;
#ifdef MOZ_DOM_STREAMS
RefPtr<ReadableStream> body;
MaybeTeeReadableStreamBody(aCx, getter_AddRefs(body),
getter_AddRefs(streamReader),
getter_AddRefs(inputStream), aRv);
#else
JS::Rooted<JSObject*> body(aCx);
MaybeTeeReadableStreamBody(aCx, &body, getter_AddRefs(streamReader),
getter_AddRefs(inputStream), aRv);
#endif
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
@ -496,16 +404,10 @@ already_AddRefed<Response> Response::CloneUnfiltered(JSContext* aCx,
RefPtr<FetchStreamReader> streamReader;
nsCOMPtr<nsIInputStream> inputStream;
#ifdef MOZ_DOM_STREAMS
RefPtr<ReadableStream> body;
MaybeTeeReadableStreamBody(aCx, getter_AddRefs(body),
getter_AddRefs(streamReader),
getter_AddRefs(inputStream), aRv);
#else
JS::Rooted<JSObject*> body(aCx);
MaybeTeeReadableStreamBody(aCx, &body, getter_AddRefs(streamReader),
getter_AddRefs(inputStream), aRv);
#endif
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}

Просмотреть файл

@ -10,9 +10,7 @@
#include "MemoryBlobImpl.h"
#include "mozilla/dom/BlobBinding.h"
#include "mozilla/dom/BodyStream.h"
#ifdef MOZ_DOM_STREAMS
# include "mozilla/dom/ReadableStream.h"
#endif
#include "mozilla/dom/ReadableStream.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/HoldDropJSObjects.h"
@ -314,7 +312,6 @@ class BlobBodyStreamHolder final : public BodyStreamHolder {
void MarkAsRead() override {}
#ifdef MOZ_DOM_STREAMS
void SetReadableStreamBody(ReadableStream* aBody) override {
mStream = aBody;
}
@ -322,17 +319,6 @@ class BlobBodyStreamHolder final : public BodyStreamHolder {
private:
RefPtr<ReadableStream> mStream;
#else
void SetReadableStreamBody(JSObject* aBody) override {
MOZ_ASSERT(aBody);
mStream = aBody;
}
JSObject* GetReadableStreamBody() override { return mStream; }
// Public to make trace happy.
JS::Heap<JSObject*> mStream;
#endif
protected:
virtual ~BlobBodyStreamHolder() { NullifyStream(); }
@ -342,24 +328,17 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(BlobBodyStreamHolder)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(BlobBodyStreamHolder,
BodyStreamHolder)
#ifndef MOZ_DOM_STREAMS
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mStream)
#endif
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BlobBodyStreamHolder,
BodyStreamHolder)
#ifdef MOZ_DOM_STREAMS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStream)
#endif
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BlobBodyStreamHolder,
BodyStreamHolder)
tmp->NullifyStream();
#ifdef MOZ_DOM_STREAMS
NS_IMPL_CYCLE_COLLECTION_UNLINK(mStream)
#endif
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_ADDREF_INHERITED(BlobBodyStreamHolder, BodyStreamHolder)
@ -370,7 +349,6 @@ NS_INTERFACE_MAP_END_INHERITING(BodyStreamHolder)
} // anonymous namespace
#ifdef MOZ_DOM_STREAMS
already_AddRefed<ReadableStream> Blob::Stream(JSContext* aCx,
ErrorResult& aRv) {
nsCOMPtr<nsIInputStream> stream;
@ -394,29 +372,5 @@ already_AddRefed<ReadableStream> Blob::Stream(JSContext* aCx,
RefPtr<ReadableStream> rStream = holder->GetReadableStreamBody();
return rStream.forget();
}
#else
void Blob::Stream(JSContext* aCx, JS::MutableHandle<JSObject*> aStream,
ErrorResult& aRv) {
nsCOMPtr<nsIInputStream> stream;
CreateInputStream(getter_AddRefs(stream), aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
if (NS_WARN_IF(!mGlobal)) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
RefPtr<BlobBodyStreamHolder> holder = new BlobBodyStreamHolder();
BodyStream::Create(aCx, holder, mGlobal, stream, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
aStream.set(holder->GetReadableStreamBody());
}
#endif
} // namespace mozilla::dom

Просмотреть файл

@ -28,9 +28,7 @@ class GlobalObject;
class OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString;
class Promise;
#ifdef MOZ_DOM_STREAMS
class ReadableStream;
#endif
#define NS_DOM_BLOB_IID \
{ \
@ -122,12 +120,7 @@ class Blob : public nsSupportsWeakReference, public nsWrapperCache {
nsresult GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength,
nsACString& aContentType, nsACString& aCharset) const;
#ifdef MOZ_DOM_STREAMS
already_AddRefed<ReadableStream> Stream(JSContext* aCx, ErrorResult& aRv);
#else
void Stream(JSContext* aCx, JS::MutableHandle<JSObject*> aStream,
ErrorResult& aRv);
#endif
already_AddRefed<Promise> Text(ErrorResult& aRv);
already_AddRefed<Promise> ArrayBuffer(ErrorResult& aRv);

Просмотреть файл

@ -43,7 +43,6 @@ already_AddRefed<Promise> FileSystemFileHandle::GetFile() {
return promise.forget();
}
#ifdef MOZ_DOM_STREAMS
already_AddRefed<Promise> FileSystemFileHandle::CreateWritable(
const FileSystemCreateWritableOptions& aOptions) {
IgnoredErrorResult rv;
@ -57,7 +56,6 @@ already_AddRefed<Promise> FileSystemFileHandle::CreateWritable(
return promise.forget();
}
#endif
already_AddRefed<Promise> FileSystemFileHandle::CreateSyncAccessHandle() {
IgnoredErrorResult rv;

Просмотреть файл

@ -28,10 +28,8 @@ class FileSystemFileHandle final : public FileSystemHandle {
already_AddRefed<Promise> GetFile();
#ifdef MOZ_DOM_STREAMS
already_AddRefed<Promise> CreateWritable(
const FileSystemCreateWritableOptions& aOptions);
#endif
already_AddRefed<Promise> CreateSyncAccessHandle();

Просмотреть файл

@ -10,6 +10,7 @@ EXPORTS.mozilla.dom += [
"FileSystemFileHandle.h",
"FileSystemHandle.h",
"FileSystemSyncAccessHandle.h",
"FileSystemWritableFileStream.h",
]
UNIFIED_SOURCES += [
@ -18,16 +19,9 @@ UNIFIED_SOURCES += [
"FileSystemFileHandle.cpp",
"FileSystemHandle.cpp",
"FileSystemSyncAccessHandle.cpp",
"FileSystemWritableFileStream.cpp",
]
if CONFIG["MOZ_DOM_STREAMS"]:
EXPORTS.mozilla.dom += [
"FileSystemWritableFileStream.h",
]
UNIFIED_SOURCES += [
"FileSystemWritableFileStream.cpp",
]
include("/ipc/chromium/chromium-config.mozbuild")
FINAL_LIBRARY = "xul"

Просмотреть файл

@ -84,6 +84,7 @@ DIRS += [
"messagechannel",
"promise",
"smil",
"streams",
"url",
"webauthn",
"webidl",
@ -112,8 +113,6 @@ DIRS += [
"origin-trials",
]
if CONFIG["MOZ_DOM_STREAMS"]:
DIRS += ["streams"]
TEST_DIRS += [
"tests",

Просмотреть файл

@ -19,10 +19,6 @@
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
#ifndef MOZ_DOM_STREAMS
# error "Shouldn't be compiling with this header without MOZ_DOM_STREAMS set"
#endif
namespace mozilla::dom {
class Promise;

Просмотреть файл

@ -15,10 +15,6 @@
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
#ifndef MOZ_DOM_STREAMS
# error "Shouldn't be compiling with this header without MOZ_DOM_STREAMS set"
#endif
namespace mozilla::dom {
class WritableStream;

Просмотреть файл

@ -16,10 +16,6 @@
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
#ifndef MOZ_DOM_STREAMS
# error "Shouldn't be compiling with this header without MOZ_DOM_STREAMS set"
#endif
namespace mozilla::dom {
class TransformStream;

Просмотреть файл

@ -19,10 +19,6 @@
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
#ifndef MOZ_DOM_STREAMS
# error "Shouldn't be compiling with this header without MOZ_DOM_STREAMS set"
#endif
namespace mozilla::dom {
class Promise;

Просмотреть файл

@ -17,10 +17,6 @@
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
#ifndef MOZ_DOM_STREAMS
# error "Shouldn't be compiling with this header without MOZ_DOM_STREAMS set"
#endif
namespace mozilla::dom {
class Promise;

Просмотреть файл

@ -3,19 +3,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifdef MOZ_DOM_STREAMS
dictionary FileSystemCreateWritableOptions {
boolean keepExistingData = false;
};
#endif
// TODO: Add Serializable
[Exposed=(Window,Worker), SecureContext, Pref="dom.fs.enabled"]
interface FileSystemFileHandle : FileSystemHandle {
Promise<File> getFile();
#ifdef MOZ_DOM_STREAMS
Promise<FileSystemWritableFileStream> createWritable(optional FileSystemCreateWritableOptions options = {});
#endif
[Exposed=DedicatedWorker]
Promise<FileSystemSyncAccessHandle> createSyncAccessHandle();

Просмотреть файл

@ -391,7 +391,6 @@ GENERATED_WEBIDL_FILES = [
PREPROCESSED_WEBIDL_FILES = [
"Animation.webidl",
"FileSystemFileHandle.webidl",
"Node.webidl",
"Window.webidl",
]
@ -555,6 +554,7 @@ WEBIDL_FILES = [
"FileSystemDirectoryReader.webidl",
"FileSystemEntry.webidl",
"FileSystemFileEntry.webidl",
"FileSystemFileHandle.webidl",
"FileSystemHandle.webidl",
"FileSystemSyncAccessHandle.webidl",
"FinalizationRegistry.webidl",

Просмотреть файл

@ -68,9 +68,7 @@
#include "mozilla/dom/PromiseDebuggingBinding.h"
#include "mozilla/dom/RangeBinding.h"
#include "mozilla/dom/RequestBinding.h"
#ifdef MOZ_DOM_STREAMS
# include "mozilla/dom/ReadableStreamBinding.h"
#endif
#include "mozilla/dom/ReadableStreamBinding.h"
#include "mozilla/dom/ResponseBinding.h"
#ifdef MOZ_WEBRTC
# include "mozilla/dom/RTCIdentityProviderRegistrar.h"
@ -974,10 +972,8 @@ bool xpc::GlobalProperties::Parse(JSContext* cx, JS::HandleObject obj) {
Window = true;
} else if (JS_LinearStringEqualsLiteral(nameStr, "XMLSerializer")) {
XMLSerializer = true;
#ifdef MOZ_DOM_STREAMS
} else if (JS_LinearStringEqualsLiteral(nameStr, "ReadableStream")) {
ReadableStream = true;
#endif
} else if (JS_LinearStringEqualsLiteral(nameStr, "atob")) {
atob = true;
} else if (JS_LinearStringEqualsLiteral(nameStr, "btoa")) {
@ -1140,10 +1136,8 @@ bool xpc::GlobalProperties::Define(JSContext* cx, JS::HandleObject obj) {
if (XMLSerializer && !dom::XMLSerializer_Binding::GetConstructorObject(cx))
return false;
#ifdef MOZ_DOM_STREAMS
if (ReadableStream && !dom::ReadableStream_Binding::GetConstructorObject(cx))
return false;
#endif
if (atob && !JS_DefineFunction(cx, obj, "atob", Atob, 1, 0)) return false;

Просмотреть файл

@ -797,8 +797,6 @@ void xpc::SetPrefableRealmOptions(JS::RealmOptions& options) {
.setCoopAndCoepEnabled(
StaticPrefs::browser_tabs_remote_useCrossOriginOpenerPolicy() &&
StaticPrefs::browser_tabs_remote_useCrossOriginEmbedderPolicy())
.setStreamsEnabled(
sStreamsEnabled) // Note: Overridden by MOZ_DOM_STREAMS
.setWritableStreamsEnabled(
StaticPrefs::javascript_options_writable_streams())
.setPropertyErrorMessageFixEnabled(sPropertyErrorMessageFixEnabled)

Просмотреть файл

@ -3014,19 +3014,6 @@ void XPCJSRuntime::Initialize(JSContext* cx) {
js::SetWindowProxyClass(cx, &OuterWindowProxyClass);
#ifndef MOZ_DOM_STREAMS
{
JS::AbortSignalIsAborted isAborted = [](JSObject* obj) {
dom::AbortSignal* domObj = dom::UnwrapDOMObject<dom::AbortSignal>(obj);
MOZ_ASSERT(domObj);
return domObj->Aborted();
};
JS::InitPipeToHandling(dom::AbortSignal_Binding::GetJSClass(), isAborted,
cx);
}
#endif
JS::SetXrayJitInfo(&gXrayJitInfo);
JS::SetProcessLargeAllocationFailureCallback(
OnLargeAllocationFailureCallback);

Просмотреть файл

@ -2255,9 +2255,7 @@ struct GlobalProperties {
bool WebSocket : 1;
bool Window : 1;
bool XMLSerializer : 1;
#ifdef MOZ_DOM_STREAMS
bool ReadableStream : 1;
#endif
// Ad-hoc property names we implement.
bool atob : 1;

Просмотреть файл

@ -2771,13 +2771,9 @@ wine = check_prog(
# DOM Streams
# ==============================================================
option(
"--disable-dom-streams",
help="Disable DOM Streams (use JS Streams)",
)
set_config("MOZ_DOM_STREAMS", True, when="--enable-dom-streams")
set_define("MOZ_DOM_STREAMS", True, when="--enable-dom-streams")
# Set this to true so the JS engine knows we're doing a browser build.
set_config("MOZ_DOM_STREAMS", True)
set_define("MOZ_DOM_STREAMS", True)
# libevent
# ==============================================================