Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add support for FetchRequest.body
https://bugs.webkit.org/show_bug.cgi?id=176066

Patch by Youenn Fablet <youenn@apple.com> on 2017-08-29
Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

* web-platform-tests/fetch/api/request/request-disturbed-expected.txt:
* web-platform-tests/fetch/api/request/request-idl-expected.txt:

Source/WebCore:

Covered by existing tests.

Adding support for body attribute getter for FetchRequest.
To do so, FetchRequest will need to create a ReadableStream.
Adding support for DOM based creation of ReadableStream and conversion to JS values.
Small refactoring to make names more consistent.

* CMakeLists.txt:
* Modules/beacon/NavigatorBeacon.cpp:
(WebCore::NavigatorBeacon::sendBeacon):
* Modules/cache/Cache.cpp:
(WebCore::Cache::put):
* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::extract):
* Modules/fetch/FetchBody.h:
(WebCore::FetchBody::hasReadableStream const):
(WebCore::FetchBody::readableStream):
(WebCore::FetchBody::setReadableStream):
(WebCore::FetchBody::FetchBody):
(WebCore::FetchBody::isReadableStream const): Deleted.
(WebCore::FetchBody::setAsReadableStream): Deleted.
* Modules/fetch/FetchBody.idl:
* Modules/fetch/FetchBodyOwner.cpp:
(WebCore::FetchBodyOwner::readableStream):
* Modules/fetch/FetchBodyOwner.h:
(WebCore::FetchBodyOwner::hasReadableStreamBody const):
(WebCore::FetchBodyOwner::isReadableStreamBody const): Deleted.
* Modules/fetch/FetchRequest.cpp:
(WebCore::FetchRequest::setBody):
* Modules/fetch/FetchRequest.h:
* Modules/fetch/FetchResponse.cpp:
(WebCore::FetchResponse::setBodyAsReadableStream):
(WebCore::FetchResponse::fetch):
* Modules/fetch/FetchResponse.h:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/ReadableStream.h:
(WebCore::JSConverter<IDLInterface<ReadableStream>>::convert):

Canonical link: https://commits.webkit.org/192756@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221329 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
youennf authored and webkit-commit-queue committed Aug 30, 2017
1 parent e255308 commit 67cb061
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 20 deletions.
10 changes: 10 additions & 0 deletions LayoutTests/imported/w3c/ChangeLog
@@ -1,3 +1,13 @@
2017-08-29 Youenn Fablet <youenn@apple.com>

Add support for FetchRequest.body
https://bugs.webkit.org/show_bug.cgi?id=176066

Reviewed by Alex Christensen.

* web-platform-tests/fetch/api/request/request-disturbed-expected.txt:
* web-platform-tests/fetch/api/request/request-idl-expected.txt:

2017-08-25 Youenn Fablet <youenn@apple.com>

WPT server should not need to copy test harness files
Expand Down
@@ -1,9 +1,9 @@

