Log Message
[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:
Modified Paths
- trunk/LayoutTests/ChangeLog
- trunk/LayoutTests/streams/reference-implementation/bad-underlying-sources-expected.txt
- trunk/LayoutTests/streams/reference-implementation/readable-stream-expected.txt
- trunk/Source/WebCore/ChangeLog
- trunk/Source/WebCore/bindings/js/JSReadableStreamCustom.cpp
- trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp
- trunk/Source/WebCore/bindings/js/ReadableJSStream.h
Diff
Modified: trunk/LayoutTests/ChangeLog (185355 => 185356)
--- trunk/LayoutTests/ChangeLog 2015-06-09 05:29:04 UTC (rev 185355)
+++ trunk/LayoutTests/ChangeLog 2015-06-09 07:45:12 UTC (rev 185356)
@@ -1,3 +1,13 @@
+2015-06-09 Xabier Rodriguez Calvar <[email protected]> and Youenn Fablet <[email protected]>
+
+ [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:
+
2015-06-08 Daniel Bates <[email protected]>
Update iOS TestExpectations files
Modified: trunk/LayoutTests/streams/reference-implementation/bad-underlying-sources-expected.txt (185355 => 185356)
--- 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)
@@ -1,7 +1,5 @@
-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")
+PASS Underlying source start: throwing getter
PASS Underlying source start: throwing method
TIMEOUT Underlying source: throwing pull getter (initial pull) Test timed out
TIMEOUT Underlying source: throwing pull method (initial pull) Test timed out
Modified: trunk/LayoutTests/streams/reference-implementation/readable-stream-expected.txt (185355 => 185356)
--- 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)
@@ -1,5 +1,5 @@
-FAIL ReadableStream can be constructed with no errors ReadableStream constructor should get an object as argument.
+PASS ReadableStream can be constructed with no errors
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
PASS ReadableStream constructor should throw for non-function start arguments
PASS ReadableStream constructor can get initial garbage as cancel argument
Modified: trunk/Source/WebCore/ChangeLog (185355 => 185356)
--- 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)
@@ -1,3 +1,29 @@
+2015-06-09 Xabier Rodriguez Calvar <[email protected]> and Youenn Fablet <[email protected]>
+
+ [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:
+
2015-06-08 Dan Bernstein <[email protected]>
Made MicroTask.h a project header.
Modified: trunk/Source/WebCore/bindings/js/JSReadableStreamCustom.cpp (185355 => 185356)
--- 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)
@@ -40,6 +40,7 @@
#include "ReadableStream.h"
#include "ReadableStreamReader.h"
#include <runtime/Error.h>
+#include <runtime/Exception.h>
#include <wtf/NeverDestroyed.h>
using namespace JSC;
@@ -73,13 +74,15 @@
EncodedJSValue JSC_HOST_CALL constructJSReadableStream(ExecState* exec)
{
- if (exec->argumentCount() && !exec->argument(0).isObject())
- return throwVMError(exec, createTypeError(exec, ASCIILiteral("ReadableStream constructor should get an object as argument.")));
-
DOMConstructorObject* jsConstructor = jsCast<DOMConstructorObject*>(exec->callee());
ASSERT(jsConstructor);
- Ref<ReadableJSStream> readableStream = ReadableJSStream::create(*exec, *jsConstructor->scriptExecutionContext());
+ RefPtr<ReadableJSStream> readableStream = ReadableJSStream::create(*exec, *jsConstructor->scriptExecutionContext());
+
+ if (!readableStream) {
+ ASSERT(exec->hadException());
+ return JSValue::encode(jsUndefined());
+ }
return JSValue::encode(toJS(exec, jsCast<JSDOMGlobalObject*>(exec->callee()->globalObject()), WTF::move(readableStream)));
}
Modified: trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp (185355 => 185356)
--- 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)
@@ -47,18 +47,35 @@
namespace WebCore {
-static inline JSValue getPropertyFromObject(ExecState* exec, JSObject* object, const char* identifier)
+static inline JSValue getPropertyFromObject(ExecState& exec, JSObject* object, const char* identifier)
{
- return object->get(exec, Identifier::fromString(exec, identifier));
+ return object->get(&exec, Identifier::fromString(&exec, identifier));
}
-static inline JSValue callFunction(ExecState* exec, JSValue jsFunction, JSValue thisValue, const ArgList& arguments, Exception*& exception)
+static inline JSValue callFunction(ExecState& exec, JSValue jsFunction, JSValue thisValue, const ArgList& arguments)
{
CallData callData;
CallType callType = getCallData(jsFunction, callData);
- return call(exec, jsFunction, callType, callData, thisValue, arguments, exception);
+ return call(&exec, jsFunction, callType, callData, thisValue, arguments);
}
+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);
+}
+
JSDOMGlobalObject* ReadableJSStream::globalObject()
{
return jsDynamicCast<JSDOMGlobalObject*>(m_source->globalObject());
@@ -76,37 +93,33 @@
{
JSLockHolder lock(&exec);
- 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;
- }
+ invoke(exec, "start");
- MarkedArgumentBuffer arguments;
- arguments.append(jsController(exec, globalObject()));
-
- Exception* exception;
- callFunction(&exec, startFunction, m_source.get(), arguments, exception);
-
- if (exception) {
- throwVMError(&exec, exception);
+ if (exec.hadException())
return;
- }
// FIXME: Implement handling promise as result of calling start function.
startReadableStreamAsync(*this);
}
-Ref<ReadableJSStream> ReadableJSStream::create(ExecState& exec, ScriptExecutionContext& scriptExecutionContext)
+RefPtr<ReadableJSStream> ReadableJSStream::create(ExecState& exec, ScriptExecutionContext& scriptExecutionContext)
{
- 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));
+ 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));
- Ref<ReadableJSStream> readableStream = adoptRef(*new ReadableJSStream(scriptExecutionContext, exec, source));
+ RefPtr<ReadableJSStream> readableStream = adoptRef(*new ReadableJSStream(scriptExecutionContext, exec, jsSource));
readableStream->doStart(exec);
+
+ if (exec.hadException())
+ return nullptr;
+
return readableStream;
}
Modified: trunk/Source/WebCore/bindings/js/ReadableJSStream.h (185355 => 185356)
--- 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)
@@ -47,7 +47,7 @@
class ReadableJSStream: public ReadableStream {
public:
- static Ref<ReadableJSStream> create(JSC::ExecState&, ScriptExecutionContext&);
+ static RefPtr<ReadableJSStream> create(JSC::ExecState&, ScriptExecutionContext&);
JSC::JSValue jsController(JSC::ExecState&, JSDOMGlobalObject*);
@@ -61,6 +61,8 @@
void doStart(JSC::ExecState&);
+ JSC::JSValue invoke(JSC::ExecState&, const char*);
+
virtual bool hasValue() const override;
virtual JSC::JSValue read() override;
_______________________________________________ webkit-changes mailing list [email protected] https://lists.webkit.org/mailman/listinfo/webkit-changes
