diff --git a/Userland/Libraries/LibWeb/Fetch/BodyInit.cpp b/Userland/Libraries/LibWeb/Fetch/BodyInit.cpp index bbe2457887..2360178865 100644 --- a/Userland/Libraries/LibWeb/Fetch/BodyInit.cpp +++ b/Userland/Libraries/LibWeb/Fetch/BodyInit.cpp @@ -13,6 +13,19 @@ namespace Web::Fetch { +// https://fetch.spec.whatwg.org/#bodyinit-safely-extract +WebIDL::ExceptionOr safely_extract_body(JS::Realm& realm, BodyInitOrReadbleBytes const& object) +{ + // 1. If object is a ReadableStream object, then: + if (auto const* stream = object.get_pointer>()) { + // 1. Assert: object is neither disturbed nor locked. + VERIFY(!((*stream)->is_disturbed() || (*stream)->is_locked())); + } + + // 2. Return the result of extracting object. + return extract_body(realm, object); +} + // https://fetch.spec.whatwg.org/#concept-bodyinit-extract WebIDL::ExceptionOr extract_body(JS::Realm& realm, BodyInitOrReadbleBytes const& object, bool keepalive) { diff --git a/Userland/Libraries/LibWeb/Fetch/BodyInit.h b/Userland/Libraries/LibWeb/Fetch/BodyInit.h index 93c390f8b0..1a14dcae94 100644 --- a/Userland/Libraries/LibWeb/Fetch/BodyInit.h +++ b/Userland/Libraries/LibWeb/Fetch/BodyInit.h @@ -20,6 +20,7 @@ using XMLHttpRequestBodyInit = Variant, JS::Handle, JS::Handle, JS::Handle, JS::Handle, String>; using BodyInitOrReadbleBytes = Variant, JS::Handle, JS::Handle, JS::Handle, String, ReadonlyBytes>; +WebIDL::ExceptionOr safely_extract_body(JS::Realm&, BodyInitOrReadbleBytes const&); WebIDL::ExceptionOr extract_body(JS::Realm&, BodyInitOrReadbleBytes const&, bool keepalive = false); }