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

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

Issue 1492763002: Add a utility class to call stream methods implemented with v8 extras. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@v8-extra-switch
Patch Set: Created 5 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "bindings/core/v8/ReadableStreamOperations.h"
7
8 #include "bindings/core/v8/ScriptState.h"
9
10 namespace blink {
11
12 namespace {
13
14 v8::MaybeLocal<v8::Value> call(ScriptState* scriptState, const char* name, size_ t numArgs, v8::Local<v8::Value>* args)
15 {
16 v8::Isolate* isolate = scriptState->isolate();
17 v8::Local<v8::Context> context = scriptState->context();
18 v8::Local<v8::Value> undefined = v8::Undefined(isolate);
19 v8::Local<v8::Value> functionValue = scriptState->getFromExtrasExports(name) .v8Value();
20 ASSERT(!functionValue.IsEmpty() && functionValue->IsFunction());
21 v8::Local<v8::Function> function = functionValue.As<v8::Function>();
22 return function->Call(context, undefined, numArgs, args);
23 }
24
25 template <size_t N>
domenic 2015/12/02 17:53:03 Do you think this might be useful enough that it s
yhirano 2015/12/03 11:18:29 For now, I think having this utility function here
26 v8::MaybeLocal<v8::Value> call(ScriptState* scriptState, const char* name, v8::L ocal<v8::Value>(&args)[N])
27 {
28 return call(scriptState, name, N, args);
29 }
30
31 } // namespace
32
33 ScriptValue ReadableStreamOperations::getReader(ScriptState* scriptState, v8::Lo cal<v8::Value> stream)
34 {
35 ASSERT(isReadableStream(scriptState, stream));
36
37 v8::Local<v8::Value> args[] = { stream };
38 return ScriptValue(scriptState, call(scriptState, "AcquireReadableStreamRead er", args));
39 }
40
41 bool ReadableStreamOperations::isReadableStream(ScriptState* scriptState, v8::Lo cal<v8::Value> value)
42 {
43 if (!value->IsObject())
44 return false;
45
46 v8::Local<v8::Value> args[] = { value };
47 v8::Local<v8::Value> resultValue;
48 bool ok = call(scriptState, "IsReadableStream", args).ToLocal(&resultValue);
49 ASSERT_UNUSED(ok, ok);
50 return resultValue->ToBoolean()->Value();
51 }
52
53 bool ReadableStreamOperations::isDisturbed(ScriptState* scriptState, v8::Local<v 8::Value> stream)
54 {
55 ASSERT(isReadableStream(scriptState, stream));
56
57 v8::Local<v8::Value> args[] = { stream };
58 v8::Local<v8::Value> resultValue;
59 bool ok = call(scriptState, "IsReadableStreamDisturbed", args).ToLocal(&resu ltValue);
60 ASSERT_UNUSED(ok, ok);
61 return resultValue->ToBoolean()->Value();
62 }
63
64 bool ReadableStreamOperations::isLocked(ScriptState* scriptState, v8::Local<v8:: Value> stream)
65 {
66 ASSERT(isReadableStream(scriptState, stream));
67
68 v8::Local<v8::Value> resultValue;
69 v8::Local<v8::Value> args[] = { stream };
70 bool ok = call(scriptState, "IsReadableStreamLocked", args).ToLocal(&resultV alue);
71 ASSERT_UNUSED(ok, ok);
72 return resultValue->ToBoolean()->Value();
73 }
74
75 bool ReadableStreamOperations::isReadableStreamReader(ScriptState* scriptState, v8::Local<v8::Value> value)
76 {
77 if (!value->IsObject())
78 return false;
79
80 v8::Local<v8::Value> resultValue;
81 v8::Local<v8::Value> args[] = { value };
82 bool ok = call(scriptState, "IsReadableStreamReader", args).ToLocal(&resultV alue);
83 ASSERT_UNUSED(ok, ok);
84 return resultValue->ToBoolean()->Value();
85 }
86
87 ScriptPromise ReadableStreamOperations::read(ScriptState* scriptState, v8::Local <v8::Value> reader)
88 {
89 ASSERT(isReadableStreamReader(scriptState, reader));
90
91 v8::Local<v8::Value> resultValue;
92 v8::Local<v8::Value> args[] = { reader };
93 bool ok = call(scriptState, "ReadFromReadableStreamReader", args).ToLocal(&r esultValue);
94 ASSERT_UNUSED(ok, ok);
95 return ScriptPromise::cast(scriptState, resultValue);
96 }
97
98 } // namespace blink
99
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698