Function mozjs::jsapi::JS::NewReadableExternalSourceStreamObject
source · pub unsafe extern "C" fn NewReadableExternalSourceStreamObject(
cx: *mut JSContext,
underlyingSource: *mut ReadableStreamUnderlyingSource,
nsISupportsObject_alreadyAddreffed: *mut c_void,
proto: Handle<*mut JSObject>,
) -> *mut JSObject
Expand description
Returns a new instance of the ReadableStream builtin class in the current compartment.
The instance is a byte stream backed by an embedding-provided underlying
source, using the virtual methods of underlyingSource
as callbacks. The
embedding must ensure that *underlyingSource
lives as long as the new
stream object. The JS engine will call the finalize() method when the stream
object is destroyed.
nsISupportsObject_alreadyAddreffed
is an optional pointer that can be used
to make the new stream participate in Gecko’s cycle collection. Here are the
rules for using this parameter properly:
-
*underlyingSource
must not be a cycle-collected object. (It would lead to memory leaks as the cycle collector would not be able to collect cycles containing that object.) -
*underlyingSource
must not contain nsCOMPtrs that point to cycle- collected objects. (Same reason.) -
*underlyingSource
may contain a pointer to a single cycle-collected object. -
The pointer may be stored in
*underlyingSource
as a raw pointer. -
The pointer to the nsISupports interface of the same object must be passed as the
nsISupportsObject_alreadyAddreffed
parameter to this function. (This is how the cycle collector knows about it, so omitting this would again cause leaks.)
If proto
is non-null, it is used as the instance’s [[Prototype]] instead
of the original value of ReadableStream.prototype
.