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

Side by Side Diff: Source/core/streams/ReadableStream.cpp

Issue 407453002: ReadableStream initial implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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
« no previous file with comments | « Source/core/streams/ReadableStream.h ('k') | Source/core/streams/ReadableStreamTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/streams/ReadableStream.h"
7
8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/ScriptFunction.h"
10 #include "bindings/core/v8/V8Binding.h"
11 #include "core/streams/UnderlyingSource.h"
12
13 namespace blink {
14
15 class ReadableStream::OnStarted : public ScriptFunction {
16 public:
17 OnStarted(v8::Isolate* isolate, ReadableStream* stream)
18 : ScriptFunction(isolate)
19 , m_stream(stream) { }
20 virtual ScriptValue call(ScriptValue value) OVERRIDE
21 {
22 m_stream->onStarted();
23 return value;
24 }
25
26 private:
27 Persistent<ReadableStream> m_stream;
28 };
29
30 class ReadableStream::OnStartFailed : public ScriptFunction {
31 public:
32 OnStartFailed(v8::Isolate* isolate, ReadableStream* stream)
33 : ScriptFunction(isolate)
34 , m_stream(stream) { }
35 virtual ScriptValue call(ScriptValue value) OVERRIDE
36 {
37 m_stream->error(value);
38 return value;
39 }
40
41 private:
42 Persistent<ReadableStream> m_stream;
43 };
44
45 ReadableStream::ReadableStream(ScriptState* scriptState, UnderlyingSource* sourc e, ExceptionState* exceptionState)
46 : m_scriptState(scriptState)
47 , m_source(source)
48 , m_isStarted(false)
49 , m_isDraining(false)
50 , m_isPulling(false)
51 , m_state(Waiting)
52 {
53 ScriptPromise promise = source->startSource(exceptionState);
54 promise.then(adoptPtr(new OnStarted(scriptState->isolate(), this)), adoptPtr (new OnStartFailed(scriptState->isolate(), this)));
55 }
56
57 ReadableStream::~ReadableStream()
58 {
59 }
60
61 bool ReadableStream::enqueueInternal(ScriptValue chunk)
62 {
63 // FIXME: Implemnt this method.
64 return false;
65 }
66
67 void ReadableStream::error(ScriptValue error)
68 {
69 // FIXME: Implement this function correctly.
70 m_state = Errored;
71 }
72
73 void ReadableStream::onStarted()
74 {
75 m_isStarted = true;
76 }
77
78 void ReadableStream::trace(Visitor* visitor)
79 {
80 visitor->trace(m_source);
81 }
82
83 } // namespace blink
84
OLDNEW
« no previous file with comments | « Source/core/streams/ReadableStream.h ('k') | Source/core/streams/ReadableStreamTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698