Changeset 268228 in webkit


Ignore:
Timestamp:
Oct 8, 2020 4:28:32 PM (4 years ago)
Author:
achristensen@apple.com
Message:

Implement Blob.stream
https://bugs.webkit.org/show_bug.cgi?id=217457

Reviewed by Youenn Fablet.

LayoutTests/imported/w3c:

  • web-platform-tests/FileAPI/blob/Blob-stream.any-expected.txt:
  • web-platform-tests/FileAPI/blob/Blob-stream.any.worker-expected.txt:
  • web-platform-tests/FileAPI/idlharness-expected.txt:
  • web-platform-tests/FileAPI/idlharness.worker-expected.txt:

Source/WebCore:

It's implemented in Chrome and Firefox.

  • Modules/async-clipboard/ClipboardItemBindingsDataSource.h:
  • bindings/js/ReadableStream.h:

(WebCore::toJSNewlyCreated):

  • bindings/scripts/CodeGeneratorJS.pm:

(AddToIncludesForIDLType):

  • fileapi/Blob.cpp:

(WebCore::Blob::stream):

  • fileapi/Blob.h:
  • fileapi/Blob.idl:
  • fileapi/FileReaderLoader.cpp:

(WebCore::FileReaderLoader::FileReaderLoader):
(WebCore::FileReaderLoader::takeRawData):

  • fileapi/FileReaderLoader.h:
  • fileapi/FileReaderLoaderClient.h:

LayoutTests:

  • fast/files/blob-stream-error-expected.txt: Added.
  • fast/files/blob-stream-error.html: Added.
  • fast/files/blob-stream-frame-expected.txt: Added.
  • fast/files/blob-stream-frame.html: Added.
  • fast/files/resources/blob-stream-iframe.html: Added.
