Bug 1557781 - Better life-time management for BodyStream/FetchStream - part 3 - JS::ReadableStreamReleaseCCObject, r=jorendorff
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 01 Jul 2019 20:01:17 +0000
changeset 543675 00eaa63cc4d71de171c083df48bde2c1d32a6cd7
parent 543674 ea96413122a8329ccb00eacc31416354c854b7b0
child 543676 78d99b96c1045f89d3833b12bd7516d53f1efc29
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1557781
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1557781 - Better life-time management for BodyStream/FetchStream - part 3 - JS::ReadableStreamReleaseCCObject, r=jorendorff Differential Revision: https://phabricator.services.mozilla.com/D36466
dom/base/BodyStream.cpp
js/public/Stream.h
js/src/builtin/Stream.cpp
--- a/dom/base/BodyStream.cpp
+++ b/dom/base/BodyStream.cpp
@@ -480,16 +480,19 @@ void BodyStream::ReleaseObjects(const Mu
 
   if (NS_IsMainThread()) {
     nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
     if (obs) {
       obs->RemoveObserver(this, DOM_WINDOW_DESTROYED_TOPIC);
     }
   }
 
+  // Let's inform the JSEngine that we are going to be released.
+  JS::ReadableStreamReleaseCCObject(mStreamHolder->ReadableStreamBody());
+
   mWorkerRef = nullptr;
   mGlobal = nullptr;
 
   mStreamHolder->NullifyStream();
   mStreamHolder = nullptr;
 }
 
 #ifdef DEBUG
--- a/js/public/Stream.h
+++ b/js/public/Stream.h
@@ -256,16 +256,23 @@ extern JS_PUBLIC_API bool ReadableStream
  *
  * Asserts that |stream| is a ReadableStream object or an unwrappable wrapper
  * for one.
  */
 extern JS_PUBLIC_API bool ReadableStreamUpdateDataAvailableFromSource(
     JSContext* cx, HandleObject stream, uint32_t availableData);
 
 /**
+ * Break the cycle between this object and the
+ * nsISupportsObject_alreadyAddreffed passed in
+ * NewReadableExternalSourceStreamObject().
+ */
+extern JS_PUBLIC_API void ReadableStreamReleaseCCObject(JSObject* stream);
+
+/**
  * Returns true if the given object is a ReadableStream object or an
  * unwrappable wrapper for one, false otherwise.
  */
 extern JS_PUBLIC_API bool IsReadableStream(JSObject* obj);
 
 /**
  * Returns true if the given object is a ReadableStreamDefaultReader or
  * ReadableStreamBYOBReader object or an unwrappable wrapper for one, false
--- a/js/src/builtin/Stream.cpp
+++ b/js/src/builtin/Stream.cpp
@@ -4780,16 +4780,21 @@ JS_PUBLIC_API bool JS::ReadableStreamUpd
     // Step b: Perform ! ReadableByteStreamControllerEnqueueChunkToQueue(
     //         controller, transferredBuffer, byteOffset, byteLength).
     // (Not needed for external underlying sources.)
   }
 
   return true;
 }
 
+JS_PUBLIC_API void JS::ReadableStreamReleaseCCObject(JSObject* streamObj) {
+  MOZ_ASSERT(JS::IsReadableStream(streamObj));
+  JS_SetPrivate(streamObj, nullptr);
+}
+
 JS_PUBLIC_API bool JS::ReadableStreamTee(JSContext* cx, HandleObject streamObj,
                                          MutableHandleObject branch1Obj,
                                          MutableHandleObject branch2Obj) {
   AssertHeapIsIdle();
   CHECK_THREAD(cx);
 
   Rooted<ReadableStream*> unwrappedStream(
       cx, APIUnwrapAndDowncast<ReadableStream>(cx, streamObj));