Chromium Code Reviews

Unified Diff: Source/core/streams/ReadableStream2.h

Issue 1167343002: Add methods for creating V8 extras-based ReadableStreams from C++ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: Source/core/streams/ReadableStream2.h
diff --git a/Source/core/streams/ReadableStream2.h b/Source/core/streams/ReadableStream2.h
new file mode 100644
index 0000000000000000000000000000000000000000..937077665cc163135d208ce41e106e284b984f23
--- /dev/null
+++ b/Source/core/streams/ReadableStream2.h
@@ -0,0 +1,91 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ReadableStream2_h
+#define ReadableStream2_h
+
+#include "bindings/core/v8/ScriptState.h"
+#include "bindings/core/v8/ScriptValue.h"
+#include "core/CoreExport.h"
+#include "core/streams/QueuingStrategyBase.h"
+#include "core/streams/UnderlyingSourceBase.h"
+#include <v8.h>
+
+namespace blink {
+
+// TODO probably needs to be GCed. Like ScriptPromiseProperty? Or we need a separate ReadableStreamProperty?
+
+class CORE_EXPORT ReadableStream2 {
+public:
+ enum State {
+ Readable = 0,
+ Closed = 1,
+ Errored = 2,
+ };
+
+ // This is for UA-created ReadableStreams
+ ReadableStream2(ScriptState*, UnderlyingSourceBase*, QueuingStrategyBase*);
+
+ bool isLocked() const;
+
+ // TODO(domenic): also a constructor for converting author-created ReadableStreams, e.g. for use in the bindings for
+ // functions/setters that accept ReadableStream?
+
+ bool isObject() const
+ {
+ return m_stream.isObject();
+ }
+
+ bool isNull() const
+ {
+ return m_stream.isNull();
+ }
+
+ bool isUndefinedOrNull() const
+ {
+ return m_stream.isUndefined() || m_stream.isNull();
+ }
+
+ ScriptValue scriptValue() const
+ {
+ return m_stream;
+ }
+
+ v8::Local<v8::Value> v8Value() const
+ {
+ return m_stream.v8Value();
+ }
+
+ v8::Isolate* isolate() const
+ {
+ return m_stream.isolate();
+ }
+
+ bool isEmpty() const
+ {
+ return m_stream.isEmpty();
+ }
+
+ void clear()
+ {
+ m_stream.clear();
+ }
+
+ bool operator==(const ReadableStream2& value) const
+ {
+ return m_stream == value.m_stream;
+ }
+
+ bool operator!=(const ReadableStream2& value) const
+ {
+ return !operator==(value);
+ }
+
+private:
+ ScriptValue m_stream;
+};
+
+} // namespace blink
+
+#endif // ReadableStream2_h

Powered by Google App Engine