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

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/ExceptionState.h"
9 #include "bindings/core/v8/ScriptState.h"
10
11 namespace blink {
12
13 namespace {
14
15 v8::MaybeLocal<v8::Value> call(ScriptState* scriptState, const char* name, size_ t numArgs, v8::Local<v8::Value>* args)
16 {
17 v8::Isolate* isolate = scriptState->isolate();
18 v8::Local<v8::Context> context = scriptState->context();
19 v8::Local<v8::Value> undefined = v8::Undefined(isolate);
20 v8::Local<v8::Value> functionValue = scriptState->getFromExtrasExports(name) .v8Value();
21 ASSERT(!functionValue.IsEmpty() && functionValue->IsFunction());
22 v8::Local<v8::Function> function = functionValue.As<v8::Function>();
23 return function->Call(context, undefined, numArgs, args);
24 }
25
26 template <size_t N>
27 v8::MaybeLocal<v8::Value> call(ScriptState* scriptState, const char* name, v8::L ocal<v8::Value>(&args)[N])
28 {
29 return call(scriptState, name, N, args);
30 }
31
32 } // namespace
33
34 ScriptValue ReadableStreamOperations::getReader(ScriptState* scriptState, v8::Lo cal<v8::Value> stream, ExceptionState& es)
35 {
36 ASSERT(isReadableStream(scriptState, stream));
37
38 v8::TryCatch block(scriptState->isolate());
39 v8::Local<v8::Value> args[] = { stream };
40 ScriptValue result(scriptState, call(scriptState, "AcquireReadableStreamRead er", args));
41 if (block.HasCaught())
42 es.rethrowV8Exception(block.Exception());
43 return result;
44 }
45
46 bool ReadableStreamOperations::isReadableStream(ScriptState* scriptState, v8::Lo cal<v8::Value> value)
47 {
48 if (!value->IsObject())
49 return false;
50
51 v8::Local<v8::Value> args[] = { value };
52 v8::Local<v8::Value> resultValue;
53 bool ok = call(scriptState, "IsReadableStream", args).ToLocal(&resultValue);
haraken 2015/12/04 01:41:05 Can we use v8CallOrBoolean? The same comment for o
yhirano 2015/12/04 05:55:47 Fixed. I talked with bashi@ and added v8Call(Mayb
bashi 2015/12/04 06:48:53 In this specific case, we may just want to do: re
54 ASSERT_UNUSED(ok, ok);
55 return resultValue->ToBoolean()->Value();
56 }
57
58 bool ReadableStreamOperations::isDisturbed(ScriptState* scriptState, v8::Local<v 8::Value> stream)
59 {
60 ASSERT(isReadableStream(scriptState, stream));
61
62 v8::Local<v8::Value> args[] = { stream };
63 v8::Local<v8::Value> resultValue;
64 bool ok = call(scriptState, "IsReadableStreamDisturbed", args).ToLocal(&resu ltValue);
65 ASSERT_UNUSED(ok, ok);
66 return resultValue->ToBoolean()->Value();
67 }
68
69 bool ReadableStreamOperations::isLocked(ScriptState* scriptState, v8::Local<v8:: Value> stream)
70 {
71 ASSERT(isReadableStream(scriptState, stream));
72
73 v8::Local<v8::Value> resultValue;
74 v8::Local<v8::Value> args[] = { stream };
75 bool ok = call(scriptState, "IsReadableStreamLocked", args).ToLocal(&resultV alue);
76 ASSERT_UNUSED(ok, ok);
77 return resultValue->ToBoolean()->Value();
78 }
79
80 bool ReadableStreamOperations::isReadableStreamReader(ScriptState* scriptState, v8::Local<v8::Value> value)
81 {
82 if (!value->IsObject())
83 return false;
84
85 v8::Local<v8::Value> resultValue;
86 v8::Local<v8::Value> args[] = { value };
87 bool ok = call(scriptState, "IsReadableStreamReader", args).ToLocal(&resultV alue);
88 ASSERT_UNUSED(ok, ok);
89 return resultValue->ToBoolean()->Value();
90 }
91
92 ScriptPromise ReadableStreamOperations::read(ScriptState* scriptState, v8::Local <v8::Value> reader)
93 {
94 ASSERT(isReadableStreamReader(scriptState, reader));
95
96 v8::Local<v8::Value> resultValue;
97 v8::Local<v8::Value> args[] = { reader };
98 bool ok = call(scriptState, "ReadFromReadableStreamReader", args).ToLocal(&r esultValue);
99 ASSERT_UNUSED(ok, ok);
100 return ScriptPromise::cast(scriptState, resultValue);
101 }
102
103 } // namespace blink
104
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698