Bug 213168

Summary: Implement Blob.text and Blob.arrayBuffer
Product: WebKit Reporter: Tetsuharu Ohzeki [UTC+9] <tetsuharu.ohzeki>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: annulen, cdumez, esprehn+autocc, ews-watchlist, gyuyoung.kim, kondapallykalyan, ryuan.choi, sam, sergio, youennf
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 213119, 213170, 213198    
Bug Blocks: 196258    
Attachments:
Description Flags
WIP
none
Patch youennf: review-

Description Tetsuharu Ohzeki [UTC+9] 2020-06-13 10:45:59 PDT
This is a part of bug 196258.
`Blob.stream` needs ReadableStream but it's switched the compile flag `if ENABLE(STREAMS_API)`.

So First, I implements Blob.text and Blob.arrayBuffer which we can implement without ReadableStream.

https://w3c.github.io/FileAPI/#text-method-algo
https://w3c.github.io/FileAPI/#arraybuffer-method-algo
Comment 1 Tetsuharu Ohzeki [UTC+9] 2020-06-14 01:39:27 PDT
Created attachment 401853 [details]
WIP
Comment 2 Tetsuharu Ohzeki [UTC+9] 2020-06-17 07:09:11 PDT
Created attachment 402103 [details]
Patch
Comment 3 Sam Weinig 2020-06-17 08:52:16 PDT
Thanks for tackling this Tetsuharu!

As far as I can tell, ENABLE_STREAMS_API is enabled by default (at least for macOS and iOS, I always have a bit of trouble remembering where to look for other ports).

Given that, does it still make sense to use this implementation strategy? Or would it make more sense to try build these two methods on top of a general ReadableStream based implementation? (It may very well make sense to use this strategy, I am not professing support one way or another, simply asking).
Comment 4 Tetsuharu Ohzeki [UTC+9] 2020-06-17 10:30:49 PDT
(In reply to Sam Weinig from comment #3)
> Thanks for tackling this Tetsuharu!
> 
> As far as I can tell, ENABLE_STREAMS_API is enabled by default (at least for
> macOS and iOS, I always have a bit of trouble remembering where to look for
> other ports).
> 
> Given that, does it still make sense to use this implementation strategy? Or
> would it make more sense to try build these two methods on top of a general
> ReadableStream based implementation? (It may very well make sense to use
> this strategy, I am not professing support one way or another, simply
> asking).

To be honest, I thought (planned) that we (probably I) should refactor these implementation after implementing `Blob.stream`. I'm not sure about that we can build these methods on the top of ReadableStream and its way is simple to implement them and I need to investigate about buiding on general ReadableStream to answer to your question.


---------------


By the way, I seem all(?) ports has enabled ENABLE_STREAMS_API by default.
Cannot we remove this flag? Should I post about it to webkit-dev?


- http://trac.webkit.org/browser/trunk/Source/WTF/wtf/PlatformEnable.h#L465
- http://trac.webkit.org/browser/trunk/Source/cmake/OptionsFTW.cmake#L104
- http://trac.webkit.org/browser/trunk/Source/cmake/OptionsWin.cmake#L58
- http://trac.webkit.org/browser/trunk/Source/cmake/OptionsMac.cmake#L87
- http://trac.webkit.org/browser/trunk/Source/cmake/WebKitFeatures.cmake#L210
Comment 5 Sam Weinig 2020-06-18 10:04:25 PDT
(In reply to Tetsuharu Ohzeki from comment #4)
> (In reply to Sam Weinig from comment #3)
> > Thanks for tackling this Tetsuharu!
> > 
> > As far as I can tell, ENABLE_STREAMS_API is enabled by default (at least for
> > macOS and iOS, I always have a bit of trouble remembering where to look for
> > other ports).
> > 
> > Given that, does it still make sense to use this implementation strategy? Or
> > would it make more sense to try build these two methods on top of a general
> > ReadableStream based implementation? (It may very well make sense to use
> > this strategy, I am not professing support one way or another, simply
> > asking).
> 
> To be honest, I thought (planned) that we (probably I) should refactor these
> implementation after implementing `Blob.stream`. I'm not sure about that we
> can build these methods on the top of ReadableStream and its way is simple
> to implement them and I need to investigate about buiding on general
> ReadableStream to answer to your question.
> 
> 
> ---------------
> 
> 
> By the way, I seem all(?) ports has enabled ENABLE_STREAMS_API by default.
> Cannot we remove this flag? Should I post about it to webkit-dev?

Couldn't hurt to email webkit-dev.
Comment 6 youenn fablet 2020-06-19 01:36:30 PDT
Comment on attachment 402103 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=402103&action=review

> Source/WebCore/ChangeLog:14
> +        without `ReadableStream` implementation.

Since the goal is to go with supporting ReadableStream at some point, we should probably extract existing functionality from FetchBodyOwner/FetchBoydConsumer.
Ideally, split FetchBodyOwner in two classes, one that will continue be the base class from FetchRequest and FetchResponse, plus be an ActiveDOMObject.
And the other one which can be reused jointly with FetchBodyConsumer to implement text/arrayBuffer/ReadableStream.

> Source/WebCore/fileapi/BlobPromiseLoader.cpp:65
> +    delete this;

This is a risky pattern.
I do not think we need BlobPromiseLoader to be an ActiveDOMObject.
It might be best to make Blob own the BlobPromiseLoader.
Comment 7 Tetsuharu Ohzeki [UTC+9] 2020-06-19 01:48:06 PDT
(In reply to youenn fablet from comment #6)
> This is a risky pattern.
> I do not think we need BlobPromiseLoader to be an ActiveDOMObject.
> It might be best to make Blob own the BlobPromiseLoader.

text/arrayBuffer/ReadableStream is marked as `[NewObject]` in IDL.

If we make Blob owns the BlobPromiseLoader, we need to hold multiple `DeferredPromise` or `BlobPromiseLoader` in Blob by vector or map, right?
Comment 8 youenn fablet 2020-06-19 02:11:13 PDT
> text/arrayBuffer/ReadableStream is marked as `[NewObject]` in IDL.

For text and arrayBuffer, this is the promise that is new, and this is already handled by the binding generator.

Given the algorithm though, you are correct that text and arrayBuffer will be also brand new object. For ReadableStream, a new one needs to be created indeed.

> If we make Blob owns the BlobPromiseLoader, we need to hold multiple
> `DeferredPromise` or `BlobPromiseLoader` in Blob by vector or map, right?


Right, this could be a HashSet.

Thinking a bit more, BlobLoader in BlobLoader.h might be the one you actually want to use.
It could be easily extended to support String, and could be probably extended to ReadableStream as well.
Comment 9 Tetsuharu Ohzeki [UTC+9] 2020-09-03 11:11:05 PDT

*** This bug has been marked as a duplicate of bug 215663 ***