| Differences between
and this patch
- a/Source/WebCore/ChangeLog +24 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2015-02-21  Xabier Rodriguez Calvar <calvaris@igalia.com> and Youenn Fablet  <youenn.fablet@crf.canon.fr>
2
3
        [Streams API] Reading ReadableStream ready and closed attributes should not always create a new promise
4
        https://bugs.webkit.org/show_bug.cgi?id=141650
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Stored ready and closed JSPromiseDeferred as slots in JSReadableStream.
9
        Added new constructor for DeferredWrapper to use these stored values.
10
        Updated ready and closed methods to use that new constructor.
11
        Changes are covered by new test in streams/readablestream-constructor.html.
12
13
        * bindings/js/JSDOMPromise.cpp:
14
        (WebCore::DeferredWrapper::DeferredWrapper):
15
        * bindings/js/JSDOMPromise.h:
16
        * bindings/js/JSReadableStreamCustom.cpp:
17
        (WebCore::getOrCreatePromiseDeferredFromObject):
18
        (WebCore::JSReadableStream::ready):
19
        (WebCore::JSReadableStream::closed):
20
        * bindings/js/ReadableStreamJSSource.cpp:
21
        (WebCore::setInternalSlotToObject):
22
        (WebCore::getInternalSlotFromObject):
23
        * bindings/js/ReadableStreamJSSource.h:
24
1
2015-02-15  Alexey Proskuryakov  <ap@apple.com>
25
2015-02-15  Alexey Proskuryakov  <ap@apple.com>
2
26
3
        More build fixing.
27
        More build fixing.