Location:
trunk
Files:
5 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r268214 r268228  
     12020-10-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        Implement Blob.stream
     4        https://bugs.webkit.org/show_bug.cgi?id=217457
     5
     6        Reviewed by Youenn Fablet.
     7
     8        * fast/files/blob-stream-error-expected.txt: Added.
     9        * fast/files/blob-stream-error.html: Added.
     10        * fast/files/blob-stream-frame-expected.txt: Added.
     11        * fast/files/blob-stream-frame.html: Added.
     12        * fast/files/resources/blob-stream-iframe.html: Added.
     13
    1142020-10-08  Alex Christensen  <achristensen@webkit.org>
    215
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r268178 r268228  
     12020-10-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        Implement Blob.stream
     4        https://bugs.webkit.org/show_bug.cgi?id=217457
     5
     6        Reviewed by Youenn Fablet.
     7
     8        * web-platform-tests/FileAPI/blob/Blob-stream.any-expected.txt:
     9        * web-platform-tests/FileAPI/blob/Blob-stream.any.worker-expected.txt:
     10        * web-platform-tests/FileAPI/idlharness-expected.txt:
     11        * web-platform-tests/FileAPI/idlharness.worker-expected.txt:
     12
    1132020-10-08  Rob Buis  <rbuis@igalia.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/FileAPI/blob/Blob-stream.any-expected.txt

    r263059 r268228  
    11
    2 FAIL Blob.stream() promise_test: Unhandled rejection with value: object "TypeError: blob.stream is not a function. (In 'blob.stream()', 'blob.stream' is undefined)"
    3 FAIL Blob.stream() empty Blob promise_test: Unhandled rejection with value: object "TypeError: blob.stream is not a function. (In 'blob.stream()', 'blob.stream' is undefined)"
    4 FAIL Blob.stream() non-unicode input promise_test: Unhandled rejection with value: object "TypeError: blob.stream is not a function. (In 'blob.stream()', 'blob.stream' is undefined)"
    5 FAIL Blob.stream() garbage collection of blob shouldn't break streamconsumption promise_test: Unhandled rejection with value: object "TypeError: blob.stream is not a function. (In 'blob.stream()', 'blob.stream' is undefined)"
     2PASS Blob.stream()
     3PASS Blob.stream() empty Blob
     4PASS Blob.stream() non-unicode input
     5PASS Blob.stream() garbage collection of blob shouldn't break streamconsumption
    66
  • trunk/LayoutTests/imported/w3c/web-platform-tests/FileAPI/blob/Blob-stream.any.worker-expected.txt

    r263059 r268228  
    11
    2 FAIL Blob.stream() promise_test: Unhandled rejection with value: object "TypeError: blob.stream is not a function. (In 'blob.stream()', 'blob.stream' is undefined)"
    3 FAIL Blob.stream() empty Blob promise_test: Unhandled rejection with value: object "TypeError: blob.stream is not a function. (In 'blob.stream()', 'blob.stream' is undefined)"
    4 FAIL Blob.stream() non-unicode input promise_test: Unhandled rejection with value: object "TypeError: blob.stream is not a function. (In 'blob.stream()', 'blob.stream' is undefined)"
    5 FAIL Blob.stream() garbage collection of blob shouldn't break streamconsumption promise_test: Unhandled rejection with value: object "TypeError: blob.stream is not a function. (In 'blob.stream()', 'blob.stream' is undefined)"
     2PASS Blob.stream()
     3PASS Blob.stream() empty Blob
     4PASS Blob.stream() non-unicode input
     5PASS Blob.stream() garbage collection of blob shouldn't break streamconsumption
    66
  • trunk/LayoutTests/imported/w3c/web-platform-tests/FileAPI/idlharness-expected.txt

    r267651 r268228  
    1616PASS Blob interface: attribute type
    1717PASS Blob interface: operation slice(optional long long, optional long long, optional DOMString)
    18 FAIL Blob interface: operation stream() assert_own_property: interface prototype object missing non-static operation expected property "stream" missing
     18PASS Blob interface: operation stream()
    1919PASS Blob interface: operation text()
    2020PASS Blob interface: operation arrayBuffer()
     
    2525PASS Blob interface: new Blob(["TEST"]) must inherit property "slice(optional long long, optional long long, optional DOMString)" with the proper type
    2626PASS Blob interface: calling slice(optional long long, optional long long, optional DOMString) on new Blob(["TEST"]) with too few arguments must throw TypeError
    27 FAIL Blob interface: new Blob(["TEST"]) must inherit property "stream()" with the proper type assert_inherits: property "stream" not found in prototype chain
     27PASS Blob interface: new Blob(["TEST"]) must inherit property "stream()" with the proper type
    2828PASS Blob interface: new Blob(["TEST"]) must inherit property "text()" with the proper type
    2929PASS Blob interface: new Blob(["TEST"]) must inherit property "arrayBuffer()" with the proper type
     
    4444PASS Blob interface: new File(["myFileBits"], "myFileName") must inherit property "slice(optional long long, optional long long, optional DOMString)" with the proper type
    4545PASS Blob interface: calling slice(optional long long, optional long long, optional DOMString) on new File(["myFileBits"], "myFileName") with too few arguments must throw TypeError
    46 FAIL Blob interface: new File(["myFileBits"], "myFileName") must inherit property "stream()" with the proper type assert_inherits: property "stream" not found in prototype chain
     46PASS Blob interface: new File(["myFileBits"], "myFileName") must inherit property "stream()" with the proper type
    4747PASS Blob interface: new File(["myFileBits"], "myFileName") must inherit property "text()" with the proper type
    4848PASS Blob interface: new File(["myFileBits"], "myFileName") must inherit property "arrayBuffer()" with the proper type
  • trunk/LayoutTests/imported/w3c/web-platform-tests/FileAPI/idlharness.worker-expected.txt

    r267651 r268228  
    1414PASS Blob interface: attribute type
    1515PASS Blob interface: operation slice(optional long long, optional long long, optional DOMString)
    16 FAIL Blob interface: operation stream() assert_own_property: interface prototype object missing non-static operation expected property "stream" missing
     16PASS Blob interface: operation stream()
    1717PASS Blob interface: operation text()
    1818PASS Blob interface: operation arrayBuffer()
     
    2323PASS Blob interface: new Blob(["TEST"]) must inherit property "slice(optional long long, optional long long, optional DOMString)" with the proper type
    2424PASS Blob interface: calling slice(optional long long, optional long long, optional DOMString) on new Blob(["TEST"]) with too few arguments must throw TypeError
    25 FAIL Blob interface: new Blob(["TEST"]) must inherit property "stream()" with the proper type assert_inherits: property "stream" not found in prototype chain
     25PASS Blob interface: new Blob(["TEST"]) must inherit property "stream()" with the proper type
    2626PASS Blob interface: new Blob(["TEST"]) must inherit property "text()" with the proper type
    2727PASS Blob interface: new Blob(["TEST"]) must inherit property "arrayBuffer()" with the proper type
     
    4242PASS Blob interface: new File(["myFileBits"], "myFileName") must inherit property "slice(optional long long, optional long long, optional DOMString)" with the proper type
    4343PASS Blob interface: calling slice(optional long long, optional long long, optional DOMString) on new File(["myFileBits"], "myFileName") with too few arguments must throw TypeError
    44 FAIL Blob interface: new File(["myFileBits"], "myFileName") must inherit property "stream()" with the proper type assert_inherits: property "stream" not found in prototype chain
     44PASS Blob interface: new File(["myFileBits"], "myFileName") must inherit property "stream()" with the proper type
    4545PASS Blob interface: new File(["myFileBits"], "myFileName") must inherit property "text()" with the proper type
    4646PASS Blob interface: new File(["myFileBits"], "myFileName") must inherit property "arrayBuffer()" with the proper type
  • trunk/Source/WebCore/ChangeLog

    r268208 r268228  
     12020-10-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        Implement Blob.stream
     4        https://bugs.webkit.org/show_bug.cgi?id=217457
     5
     6        Reviewed by Youenn Fablet.
     7
     8        It's implemented in Chrome and Firefox.
     9
     10        * Modules/async-clipboard/ClipboardItemBindingsDataSource.h:
     11        * bindings/js/ReadableStream.h:
     12        (WebCore::toJSNewlyCreated):
     13        * bindings/scripts/CodeGeneratorJS.pm:
     14        (AddToIncludesForIDLType):
     15        * fileapi/Blob.cpp:
     16        (WebCore::Blob::stream):
     17        * fileapi/Blob.h:
     18        * fileapi/Blob.idl:
     19        * fileapi/FileReaderLoader.cpp:
     20        (WebCore::FileReaderLoader::FileReaderLoader):
     21        (WebCore::FileReaderLoader::takeRawData):
     22        * fileapi/FileReaderLoader.h:
     23        * fileapi/FileReaderLoaderClient.h:
     24
    1252020-10-08  Fujii Hironori  <Hironori.Fujii@sony.com>
    226
  • trunk/Source/WebCore/Modules/async-clipboard/ClipboardItemBindingsDataSource.h

    r262999 r268228  
    5656
    5757    using BufferOrString = Variant<String, Ref<SharedBuffer>>;
    58     class ClipboardItemTypeLoader : public FileReaderLoaderClient, public RefCounted<ClipboardItemTypeLoader>, public CanMakeWeakPtr<ClipboardItemTypeLoader> {
     58    class ClipboardItemTypeLoader : public FileReaderLoaderClient, public RefCounted<ClipboardItemTypeLoader> {
    5959    public:
    6060        static Ref<ClipboardItemTypeLoader> create(const String& type, CompletionHandler<void()>&& completionHandler)
  • trunk/Source/WebCore/bindings/js/ReadableStream.h

    r263883 r268228  
    8585}
    8686
     87inline JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject*, Ref<ReadableStream>&& stream)
     88{
     89    return stream->readableStream();
    8790}
     91
     92}
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r268114 r268228  
    631631        AddToIncludes("JSEventListener.h", $includesRef, $conditional);
    632632        AddToIncludes("JSDOMConvertEventListener.h", $includesRef, $conditional);
     633        return;
     634    }
     635
     636    if ($type->name eq "ReadableStream") {
     637        AddToIncludes("ReadableStream.h", $includesRef, $conditional);
    633638        return;
    634639    }
  • trunk/Source/WebCore/fileapi/Blob.cpp

    r266168 r268228  
    3838#include "File.h"
    3939#include "JSDOMPromiseDeferred.h"
     40#include "ReadableStream.h"
     41#include "ReadableStreamSource.h"
    4042#include "ScriptExecutionContext.h"
    4143#include "SharedBuffer.h"
     
    237239}
    238240
     241ExceptionOr<Ref<ReadableStream>> Blob::stream(ScriptExecutionContext& scriptExecutionContext)
     242{
     243    class BlobStreamSource : public FileReaderLoaderClient, public ReadableStreamSource {
     244    public:
     245        BlobStreamSource(ScriptExecutionContext& scriptExecutionContext, Blob& blob)
     246            : m_loader(makeUniqueRef<FileReaderLoader>(FileReaderLoader::ReadType::ReadAsArrayBuffer, this))
     247        {
     248            m_loader->start(&scriptExecutionContext, blob);
     249        }
     250
     251    private:
     252        // ReadableStreamSource
     253        void setActive() final { }
     254        void setInactive() final { }
     255        void doStart() final { }
     256        void doPull() final { }
     257        void doCancel() final
     258        {
     259            m_loader->cancel();
     260        }
     261
     262        // FileReaderLoaderClient
     263        void didStartLoading() final { }
     264        void didReceiveData() final
     265        {
     266            controller().enqueue(m_loader->takeRawData());
     267        }
     268        void didFinishLoading() final
     269        {
     270            controller().close();
     271        }
     272        void didFail(ExceptionCode exception) final
     273        {
     274            controller().error(Exception { exception });
     275        }
     276
     277        UniqueRef<FileReaderLoader> m_loader;
     278    };
     279
     280    return ReadableStream::create(*scriptExecutionContext.execState(), adoptRef(*new BlobStreamSource(scriptExecutionContext, *this)));
     281}
     282
    239283#if ASSERT_ENABLED
    240284bool Blob::isNormalizedContentType(const String& contentType)
  • trunk/Source/WebCore/fileapi/Blob.h

    r266168 r268228  
    5151class BlobLoader;
    5252class DeferredPromise;
     53class ReadableStream;
    5354class ScriptExecutionContext;
    5455class SharedBuffer;
     56
     57template<typename> class ExceptionOr;
    5558
    5659using BlobPartVariant = Variant<RefPtr<JSC::ArrayBufferView>, RefPtr<JSC::ArrayBuffer>, RefPtr<Blob>, String>;
     
    124127    void text(ScriptExecutionContext&, Ref<DeferredPromise>&&);
    125128    void arrayBuffer(ScriptExecutionContext&, Ref<DeferredPromise>&&);
     129    ExceptionOr<Ref<ReadableStream>> stream(ScriptExecutionContext&);
    126130
    127131protected:
  • trunk/Source/WebCore/fileapi/Blob.idl

    r266168 r268228  
    4444    [CallWith=ScriptExecutionContext] Blob slice(optional long long start = 0, optional long long end = 0x7FFFFFFFFFFFFFFF, optional DOMString contentType = "");
    4545
    46     // [NewObject] ReadableStream stream();
     46    [NewObject, CallWith=ScriptExecutionContext, MayThrowException] ReadableStream stream();
    4747    [NewObject, CallWith=ScriptExecutionContext] Promise<USVString> text();
    4848    [NewObject, CallWith=ScriptExecutionContext] Promise<ArrayBuffer> arrayBuffer();
  • trunk/Source/WebCore/fileapi/FileReaderLoader.cpp

    r262999 r268228  
    5757FileReaderLoader::FileReaderLoader(ReadType readType, FileReaderLoaderClient* client)
    5858    : m_readType(readType)
    59     , m_client(client)
     59    , m_client(makeWeakPtr(client))
    6060    , m_isRawDataConverted(false)
    6161    , m_stringResult(emptyString())
     
    280280}
    281281
     282RefPtr<JSC::ArrayBuffer> FileReaderLoader::takeRawData()
     283{
     284    return std::exchange(m_rawData, nullptr);
     285}
     286
    282287String FileReaderLoader::stringResult()
    283288{
  • trunk/Source/WebCore/fileapi/FileReaderLoader.h

    r262999 r268228  
    3838#include <wtf/Forward.h>
    3939#include <wtf/Optional.h>
     40#include <wtf/WeakPtr.h>
    4041#include <wtf/text/WTFString.h>
    4142
     
    7980    unsigned bytesLoaded() const { return m_bytesLoaded; }
    8081    unsigned totalBytes() const { return m_totalBytes; }
     82    RefPtr<JSC::ArrayBuffer> takeRawData();
    8183    Optional<ExceptionCode> errorCode() const { return m_errorCode; }
    8284
     
    99101
    100102    ReadType m_readType;
    101     FileReaderLoaderClient* m_client;
     103    WeakPtr<FileReaderLoaderClient> m_client;
    102104    TextEncoding m_encoding;
    103105    String m_dataType;
  • trunk/Source/WebCore/fileapi/FileReaderLoaderClient.h

    r262999 r268228  
    3232
    3333#include "ExceptionCode.h"
     34#include <wtf/WeakPtr.h>
    3435
    3536namespace WebCore {
    3637
    37 class FileReaderLoaderClient {
     38class FileReaderLoaderClient : public CanMakeWeakPtr<FileReaderLoaderClient> {
    3839public:
    3940    virtual ~FileReaderLoaderClient() = default;
Note: See TracChangeset for help on using the changeset viewer.