OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/streams/ReadableStream.h" | 6 #include "core/streams/ReadableStream.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptFunction.h" | 9 #include "bindings/core/v8/ScriptFunction.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 bool ReadableStream::enqueuePostAction(size_t totalQueueSize) | 65 bool ReadableStream::enqueuePostAction(size_t totalQueueSize) |
66 { | 66 { |
67 m_isPulling = false; | 67 m_isPulling = false; |
68 | 68 |
69 // FIXME: Set needsMore correctly. | 69 // FIXME: Set needsMore correctly. |
70 bool needsMore = true; | 70 bool needsMore = true; |
71 | 71 |
72 if (m_state == Waiting) { | 72 if (m_state == Waiting) { |
73 m_state = Readable; | 73 m_state = Readable; |
74 if (m_wait->state() == m_wait->Pending) | 74 m_wait->resolve(V8UndefinedType()); |
75 m_wait->resolve(V8UndefinedType()); | |
76 } | 75 } |
77 | 76 |
78 return needsMore; | 77 return needsMore; |
79 } | 78 } |
80 | 79 |
81 void ReadableStream::close() | 80 void ReadableStream::close() |
82 { | 81 { |
83 if (m_state == Waiting) { | 82 if (m_state == Waiting) { |
84 if (m_wait->state() == m_wait->Pending) | 83 m_wait->resolve(V8UndefinedType()); |
85 m_wait->resolve(V8UndefinedType()); | |
86 m_closed->resolve(V8UndefinedType()); | 84 m_closed->resolve(V8UndefinedType()); |
87 m_state = Closed; | 85 m_state = Closed; |
88 } else if (m_state == Readable) { | 86 } else if (m_state == Readable) { |
89 m_isDraining = true; | 87 m_isDraining = true; |
90 } | 88 } |
91 } | 89 } |
92 | 90 |
93 void ReadableStream::readPreliminaryCheck(ExceptionState* exceptionState) | 91 void ReadableStream::readPreliminaryCheck(ExceptionState* exceptionState) |
94 { | 92 { |
95 if (m_state == Waiting) { | 93 if (m_state == Waiting) { |
96 exceptionState->throwTypeError("read is called while state is waiting"); | 94 exceptionState->throwTypeError("read is called while state is waiting"); |
97 return; | 95 return; |
98 } | 96 } |
99 if (m_state == Closed) { | 97 if (m_state == Closed) { |
100 exceptionState->throwTypeError("read is called while state is closed"); | 98 exceptionState->throwTypeError("read is called while state is closed"); |
101 return; | 99 return; |
102 } | 100 } |
103 if (m_state == Errored) { | 101 if (m_state == Errored) { |
104 exceptionState->throwDOMException(m_exception->code(), m_exception->mess
age()); | 102 exceptionState->throwDOMException(m_exception->code(), m_exception->mess
age()); |
105 return; | 103 return; |
106 } | 104 } |
107 } | 105 } |
108 | 106 |
109 void ReadableStream::readPostAction() | 107 void ReadableStream::readPostAction() |
110 { | 108 { |
111 ASSERT(m_state == Readable); | 109 ASSERT(m_state == Readable); |
112 if (isQueueEmpty()) { | 110 if (isQueueEmpty()) { |
113 if (m_isDraining) { | 111 if (m_isDraining) { |
114 m_state = Closed; | 112 m_state = Closed; |
115 // FIXME: Use reset. | 113 m_wait->reset(); |
116 // m_wait->reset(); | 114 m_wait->resolve(V8UndefinedType()); |
117 if (m_wait->state() == m_wait->Pending) | |
118 m_wait->resolve(V8UndefinedType()); | |
119 m_closed->resolve(V8UndefinedType()); | 115 m_closed->resolve(V8UndefinedType()); |
120 } else { | 116 } else { |
121 m_state = Waiting; | 117 m_state = Waiting; |
122 // FIXME: Use reset. | 118 m_wait->reset(); |
123 // m_wait->reset(); | |
124 callOrSchedulePull(); | 119 callOrSchedulePull(); |
125 } | 120 } |
126 } | 121 } |
127 } | 122 } |
128 | 123 |
129 ScriptPromise ReadableStream::wait(ScriptState* scriptState) | 124 ScriptPromise ReadableStream::wait(ScriptState* scriptState) |
130 { | 125 { |
131 if (m_state == Waiting) | 126 if (m_state == Waiting) |
132 callOrSchedulePull(); | 127 callOrSchedulePull(); |
133 return m_wait->promise(scriptState->world()); | 128 return m_wait->promise(scriptState->world()); |
134 } | 129 } |
135 | 130 |
136 ScriptPromise ReadableStream::cancel(ScriptState* scriptState, ScriptValue reaso
n) | 131 ScriptPromise ReadableStream::cancel(ScriptState* scriptState, ScriptValue reaso
n) |
137 { | 132 { |
138 if (m_state == Errored) { | 133 if (m_state == Errored) { |
139 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(s
criptState); | 134 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(s
criptState); |
140 ScriptPromise promise = resolver->promise(); | 135 ScriptPromise promise = resolver->promise(); |
141 resolver->reject(m_exception); | 136 resolver->reject(m_exception); |
142 return promise; | 137 return promise; |
143 } | 138 } |
144 if (m_state == Closed) | 139 if (m_state == Closed) |
145 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isola
te())); | 140 return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isola
te())); |
146 | 141 |
147 if (m_state == Waiting) { | 142 if (m_state == Waiting) { |
148 if (m_wait->state() == m_wait->Pending) | 143 m_wait->resolve(V8UndefinedType()); |
149 m_wait->resolve(V8UndefinedType()); | |
150 } else { | 144 } else { |
151 ASSERT(m_state == Readable); | 145 ASSERT(m_state == Readable); |
152 // FIXME: Use reset here. | 146 m_wait->reset(); |
153 // m_wait->reset(); | 147 m_wait->resolve(V8UndefinedType()); |
154 if (m_wait->state() == m_wait->Pending) | |
155 m_wait->resolve(V8UndefinedType()); | |
156 } | 148 } |
157 | 149 |
158 clearQueue(); | 150 clearQueue(); |
159 m_state = Closed; | 151 m_state = Closed; |
160 m_closed->resolve(V8UndefinedType()); | 152 m_closed->resolve(V8UndefinedType()); |
161 return m_source->cancelSource(scriptState, reason); | 153 return m_source->cancelSource(scriptState, reason); |
162 } | 154 } |
163 | 155 |
164 ScriptPromise ReadableStream::closed(ScriptState* scriptState) | 156 ScriptPromise ReadableStream::closed(ScriptState* scriptState) |
165 { | 157 { |
166 return m_closed->promise(scriptState->world()); | 158 return m_closed->promise(scriptState->world()); |
167 } | 159 } |
168 | 160 |
169 void ReadableStream::error(PassRefPtrWillBeRawPtr<DOMException> exception) | 161 void ReadableStream::error(PassRefPtrWillBeRawPtr<DOMException> exception) |
170 { | 162 { |
171 if (m_state == Readable) { | 163 if (m_state == Readable) { |
172 clearQueue(); | 164 clearQueue(); |
173 // FIXME: Use reset here. | 165 m_wait->reset(); |
174 // m_wait->reset(); | |
175 } | 166 } |
176 | 167 |
177 if (m_state == Waiting || m_state == Readable) { | 168 if (m_state == Waiting || m_state == Readable) { |
178 m_state = Errored; | 169 m_state = Errored; |
179 m_exception = exception; | 170 m_exception = exception; |
180 if (m_wait->state() == m_wait->Pending) | 171 if (m_wait->state() == m_wait->Pending) |
181 m_wait->reject(m_exception); | 172 m_wait->reject(m_exception); |
182 m_closed->reject(m_exception); | 173 m_closed->reject(m_exception); |
183 } | 174 } |
184 } | 175 } |
(...skipping 19 matching lines...) Expand all Loading... |
204 void ReadableStream::trace(Visitor* visitor) | 195 void ReadableStream::trace(Visitor* visitor) |
205 { | 196 { |
206 visitor->trace(m_source); | 197 visitor->trace(m_source); |
207 visitor->trace(m_wait); | 198 visitor->trace(m_wait); |
208 visitor->trace(m_closed); | 199 visitor->trace(m_closed); |
209 visitor->trace(m_exception); | 200 visitor->trace(m_exception); |
210 } | 201 } |
211 | 202 |
212 } // namespace blink | 203 } // namespace blink |
213 | 204 |
OLD | NEW |