- a/Source/WebCore/bindings/js/JSDOMPromise.cpp +6 lines
Lines 38-43 DeferredWrapper::DeferredWrapper(ExecState* exec, JSDOMGlobalObject* globalObjec a/Source/WebCore/bindings/js/JSDOMPromise.cpp_sec1
38
{
38
{
39
}
39
}
40
40
41
DeferredWrapper::DeferredWrapper(ExecState* exec, JSDOMGlobalObject* globalObject, JSPromiseDeferred* promiseDeferred)
42
    : m_globalObject(exec->vm(), globalObject)
43
    , m_deferred(exec->vm(), promiseDeferred)
44
{
45
}
46
41
JSObject* DeferredWrapper::promise() const
47
JSObject* DeferredWrapper::promise() const
42
{
48
{
43
    return m_deferred->promise();
49
    return m_deferred->promise();
- a/Source/WebCore/bindings/js/JSDOMPromise.h +1 lines
Lines 39-44 namespace WebCore { a/Source/WebCore/bindings/js/JSDOMPromise.h_sec1
39
class DeferredWrapper {
39
class DeferredWrapper {
40
public:
40
public:
41
    DeferredWrapper(JSC::ExecState*, JSDOMGlobalObject*);
41
    DeferredWrapper(JSC::ExecState*, JSDOMGlobalObject*);
42
    DeferredWrapper(JSC::ExecState*, JSDOMGlobalObject*, JSC::JSPromiseDeferred*);
42
43
43
    template<class ResolveResultType>
44
    template<class ResolveResultType>
44
    void resolve(const ResolveResultType&);
45
    void resolve(const ResolveResultType&);
- a/Source/WebCore/bindings/js/JSReadableStreamCustom.cpp -2 / +18 lines
Lines 47-55 JSValue JSReadableStream::read(ExecState* exec) a/Source/WebCore/bindings/js/JSReadableStreamCustom.cpp_sec1
47
    return exec->vm().throwException(exec, error);
47
    return exec->vm().throwException(exec, error);
48
}
48
}
49
49
50
static JSPromiseDeferred* getOrCreatePromiseDeferredFromObject(ExecState* exec, JSValue thisObject, JSGlobalObject* globalObject, PrivateName &name)
51
{
52
    JSValue slot = getInternalSlotFromObject(exec, thisObject, name);
53
    JSPromiseDeferred* promiseDeferred = jsDynamicCast<JSPromiseDeferred*>(slot);
54
55
    if (!promiseDeferred) {
56
        promiseDeferred = JSPromiseDeferred::create(exec, globalObject);
57
        setInternalSlotToObject(exec, thisObject, name, promiseDeferred);
58
    }
59
    return promiseDeferred;
60
}
61
62
static JSC::PrivateName readyPromiseSlot("readyPromise");
50
JSValue JSReadableStream::ready(ExecState* exec) const
63
JSValue JSReadableStream::ready(ExecState* exec) const
51
{
64
{
52
    DeferredWrapper wrapper(exec, globalObject());
65
    JSPromiseDeferred* promiseDeferred = getOrCreatePromiseDeferredFromObject(exec, this, globalObject(), readyPromiseSlot);
66
    DeferredWrapper wrapper(exec, globalObject(), promiseDeferred);
53
    auto successCallback = [wrapper](RefPtr<ReadableStream> stream) mutable {
67
    auto successCallback = [wrapper](RefPtr<ReadableStream> stream) mutable {
54
        wrapper.resolve(stream.get());
68
        wrapper.resolve(stream.get());
55
    };
69
    };
Lines 58-66 JSValue JSReadableStream::ready(ExecState* exec) const a/Source/WebCore/bindings/js/JSReadableStreamCustom.cpp_sec2
58
    return wrapper.promise();
72
    return wrapper.promise();
59
}
73
}
60
74
75
static JSC::PrivateName closedPromiseSlot("closedPromise");
61
JSValue JSReadableStream::closed(ExecState* exec) const
76
JSValue JSReadableStream::closed(ExecState* exec) const
62
{
77
{
63
    DeferredWrapper wrapper(exec, globalObject());
78
    JSPromiseDeferred* promiseDeferred = getOrCreatePromiseDeferredFromObject(exec, this, globalObject(), closedPromiseSlot);
79
    DeferredWrapper wrapper(exec, globalObject(), promiseDeferred);
64
    auto successCallback = [wrapper](RefPtr<ReadableStream> stream) mutable {
80
    auto successCallback = [wrapper](RefPtr<ReadableStream> stream) mutable {
65
        wrapper.resolve(stream.get());
81
        wrapper.resolve(stream.get());
66
    };
82
    };
- a/Source/WebCore/bindings/js/ReadableStreamJSSource.cpp +22 lines
Lines 32-45 a/Source/WebCore/bindings/js/ReadableStreamJSSource.cpp_sec1
32
#if ENABLE(STREAMS_API)
32
#if ENABLE(STREAMS_API)
33
#include "ReadableStreamJSSource.h"
33
#include "ReadableStreamJSSource.h"
34
34
35
#include "JSDOMPromise.h"
35
#include "JSReadableStream.h"
36
#include "JSReadableStream.h"
36
#include <runtime/Error.h>
37
#include <runtime/Error.h>
37
#include <runtime/JSCJSValueInlines.h>
38
#include <runtime/JSCJSValueInlines.h>
39
#include <runtime/JSString.h>
40
#include <runtime/StructureInlines.h>
38
41
39
using namespace JSC;
42
using namespace JSC;
40
43
41
namespace WebCore {
44
namespace WebCore {
42
45
46
// setInternalSlotToObject is used on JS functions so that the JSReadableStream object can be retrieved when executing the corresponding JS function.
47
void setInternalSlotToObject(ExecState* exec, JSValue objectValue, PrivateName& name, JSValue value)
48
{
49
    JSObject* object = objectValue.toObject(exec);
50
    PutPropertySlot propertySlot(objectValue);
51
    object->put(object, exec, Identifier::from(name), value, propertySlot);
52
}
53
54
JSValue getInternalSlotFromObject(ExecState* exec, JSValue objectValue, PrivateName& name)
55
{
56
    JSObject* object = objectValue.toObject(exec);
57
    PropertySlot propertySlot(objectValue);
58
59
    PropertyName propertyName = Identifier::from(name);
60
    if (!object->getOwnPropertySlot(object, exec, propertyName, propertySlot))
61
        return jsUndefined();
62
    return propertySlot.getValue(exec, propertyName);
63
}
64
43
Ref<ReadableStreamJSSource> ReadableStreamJSSource::create(JSC::ExecState* exec)
65
Ref<ReadableStreamJSSource> ReadableStreamJSSource::create(JSC::ExecState* exec)
44
{
66
{
45
    return adoptRef(*new ReadableStreamJSSource(exec));
67
    return adoptRef(*new ReadableStreamJSSource(exec));
- a/Source/WebCore/bindings/js/ReadableStreamJSSource.h +4 lines
Lines 36-41 a/Source/WebCore/bindings/js/ReadableStreamJSSource.h_sec1
36
#include <heap/Strong.h>
36
#include <heap/Strong.h>
37
#include <heap/StrongInlines.h>
37
#include <heap/StrongInlines.h>
38
#include <runtime/JSCJSValue.h>
38
#include <runtime/JSCJSValue.h>
39
#include <runtime/PrivateName.h>
39
#include <wtf/Ref.h>
40
#include <wtf/Ref.h>
40
41
41
namespace WebCore {
42
namespace WebCore {
Lines 61-66 private: a/Source/WebCore/bindings/js/ReadableStreamJSSource.h_sec2
61
    JSC::Strong<JSC::Unknown> m_error;
62
    JSC::Strong<JSC::Unknown> m_error;
62
};
63
};
63
64
65
void setInternalSlotToObject(JSC::ExecState*, JSC::JSValue, JSC::PrivateName&, JSC::JSValue);
66
JSC::JSValue getInternalSlotFromObject(JSC::ExecState*, JSC::JSValue, JSC::PrivateName&);
67
64
} // namespace WebCore
68
} // namespace WebCore
65
69
66
#endif // ENABLE(STREAMS_API)
70
#endif // ENABLE(STREAMS_API)
- a/LayoutTests/ChangeLog +10 lines
Lines 1-3 a/LayoutTests/ChangeLog_sec1
1
2015-02-21  Xabier Rodriguez Calvar <calvaris@igalia.com> and Youenn Fablet  <youenn.fablet@crf.canon.fr>
2
3
        [Streams API] Reading ReadableStream ready and closed attributes should not always create a new promise
4
        https://bugs.webkit.org/show_bug.cgi?id=141650
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        * streams/readablestream-constructor-expected.txt:
9
        * streams/readablestream-constructor.html: Added test to ensure ready and closed always return the same promise object.
10
1
2015-02-14  Benjamin Poulain  <benjamin@webkit.org>
11
2015-02-14  Benjamin Poulain  <benjamin@webkit.org>
2
12
3
        Add the initial matching implementation for attribute selectors with case-insensitive value
13
        Add the initial matching implementation for attribute selectors with case-insensitive value
- a/LayoutTests/streams/readablestream-constructor-expected.txt +1 lines
Lines 3-6 PASS ReadableStream constructor should get an object as argument a/LayoutTests/streams/readablestream-constructor-expected.txt_sec1
3
PASS ReadableStream instances should have the correct list of properties 
3
PASS ReadableStream instances should have the correct list of properties 
4
PASS ReadableStream can be constructed with no arguments 
4
PASS ReadableStream can be constructed with no arguments 
5
PASS ReadableStream instances have the correct methods and properties 
5
PASS ReadableStream instances have the correct methods and properties 
6
PASS ReadableStream ready and closed should always return the same promise object 
6
7
- a/LayoutTests/streams/readablestream-constructor.html +11 lines
Lines 58-61 test(function() { a/LayoutTests/streams/readablestream-constructor.html_sec1
58
    assert_equals(typeof rs.closed.then, 'function', 'closed property is thenable');
58
    assert_equals(typeof rs.closed.then, 'function', 'closed property is thenable');
59
}, 'ReadableStream instances have the correct methods and properties');
59
}, 'ReadableStream instances have the correct methods and properties');
60
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
    assert_array_equals(Object.keys(rs), ['closed', 'ready']);
70
}, 'ReadableStream ready and closed should always return the same promise object');
71
61
</script>
72
</script>

Return to Bug 141650