Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef ReadableStreamController_h | 5 #ifndef ReadableStreamController_h |
| 6 #define ReadableStreamController_h | 6 #define ReadableStreamController_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScopedPersistent.h" | 8 #include "bindings/core/v8/ScopedPersistent.h" |
| 9 #include "bindings/core/v8/ScriptValue.h" | 9 #include "bindings/core/v8/ScriptValue.h" |
| 10 #include "bindings/core/v8/ToV8.h" | 10 #include "bindings/core/v8/ToV8.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 void close() | 43 void close() |
| 44 { | 44 { |
| 45 ScriptState* scriptState = m_scriptState.get(); | 45 ScriptState* scriptState = m_scriptState.get(); |
| 46 ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated | 46 ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated |
| 47 v8::Isolate* isolate = scriptState->isolate(); | 47 v8::Isolate* isolate = scriptState->isolate(); |
| 48 | 48 |
| 49 v8::Local<v8::Value> stream = m_stream.newLocal(isolate); | 49 v8::Local<v8::Value> stream = m_stream.newLocal(isolate); |
| 50 if (stream.IsEmpty()) | 50 if (stream.IsEmpty()) |
| 51 return; | 51 return; |
| 52 | 52 |
| 53 v8::Local<v8::Value> args[] = { stream }; | 53 v8::Local<v8::Value> args[] = { stream }; |
|
domenic
2016/04/27 21:12:24
Don't you need to pass the controller now, not the
tyoshino (SeeGerritForStatus)
2016/04/28 14:51:11
Right! Just forgot to. Done.
| |
| 54 V8ScriptRunner::callExtraOrCrash(scriptState, "CloseReadableStream", arg s); | 54 V8ScriptRunner::callExtraOrCrash(scriptState, "ReadableStreamDefaultCont rollerClose", args); |
| 55 | 55 |
| 56 m_stream.clear(); | 56 m_stream.clear(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 double desiredSize() const | 59 double desiredSize() const |
| 60 { | 60 { |
| 61 ScriptState* scriptState = m_scriptState.get(); | 61 ScriptState* scriptState = m_scriptState.get(); |
| 62 ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated | 62 ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated |
| 63 v8::Isolate* isolate = scriptState->isolate(); | 63 v8::Isolate* isolate = scriptState->isolate(); |
| 64 | 64 |
| 65 v8::Local<v8::Value> stream = m_stream.newLocal(isolate); | 65 v8::Local<v8::Value> stream = m_stream.newLocal(isolate); |
| 66 if (stream.IsEmpty()) | 66 if (stream.IsEmpty()) |
| 67 return 0; | 67 return 0; |
| 68 | 68 |
| 69 v8::Local<v8::Value> args[] = { stream }; | 69 v8::Local<v8::Value> args[] = { stream }; |
| 70 v8::Local<v8::Value> result = V8ScriptRunner::callExtraOrCrash(scriptSta te, "GetReadableStreamDesiredSize", args); | 70 v8::Local<v8::Value> result = V8ScriptRunner::callExtraOrCrash(scriptSta te, "ReadableStreamDefaultControllerGetDesiredSize", args); |
| 71 | 71 |
| 72 return result.As<v8::Number>()->Value(); | 72 return result.As<v8::Number>()->Value(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 template <typename ChunkType> | 75 template <typename ChunkType> |
| 76 void enqueue(ChunkType chunk) const | 76 void enqueue(ChunkType chunk) const |
| 77 { | 77 { |
| 78 ScriptState* scriptState = m_scriptState.get(); | 78 ScriptState* scriptState = m_scriptState.get(); |
| 79 ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated | 79 ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated |
| 80 v8::Isolate* isolate = scriptState->isolate(); | 80 v8::Isolate* isolate = scriptState->isolate(); |
| 81 | 81 |
| 82 v8::Local<v8::Value> stream = m_stream.newLocal(isolate); | 82 v8::Local<v8::Value> stream = m_stream.newLocal(isolate); |
| 83 if (stream.IsEmpty()) | 83 if (stream.IsEmpty()) |
| 84 return; | 84 return; |
| 85 | 85 |
| 86 v8::Local<v8::Value> jsChunk = toV8(chunk, scriptState); | 86 v8::Local<v8::Value> jsChunk = toV8(chunk, scriptState); |
| 87 v8::Local<v8::Value> args[] = { stream, jsChunk }; | 87 v8::Local<v8::Value> args[] = { stream, jsChunk }; |
| 88 V8ScriptRunner::callExtraOrCrash(scriptState, "EnqueueInReadableStream", args); | 88 V8ScriptRunner::callExtraOrCrash(scriptState, "ReadableStreamDefaultCont rollerEnqueue", args); |
| 89 } | 89 } |
| 90 | 90 |
| 91 template <typename ErrorType> | 91 template <typename ErrorType> |
| 92 void error(ErrorType error) | 92 void error(ErrorType error) |
| 93 { | 93 { |
| 94 ScriptState* scriptState = m_scriptState.get(); | 94 ScriptState* scriptState = m_scriptState.get(); |
| 95 ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated | 95 ScriptState::Scope scope(scriptState); // will assert context is valid; do not call this method when the context is invalidated |
| 96 v8::Isolate* isolate = scriptState->isolate(); | 96 v8::Isolate* isolate = scriptState->isolate(); |
| 97 | 97 |
| 98 v8::Local<v8::Value> stream = m_stream.newLocal(isolate); | 98 v8::Local<v8::Value> stream = m_stream.newLocal(isolate); |
| 99 if (stream.IsEmpty()) | 99 if (stream.IsEmpty()) |
| 100 return; | 100 return; |
| 101 | 101 |
| 102 v8::Local<v8::Value> jsError = toV8(error, scriptState); | 102 v8::Local<v8::Value> jsError = toV8(error, scriptState); |
| 103 v8::Local<v8::Value> args[] = { stream, jsError }; | 103 v8::Local<v8::Value> args[] = { stream, jsError }; |
| 104 V8ScriptRunner::callExtraOrCrash(scriptState, "ErrorReadableStream", arg s); | 104 V8ScriptRunner::callExtraOrCrash(scriptState, "ReadableStreamDefaultCont rollerError", args); |
| 105 | 105 |
| 106 m_stream.clear(); | 106 m_stream.clear(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 private: | 109 private: |
| 110 static void streamWeakCallback(const v8::WeakCallbackInfo<ScopedPersistent<v 8::Value>>& weakInfo) | 110 static void streamWeakCallback(const v8::WeakCallbackInfo<ScopedPersistent<v 8::Value>>& weakInfo) |
| 111 { | 111 { |
| 112 weakInfo.GetParameter()->clear(); | 112 weakInfo.GetParameter()->clear(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 RefPtr<ScriptState> m_scriptState; | 115 RefPtr<ScriptState> m_scriptState; |
| 116 ScopedPersistent<v8::Value> m_stream; | 116 ScopedPersistent<v8::Value> m_stream; |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 } // namespace blink | 119 } // namespace blink |
| 120 | 120 |
| 121 #endif // ReadableStreamController_h | 121 #endif // ReadableStreamController_h |
| OLD | NEW |