FAIL Request's body: initial state assert_equals: body's default value is null expected (object) null but got (undefined) undefined
PASS Request's body: initial state
PASS Request without body cannot be disturbed
PASS Check cloning a disturbed request
PASS Check creating a new request from a disturbed request
FAIL Input request used for creating new request became disturbed assert_not_equals: body should not be undefined got disallowed value undefined
FAIL Input request used for creating new request became disturbed assert_equals: body should not change expected object "[object ReadableStream]" but got object "[object ReadableStream]"
FAIL Input request used for creating new request became disturbed even if body is not used assert_true: bodyUsed is true when request is disturbed expected true got false
PASS Check consuming a disturbed request
PASS Request construction failure should not set "bodyUsed"
Expand Down
Expand Up @@ -18,7 +18,7 @@ PASS Request interface: attribute redirect
PASS Request interface: attribute integrity
PASS Request interface: attribute keepalive
PASS Request interface: operation clone()
FAIL Request interface: attribute body assert_true: The prototype object must have a property "body" expected true got false
PASS Request interface: attribute body
PASS Request interface: attribute bodyUsed
PASS Request interface: operation arrayBuffer()
PASS Request interface: operation blob()
Expand All @@ -39,7 +39,7 @@ PASS Request interface: new Request("") must inherit property "redirect" with th
PASS Request interface: new Request("") must inherit property "integrity" with the proper type (11)
PASS Request interface: new Request("") must inherit property "keepalive" with the proper type (12)
PASS Request interface: new Request("") must inherit property "clone" with the proper type (13)
FAIL Request interface: new Request("") must inherit property "body" with the proper type (14) assert_inherits: property "body" not found in prototype chain
PASS Request interface: new Request("") must inherit property "body" with the proper type (14)
PASS Request interface: new Request("") must inherit property "bodyUsed" with the proper type (15)
PASS Request interface: new Request("") must inherit property "arrayBuffer" with the proper type (16)
PASS Request interface: new Request("") must inherit property "blob" with the proper type (17)
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/CMakeLists.txt
Expand Up @@ -1285,6 +1285,7 @@ set(WebCore_SOURCES
bindings/js/JSXMLHttpRequestCustom.cpp
bindings/js/JSXPathNSResolverCustom.cpp
bindings/js/JSXPathResultCustom.cpp
bindings/js/ReadableStream.cpp
bindings/js/ReadableStreamDefaultController.cpp
bindings/js/ScheduledAction.cpp
bindings/js/ScriptCachedFrameData.cpp
Expand Down
45 changes: 45 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,48 @@
2017-08-29 Youenn Fablet <youenn@apple.com>

Add support for FetchRequest.body
https://bugs.webkit.org/show_bug.cgi?id=176066

Reviewed by Alex Christensen.

Covered by existing tests.

Adding support for body attribute getter for FetchRequest.
To do so, FetchRequest will need to create a ReadableStream.
Adding support for DOM based creation of ReadableStream and conversion to JS values.
Small refactoring to make names more consistent.

* CMakeLists.txt:
* Modules/beacon/NavigatorBeacon.cpp:
(WebCore::NavigatorBeacon::sendBeacon):
* Modules/cache/Cache.cpp:
(WebCore::Cache::put):
* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::extract):
* Modules/fetch/FetchBody.h:
(WebCore::FetchBody::hasReadableStream const):
(WebCore::FetchBody::readableStream):
(WebCore::FetchBody::setReadableStream):
(WebCore::FetchBody::FetchBody):
(WebCore::FetchBody::isReadableStream const): Deleted.
(WebCore::FetchBody::setAsReadableStream): Deleted.
* Modules/fetch/FetchBody.idl:
* Modules/fetch/FetchBodyOwner.cpp:
(WebCore::FetchBodyOwner::readableStream):
* Modules/fetch/FetchBodyOwner.h:
(WebCore::FetchBodyOwner::hasReadableStreamBody const):
(WebCore::FetchBodyOwner::isReadableStreamBody const): Deleted.
* Modules/fetch/FetchRequest.cpp:
(WebCore::FetchRequest::setBody):
* Modules/fetch/FetchRequest.h:
* Modules/fetch/FetchResponse.cpp:
(WebCore::FetchResponse::setBodyAsReadableStream):
(WebCore::FetchResponse::fetch):
* Modules/fetch/FetchResponse.h:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/ReadableStream.h:
(WebCore::JSConverter<IDLInterface<ReadableStream>>::convert):

2017-08-29 Yusuke Suzuki <utatane.tea@gmail.com>

