Changeset 181736 in webkit


Ignore:
Timestamp:
Mar 19, 2015 1:27:27 AM (9 years ago)
Author:
youenn.fablet@crf.canon.fr
Message:

[Streams API] Update ReadableStream API according new version of the specification
https://bugs.webkit.org/show_bug.cgi?id=142822

Reviewed by Benjamin Poulain.

Source/WebCore:

This patch updates the IDL of ReadableStream according the new version of the spec, which splits functionality between ReadableStream and ReadableStreamReader.
In particular, this patch removes read(), ready, closed and state from ReadableStream and it adds the getReader method.

Covered by updated readablestream-constructor.html test.

  • Modules/streams/ReadableStream.cpp:

(WebCore::ReadableStream::ReadableStream):
(WebCore::ReadableStream::state): Deleted.
(WebCore::ReadableStream::closed): Deleted.
(WebCore::ReadableStream::ready): Deleted.

  • Modules/streams/ReadableStream.h:

(WebCore::ReadableStream::internalState): Added to make mac build system happy, to be used by ReadableStreamReader.

  • Modules/streams/ReadableStream.idl:
  • bindings/js/JSReadableStreamCustom.cpp:

(WebCore::JSReadableStream::cancel):
(WebCore::JSReadableStream::getReader):
(WebCore::JSReadableStream::read): Deleted.
(WebCore::getOrCreatePromiseDeferredFromObject): Deleted.
(WebCore::readyPromiseSlotName): Deleted.
(WebCore::JSReadableStream::ready): Deleted.
(WebCore::closedPromiseSlotName): Deleted.
(WebCore::JSReadableStream::closed): Deleted.

LayoutTests:

