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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ReadableStreamOperations.cpp

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: Don't modify UnderlyingSource.h, oops Created 4 years, 11 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
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 "bindings/core/v8/ReadableStreamOperations.h" 5 #include "bindings/core/v8/ReadableStreamOperations.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/ScriptState.h" 8 #include "bindings/core/v8/ScriptState.h"
9 #include "bindings/core/v8/ToV8.h"
9 #include "bindings/core/v8/V8BindingMacros.h" 10 #include "bindings/core/v8/V8BindingMacros.h"
11 #include "bindings/core/v8/V8RecursionScope.h"
12 #include "core/streams/UnderlyingSourceBase.h"
10 13
11 namespace blink { 14 namespace blink {
12 15
13 namespace { 16 ScriptValue ReadableStreamOperations::createReadableStream(ScriptState* scriptSt ate, UnderlyingSourceBase* underlyingSource, ScriptValue strategy)
17 {
18 ScriptState::Scope scope(scriptState);
19 v8::Local<v8::Context> context = scriptState->context();
20 v8::Local<v8::Object> global = context->Global();
21 v8::Isolate* isolate = scriptState->isolate();
14 22
15 v8::MaybeLocal<v8::Value> call(ScriptState* scriptState, const char* name, size_ t numArgs, v8::Local<v8::Value>* args) 23 v8::Local<v8::Value> jsUnderlyingSource = toV8(underlyingSource, global, iso late);
16 { 24 v8::Local<v8::Value> jsStrategy = strategy.v8Value();
17 v8::Isolate* isolate = scriptState->isolate(); 25
18 v8::Local<v8::Context> context = scriptState->context(); 26 V8RecursionScope::MicrotaskSuppression mtsScope(isolate);
19 v8::Local<v8::Value> undefined = v8::Undefined(isolate); 27 v8::Local<v8::Value> args[] = { jsUnderlyingSource, jsStrategy };
20 v8::Local<v8::Value> functionValue = scriptState->getFromExtrasExports(name) .v8Value(); 28 v8::Local<v8::Value> jsStream = v8CallExtraOrCrash(scriptState, "createReada bleStreamWithExternalController", args);
21 ASSERT(!functionValue.IsEmpty() && functionValue->IsFunction()); 29
22 v8::Local<v8::Function> function = functionValue.As<v8::Function>(); 30 return ScriptValue(scriptState, jsStream);
23 return function->Call(context, undefined, numArgs, args);
24 } 31 }
25 32
26 template <size_t N> 33 ScriptValue ReadableStreamOperations::createCountQueuingStrategy(ScriptState* sc riptState, size_t highWaterMark)
27 v8::MaybeLocal<v8::Value> call(ScriptState* scriptState, const char* name, v8::L ocal<v8::Value>(&args)[N])
28 { 34 {
29 return call(scriptState, name, N, args); 35 ScriptState::Scope scope(scriptState);
36 v8::Isolate* isolate = scriptState->isolate();
37
38 v8::Local<v8::Value> args[] = { v8::Number::New(isolate, highWaterMark) };
39 v8::Local<v8::Value> jsStrategy = v8CallExtraOrCrash(scriptState, "createBui ltInCountQueuingStrategy", args);
40
41 return ScriptValue(scriptState, jsStrategy);
30 } 42 }
31 43
32 } // namespace 44 ScriptValue ReadableStreamOperations::getReader(ScriptState* scriptState, Script Value stream, ExceptionState& es)
33
34 ScriptValue ReadableStreamOperations::getReader(ScriptState* scriptState, v8::Lo cal<v8::Value> stream, ExceptionState& es)
35 { 45 {
36 ASSERT(isReadableStream(scriptState, stream)); 46 ASSERT(isReadableStream(scriptState, stream));
37 47
38 v8::TryCatch block(scriptState->isolate()); 48 v8::TryCatch block(scriptState->isolate());
39 v8::Local<v8::Value> args[] = { stream }; 49 v8::Local<v8::Value> args[] = { stream.v8Value() };
40 ScriptValue result(scriptState, call(scriptState, "AcquireReadableStreamRead er", args)); 50 ScriptValue result(scriptState, v8CallExtra(scriptState, "AcquireReadableStr eamReader", args));
41 if (block.HasCaught()) 51 if (block.HasCaught())
42 es.rethrowV8Exception(block.Exception()); 52 es.rethrowV8Exception(block.Exception());
43 return result; 53 return result;
44 } 54 }
45 55
46 bool ReadableStreamOperations::isReadableStream(ScriptState* scriptState, v8::Lo cal<v8::Value> value) 56 bool ReadableStreamOperations::isReadableStream(ScriptState* scriptState, Script Value value)
47 { 57 {
48 if (!value->IsObject()) 58 if (!value.isObject())
49 return false; 59 return false;
50 60
51 v8::Local<v8::Value> args[] = { value }; 61 v8::Local<v8::Value> args[] = { value.v8Value() };
52 return v8CallOrCrash(call(scriptState, "IsReadableStream", args))->ToBoolean ()->Value(); 62 return v8CallExtraOrCrash(scriptState, "IsReadableStream", args)->ToBoolean( )->Value();
53 } 63 }
54 64
55 bool ReadableStreamOperations::isDisturbed(ScriptState* scriptState, v8::Local<v 8::Value> stream) 65 bool ReadableStreamOperations::isDisturbed(ScriptState* scriptState, ScriptValue stream)
56 { 66 {
57 ASSERT(isReadableStream(scriptState, stream)); 67 ASSERT(isReadableStream(scriptState, stream));
58 68
59 v8::Local<v8::Value> args[] = { stream }; 69 v8::Local<v8::Value> args[] = { stream.v8Value() };
60 return v8CallOrCrash(call(scriptState, "IsReadableStreamDisturbed", args))-> ToBoolean()->Value(); 70 return v8CallExtraOrCrash(scriptState, "IsReadableStreamDisturbed", args)->T oBoolean()->Value();
61 } 71 }
62 72
63 bool ReadableStreamOperations::isLocked(ScriptState* scriptState, v8::Local<v8:: Value> stream) 73 bool ReadableStreamOperations::isLocked(ScriptState* scriptState, ScriptValue st ream)
64 { 74 {
65 ASSERT(isReadableStream(scriptState, stream)); 75 ASSERT(isReadableStream(scriptState, stream));
66 76
67 v8::Local<v8::Value> args[] = { stream }; 77 v8::Local<v8::Value> args[] = { stream.v8Value() };
68 return v8CallOrCrash(call(scriptState, "IsReadableStreamLocked", args))->ToB oolean()->Value(); 78 return v8CallExtraOrCrash(scriptState, "IsReadableStreamLocked", args)->ToBo olean()->Value();
69 } 79 }
70 80
71 bool ReadableStreamOperations::isReadableStreamReader(ScriptState* scriptState, v8::Local<v8::Value> value) 81 bool ReadableStreamOperations::isReadableStreamReader(ScriptState* scriptState, ScriptValue value)
72 { 82 {
73 if (!value->IsObject()) 83 if (!value.isObject())
74 return false; 84 return false;
75 85
76 v8::Local<v8::Value> args[] = { value }; 86 v8::Local<v8::Value> args[] = { value.v8Value() };
77 return v8CallOrCrash(call(scriptState, "IsReadableStreamReader", args))->ToB oolean()->Value(); 87 return v8CallExtraOrCrash(scriptState, "IsReadableStreamReader", args)->ToBo olean()->Value();
78 } 88 }
79 89
80 ScriptPromise ReadableStreamOperations::read(ScriptState* scriptState, v8::Local <v8::Value> reader) 90 ScriptPromise ReadableStreamOperations::read(ScriptState* scriptState, ScriptVal ue reader)
81 { 91 {
82 ASSERT(isReadableStreamReader(scriptState, reader)); 92 ASSERT(isReadableStreamReader(scriptState, reader));
83 93
84 v8::Local<v8::Value> args[] = { reader }; 94 v8::Local<v8::Value> args[] = { reader.v8Value() };
85 return ScriptPromise::cast(scriptState, v8CallOrCrash(call(scriptState, "Rea dFromReadableStreamReader", args))); 95 return ScriptPromise::cast(scriptState, v8CallExtraOrCrash(scriptState, "Rea dFromReadableStreamReader", args));
86 } 96 }
87 97
88 } // namespace blink 98 } // namespace blink
89 99
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698