<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[185356] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/185356">185356</a></dd>
<dt>Author</dt> <dd>youenn.fablet@crf.canon.fr</dd>
<dt>Date</dt> <dd>2015-06-09 00:45:12 -0700 (Tue, 09 Jun 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>[Streams API] ReadableJSStream should handle JS source getters that throw
https://bugs.webkit.org/show_bug.cgi?id=145600
Reviewed by Darin Adler.
Source/WebCore:
Checking whether there is an exception when trying to access to a source method.
If so, rethrowing it in case of "start".
Refactoring of code to prepare pulling, cancelling and additional parameter handling in ReadableStream construtor.
Fixed the case of ReadableStream constructor called with an undefined parameter.
Covered by rebased test expectation.
* bindings/js/JSReadableStreamCustom.cpp:
(WebCore::constructJSReadableStream): Refactoring to group all parameter check and exception handling in ReadableJSStream::create.
* bindings/js/ReadableJSStream.cpp:
(WebCore::getPropertyFromObject):
(WebCore::callFunction):
(WebCore::ReadableJSStream::invoke): Added method to be used also for pulling and cancelling.
(WebCore::ReadableJSStream::doStart):
(WebCore::ReadableJSStream::create):
* bindings/js/ReadableJSStream.h:
LayoutTests:
* streams/reference-implementation/bad-underlying-sources-expected.txt:
* streams/reference-implementation/readable-stream-expected.txt:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsstreamsreferenceimplementationbadunderlyingsourcesexpectedtxt">trunk/LayoutTests/streams/reference-implementation/bad-underlying-sources-expected.txt</a></li>
<li><a href="#trunkLayoutTestsstreamsreferenceimplementationreadablestreamexpectedtxt">trunk/LayoutTests/streams/reference-implementation/readable-stream-expected.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSReadableStreamCustomcpp">trunk/Source/WebCore/bindings/js/JSReadableStreamCustom.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsjsReadableJSStreamcpp">trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsjsReadableJSStreamh">trunk/Source/WebCore/bindings/js/ReadableJSStream.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (185355 => 185356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-06-09 05:29:04 UTC (rev 185355)
+++ trunk/LayoutTests/ChangeLog        2015-06-09 07:45:12 UTC (rev 185356)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2015-06-09 Xabier Rodriguez Calvar <calvaris@igalia.com> and Youenn Fablet <youenn.fablet@crf.canon.fr>
+
+ [Streams API] ReadableJSStream should handle JS source getters that throw
+ https://bugs.webkit.org/show_bug.cgi?id=145600
+
+ Reviewed by Darin Adler.
+
+ * streams/reference-implementation/bad-underlying-sources-expected.txt:
+ * streams/reference-implementation/readable-stream-expected.txt:
+
</ins><span class="cx"> 2015-06-08 Daniel Bates <dabates@apple.com>
</span><span class="cx">
</span><span class="cx"> Update iOS TestExpectations files
</span></span></pre></div>
<a id="trunkLayoutTestsstreamsreferenceimplementationbadunderlyingsourcesexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/streams/reference-implementation/bad-underlying-sources-expected.txt (185355 => 185356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/streams/reference-implementation/bad-underlying-sources-expected.txt        2015-06-09 05:29:04 UTC (rev 185355)
+++ trunk/LayoutTests/streams/reference-implementation/bad-underlying-sources-expected.txt        2015-06-09 07:45:12 UTC (rev 185356)
</span><span class="lines">@@ -1,7 +1,5 @@
</span><span class="cx">
</span><del>-FAIL Underlying source start: throwing getter assert_throws: constructing the stream should re-throw the error function "function () {
- new ReadableStream({
- ge..." threw object "TypeError: ReadableStream constructor object start proper..." ("TypeError") expected object "Error: a unique string" ("Error")
</del><ins>+PASS Underlying source start: throwing getter
</ins><span class="cx"> PASS Underlying source start: throwing method
</span><span class="cx"> TIMEOUT Underlying source: throwing pull getter (initial pull) Test timed out
</span><span class="cx"> TIMEOUT Underlying source: throwing pull method (initial pull) Test timed out
</span></span></pre></div>
<a id="trunkLayoutTestsstreamsreferenceimplementationreadablestreamexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/streams/reference-implementation/readable-stream-expected.txt (185355 => 185356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/streams/reference-implementation/readable-stream-expected.txt        2015-06-09 05:29:04 UTC (rev 185355)
+++ trunk/LayoutTests/streams/reference-implementation/readable-stream-expected.txt        2015-06-09 07:45:12 UTC (rev 185356)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx">
</span><del>-FAIL ReadableStream can be constructed with no errors ReadableStream constructor should get an object as argument.
</del><ins>+PASS ReadableStream can be constructed with no errors
</ins><span class="cx"> FAIL ReadableStream instances should have the correct list of properties assert_array_equals: should have all the correct methods lengths differ, expected 6 got 5
</span><span class="cx"> PASS ReadableStream constructor should throw for non-function start arguments
</span><span class="cx"> PASS ReadableStream constructor can get initial garbage as cancel argument
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (185355 => 185356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-06-09 05:29:04 UTC (rev 185355)
+++ trunk/Source/WebCore/ChangeLog        2015-06-09 07:45:12 UTC (rev 185356)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2015-06-09 Xabier Rodriguez Calvar <calvaris@igalia.com> and Youenn Fablet <youenn.fablet@crf.canon.fr>
+
+ [Streams API] ReadableJSStream should handle JS source getters that throw
+ https://bugs.webkit.org/show_bug.cgi?id=145600
+
+ Reviewed by Darin Adler.
+
+ Checking whether there is an exception when trying to access to a source method.
+ If so, rethrowing it in case of "start".
+
+ Refactoring of code to prepare pulling, cancelling and additional parameter handling in ReadableStream construtor.
+
+ Fixed the case of ReadableStream constructor called with an undefined parameter.
+
+ Covered by rebased test expectation.
+
+ * bindings/js/JSReadableStreamCustom.cpp:
+ (WebCore::constructJSReadableStream): Refactoring to group all parameter check and exception handling in ReadableJSStream::create.
+ * bindings/js/ReadableJSStream.cpp:
+ (WebCore::getPropertyFromObject):
+ (WebCore::callFunction):
+ (WebCore::ReadableJSStream::invoke): Added method to be used also for pulling and cancelling.
+ (WebCore::ReadableJSStream::doStart):
+ (WebCore::ReadableJSStream::create):
+ * bindings/js/ReadableJSStream.h:
+
</ins><span class="cx"> 2015-06-08 Dan Bernstein <mitz@apple.com>
</span><span class="cx">
</span><span class="cx"> Made MicroTask.h a project header.
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSReadableStreamCustomcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSReadableStreamCustom.cpp (185355 => 185356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSReadableStreamCustom.cpp        2015-06-09 05:29:04 UTC (rev 185355)
+++ trunk/Source/WebCore/bindings/js/JSReadableStreamCustom.cpp        2015-06-09 07:45:12 UTC (rev 185356)
</span><span class="lines">@@ -40,6 +40,7 @@
</span><span class="cx"> #include "ReadableStream.h"
</span><span class="cx"> #include "ReadableStreamReader.h"
</span><span class="cx"> #include <runtime/Error.h>
</span><ins>+#include <runtime/Exception.h>
</ins><span class="cx"> #include <wtf/NeverDestroyed.h>
</span><span class="cx">
</span><span class="cx"> using namespace JSC;
</span><span class="lines">@@ -73,13 +74,15 @@
</span><span class="cx">
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL constructJSReadableStream(ExecState* exec)
</span><span class="cx"> {
</span><del>- if (exec->argumentCount() && !exec->argument(0).isObject())
- return throwVMError(exec, createTypeError(exec, ASCIILiteral("ReadableStream constructor should get an object as argument.")));
-
</del><span class="cx"> DOMConstructorObject* jsConstructor = jsCast<DOMConstructorObject*>(exec->callee());
</span><span class="cx"> ASSERT(jsConstructor);
</span><span class="cx">
</span><del>- Ref<ReadableJSStream> readableStream = ReadableJSStream::create(*exec, *jsConstructor->scriptExecutionContext());
</del><ins>+ RefPtr<ReadableJSStream> readableStream = ReadableJSStream::create(*exec, *jsConstructor->scriptExecutionContext());
+
+ if (!readableStream) {
+ ASSERT(exec->hadException());
+ return JSValue::encode(jsUndefined());
+ }
</ins><span class="cx"> return JSValue::encode(toJS(exec, jsCast<JSDOMGlobalObject*>(exec->callee()->globalObject()), WTF::move(readableStream)));
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsReadableJSStreamcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp (185355 => 185356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp        2015-06-09 05:29:04 UTC (rev 185355)
+++ trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp        2015-06-09 07:45:12 UTC (rev 185356)
</span><span class="lines">@@ -47,18 +47,35 @@
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><del>-static inline JSValue getPropertyFromObject(ExecState* exec, JSObject* object, const char* identifier)
</del><ins>+static inline JSValue getPropertyFromObject(ExecState& exec, JSObject* object, const char* identifier)
</ins><span class="cx"> {
</span><del>- return object->get(exec, Identifier::fromString(exec, identifier));
</del><ins>+ return object->get(&exec, Identifier::fromString(&exec, identifier));
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-static inline JSValue callFunction(ExecState* exec, JSValue jsFunction, JSValue thisValue, const ArgList& arguments, Exception*& exception)
</del><ins>+static inline JSValue callFunction(ExecState& exec, JSValue jsFunction, JSValue thisValue, const ArgList& arguments)
</ins><span class="cx"> {
</span><span class="cx"> CallData callData;
</span><span class="cx"> CallType callType = getCallData(jsFunction, callData);
</span><del>- return call(exec, jsFunction, callType, callData, thisValue, arguments, exception);
</del><ins>+ return call(&exec, jsFunction, callType, callData, thisValue, arguments);
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+JSValue ReadableJSStream::invoke(ExecState& exec, const char* propertyName)
+{
+ JSValue function = getPropertyFromObject(exec, m_source.get(), propertyName);
+ if (exec.hadException())
+ return jsUndefined();
+
+ if (!function.isFunction()) {
+ if (!function.isUndefined())
+ throwVMError(&exec, createTypeError(&exec, ASCIILiteral("ReadableStream trying to call a property that is not callable")));
+ return jsUndefined();
+ }
+
+ MarkedArgumentBuffer arguments;
+ arguments.append(jsController(exec, globalObject()));
+ return callFunction(exec, function, m_source.get(), arguments);
+}
+
</ins><span class="cx"> JSDOMGlobalObject* ReadableJSStream::globalObject()
</span><span class="cx"> {
</span><span class="cx"> return jsDynamicCast<JSDOMGlobalObject*>(m_source->globalObject());
</span><span class="lines">@@ -76,37 +93,33 @@
</span><span class="cx"> {
</span><span class="cx"> JSLockHolder lock(&exec);
</span><span class="cx">
</span><del>- JSValue startFunction = getPropertyFromObject(&exec, m_source.get(), "start");
- if (!startFunction.isFunction()) {
- if (!startFunction.isUndefined())
- throwVMError(&exec, createTypeError(&exec, ASCIILiteral("ReadableStream constructor object start property should be a function.")));
- else
- startReadableStreamAsync(*this);
- return;
- }
</del><ins>+ invoke(exec, "start");
</ins><span class="cx">
</span><del>- MarkedArgumentBuffer arguments;
- arguments.append(jsController(exec, globalObject()));
-
- Exception* exception;
- callFunction(&exec, startFunction, m_source.get(), arguments, exception);
-
- if (exception) {
- throwVMError(&exec, exception);
</del><ins>+ if (exec.hadException())
</ins><span class="cx"> return;
</span><del>- }
</del><span class="cx">
</span><span class="cx"> // FIXME: Implement handling promise as result of calling start function.
</span><span class="cx"> startReadableStreamAsync(*this);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-Ref<ReadableJSStream> ReadableJSStream::create(ExecState& exec, ScriptExecutionContext& scriptExecutionContext)
</del><ins>+RefPtr<ReadableJSStream> ReadableJSStream::create(ExecState& exec, ScriptExecutionContext& scriptExecutionContext)
</ins><span class="cx"> {
</span><del>- ASSERT_WITH_MESSAGE(!exec.argumentCount() || exec.argument(0).isObject(), "Caller of ReadableJSStream constructor should ensure that passed argument if any is an object.");
- JSObject* source = exec.argumentCount() ? exec.argument(0).getObject() : JSFinalObject::create(exec.vm(), JSFinalObject::createStructure(exec.vm(), exec.callee()->globalObject(), jsNull(), 1));
</del><ins>+ JSObject* jsSource;
+ JSValue value = exec.argument(0);
+ if (value.isObject())
+ jsSource = value.getObject();
+ else if (!value.isUndefined()) {
+ throwVMError(&exec, createTypeError(&exec, ASCIILiteral("ReadableStream constructor first argument, if any, should be an object")));
+ return nullptr;
+ } else
+ jsSource = JSFinalObject::create(exec.vm(), JSFinalObject::createStructure(exec.vm(), exec.callee()->globalObject(), jsNull(), 1));
</ins><span class="cx">
</span><del>- Ref<ReadableJSStream> readableStream = adoptRef(*new ReadableJSStream(scriptExecutionContext, exec, source));
</del><ins>+ RefPtr<ReadableJSStream> readableStream = adoptRef(*new ReadableJSStream(scriptExecutionContext, exec, jsSource));
</ins><span class="cx"> readableStream->doStart(exec);
</span><ins>+
+ if (exec.hadException())
+ return nullptr;
+
</ins><span class="cx"> return readableStream;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsReadableJSStreamh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/ReadableJSStream.h (185355 => 185356)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/ReadableJSStream.h        2015-06-09 05:29:04 UTC (rev 185355)
+++ trunk/Source/WebCore/bindings/js/ReadableJSStream.h        2015-06-09 07:45:12 UTC (rev 185356)
</span><span class="lines">@@ -47,7 +47,7 @@
</span><span class="cx">
</span><span class="cx"> class ReadableJSStream: public ReadableStream {
</span><span class="cx"> public:
</span><del>- static Ref<ReadableJSStream> create(JSC::ExecState&, ScriptExecutionContext&);
</del><ins>+ static RefPtr<ReadableJSStream> create(JSC::ExecState&, ScriptExecutionContext&);
</ins><span class="cx">
</span><span class="cx"> JSC::JSValue jsController(JSC::ExecState&, JSDOMGlobalObject*);
</span><span class="cx">
</span><span class="lines">@@ -61,6 +61,8 @@
</span><span class="cx">
</span><span class="cx"> void doStart(JSC::ExecState&);
</span><span class="cx">
</span><ins>+ JSC::JSValue invoke(JSC::ExecState&, const char*);
+
</ins><span class="cx"> virtual bool hasValue() const override;
</span><span class="cx"> virtual JSC::JSValue read() override;
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>