Removing tests checking ready and closed.
Removing assertions checking read(), ready, closed and state.
Adding assertions to test getReader() and parameters of remaining methods.

  • streams/readablestream-constructor-expected.txt:
  • streams/readablestream-constructor.html:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r181734 r181736  
     12015-03-19  Xabier Rodriguez Calvar <calvaris@igalia.com> and Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        [Streams API] Update ReadableStream API according new version of the specification
     4        https://bugs.webkit.org/show_bug.cgi?id=142822
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        Removing tests checking ready and closed.
     9        Removing assertions checking read(), ready, closed and state.
     10        Adding assertions to test getReader() and parameters of remaining methods.
     11
     12        * streams/readablestream-constructor-expected.txt:
     13        * streams/readablestream-constructor.html:
     14
    1152015-03-19  Chris Dumez  <cdumez@apple.com>
    216
  • trunk/LayoutTests/streams/readablestream-constructor-expected.txt

    r180559 r181736  
    11
    22PASS ReadableStream constructor should get an object as argument
     3PASS ReadableStream can be constructed with no arguments
    34PASS ReadableStream instances should have the correct list of properties
    4 PASS ReadableStream can be constructed with no arguments
    5 PASS ReadableStream instances have the correct methods and properties
    6 PASS ReadableStream ready and closed should always return the same promise object
    75
  • trunk/LayoutTests/streams/readablestream-constructor.html

    r180559 r181736  
    1111
    1212test(function() {
     13    new ReadableStream();
     14}, 'ReadableStream can be constructed with no arguments');
     15
     16test(function() {
    1317    rs = new ReadableStream();
    14     assert_array_equals(Object.getOwnPropertyNames(rs), ['closed', 'ready']);
    15     assert_array_equals(Object.getOwnPropertyNames(Object.getPrototypeOf(rs)), ['constructor','state', 'read', 'cancel', 'pipeTo', 'pipeThrough']);
    16 
    17     assert_true(Object.getOwnPropertyDescriptor(rs, 'closed').enumerable);
    18     assert_false(Object.getOwnPropertyDescriptor(rs, 'closed').configurable);
    19 
    20     assert_true(Object.getOwnPropertyDescriptor(rs, 'ready').enumerable);
    21     assert_false(Object.getOwnPropertyDescriptor(rs, 'ready').configurable);
    22 
    23     assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rs), 'state').enumerable);
    24     assert_false(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rs), 'state').configurable);
    25 
    26     assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rs), 'read').enumerable);
    27     assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rs), 'read').configurable);
    28     assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rs), 'read').writable);
     18    assert_array_equals(Object.getOwnPropertyNames(rs), []);
     19    assert_array_equals(Object.getOwnPropertyNames(Object.getPrototypeOf(rs)), ['constructor','cancel', 'getReader', 'pipeTo', 'pipeThrough']);
    2920
    3021    assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rs), 'cancel').enumerable);
    3122    assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rs), 'cancel').configurable);
    3223    assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rs), 'cancel').writable);
     24
     25    assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rs), 'getReader').enumerable);
     26    assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rs), 'getReader').configurable);
     27    assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rs), 'getReader').writable);
    3328
    3429    assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rs), 'pipeTo').enumerable);
     
    3934    assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rs), 'pipeThrough').configurable);
    4035    assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rs), 'pipeThrough').writable);
     36
     37    assert_equals(typeof rs.cancel, 'function', 'has an cancel method');
     38    assert_equals(rs.cancel.length, 1);
     39    assert_equals(typeof rs.getReader, 'function', 'has a getReader method');
     40    assert_equals(rs.getReader.length, 0);
     41    assert_equals(typeof rs.pipeTo, 'function', 'has a pipeTo method');
     42    assert_equals(rs.pipeTo.length, 2);
     43    assert_equals(typeof rs.pipeThrough, 'function', 'has a pipeThrough method');
     44    assert_equals(rs.pipeThrough.length, 2);
     45
    4146}, 'ReadableStream instances should have the correct list of properties');
    4247
    43 // The following two tests are derived from https://github.com/whatwg/streams/blob/master/reference-implementation/test/readable-stream.js
    44 test(function() {
    45     new ReadableStream();
    46 }, 'ReadableStream can be constructed with no arguments');
    47 
    48 test(function() {
    49     rs = new ReadableStream();
    50     assert_equals(typeof rs.read, 'function', 'has a read method');
    51     assert_equals(typeof rs.cancel, 'function', 'has an cancel method');
    52     assert_equals(typeof rs.pipeTo, 'function', 'has a pipeTo method');
    53     assert_equals(typeof rs.pipeThrough, 'function', 'has a pipeThrough method');
    54     assert_equals(rs.state, 'waiting', 'state starts out waiting');
    55     assert_exists(rs, 'ready', 'has a ready property');
    56     assert_equals(typeof rs.ready.then, 'function', 'ready property is a thenable');
    57     assert_exists(rs, 'closed', 'has a closed property');
    58     assert_equals(typeof rs.closed.then, 'function', 'closed property is thenable');
    59 }, 'ReadableStream instances have the correct methods and properties');
    60 
    61 test(function() {
    62     rs = new ReadableStream();
    63     readyPromise = rs.ready;
    64     closedPromise = rs.closed;
    65 
    66     assert_equals(readyPromise, rs.ready);
    67     assert_equals(closedPromise, rs.closed);
    68 
    69     // We check ReadableStream properties here as ready and closed promises are persistent and need to be stored in some way that is not observable.
    70     assert_array_equals(Object.keys(rs), ['closed', 'ready']);
    71     assert_array_equals(Object.getOwnPropertyNames(rs), ['closed', 'ready']);
    72 }, 'ReadableStream ready and closed should always return the same promise object');
    73 
    7448</script>
  • trunk/Source/WebCore/ChangeLog

    r181729 r181736  
     12015-03-19  Xabier Rodriguez Calvar <calvaris@igalia.com> and Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        [Streams API] Update ReadableStream API according new version of the specification
     4        https://bugs.webkit.org/show_bug.cgi?id=142822
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        This patch updates the IDL of ReadableStream according the new version of the spec, which splits functionality between ReadableStream and ReadableStreamReader.
     9        In particular, this patch removes read(), ready, closed and state from ReadableStream and it adds the getReader method.
     10
     11        Covered by updated readablestream-constructor.html test.
     12
     13        * Modules/streams/ReadableStream.cpp:
     14        (WebCore::ReadableStream::ReadableStream):
     15        (WebCore::ReadableStream::state): Deleted.
     16        (WebCore::ReadableStream::closed): Deleted.
     17        (WebCore::ReadableStream::ready): Deleted.
     18        * Modules/streams/ReadableStream.h:
     19        (WebCore::ReadableStream::internalState): Added to make mac build system happy, to be used by ReadableStreamReader.
     20        * Modules/streams/ReadableStream.idl:
     21        * bindings/js/JSReadableStreamCustom.cpp:
     22        (WebCore::JSReadableStream::cancel):
     23        (WebCore::JSReadableStream::getReader):
     24        (WebCore::JSReadableStream::read): Deleted.
     25        (WebCore::getOrCreatePromiseDeferredFromObject): Deleted.
     26        (WebCore::readyPromiseSlotName): Deleted.
     27        (WebCore::JSReadableStream::ready): Deleted.
     28        (WebCore::closedPromiseSlotName): Deleted.
     29        (WebCore::JSReadableStream::closed): Deleted.
     30
    1312015-03-18  Manuel Rego Casasnovas  <rego@igalia.com>
    232
  • trunk/Source/WebCore/Modules/streams/ReadableStream.cpp

    r180801 r181736  
    5050ReadableStream::ReadableStream(ScriptExecutionContext& scriptExecutionContext, Ref<ReadableStreamSource>&& source)
    5151    : ActiveDOMObject(&scriptExecutionContext)
    52     , m_state(State::Waiting)
     52    , m_state(State::Readable)
    5353    , m_source(WTF::move(source))
    5454{
     
    6363    readableStreamCounter.decrement();
    6464#endif
    65 }
    66 
    67 String ReadableStream::state() const
    68 {
    69     switch (m_state) {
    70     case State::Waiting:
    71         return ASCIILiteral("waiting");
    72     case State::Closed:
    73         return ASCIILiteral("closed");
    74     case State::Readable:
    75         return ASCIILiteral("readable");
    76     case State::Errored:
    77         return ASCIILiteral("errored");
    78     }
    79     ASSERT_NOT_REACHED();
    80     return ASCIILiteral("");
    81 }
    82 
    83 void ReadableStream::closed(SuccessCallback)
    84 {
    85     notImplemented();
    86 }
    87 
    88 void ReadableStream::ready(SuccessCallback)
    89 {
    90     notImplemented();
    9165}
    9266
  • trunk/Source/WebCore/Modules/streams/ReadableStream.h

    r181262 r181736  
    5050public:
    5151    enum class State {
    52         Waiting,
     52        Readable,
    5353        Closed,
    54         Readable,
    5554        Errored
    5655    };
     
    5958    virtual ~ReadableStream();
    6059
    61     // JS API implementation.
    62     String state() const;
    63 
    64     typedef std::function<void()> SuccessCallback;
    65     void closed(SuccessCallback);
    66     void ready(SuccessCallback);
     60    State internalState() { return m_state; }
    6761
    6862private:
  • trunk/Source/WebCore/Modules/streams/ReadableStream.idl

    r179687 r181736  
    3434    Conditional=STREAMS_API
    3535] interface ReadableStream {
    36     readonly attribute ReadableStreamStateType state;
    37 
    38     [Custom, RaisesException] Object read();
    39     // FIXME: Remove RaisesException once cancel is implemented.
     36    // FIXME: Remove RaisesException once methods are actually implemented.
    4037    [Custom, RaisesException] Promise cancel(DOMString reason);
    41     // FIXME: Remove RaisesException once pipeTo is implemented.
     38    [Custom, RaisesException] Object getReader();
    4239    [Custom, RaisesException] Promise pipeTo(any streams, any options);
    4340    [Custom, RaisesException] Object pipeThrough(any dest, any options);
    44 
    45     [CustomGetter] readonly attribute Promise closed;
    46     [CustomGetter] readonly attribute Promise ready;
    47 
    4841};
  • trunk/Source/WebCore/bindings/js/JSReadableStreamCustom.cpp

    r181262 r181736  
    4343namespace WebCore {
    4444
    45 JSValue JSReadableStream::read(ExecState* exec)
     45JSValue JSReadableStream::cancel(ExecState* exec)
    4646{
    47     JSValue error = createError(exec, ASCIILiteral("read is not implemented"));
     47    JSValue error = createError(exec, ASCIILiteral("cancel is not implemented"));
    4848    return exec->vm().throwException(exec, error);
    4949}
    5050
    51 static JSPromiseDeferred* getOrCreatePromiseDeferredFromObject(ExecState* exec, JSValue thisObject, JSGlobalObject* globalObject, PrivateName &name)
     51JSValue JSReadableStream::getReader(ExecState* exec)
    5252{
    53     JSValue slot = getInternalSlotFromObject(exec, thisObject, name);
    54     JSPromiseDeferred* promiseDeferred = slot ? jsDynamicCast<JSPromiseDeferred*>(slot) : nullptr;
    55 
    56     if (!promiseDeferred) {
    57         promiseDeferred = JSPromiseDeferred::create(exec, globalObject);
    58         setInternalSlotToObject(exec, thisObject, name, promiseDeferred);
    59     }
    60     return promiseDeferred;
    61 }
    62 
    63 static JSC::PrivateName& readyPromiseSlotName()
    64 {
    65     static NeverDestroyed<JSC::PrivateName> readyPromiseSlotName("readyPromise");
    66     return readyPromiseSlotName;
    67 }
    68 
    69 JSValue JSReadableStream::ready(ExecState* exec) const
    70 {
    71     JSPromiseDeferred* promiseDeferred = getOrCreatePromiseDeferredFromObject(exec, this, globalObject(), readyPromiseSlotName());
    72     DeferredWrapper wrapper(exec, globalObject(), promiseDeferred);
    73     auto successCallback = [wrapper, this]() mutable {
    74         wrapper.resolve(&impl());
    75     };
    76     impl().ready(WTF::move(successCallback));
    77 
    78     return wrapper.promise();
    79 }
    80 
    81 static JSC::PrivateName& closedPromiseSlotName()
    82 {
    83     static NeverDestroyed<JSC::PrivateName> closedPromiseSlotName("closedPromise");
    84     return closedPromiseSlotName;
    85 }
    86 
    87 JSValue JSReadableStream::closed(ExecState* exec) const
    88 {
    89     JSPromiseDeferred* promiseDeferred = getOrCreatePromiseDeferredFromObject(exec, this, globalObject(), closedPromiseSlotName());
    90     DeferredWrapper wrapper(exec, globalObject(), promiseDeferred);
    91     auto successCallback = [wrapper, this]() mutable {
    92         wrapper.resolve(&impl());
    93     };
    94     impl().closed(WTF::move(successCallback));
    95 
    96     return wrapper.promise();
    97 }
    98 
    99 JSValue JSReadableStream::cancel(ExecState* exec)
    100 {
    101     JSValue error = createError(exec, ASCIILiteral("cancel is not implemented"));
     53    JSValue error = createError(exec, ASCIILiteral("getReader is not implemented"));
    10254    return exec->vm().throwException(exec, error);
    10355}
Note: See TracChangeset for help on using the changeset viewer.