[JSC] Use reifying system for "name" property of builtin JSFunction
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/beacon/NavigatorBeacon.cpp
Expand Up @@ -130,7 +130,7 @@ ExceptionOr<bool> NavigatorBeacon::sendBeacon(Document& document, const String&
String mimeType;
auto fetchBody = FetchBody::extract(document, WTFMove(body.value()), mimeType);

if (fetchBody.isReadableStream())
if (fetchBody.hasReadableStream())
return Exception { TypeError, ASCIILiteral("Beacons cannot send ReadableStream body") };

request.setHTTPBody(fetchBody.bodyAsFormData(document));
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/cache/Cache.cpp
Expand Up @@ -296,7 +296,7 @@ void Cache::put(RequestInfo&& info, Ref<FetchResponse>&& response, DOMPromiseDef
}

// FIXME: Add support for ReadableStream.
if (response->isReadableStreamBody()) {
if (response->hasReadableStreamBody()) {
promise.reject(Exception { NotSupportedError, ASCIILiteral("Caching a Response with data stored in a ReadableStream is not yet supported") });
return;
}
Expand Down
6 changes: 2 additions & 4 deletions Source/WebCore/Modules/fetch/FetchBody.cpp
Expand Up @@ -61,10 +61,8 @@ FetchBody FetchBody::extract(ScriptExecutionContext& context, Init&& value, Stri
}, [&](RefPtr<ArrayBufferView>& value) mutable {
Ref<const ArrayBufferView> buffer = value.releaseNonNull();
return FetchBody(WTFMove(buffer));
}, [&](RefPtr<ReadableStream>&) mutable {
FetchBody body;
body.m_isReadableStream = true;
return body;
}, [&](RefPtr<ReadableStream>& stream) mutable {
return FetchBody(stream.releaseNonNull());
}, [&](String& value) {
contentType = HTTPHeaderValues::textPlainContentType();
return FetchBody(WTFMove(value));
Expand Down
14 changes: 9 additions & 5 deletions Source/WebCore/Modules/fetch/FetchBody.h
Expand Up @@ -60,13 +60,12 @@ class FetchBody {
bool isArrayBufferView() const { return WTF::holds_alternative<Ref<const ArrayBufferView>>(m_data); }
bool isURLSearchParams() const { return WTF::holds_alternative<Ref<const URLSearchParams>>(m_data); }
bool isText() const { return WTF::holds_alternative<String>(m_data); }
bool isReadableStream() const { return m_isReadableStream; }
bool hasReadableStream() const { return !!m_readableStream; }

using Init = Variant<RefPtr<Blob>, RefPtr<ArrayBufferView>, RefPtr<ArrayBuffer>, RefPtr<DOMFormData>, RefPtr<URLSearchParams>, RefPtr<ReadableStream>, String>;
static FetchBody extract(ScriptExecutionContext&, Init&&, String&);
static FetchBody loadingBody() { return { }; }

void setAsReadableStream() { m_isReadableStream = true; }
void loadingFailed();
void loadingSucceeded();

Expand All @@ -82,6 +81,12 @@ class FetchBody {
void cleanConsumePromise() { m_consumePromise = nullptr; }

FetchBody clone() const;
ReadableStream* readableStream() { return m_readableStream.get(); }
void setReadableStream(Ref<ReadableStream>&& stream)
{
ASSERT(!m_readableStream);
m_readableStream = WTFMove(stream);
}

private:
explicit FetchBody(Ref<const Blob>&& data) : m_data(WTFMove(data)) { }
Expand All @@ -91,6 +96,7 @@ class FetchBody {
explicit FetchBody(String&& data) : m_data(WTFMove(data)) { }
explicit FetchBody(Ref<const URLSearchParams>&& data) : m_data(WTFMove(data)) { }
explicit FetchBody(const FetchBodyConsumer& consumer) : m_consumer(consumer) { }
explicit FetchBody(Ref<ReadableStream>&& stream) : m_readableStream(WTFMove(stream)) { }
FetchBody() = default;

void consume(FetchBodyOwner&, Ref<DeferredPromise>&&);
Expand All @@ -114,9 +120,7 @@ class FetchBody {

FetchBodyConsumer m_consumer { FetchBodyConsumer::Type::None };
RefPtr<DeferredPromise> m_consumePromise;

// FIXME: We probably want to keep the stream as a specific field in m_data when we will support stream data upload.
bool m_isReadableStream { false };
RefPtr<ReadableStream> m_readableStream;
};

} // namespace WebCore
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/fetch/FetchBody.idl
Expand Up @@ -33,7 +33,7 @@
NoInterfaceObject
] interface FetchBody {
// FIMXE: Add missing body attribute.
// readonly attribute ReadableStream? body;
[ImplementedAs=readableStream, CallWith=ScriptState] readonly attribute ReadableStream? body;
readonly attribute boolean bodyUsed;
[NewObject] Promise<ArrayBuffer> arrayBuffer();
[NewObject] Promise<Blob> blob();
Expand Down
11 changes: 11 additions & 0 deletions Source/WebCore/Modules/fetch/FetchBodyOwner.cpp
Expand Up @@ -288,4 +288,15 @@ void FetchBodyOwner::BlobLoader::didFail(const ResourceError&)
owner.blobLoadingFailed();
}

ReadableStream* FetchBodyOwner::readableStream(JSC::ExecState& state)
{
if (isBodyNull())
return nullptr;

if (!m_body->hasReadableStream())
m_body->setReadableStream(ReadableStream::create(state, m_readableStreamSource));

return m_body->readableStream();
}

} // namespace WebCore
3 changes: 2 additions & 1 deletion Source/WebCore/Modules/fetch/FetchBodyOwner.h
Expand Up @@ -57,7 +57,8 @@ class FetchBodyOwner : public RefCounted<FetchBodyOwner>, public ActiveDOMObject

bool isActive() const { return !!m_blobLoader; }

bool isReadableStreamBody() const { return m_body && m_body->isReadableStream(); }
ReadableStream* readableStream(JSC::ExecState&);
virtual bool hasReadableStreamBody() const { return m_body && m_body->hasReadableStream(); }

protected:
const FetchBody& body() const { return *m_body; }
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/Modules/fetch/FetchRequest.cpp
Expand Up @@ -225,6 +225,7 @@ ExceptionOr<void> FetchRequest::setBody(FetchRequest& request)
if (!request.isBodyNull()) {
if (!methodCanHaveBody(m_internalRequest))
return Exception { TypeError };
// FIXME: If body has a readable stream, we should pipe it to this new body stream.
m_body = WTFMove(request.m_body);
request.setDisturbed();
}
Expand Down
1 change: 0 additions & 1 deletion Source/WebCore/Modules/fetch/FetchRequest.h
Expand Up @@ -85,7 +85,6 @@ class FetchRequest final : public FetchBodyOwner {
const ResourceRequest& internalRequest() const { return m_internalRequest.request; }
const String& internalRequestReferrer() const { return m_internalRequest.referrer; }
const URL& url() const { return m_internalRequest.request.url(); }
bool isBodyReadableStream() const { return !isBodyNull() && body().isReadableStream(); }

ResourceRequest resourceRequest() const;

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/Modules/fetch/FetchResponse.cpp
Expand Up @@ -83,7 +83,7 @@ void FetchResponse::setBodyAsReadableStream()
{
if (isBodyNull())
setBody(FetchBody::loadingBody());
body().setAsReadableStream();
m_isReadableStream = true;
updateContentType();
}

Expand All @@ -105,7 +105,7 @@ Ref<FetchResponse> FetchResponse::cloneForJS()

void FetchResponse::fetch(ScriptExecutionContext& context, FetchRequest& request, NotificationCallback&& responseCallback)
{
if (request.isBodyReadableStream()) {
if (request.hasReadableStreamBody()) {
if (responseCallback)
responseCallback(Exception { NotSupportedError, "ReadableStream uploading is not supported" });
return;
Expand Down
5 changes: 5 additions & 0 deletions Source/WebCore/Modules/fetch/FetchResponse.h
Expand Up @@ -102,6 +102,9 @@ class FetchResponse final : public FetchBodyOwner {

const ResourceResponse& resourceResponse() const { return m_response; }

// FIXME: Remove this method and use FetchBodyOwner one once we have full support in DOM ReadableStream.
bool hasReadableStreamBody() const final { return m_isReadableStream; }

private:
FetchResponse(ScriptExecutionContext&, std::optional<FetchBody>&&, Ref<FetchHeaders>&&, ResourceResponse&&);

Expand Down Expand Up @@ -144,6 +147,8 @@ class FetchResponse final : public FetchBodyOwner {
std::optional<BodyLoader> m_bodyLoader;
mutable String m_responseURL;
bool m_shouldExposeBody { true };
// FIXME: Remove that flag once we have full support in DOM ReadableStream.
bool m_isReadableStream { false };

FetchBodyConsumer m_consumer { FetchBodyConsumer::Type::ArrayBuffer };
};
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Expand Up @@ -1762,6 +1762,7 @@
41ABE67C1D0580E0006D862D /* CrossOriginPreflightChecker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41ABE6791D0580D5006D862D /* CrossOriginPreflightChecker.cpp */; };
41AD753A1CEF6BD100A31486 /* FetchOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 41AD75391CEF6BCE00A31486 /* FetchOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
41B2A6261EF1BF6D002B9D7A /* WebAudioSourceProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 41B2A6251EF1BF60002B9D7A /* WebAudioSourceProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
41B459EF1F55EBD10000F6FD /* ReadableStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41B459ED1F55EBC70000F6FD /* ReadableStream.cpp */; };
41BF700C0FE86F49005E8DEC /* MessagePortChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 41BF700A0FE86F49005E8DEC /* MessagePortChannel.h */; settings = {ATTRIBUTES = (Private, ); }; };
41BF700F0FE86F61005E8DEC /* PlatformMessagePortChannel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41BF700D0FE86F61005E8DEC /* PlatformMessagePortChannel.cpp */; };
41BF70100FE86F61005E8DEC /* PlatformMessagePortChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 41BF700E0FE86F61005E8DEC /* PlatformMessagePortChannel.h */; };
Expand Down Expand Up @@ -9485,6 +9486,7 @@
41AD75391CEF6BCE00A31486 /* FetchOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchOptions.h; sourceTree = "<group>"; };
41B2A6251EF1BF60002B9D7A /* WebAudioSourceProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebAudioSourceProvider.h; sourceTree = "<group>"; };
41B459DA1F4CADB90000F6FD /* ReadableStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStream.h; sourceTree = "<group>"; };
41B459ED1F55EBC70000F6FD /* ReadableStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReadableStream.cpp; sourceTree = "<group>"; };
41BF700A0FE86F49005E8DEC /* MessagePortChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessagePortChannel.h; sourceTree = "<group>"; };
41BF700D0FE86F61005E8DEC /* PlatformMessagePortChannel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PlatformMessagePortChannel.cpp; path = default/PlatformMessagePortChannel.cpp; sourceTree = "<group>"; };
41BF700E0FE86F61005E8DEC /* PlatformMessagePortChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PlatformMessagePortChannel.h; path = default/PlatformMessagePortChannel.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -23877,6 +23879,7 @@
E1C36D320EB0A094007410BC /* JSWorkerGlobalScopeBase.cpp */,
E1C36D330EB0A094007410BC /* JSWorkerGlobalScopeBase.h */,
709A01FD1E3D0BCC006B0D4C /* ModuleFetchFailureKind.h */,
41B459ED1F55EBC70000F6FD /* ReadableStream.cpp */,
41B459DA1F4CADB90000F6FD /* ReadableStream.h */,
418C395E1C8F0AAB0051C8A3 /* ReadableStreamDefaultController.cpp */,
418C395F1C8F0AAB0051C8A3 /* ReadableStreamDefaultController.h */,
Expand Down Expand Up @@ -33293,6 +33296,7 @@
93F19AB908245E59001E9ABC /* Range.cpp in Sources */,
F55B3DCD1251F12D003EF269 /* RangeInputType.cpp in Sources */,
6E84E9E017668BEE00815B68 /* RasterShape.cpp in Sources */,
41B459EF1F55EBD10000F6FD /* ReadableStream.cpp in Sources */,
418C39611C8F0AB10051C8A3 /* ReadableStreamDefaultController.cpp in Sources */,
FD31603B12B0267600C1A359 /* RealtimeAnalyser.cpp in Sources */,
41103AAE1E39791000769F03 /* RealtimeIncomingAudioSource.cpp in Sources */,
Expand Down
56 changes: 56 additions & 0 deletions Source/WebCore/bindings/js/ReadableStream.cpp
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY CANON INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CANON INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "ReadableStream.h"

#include "JSReadableStreamSource.h"
#include "WebCoreJSClientData.h"

using namespace JSC;

namespace WebCore {

Ref<ReadableStream> ReadableStream::create(JSC::ExecState& execState, RefPtr<ReadableStreamSource>&& source)
{
VM& vm = execState.vm();
auto& clientData = *static_cast<JSVMClientData*>(vm.clientData);
auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(execState.lexicalGlobalObject());

auto* constructor = JSC::asObject(globalObject.get(&execState, clientData.builtinNames().ReadableStreamPrivateName()));

ConstructData constructData;
ConstructType constructType = constructor->methodTable(vm)->getConstructData(constructor, constructData);
ASSERT(constructType != ConstructType::None);

MarkedArgumentBuffer args;
args.append(source ? toJSNewlyCreated(&execState, &globalObject, source.releaseNonNull()) : JSC::jsUndefined());

auto newReadableStream = jsDynamicDowncast<JSReadableStream*>(vm, JSC::construct(&execState, constructor, constructType, constructData, args));

return create(globalObject, *newReadableStream);
}

}
16 changes: 16 additions & 0 deletions Source/WebCore/bindings/js/ReadableStream.h
Expand Up @@ -32,10 +32,14 @@

namespace WebCore {

class ReadableStreamSource;

class ReadableStream final : public DOMGuarded<JSReadableStream> {
public:
static Ref<ReadableStream> create(JSDOMGlobalObject& globalObject, JSReadableStream& readableStream) { return adoptRef(*new ReadableStream(globalObject, readableStream)); }

static Ref<ReadableStream> create(JSC::ExecState&, RefPtr<ReadableStreamSource>&&);

JSReadableStream* readableStream() { return guarded(); }

protected:
Expand Down Expand Up @@ -64,4 +68,16 @@ template<> struct JSDOMWrapperConverterTraits<ReadableStream> {
static constexpr bool needsState = true;
};

template<> struct JSConverter<IDLInterface<ReadableStream>> {
static constexpr bool needsState = false;
static constexpr bool needsGlobalObject = false;

static JSC::JSValue convert(ReadableStream* value)
{
if (!value)
return JSC::jsNull();
return value->readableStream();
}
};

}

0 comments on commit 67cb061

Please sign in to comment.