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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8FunctionCall.cpp

Issue 2295913003: [DevTools] Switch from platform/v8_inspector to v8/v8-inspector.h. (Closed)
Patch Set: rebase Created 4 years, 3 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
(Empty)
1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "platform/v8_inspector/V8FunctionCall.h"
32
33 #include "platform/v8_inspector/StringUtil.h"
34 #include "platform/v8_inspector/V8Compat.h"
35 #include "platform/v8_inspector/V8Debugger.h"
36 #include "platform/v8_inspector/V8InspectorImpl.h"
37 #include "platform/v8_inspector/public/V8InspectorClient.h"
38
39 #include <v8.h>
40
41 namespace v8_inspector {
42
43 V8FunctionCall::V8FunctionCall(V8InspectorImpl* inspector, v8::Local<v8::Context > context, v8::Local<v8::Value> value, const String16& name)
44 : m_inspector(inspector)
45 , m_context(context)
46 , m_name(toV8String(context->GetIsolate(), name))
47 , m_value(value)
48 {
49 }
50
51 void V8FunctionCall::appendArgument(v8::Local<v8::Value> value)
52 {
53 m_arguments.push_back(value);
54 }
55
56 void V8FunctionCall::appendArgument(const String16& argument)
57 {
58 m_arguments.push_back(toV8String(m_context->GetIsolate(), argument));
59 }
60
61 void V8FunctionCall::appendArgument(int argument)
62 {
63 m_arguments.push_back(v8::Number::New(m_context->GetIsolate(), argument));
64 }
65
66 void V8FunctionCall::appendArgument(bool argument)
67 {
68 m_arguments.push_back(argument ? v8::True(m_context->GetIsolate()) : v8::Fal se(m_context->GetIsolate()));
69 }
70
71 v8::Local<v8::Value> V8FunctionCall::call(bool& hadException, bool reportExcepti ons)
72 {
73 v8::TryCatch tryCatch(m_context->GetIsolate());
74 tryCatch.SetVerbose(reportExceptions);
75
76 v8::Local<v8::Value> result = callWithoutExceptionHandling();
77 hadException = tryCatch.HasCaught();
78 return result;
79 }
80
81 v8::Local<v8::Value> V8FunctionCall::callWithoutExceptionHandling()
82 {
83 v8::Local<v8::Object> thisObject = v8::Local<v8::Object>::Cast(m_value);
84 v8::Local<v8::Value> value;
85 if (!thisObject->Get(m_context, m_name).ToLocal(&value))
86 return v8::Local<v8::Value>();
87
88 DCHECK(value->IsFunction());
89
90 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value);
91 std::unique_ptr<v8::Local<v8::Value>[]> info(new v8::Local<v8::Value>[m_argu ments.size()]);
92 for (size_t i = 0; i < m_arguments.size(); ++i) {
93 info[i] = m_arguments[i];
94 DCHECK(!info[i].IsEmpty());
95 }
96
97 int contextGroupId = V8Debugger::getGroupId(m_context);
98 if (contextGroupId) {
99 m_inspector->client()->muteMetrics(contextGroupId);
100 m_inspector->muteExceptions(contextGroupId);
101 }
102 v8::MicrotasksScope microtasksScope(m_context->GetIsolate(), v8::MicrotasksS cope::kDoNotRunMicrotasks);
103 v8::MaybeLocal<v8::Value> maybeResult = function->Call(m_context, thisObject , m_arguments.size(), info.get());
104 if (contextGroupId) {
105 m_inspector->client()->unmuteMetrics(contextGroupId);
106 m_inspector->unmuteExceptions(contextGroupId);
107 }
108
109 v8::Local<v8::Value> result;
110 if (!maybeResult.ToLocal(&result))
111 return v8::Local<v8::Value>();
112 return result;
113 }
114
115 } // namespace v8_inspector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698