Bug 1764222 - Use NS_IMPL_CYCLE_COLLECTION_WITH_JS_MEMBERS for piping classes r=smaug,a=dsmith
Differential Revision:
https://phabricator.services.mozilla.com/D144886
--- a/dom/streams/ReadableStreamPipeTo.cpp
+++ b/dom/streams/ReadableStreamPipeTo.cpp
@@ -21,16 +21,19 @@
#include "js/Exception.h"
namespace mozilla::dom {
struct PipeToReadRequest;
class WriteFinishedPromiseHandler;
class ShutdownActionFinishedPromiseHandler;
+// TODO: Bug 1756794
+using ::ImplCycleCollectionUnlink;
+
// https://streams.spec.whatwg.org/#readable-stream-pipe-to (Steps 14-15.)
//
// This class implements everything that is required to read all chunks from
// the reader (source) and write them to writer (destination), while
// following the constraints given in the spec using our implementation-defined
// behavior.
//
// The cycle-collected references look roughly like this:
@@ -376,25 +379,23 @@ class WriteFinishedPromiseHandler final
MOZ_CAN_RUN_SCRIPT void RejectedCallback(JSContext* aCx,
JS::Handle<JS::Value> aReason,
ErrorResult&) override {
WriteFinished(aCx);
}
};
-NS_IMPL_CYCLE_COLLECTION(WriteFinishedPromiseHandler, mPipeToPump)
+NS_IMPL_CYCLE_COLLECTION_WITH_JS_MEMBERS(WriteFinishedPromiseHandler,
+ (mPipeToPump), (mError))
NS_IMPL_CYCLE_COLLECTING_ADDREF(WriteFinishedPromiseHandler)
NS_IMPL_CYCLE_COLLECTING_RELEASE(WriteFinishedPromiseHandler)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WriteFinishedPromiseHandler)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
-NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(WriteFinishedPromiseHandler)
- NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mError)
-NS_IMPL_CYCLE_COLLECTION_TRACE_END
// https://streams.spec.whatwg.org/#rs-pipeTo-shutdown-with-action
// Shutdown with an action: if any of the above requirements ask to shutdown
// with an action action, optionally with an error originalError, then:
void PipeToPump::ShutdownWithAction(
JSContext* aCx, ShutdownAction aAction,
JS::Handle<mozilla::Maybe<JS::Value>> aError) {
// Step 1. If shuttingDown is true, abort these substeps.
@@ -471,25 +472,23 @@ class ShutdownActionFinishedPromiseHandl
// https://streams.spec.whatwg.org/#rs-pipeTo-shutdown-with-action
// Step 6. Upon rejection of p with reason newError, finalize with
// newError.
JS::Rooted<Maybe<JS::Value>> error(aCx, Some(aReason));
mPipeToPump->Finalize(aCx, error);
}
};
-NS_IMPL_CYCLE_COLLECTION(ShutdownActionFinishedPromiseHandler, mPipeToPump)
+NS_IMPL_CYCLE_COLLECTION_WITH_JS_MEMBERS(ShutdownActionFinishedPromiseHandler,
+ (mPipeToPump), (mError))
NS_IMPL_CYCLE_COLLECTING_ADDREF(ShutdownActionFinishedPromiseHandler)
NS_IMPL_CYCLE_COLLECTING_RELEASE(ShutdownActionFinishedPromiseHandler)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ShutdownActionFinishedPromiseHandler)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
-NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(ShutdownActionFinishedPromiseHandler)
- NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mError)
-NS_IMPL_CYCLE_COLLECTION_TRACE_END
// https://streams.spec.whatwg.org/#rs-pipeTo-shutdown-with-action
// Continuation after Step 3. triggered a promise resolution.
void PipeToPump::ShutdownWithActionAfterFinishedWrite(
JSContext* aCx, ShutdownAction aAction,
JS::Handle<mozilla::Maybe<JS::Value>> aError) {
if (!aAction) {
// Used to implement shutdown without action. Finalize immediately.
--- a/dom/streams/TeeState.cpp
+++ b/dom/streams/TeeState.cpp
@@ -9,16 +9,17 @@
#include "js/Value.h"
#include "mozilla/HoldDropJSObjects.h"
#include "mozilla/dom/ReadableStream.h"
#include "mozilla/dom/ReadableStreamTee.h"
#include "mozilla/dom/Promise.h"
namespace mozilla::dom {
+// TODO: Bug 1756794
using ::ImplCycleCollectionUnlink;
NS_IMPL_CYCLE_COLLECTION_WITH_JS_MEMBERS(TeeState,
(mStream, mReader, mBranch1, mBranch2,
mCancelPromise),
(mReason1, mReason2))
NS_IMPL_CYCLE_COLLECTING_ADDREF(TeeState)
NS_IMPL_CYCLE_COLLECTING_RELEASE(TeeState)
new file mode 100644
--- /dev/null
+++ b/dom/streams/crashtests/1764222.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<script>
+ // This can't be in WPT because of bug 1766711.
+ let a = new AbortController()
+ a.abort()
+ let b = new File(['ó ¬a'], 'a', {})
+ let c = new WritableStream()
+ b.stream().tee()[0].pipeTo(c, { 'signal': a.signal })
+</script>
new file mode 100644
--- /dev/null
+++ b/dom/streams/crashtests/crashtests.list
@@ -0,0 +1,1 @@
+load 1764222.html
--- a/testing/crashtest/crashtests.list
+++ b/testing/crashtest/crashtests.list
@@ -24,16 +24,17 @@ include ../../dom/media/test/crashtests/
include ../../dom/media/webvtt/test/crashtests/crashtests.list
skip-if(!webrtc) include ../../dom/media/tests/crashtests/crashtests.list
include ../../dom/media/webspeech/synth/crashtests/crashtests.list
include ../../dom/offline/crashtests/crashtests.list
include ../../dom/plugins/test/crashtests/crashtests.list
include ../../dom/security/test/crashtests/crashtests.list
include ../../dom/serializers/crashtests/crashtests.list
include ../../dom/smil/crashtests/crashtests.list
+include ../../dom/streams/crashtests/crashtests.list
include ../../dom/svg/crashtests/crashtests.list
include ../../dom/vr/test/crashtests/crashtests.list
include ../../dom/workers/test/crashtests/crashtests.list
include ../../dom/xhr/tests/crashtests/crashtests.list
include ../../dom/xml/crashtests/crashtests.list
include ../../dom/xslt/crashtests/crashtests.list
include ../../dom/xul/crashtests/crashtests.list