summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/streams/readable_stream_operations.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/core/streams/readable_stream_operations.h')
-rw-r--r--chromium/third_party/blink/renderer/core/streams/readable_stream_operations.h115
1 files changed, 82 insertions, 33 deletions
diff --git a/chromium/third_party/blink/renderer/core/streams/readable_stream_operations.h b/chromium/third_party/blink/renderer/core/streams/readable_stream_operations.h
index 278ffa72981..d3665109766 100644
--- a/chromium/third_party/blink/renderer/core/streams/readable_stream_operations.h
+++ b/chromium/third_party/blink/renderer/core/streams/readable_stream_operations.h
@@ -5,10 +5,10 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_STREAMS_READABLE_STREAM_OPERATIONS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_STREAMS_READABLE_STREAM_OPERATIONS_H_
+#include "base/optional.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/core/core_export.h"
-#include "v8/include/v8.h"
namespace blink {
@@ -20,65 +20,114 @@ class ScriptState;
// V8 Extras.
// All methods should be called in an appropriate V8 context. All ScriptValue
// arguments must not be empty.
+//
+// Boolean methods return an optional bool, where an empty value indicates that
+// Javascript failed to return a value (ie. an exception occurred). Exceptions
+// are not caught, so that they can be handled by user Javascript. This implicit
+// exception passing is error-prone and bad.
+//
+// In methods which take an ExceptionState& parameter, exception passing is
+// explicit. Callers must check exception_state.HadException() on
+// return. Although these methods return base::nullopt if and only if an
+// exception was thrown, outside of unit tests exception_state should always be
+// used to determine failure.
+//
+// TODO(ricea): Add ExceptionState arguments to the rest of the non-Promise
+// methods to make exception passing explicit. https://crbug.com/853189.
class CORE_EXPORT ReadableStreamOperations {
STATIC_ONLY(ReadableStreamOperations);
public:
// createReadableStreamWithExternalController
// If the caller supplies an invalid strategy (e.g. one that returns
- // negative sizes, or doesn't have appropriate properties), this will crash.
+ // negative sizes, or doesn't have appropriate properties), or an exception
+ // occurs for another reason, this will return an empty value.
static ScriptValue CreateReadableStream(ScriptState*,
UnderlyingSourceBase*,
ScriptValue strategy);
// createBuiltInCountQueuingStrategy
+ // If the constructor throws, this will return an empty value.
static ScriptValue CreateCountQueuingStrategy(ScriptState*,
size_t high_water_mark);
// AcquireReadableStreamDefaultReader
- // This function assumes |isReadableStream(stream)|.
- // Returns an empty value and throws an error via the ExceptionState when
- // errored.
+ // This function assumes |IsReadableStream(stream)|.
static ScriptValue GetReader(ScriptState*,
ScriptValue stream,
ExceptionState&);
- // IsReadableStream
- static bool IsReadableStream(ScriptState*, ScriptValue);
-
- // IsReadableStreamDisturbed
- // This function assumes |isReadableStream(stream)|.
- static bool IsDisturbed(ScriptState*, ScriptValue stream);
-
- // IsReadableStreamLocked
- // This function assumes |isReadableStream(stream)|.
- static bool IsLocked(ScriptState*, ScriptValue stream);
-
- // IsReadableStreamReadable
- // This function assumes |isReadableStream(stream)|.
- static bool IsReadable(ScriptState*, ScriptValue stream);
-
- // IsReadableStreamClosed
- // This function assumes |isReadableStream(stream)|.
- static bool IsClosed(ScriptState*, ScriptValue stream);
-
- // IsReadableStreamErrored
- // This function assumes |isReadableStream(stream)|.
- static bool IsErrored(ScriptState*, ScriptValue stream);
-
- // IsReadableStreamDefaultReader
- static bool IsReadableStreamDefaultReader(ScriptState*, ScriptValue);
+ // IsReadableStream, exception-catching version. Exceptions will be passed to
+ // |exception_state|.
+ static base::Optional<bool> IsReadableStream(ScriptState*,
+ ScriptValue,
+ ExceptionState& exception_state);
+
+ // Performs IsReadableStream.
+ // Catches exceptions, and returns false if there are any. Should only be used
+ // in a DCHECK statement that passes when the return value is true.
+ static bool IsReadableStreamForDCheck(ScriptState*, ScriptValue);
+
+ // IsReadableStreamDisturbed.
+ // This function assumes |IsReadableStream(stream)|.
+ static base::Optional<bool> IsDisturbed(ScriptState*,
+ ScriptValue stream,
+ ExceptionState& exception_state);
+
+ // Performs IsReadableStreamDisturbed.
+ // Catches exceptions, and returns false if there are any. Should only be used
+ // in a DCHECK statement that passes when the return value is false.
+ static bool IsDisturbedForDCheck(ScriptState*, ScriptValue stream);
+
+ // IsReadableStreamLocked.
+ // This function assumes |IsReadableStream(stream)|.
+ static base::Optional<bool> IsLocked(ScriptState*,
+ ScriptValue stream,
+ ExceptionState&);
+
+ // Performs IsReadableStreamLocked.
+ // Catches exceptions, and returns false if there are any. Should only be used
+ // in a DCHECK statement that passes when the return value is false.
+ static bool IsLockedForDCheck(ScriptState*, ScriptValue stream);
+
+ // IsReadableStreamReadable.
+ // This function assumes |IsReadableStream(stream)|.
+ static base::Optional<bool> IsReadable(ScriptState*,
+ ScriptValue stream,
+ ExceptionState& exception_state);
+
+ // IsReadableStreamClosed.
+ // This function assumes |IsReadableStream(stream)|.
+ static base::Optional<bool> IsClosed(ScriptState*,
+ ScriptValue stream,
+ ExceptionState& exception_state);
+
+ // IsReadableStreamErrored.
+ // This function assumes |IsReadableStream(stream)|.
+ static base::Optional<bool> IsErrored(ScriptState*,
+ ScriptValue stream,
+ ExceptionState& exception_state);
+
+ // IsReadableStreamDefaultReader.
+ static base::Optional<bool> IsReadableStreamDefaultReader(
+ ScriptState*,
+ ScriptValue,
+ ExceptionState& exception_state);
// ReadableStreamDefaultReaderRead
- // This function assumes |isReadableStreamDefaultReader(reader)|.
+ // This function assumes |IsReadableStreamDefaultReader(reader)|.
+ // If an exception occurs, returns a rejected promise.
static ScriptPromise DefaultReaderRead(ScriptState*, ScriptValue reader);
// ReadableStreamTee
- // This function assumes |isReadableStream(stream)| and |!isLocked(stream)|
+ // This function assumes |IsReadableStream(stream)| and |!IsLocked(stream)|
+ // Returns without setting new_stream1 or new_stream2 if an error occurs.
+ // Exceptions are caught and rethrown on |exception_state|.
static void Tee(ScriptState*,
ScriptValue stream,
ScriptValue* new_stream1,
- ScriptValue* new_stream2);
+ ScriptValue* new_stream2,
+ ExceptionState&);
};
} // namespace blink