[Streams API] Calling controller.error() should trigger storing an undefined error
[WebKit-https.git] / Source / WebCore / bindings / js / JSReadableStreamControllerCustom.cpp
index d91d33b..12d49cb 100644 (file)
@@ -33,7 +33,6 @@
 #if ENABLE(STREAMS_API)
 
 #include "JSDOMBinding.h"
-#include "NotImplemented.h"
 #include "ReadableJSStream.h"
 #include <runtime/Error.h>
 
@@ -51,18 +50,23 @@ JSValue JSReadableStreamController::close(ExecState* exec)
     return jsUndefined();
 }
 
-JSValue JSReadableStreamController::enqueue(ExecState*)
+JSValue JSReadableStreamController::enqueue(ExecState* exec)
 {
-    notImplemented();
-    return jsBoolean(false);
+    ReadableJSStream& stream = impl().stream();
+    if (stream.isErrored())
+        return exec->vm().throwException(exec, stream.error());
+    if (stream.isCloseRequested())
+        return exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("Calling enqueue on a stream which is closing")));
+    stream.enqueue(*exec);
+    return jsUndefined();
 }
 
-JSValue JSReadableStreamController::error(ExecState* exec)
+JSValue JSReadableStreamController::error(ExecState* state)
 {
     ReadableJSStream& stream = impl().stream();
     if (!stream.isReadable())
-        return exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("Calling error on a stream which is not readable")));
-    stream.storeError(*exec);
+        return state->vm().throwException(state, createTypeError(state, ASCIILiteral("Calling error on a stream which is not readable")));
+    stream.storeError(*state, state->argument(0));
     return jsUndefined();
 }