JSObject *create_body_stream(JSContext *cx, HandleObject owner) {
  MOZ_ASSERT(is_instance(owner));
  MOZ_ASSERT(!body_stream(owner));
  RootedObject source(cx, builtins::NativeStreamSource::create(cx, owner, JS::UndefinedHandleValue,
                                                               body_source_pull_algorithm,
                                                               body_source_cancel_algorithm));
  if (!source)
    return nullptr;

  // Create a readable stream with a highwater mark of 0.0 to prevent an eager
  // pull. With the default HWM of 1.0, the streams implementation causes a
  // pull, which means we enqueue a read from the host handle, which we quite
  // often have no interest in at all.
  RootedObject body_stream(cx, JS::NewReadableDefaultStreamObject(cx, source, nullptr, 0.0));
  if (!body_stream) {
    return nullptr;
  }

  // TODO: immediately lock the stream if the owner's body is already used.

  JS_SetReservedSlot(owner, Slots::BodyStream, JS::ObjectValue(*body_stream));
  return body_stream;
}
JSObject *create_body_stream(JSContext *cx, HandleObject owner) {
  MOZ_ASSERT(is_instance(owner));
  MOZ_ASSERT(!body_stream(owner));
  RootedObject source(cx, builtins::NativeStreamSource::create(cx, owner, JS::UndefinedHandleValue,
                                                               body_source_pull_algorithm,
                                                               body_source_cancel_algorithm));
  if (!source)
    return nullptr;

   
   
   
   
  RootedObject body_stream(cx, JS::NewReadableDefaultStreamObject(cx, source, nullptr, 0.0));
  if (!body_stream) {
    return nullptr;
  }

   

  JS_SetReservedSlot(owner, Slots::BodyStream, JS::ObjectValue(*body_stream));
  return body_stream;
}