From dcded8d39f08c552ce054bdb8e7eaec22dd810d7 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 13 Oct 2022 19:11:42 +0200 Subject: [PATCH] LibWeb: Implement 'Safely extract BodyInit' AO --- Userland/Libraries/LibWeb/Fetch/BodyInit.cpp | 13 +++++++++++++ Userland/Libraries/LibWeb/Fetch/BodyInit.h | 1 + 2 files changed, 14 insertions(+) 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); }