| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "core/streams/ReadableStreamOperations.h" | 5 #include "core/streams/ReadableStreamOperations.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/ToV8ForCore.h" | 8 #include "bindings/core/v8/ToV8ForCore.h" |
| 9 #include "bindings/core/v8/V8ScriptRunner.h" | 9 #include "bindings/core/v8/V8ScriptRunner.h" |
| 10 #include "core/streams/UnderlyingSourceBase.h" | 10 #include "core/streams/UnderlyingSourceBase.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 v8::Number::New(script_state->GetIsolate(), high_water_mark)}; | 37 v8::Number::New(script_state->GetIsolate(), high_water_mark)}; |
| 38 return ScriptValue( | 38 return ScriptValue( |
| 39 script_state, | 39 script_state, |
| 40 V8ScriptRunner::CallExtraOrCrash( | 40 V8ScriptRunner::CallExtraOrCrash( |
| 41 script_state, "createBuiltInCountQueuingStrategy", args)); | 41 script_state, "createBuiltInCountQueuingStrategy", args)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 ScriptValue ReadableStreamOperations::GetReader(ScriptState* script_state, | 44 ScriptValue ReadableStreamOperations::GetReader(ScriptState* script_state, |
| 45 ScriptValue stream, | 45 ScriptValue stream, |
| 46 ExceptionState& es) { | 46 ExceptionState& es) { |
| 47 ASSERT(IsReadableStream(script_state, stream)); | 47 DCHECK(IsReadableStream(script_state, stream)); |
| 48 | 48 |
| 49 v8::TryCatch block(script_state->GetIsolate()); | 49 v8::TryCatch block(script_state->GetIsolate()); |
| 50 v8::Local<v8::Value> args[] = {stream.V8Value()}; | 50 v8::Local<v8::Value> args[] = {stream.V8Value()}; |
| 51 ScriptValue result( | 51 ScriptValue result( |
| 52 script_state, | 52 script_state, |
| 53 V8ScriptRunner::CallExtra(script_state, | 53 V8ScriptRunner::CallExtra(script_state, |
| 54 "AcquireReadableStreamDefaultReader", args)); | 54 "AcquireReadableStreamDefaultReader", args)); |
| 55 if (block.HasCaught()) | 55 if (block.HasCaught()) |
| 56 es.RethrowV8Exception(block.Exception()); | 56 es.RethrowV8Exception(block.Exception()); |
| 57 return result; | 57 return result; |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool ReadableStreamOperations::IsReadableStream(ScriptState* script_state, | 60 bool ReadableStreamOperations::IsReadableStream(ScriptState* script_state, |
| 61 ScriptValue value) { | 61 ScriptValue value) { |
| 62 DCHECK(!value.IsEmpty()); | 62 DCHECK(!value.IsEmpty()); |
| 63 | 63 |
| 64 if (!value.IsObject()) | 64 if (!value.IsObject()) |
| 65 return false; | 65 return false; |
| 66 | 66 |
| 67 v8::Local<v8::Value> args[] = {value.V8Value()}; | 67 v8::Local<v8::Value> args[] = {value.V8Value()}; |
| 68 return V8ScriptRunner::CallExtraOrCrash(script_state, "IsReadableStream", | 68 return V8ScriptRunner::CallExtraOrCrash(script_state, "IsReadableStream", |
| 69 args) | 69 args) |
| 70 ->ToBoolean() | 70 ->ToBoolean() |
| 71 ->Value(); | 71 ->Value(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 bool ReadableStreamOperations::IsDisturbed(ScriptState* script_state, | 74 bool ReadableStreamOperations::IsDisturbed(ScriptState* script_state, |
| 75 ScriptValue stream) { | 75 ScriptValue stream) { |
| 76 ASSERT(IsReadableStream(script_state, stream)); | 76 DCHECK(IsReadableStream(script_state, stream)); |
| 77 | 77 |
| 78 v8::Local<v8::Value> args[] = {stream.V8Value()}; | 78 v8::Local<v8::Value> args[] = {stream.V8Value()}; |
| 79 return V8ScriptRunner::CallExtraOrCrash(script_state, | 79 return V8ScriptRunner::CallExtraOrCrash(script_state, |
| 80 "IsReadableStreamDisturbed", args) | 80 "IsReadableStreamDisturbed", args) |
| 81 ->ToBoolean() | 81 ->ToBoolean() |
| 82 ->Value(); | 82 ->Value(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool ReadableStreamOperations::IsLocked(ScriptState* script_state, | 85 bool ReadableStreamOperations::IsLocked(ScriptState* script_state, |
| 86 ScriptValue stream) { | 86 ScriptValue stream) { |
| 87 ASSERT(IsReadableStream(script_state, stream)); | 87 DCHECK(IsReadableStream(script_state, stream)); |
| 88 | 88 |
| 89 v8::Local<v8::Value> args[] = {stream.V8Value()}; | 89 v8::Local<v8::Value> args[] = {stream.V8Value()}; |
| 90 return V8ScriptRunner::CallExtraOrCrash(script_state, | 90 return V8ScriptRunner::CallExtraOrCrash(script_state, |
| 91 "IsReadableStreamLocked", args) | 91 "IsReadableStreamLocked", args) |
| 92 ->ToBoolean() | 92 ->ToBoolean() |
| 93 ->Value(); | 93 ->Value(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool ReadableStreamOperations::IsReadable(ScriptState* script_state, | 96 bool ReadableStreamOperations::IsReadable(ScriptState* script_state, |
| 97 ScriptValue stream) { | 97 ScriptValue stream) { |
| 98 ASSERT(IsReadableStream(script_state, stream)); | 98 DCHECK(IsReadableStream(script_state, stream)); |
| 99 | 99 |
| 100 v8::Local<v8::Value> args[] = {stream.V8Value()}; | 100 v8::Local<v8::Value> args[] = {stream.V8Value()}; |
| 101 return V8ScriptRunner::CallExtraOrCrash(script_state, | 101 return V8ScriptRunner::CallExtraOrCrash(script_state, |
| 102 "IsReadableStreamReadable", args) | 102 "IsReadableStreamReadable", args) |
| 103 ->ToBoolean() | 103 ->ToBoolean() |
| 104 ->Value(); | 104 ->Value(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool ReadableStreamOperations::IsClosed(ScriptState* script_state, | 107 bool ReadableStreamOperations::IsClosed(ScriptState* script_state, |
| 108 ScriptValue stream) { | 108 ScriptValue stream) { |
| 109 ASSERT(IsReadableStream(script_state, stream)); | 109 DCHECK(IsReadableStream(script_state, stream)); |
| 110 | 110 |
| 111 v8::Local<v8::Value> args[] = {stream.V8Value()}; | 111 v8::Local<v8::Value> args[] = {stream.V8Value()}; |
| 112 return V8ScriptRunner::CallExtraOrCrash(script_state, | 112 return V8ScriptRunner::CallExtraOrCrash(script_state, |
| 113 "IsReadableStreamClosed", args) | 113 "IsReadableStreamClosed", args) |
| 114 ->ToBoolean() | 114 ->ToBoolean() |
| 115 ->Value(); | 115 ->Value(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 bool ReadableStreamOperations::IsErrored(ScriptState* script_state, | 118 bool ReadableStreamOperations::IsErrored(ScriptState* script_state, |
| 119 ScriptValue stream) { | 119 ScriptValue stream) { |
| 120 ASSERT(IsReadableStream(script_state, stream)); | 120 DCHECK(IsReadableStream(script_state, stream)); |
| 121 | 121 |
| 122 v8::Local<v8::Value> args[] = {stream.V8Value()}; | 122 v8::Local<v8::Value> args[] = {stream.V8Value()}; |
| 123 return V8ScriptRunner::CallExtraOrCrash(script_state, | 123 return V8ScriptRunner::CallExtraOrCrash(script_state, |
| 124 "IsReadableStreamErrored", args) | 124 "IsReadableStreamErrored", args) |
| 125 ->ToBoolean() | 125 ->ToBoolean() |
| 126 ->Value(); | 126 ->Value(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 bool ReadableStreamOperations::IsReadableStreamDefaultReader( | 129 bool ReadableStreamOperations::IsReadableStreamDefaultReader( |
| 130 ScriptState* script_state, | 130 ScriptState* script_state, |
| 131 ScriptValue value) { | 131 ScriptValue value) { |
| 132 DCHECK(!value.IsEmpty()); | 132 DCHECK(!value.IsEmpty()); |
| 133 | 133 |
| 134 if (!value.IsObject()) | 134 if (!value.IsObject()) |
| 135 return false; | 135 return false; |
| 136 | 136 |
| 137 v8::Local<v8::Value> args[] = {value.V8Value()}; | 137 v8::Local<v8::Value> args[] = {value.V8Value()}; |
| 138 return V8ScriptRunner::CallExtraOrCrash(script_state, | 138 return V8ScriptRunner::CallExtraOrCrash(script_state, |
| 139 "IsReadableStreamDefaultReader", args) | 139 "IsReadableStreamDefaultReader", args) |
| 140 ->ToBoolean() | 140 ->ToBoolean() |
| 141 ->Value(); | 141 ->Value(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 ScriptPromise ReadableStreamOperations::DefaultReaderRead( | 144 ScriptPromise ReadableStreamOperations::DefaultReaderRead( |
| 145 ScriptState* script_state, | 145 ScriptState* script_state, |
| 146 ScriptValue reader) { | 146 ScriptValue reader) { |
| 147 ASSERT(IsReadableStreamDefaultReader(script_state, reader)); | 147 DCHECK(IsReadableStreamDefaultReader(script_state, reader)); |
| 148 | 148 |
| 149 v8::Local<v8::Value> args[] = {reader.V8Value()}; | 149 v8::Local<v8::Value> args[] = {reader.V8Value()}; |
| 150 return ScriptPromise::Cast( | 150 return ScriptPromise::Cast( |
| 151 script_state, V8ScriptRunner::CallExtraOrCrash( | 151 script_state, V8ScriptRunner::CallExtraOrCrash( |
| 152 script_state, "ReadableStreamDefaultReaderRead", args)); | 152 script_state, "ReadableStreamDefaultReaderRead", args)); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void ReadableStreamOperations::Tee(ScriptState* script_state, | 155 void ReadableStreamOperations::Tee(ScriptState* script_state, |
| 156 ScriptValue stream, | 156 ScriptValue stream, |
| 157 ScriptValue* new_stream1, | 157 ScriptValue* new_stream1, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 173 branches->Get(script_state->GetContext(), 0).ToLocalChecked()); | 173 branches->Get(script_state->GetContext(), 0).ToLocalChecked()); |
| 174 *new_stream2 = ScriptValue( | 174 *new_stream2 = ScriptValue( |
| 175 script_state, | 175 script_state, |
| 176 branches->Get(script_state->GetContext(), 1).ToLocalChecked()); | 176 branches->Get(script_state->GetContext(), 1).ToLocalChecked()); |
| 177 | 177 |
| 178 DCHECK(IsReadableStream(script_state, *new_stream1)); | 178 DCHECK(IsReadableStream(script_state, *new_stream1)); |
| 179 DCHECK(IsReadableStream(script_state, *new_stream2)); | 179 DCHECK(IsReadableStream(script_state, *new_stream2)); |
| 180 } | 180 } |
| 181 | 181 |
| 182 } // namespace blink | 182 } // namespace blink |
| OLD | NEW |