Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: Source/core/streams/ReadableStreamController.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: Remove C++ queuing strategies Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef ReadableStreamController_h
6 #define ReadableStreamController_h
7
8 #include "bindings/core/v8/ScriptValue.h"
9 #include "bindings/core/v8/ToV8.h"
10 #include "core/CoreExport.h"
11 #include <v8.h>
12
13 namespace blink {
14
15 class CORE_EXPORT ReadableStreamController {
16 public:
17 explicit ReadableStreamController(ScriptValue stream) : m_stream(stream)
18 {
19 }
20
21 void close()
22 {
23 if (m_stream.isEmpty())
24 return;
25
26 ScriptState::Scope scope(m_stream.scriptState());
27
28 auto func = m_stream.scriptState()->getFromExtrasExports("CloseReadableS tream").v8Value().As<v8::Function>();
29
30 auto undefined = v8::Undefined(m_stream.isolate());
31 v8::Local<v8::Value> args[] = { m_stream.v8Value() };
32 auto result = func->Call(m_stream.context(), undefined, arraysize(args), args);
33
34 ASSERT(!result.IsEmpty());
35 m_stream.clear();
36 }
37
38 double desiredSize() const
39 {
40 if (m_stream.isEmpty())
41 return 0;
42
43 ScriptState::Scope scope(m_stream.scriptState());
44
45 auto func = m_stream.scriptState()->getFromExtrasExports("GetReadableStr eamDesiredSize").v8Value()
46 .As<v8::Function>();
47
48 auto undefined = v8::Undefined(m_stream.isolate());
49 v8::Local<v8::Value> args[] = { m_stream.v8Value() };
50 auto result = func->Call(m_stream.context(), undefined, arraysize(args), args).ToLocalChecked();
51
52 return result.As<v8::Number>()->Value();
53 }
54
55 template<typename ChunkType>
56 void enqueue(ChunkType chunk) const
57 {
58 if (m_stream.isEmpty())
59 return;
60
61 ScriptState::Scope scope(m_stream.scriptState());
62
63 auto func = m_stream.scriptState()->getFromExtrasExports("EnqueueInReada bleStream").v8Value()
64 .As<v8::Function>();
65
66 auto chunkForV8 = toV8(chunk, m_stream.context()->Global(), m_stream.iso late());
67 auto undefined = v8::Undefined(m_stream.isolate());
68 v8::Local<v8::Value> args[] = { m_stream.v8Value(), chunkForV8 };
69
70 auto result = func->Call(m_stream.context(), undefined, arraysize(args), args);
71
72 ASSERT(!result.IsEmpty());
73 }
74
75 template<typename ErrorType>
76 void error(ErrorType e)
77 {
78 if (m_stream.isEmpty())
79 return;
80
81 ScriptState::Scope scope(m_stream.scriptState());
82
83 auto func = m_stream.scriptState()->getFromExtrasExports("ErrorReadableS tream").v8Value().As<v8::Function>();
84
85 auto errorForV8 = toV8(e, m_stream.context()->Global(), m_stream.isolate ());
86 auto undefined = v8::Undefined(m_stream.isolate());
87 v8::Local<v8::Value> args[] = { m_stream.v8Value(), errorForV8 };
88 auto result = func->Call(m_stream.context(), undefined, arraysize(args), args);
89
90 ASSERT(!result.IsEmpty());
91 m_stream.clear();
92 }
93
94 private:
95 ScriptValue m_stream;
96 };
97
98 } // namespace blink
99
100 #endif // ReadableStreamController_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698