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

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 #include "bindings/core/v8/V8BindingMacros.h"
11
12 namespace blink {
13
14 namespace {
15
16 v8::MaybeLocal<v8::Value> call(ScriptState* scriptState, const char* name, size_ t numArgs, v8::Local<v8::Value>* args)
17 {
18 v8::Isolate* isolate = scriptState->isolate();
19 v8::Local<v8::Context> context = scriptState->context();
20 v8::Local<v8::Value> undefined = v8::Undefined(isolate);
21 v8::Local<v8::Value> functionValue = scriptState->getFromExtrasExports(name) .v8Value();
22 ASSERT(!functionValue.IsEmpty() && functionValue->IsFunction());
23 v8::Local<v8::Function> function = functionValue.As<v8::Function>();
24 return function->Call(context, undefined, numArgs, args);
25 }
26
27 template <size_t N>
28 v8::MaybeLocal<v8::Value> call(ScriptState* scriptState, const char* name, v8::L ocal<v8::Value>(&args)[N])
29 {
30 return call(scriptState, name, N, args);
31 }
32
33 } // namespace
34
35 ScriptValue ReadableStreamOperations::getReader(ScriptState* scriptState, v8::Lo cal<v8::Value> stream, ExceptionState& es)
36 {
37 ASSERT(isReadableStream(scriptState, stream));
38
39 v8::TryCatch block(scriptState->isolate());
40 v8::Local<v8::Value> args[] = { stream };
41 ScriptValue result(scriptState, call(scriptState, "AcquireReadableStreamRead er", args));
42 if (block.HasCaught())
43 es.rethrowV8Exception(block.Exception());
44 return result;
45 }
46
47 bool ReadableStreamOperations::isReadableStream(ScriptState* scriptState, v8::Lo cal<v8::Value> value)
48 {
49 if (!value->IsObject())
50 return false;
51
52 v8::Local<v8::Value> args[] = { value };
53 return v8CallOrCrash(call(scriptState, "IsReadableStream", args))->ToBoolean ()->Value();
54 }
55
56 bool ReadableStreamOperations::isDisturbed(ScriptState* scriptState, v8::Local<v 8::Value> stream)
57 {
58 ASSERT(isReadableStream(scriptState, stream));
59
60 v8::Local<v8::Value> args[] = { stream };
61 return v8CallOrCrash(call(scriptState, "IsReadableStreamDisturbed", args))-> 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> args[] = { stream };
69 return v8CallOrCrash(call(scriptState, "IsReadableStreamLocked", args))->ToB oolean()->Value();
70 }
71
72 bool ReadableStreamOperations::isReadableStreamReader(ScriptState* scriptState, v8::Local<v8::Value> value)
73 {
74 if (!value->IsObject())
75 return false;
76
77 v8::Local<v8::Value> args[] = { value };
78 return v8CallOrCrash(call(scriptState, "IsReadableStreamReader", args))->ToB oolean()->Value();
79 }
80
81 ScriptPromise ReadableStreamOperations::read(ScriptState* scriptState, v8::Local <v8::Value> reader)
82 {
83 ASSERT(isReadableStreamReader(scriptState, reader));
84
85 v8::Local<v8::Value> args[] = { reader };
86 return ScriptPromise::cast(scriptState, v8CallOrCrash(call(scriptState, "Rea dFromReadableStreamReader", args)));
87 }
88
89 } // namespace blink
90
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698