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

Side by Side Diff: src/inspector/v8-console.cc

Issue 2784713002: [inspector] console get all information from inspector when needed (Closed)
Patch Set: fixed last test Created 3 years, 8 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
« no previous file with comments | « src/inspector/v8-console.h ('k') | src/inspector/v8-console-message.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project 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 "src/inspector/v8-console.h" 5 #include "src/inspector/v8-console.h"
6 6
7 #include "src/base/macros.h" 7 #include "src/base/macros.h"
8 #include "src/inspector/injected-script.h" 8 #include "src/inspector/injected-script.h"
9 #include "src/inspector/inspected-context.h" 9 #include "src/inspector/inspected-context.h"
10 #include "src/inspector/string-util.h" 10 #include "src/inspector/string-util.h"
11 #include "src/inspector/v8-console-message.h" 11 #include "src/inspector/v8-console-message.h"
12 #include "src/inspector/v8-debugger-agent-impl.h" 12 #include "src/inspector/v8-debugger-agent-impl.h"
13 #include "src/inspector/v8-inspector-impl.h" 13 #include "src/inspector/v8-inspector-impl.h"
14 #include "src/inspector/v8-inspector-session-impl.h" 14 #include "src/inspector/v8-inspector-session-impl.h"
15 #include "src/inspector/v8-profiler-agent-impl.h" 15 #include "src/inspector/v8-profiler-agent-impl.h"
16 #include "src/inspector/v8-runtime-agent-impl.h" 16 #include "src/inspector/v8-runtime-agent-impl.h"
17 #include "src/inspector/v8-stack-trace-impl.h" 17 #include "src/inspector/v8-stack-trace-impl.h"
18 #include "src/inspector/v8-value-copier.h" 18 #include "src/inspector/v8-value-copier.h"
19 19
20 #include "include/v8-inspector.h" 20 #include "include/v8-inspector.h"
21 21
22 namespace v8_inspector { 22 namespace v8_inspector {
23 23
24 namespace { 24 namespace {
25 25
26 v8::Local<v8::Private> inspectedContextPrivateKey(v8::Isolate* isolate) {
27 return v8::Private::ForApi(
28 isolate, toV8StringInternalized(isolate, "V8Console#InspectedContext"));
29 }
30
31 class ConsoleHelper { 26 class ConsoleHelper {
32 public: 27 public:
33 explicit ConsoleHelper(const v8::FunctionCallbackInfo<v8::Value>& info) 28 explicit ConsoleHelper(const v8::FunctionCallbackInfo<v8::Value>& info)
34 : m_info(info), 29 : m_info(info),
35 m_isolate(info.GetIsolate()), 30 m_isolate(info.GetIsolate()),
36 m_context(info.GetIsolate()->GetCurrentContext()), 31 m_context(info.GetIsolate()->GetCurrentContext()),
37 m_inspectedContext(nullptr), 32 m_contextId(InspectedContext::contextId(m_context)) {
38 m_inspectorClient(nullptr) {} 33 m_inspector = static_cast<V8InspectorImpl*>(
39 34 m_info.Data().As<v8::External>()->Value());
40 v8::Local<v8::Object> ensureConsole() { 35 m_groupId = m_inspector->contextGroupId(m_contextId);
41 if (m_console.IsEmpty()) {
42 DCHECK(!m_info.Data().IsEmpty());
43 DCHECK(!m_info.Data()->IsUndefined());
44 m_console = m_info.Data().As<v8::Object>();
45 }
46 return m_console;
47 } 36 }
48 37
49 InspectedContext* ensureInspectedContext() { 38 V8InspectorImpl* inspector() { return m_inspector; }
50 if (m_inspectedContext) return m_inspectedContext;
51 v8::Local<v8::Object> console = ensureConsole();
52 39
53 v8::Local<v8::Private> key = inspectedContextPrivateKey(m_isolate); 40 int contextId() const { return m_contextId; }
54 v8::Local<v8::Value> inspectedContextValue; 41 int groupId() const { return m_groupId; }
55 if (!console->GetPrivate(m_context, key).ToLocal(&inspectedContextValue)) 42
56 return nullptr; 43 InjectedScript* injectedScript() {
57 DCHECK(inspectedContextValue->IsExternal()); 44 InspectedContext* context = m_inspector->getContext(m_groupId, m_contextId);
58 m_inspectedContext = static_cast<InspectedContext*>( 45 if (!context) return nullptr;
59 inspectedContextValue.As<v8::External>()->Value()); 46 return context->getInjectedScript();
60 return m_inspectedContext;
61 } 47 }
62 48
63 V8InspectorClient* ensureDebuggerClient() { 49 V8ConsoleMessageStorage* consoleMessageStorage() {
64 if (m_inspectorClient) return m_inspectorClient; 50 return inspector()->ensureConsoleMessageStorage(m_groupId);
65 InspectedContext* inspectedContext = ensureInspectedContext();
66 if (!inspectedContext) return nullptr;
67 m_inspectorClient = inspectedContext->inspector()->client();
68 return m_inspectorClient;
69 } 51 }
70 52
71 void reportCall(ConsoleAPIType type) { 53 void reportCall(ConsoleAPIType type) {
72 if (!m_info.Length()) return; 54 if (!m_info.Length()) return;
73 std::vector<v8::Local<v8::Value>> arguments; 55 std::vector<v8::Local<v8::Value>> arguments;
74 for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]); 56 for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]);
75 reportCall(type, arguments); 57 reportCall(type, arguments);
76 } 58 }
77 59
78 void reportCallWithDefaultArgument(ConsoleAPIType type, 60 void reportCallWithDefaultArgument(ConsoleAPIType type,
79 const String16& message) { 61 const String16& message) {
80 std::vector<v8::Local<v8::Value>> arguments; 62 std::vector<v8::Local<v8::Value>> arguments;
81 for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]); 63 for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]);
82 if (!m_info.Length()) arguments.push_back(toV8String(m_isolate, message)); 64 if (!m_info.Length()) arguments.push_back(toV8String(m_isolate, message));
83 reportCall(type, arguments); 65 reportCall(type, arguments);
84 } 66 }
85 67
86 void reportCallWithArgument(ConsoleAPIType type, const String16& message) { 68 void reportCallWithArgument(ConsoleAPIType type, const String16& message) {
87 std::vector<v8::Local<v8::Value>> arguments(1, 69 std::vector<v8::Local<v8::Value>> arguments(1,
88 toV8String(m_isolate, message)); 70 toV8String(m_isolate, message));
89 reportCall(type, arguments); 71 reportCall(type, arguments);
90 } 72 }
91 73
92 void reportCall(ConsoleAPIType type, 74 void reportCall(ConsoleAPIType type,
93 const std::vector<v8::Local<v8::Value>>& arguments) { 75 const std::vector<v8::Local<v8::Value>>& arguments) {
94 InspectedContext* inspectedContext = ensureInspectedContext(); 76 if (!m_groupId) return;
95 if (!inspectedContext) return;
96 int contextGroupId = inspectedContext->contextGroupId();
97 V8InspectorImpl* inspector = inspectedContext->inspector();
98 std::unique_ptr<V8ConsoleMessage> message = 77 std::unique_ptr<V8ConsoleMessage> message =
99 V8ConsoleMessage::createForConsoleAPI( 78 V8ConsoleMessage::createForConsoleAPI(
100 inspector->client()->currentTimeMS(), type, arguments, 79 m_context, m_contextId, m_groupId, m_inspector,
101 inspector->debugger()->captureStackTrace(false), inspectedContext); 80 m_inspector->client()->currentTimeMS(), type, arguments,
102 inspector->ensureConsoleMessageStorage(contextGroupId) 81 m_inspector->debugger()->captureStackTrace(false));
103 ->addMessage(std::move(message)); 82 consoleMessageStorage()->addMessage(std::move(message));
104 } 83 }
105 84
106 void reportDeprecatedCall(const char* id, const String16& message) { 85 void reportDeprecatedCall(const char* id, const String16& message) {
107 if (checkAndSetPrivateFlagOnConsole(id, false)) return; 86 if (!consoleMessageStorage()->shouldReportDeprecationMessage(m_contextId,
87 id)) {
88 return;
89 }
108 std::vector<v8::Local<v8::Value>> arguments(1, 90 std::vector<v8::Local<v8::Value>> arguments(1,
109 toV8String(m_isolate, message)); 91 toV8String(m_isolate, message));
110 reportCall(ConsoleAPIType::kWarning, arguments); 92 reportCall(ConsoleAPIType::kWarning, arguments);
111 } 93 }
112 94
113 bool firstArgToBoolean(bool defaultValue) { 95 bool firstArgToBoolean(bool defaultValue) {
114 if (m_info.Length() < 1) return defaultValue; 96 if (m_info.Length() < 1) return defaultValue;
115 if (m_info[0]->IsBoolean()) return m_info[0].As<v8::Boolean>()->Value(); 97 if (m_info[0]->IsBoolean()) return m_info[0].As<v8::Boolean>()->Value();
116 return m_info[0]->BooleanValue(m_context).FromMaybe(defaultValue); 98 return m_info[0]->BooleanValue(m_context).FromMaybe(defaultValue);
117 } 99 }
(...skipping 20 matching lines...) Expand all
138 120
139 v8::MaybeLocal<v8::Function> firstArgAsFunction() { 121 v8::MaybeLocal<v8::Function> firstArgAsFunction() {
140 if (m_info.Length() < 1 || !m_info[0]->IsFunction()) 122 if (m_info.Length() < 1 || !m_info[0]->IsFunction())
141 return v8::MaybeLocal<v8::Function>(); 123 return v8::MaybeLocal<v8::Function>();
142 v8::Local<v8::Function> func = m_info[0].As<v8::Function>(); 124 v8::Local<v8::Function> func = m_info[0].As<v8::Function>();
143 while (func->GetBoundFunction()->IsFunction()) 125 while (func->GetBoundFunction()->IsFunction())
144 func = func->GetBoundFunction().As<v8::Function>(); 126 func = func->GetBoundFunction().As<v8::Function>();
145 return func; 127 return func;
146 } 128 }
147 129
148 v8::MaybeLocal<v8::Map> privateMap(const char* name) {
149 v8::Local<v8::Object> console = ensureConsole();
150 v8::Local<v8::Private> privateKey =
151 v8::Private::ForApi(m_isolate, toV8StringInternalized(m_isolate, name));
152 v8::Local<v8::Value> mapValue;
153 if (!console->GetPrivate(m_context, privateKey).ToLocal(&mapValue))
154 return v8::MaybeLocal<v8::Map>();
155 if (mapValue->IsUndefined()) {
156 v8::Local<v8::Map> map = v8::Map::New(m_isolate);
157 if (!console->SetPrivate(m_context, privateKey, map).FromMaybe(false))
158 return v8::MaybeLocal<v8::Map>();
159 return map;
160 }
161 return mapValue->IsMap() ? mapValue.As<v8::Map>()
162 : v8::MaybeLocal<v8::Map>();
163 }
164
165 int32_t getIntFromMap(v8::Local<v8::Map> map, const String16& key,
166 int32_t defaultValue) {
167 v8::Local<v8::String> v8Key = toV8String(m_isolate, key);
168 if (!map->Has(m_context, v8Key).FromMaybe(false)) return defaultValue;
169 v8::Local<v8::Value> intValue;
170 if (!map->Get(m_context, v8Key).ToLocal(&intValue)) return defaultValue;
171 return static_cast<int32_t>(intValue.As<v8::Integer>()->Value());
172 }
173
174 void setIntOnMap(v8::Local<v8::Map> map, const String16& key, int32_t value) {
175 v8::Local<v8::String> v8Key = toV8String(m_isolate, key);
176 if (!map->Set(m_context, v8Key, v8::Integer::New(m_isolate, value))
177 .ToLocal(&map))
178 return;
179 }
180
181 double getDoubleFromMap(v8::Local<v8::Map> map, const String16& key,
182 double defaultValue) {
183 v8::Local<v8::String> v8Key = toV8String(m_isolate, key);
184 if (!map->Has(m_context, v8Key).FromMaybe(false)) return defaultValue;
185 v8::Local<v8::Value> intValue;
186 if (!map->Get(m_context, v8Key).ToLocal(&intValue)) return defaultValue;
187 return intValue.As<v8::Number>()->Value();
188 }
189
190 void setDoubleOnMap(v8::Local<v8::Map> map, const String16& key,
191 double value) {
192 v8::Local<v8::String> v8Key = toV8String(m_isolate, key);
193 if (!map->Set(m_context, v8Key, v8::Number::New(m_isolate, value))
194 .ToLocal(&map))
195 return;
196 }
197
198 V8ProfilerAgentImpl* profilerAgent() { 130 V8ProfilerAgentImpl* profilerAgent() {
199 if (V8InspectorSessionImpl* session = currentSession()) { 131 if (V8InspectorSessionImpl* session = currentSession()) {
200 if (session && session->profilerAgent()->enabled()) 132 if (session && session->profilerAgent()->enabled())
201 return session->profilerAgent(); 133 return session->profilerAgent();
202 } 134 }
203 return nullptr; 135 return nullptr;
204 } 136 }
205 137
206 V8DebuggerAgentImpl* debuggerAgent() { 138 V8DebuggerAgentImpl* debuggerAgent() {
207 if (V8InspectorSessionImpl* session = currentSession()) { 139 if (V8InspectorSessionImpl* session = currentSession()) {
208 if (session && session->debuggerAgent()->enabled()) 140 if (session && session->debuggerAgent()->enabled())
209 return session->debuggerAgent(); 141 return session->debuggerAgent();
210 } 142 }
211 return nullptr; 143 return nullptr;
212 } 144 }
213 145
214 V8InspectorSessionImpl* currentSession() { 146 V8InspectorSessionImpl* currentSession() {
215 InspectedContext* inspectedContext = ensureInspectedContext(); 147 return m_inspector->sessionForContextGroup(m_groupId);
216 if (!inspectedContext) return nullptr;
217 return inspectedContext->inspector()->sessionForContextGroup(
218 inspectedContext->contextGroupId());
219 } 148 }
220 149
221 private: 150 private:
222 const v8::FunctionCallbackInfo<v8::Value>& m_info; 151 const v8::FunctionCallbackInfo<v8::Value>& m_info;
223 v8::Isolate* m_isolate; 152 v8::Isolate* m_isolate;
224 v8::Local<v8::Context> m_context; 153 v8::Local<v8::Context> m_context;
225 v8::Local<v8::Object> m_console; 154 v8::Local<v8::Object> m_console;
226 InspectedContext* m_inspectedContext; 155 V8InspectorImpl* m_inspector = nullptr;
227 V8InspectorClient* m_inspectorClient; 156 int m_contextId;
228 157 int m_groupId;
229 bool checkAndSetPrivateFlagOnConsole(const char* name, bool defaultValue) {
230 v8::Local<v8::Object> console = ensureConsole();
231 v8::Local<v8::Private> key =
232 v8::Private::ForApi(m_isolate, toV8StringInternalized(m_isolate, name));
233 v8::Local<v8::Value> flagValue;
234 if (!console->GetPrivate(m_context, key).ToLocal(&flagValue))
235 return defaultValue;
236 DCHECK(flagValue->IsUndefined() || flagValue->IsBoolean());
237 if (flagValue->IsBoolean()) {
238 DCHECK(flagValue.As<v8::Boolean>()->Value());
239 return true;
240 }
241 if (!console->SetPrivate(m_context, key, v8::True(m_isolate))
242 .FromMaybe(false))
243 return defaultValue;
244 return false;
245 }
246 158
247 DISALLOW_COPY_AND_ASSIGN(ConsoleHelper); 159 DISALLOW_COPY_AND_ASSIGN(ConsoleHelper);
248 }; 160 };
249 161
250 void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 162 void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
251 info.GetReturnValue().Set(info.Data()); 163 info.GetReturnValue().Set(info.Data());
252 } 164 }
253 165
254 void createBoundFunctionProperty(v8::Local<v8::Context> context, 166 void createBoundFunctionProperty(v8::Local<v8::Context> context,
255 v8::Local<v8::Object> console, 167 v8::Local<v8::Object> console,
256 const char* name, 168 v8::Local<v8::Value> data, const char* name,
257 v8::FunctionCallback callback, 169 v8::FunctionCallback callback,
258 const char* description = nullptr) { 170 const char* description = nullptr) {
259 v8::Local<v8::String> funcName = 171 v8::Local<v8::String> funcName =
260 toV8StringInternalized(context->GetIsolate(), name); 172 toV8StringInternalized(context->GetIsolate(), name);
261 v8::Local<v8::Function> func; 173 v8::Local<v8::Function> func;
262 if (!v8::Function::New(context, callback, console, 0, 174 if (!v8::Function::New(context, callback, data, 0,
263 v8::ConstructorBehavior::kThrow) 175 v8::ConstructorBehavior::kThrow)
264 .ToLocal(&func)) 176 .ToLocal(&func))
265 return; 177 return;
266 func->SetName(funcName); 178 func->SetName(funcName);
267 if (description) { 179 if (description) {
268 v8::Local<v8::String> returnValue = 180 v8::Local<v8::String> returnValue =
269 toV8String(context->GetIsolate(), description); 181 toV8String(context->GetIsolate(), description);
270 v8::Local<v8::Function> toStringFunction; 182 v8::Local<v8::Function> toStringFunction;
271 if (v8::Function::New(context, returnDataCallback, returnValue, 0, 183 if (v8::Function::New(context, returnDataCallback, returnValue, 0,
272 v8::ConstructorBehavior::kThrow) 184 v8::ConstructorBehavior::kThrow)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 } 242 }
331 243
332 void V8Console::groupEndCallback( 244 void V8Console::groupEndCallback(
333 const v8::FunctionCallbackInfo<v8::Value>& info) { 245 const v8::FunctionCallbackInfo<v8::Value>& info) {
334 ConsoleHelper(info).reportCallWithDefaultArgument( 246 ConsoleHelper(info).reportCallWithDefaultArgument(
335 ConsoleAPIType::kEndGroup, String16("console.groupEnd")); 247 ConsoleAPIType::kEndGroup, String16("console.groupEnd"));
336 } 248 }
337 249
338 void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 250 void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
339 ConsoleHelper helper(info); 251 ConsoleHelper helper(info);
340 InspectedContext* context = helper.ensureInspectedContext(); 252 if (!helper.groupId()) return;
341 if (!context) return; 253 helper.inspector()->client()->consoleClear(helper.groupId());
342 int contextGroupId = context->contextGroupId();
343 if (V8InspectorClient* client = helper.ensureDebuggerClient())
344 client->consoleClear(contextGroupId);
345 helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear, 254 helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear,
346 String16("console.clear")); 255 String16("console.clear"));
347 } 256 }
348 257
349 void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 258 void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
350 ConsoleHelper helper(info); 259 ConsoleHelper helper(info);
351
352 String16 title = helper.firstArgToString(String16()); 260 String16 title = helper.firstArgToString(String16());
353 String16 identifier; 261 String16 identifier;
354 if (title.isEmpty()) { 262 if (title.isEmpty()) {
355 std::unique_ptr<V8StackTraceImpl> stackTrace = 263 std::unique_ptr<V8StackTraceImpl> stackTrace =
356 V8StackTraceImpl::capture(nullptr, 0, 1); 264 V8StackTraceImpl::capture(nullptr, 0, 1);
357 if (stackTrace && !stackTrace->isEmpty()) { 265 if (stackTrace && !stackTrace->isEmpty()) {
358 identifier = toString16(stackTrace->topSourceURL()) + ":" + 266 identifier = toString16(stackTrace->topSourceURL()) + ":" +
359 String16::fromInteger(stackTrace->topLineNumber()); 267 String16::fromInteger(stackTrace->topLineNumber());
360 } 268 }
361 } else { 269 } else {
362 identifier = title + "@"; 270 identifier = title + "@";
363 } 271 }
364 272
365 v8::Local<v8::Map> countMap; 273 int count =
366 if (!helper.privateMap("V8Console#countMap").ToLocal(&countMap)) return; 274 helper.consoleMessageStorage()->count(helper.contextId(), identifier);
367 int32_t count = helper.getIntFromMap(countMap, identifier, 0) + 1;
368 helper.setIntOnMap(countMap, identifier, count);
369 String16 countString = String16::fromInteger(count); 275 String16 countString = String16::fromInteger(count);
370 helper.reportCallWithArgument( 276 helper.reportCallWithArgument(
371 ConsoleAPIType::kCount, 277 ConsoleAPIType::kCount,
372 title.isEmpty() ? countString : (title + ": " + countString)); 278 title.isEmpty() ? countString : (title + ": " + countString));
373 } 279 }
374 280
375 void V8Console::assertCallback( 281 void V8Console::assertCallback(
376 const v8::FunctionCallbackInfo<v8::Value>& info) { 282 const v8::FunctionCallbackInfo<v8::Value>& info) {
377 ConsoleHelper helper(info); 283 ConsoleHelper helper(info);
378 if (helper.firstArgToBoolean(false)) return; 284 if (helper.firstArgToBoolean(false)) return;
(...skipping 29 matching lines...) Expand all
408 void V8Console::profileEndCallback( 314 void V8Console::profileEndCallback(
409 const v8::FunctionCallbackInfo<v8::Value>& info) { 315 const v8::FunctionCallbackInfo<v8::Value>& info) {
410 ConsoleHelper helper(info); 316 ConsoleHelper helper(info);
411 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) 317 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent())
412 profilerAgent->consoleProfileEnd(helper.firstArgToString(String16())); 318 profilerAgent->consoleProfileEnd(helper.firstArgToString(String16()));
413 } 319 }
414 320
415 static void timeFunction(const v8::FunctionCallbackInfo<v8::Value>& info, 321 static void timeFunction(const v8::FunctionCallbackInfo<v8::Value>& info,
416 bool timelinePrefix) { 322 bool timelinePrefix) {
417 ConsoleHelper helper(info); 323 ConsoleHelper helper(info);
418 if (V8InspectorClient* client = helper.ensureDebuggerClient()) { 324 V8InspectorClient* client = helper.inspector()->client();
419 String16 protocolTitle = helper.firstArgToString("default"); 325 String16 protocolTitle = helper.firstArgToString("default");
420 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; 326 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'";
421 client->consoleTime(toStringView(protocolTitle)); 327 client->consoleTime(toStringView(protocolTitle));
422 328 helper.consoleMessageStorage()->time(helper.contextId(), protocolTitle);
423 v8::Local<v8::Map> timeMap;
424 if (!helper.privateMap("V8Console#timeMap").ToLocal(&timeMap)) return;
425 helper.setDoubleOnMap(timeMap, protocolTitle, client->currentTimeMS());
426 }
427 } 329 }
428 330
429 static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info, 331 static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info,
430 bool timelinePrefix) { 332 bool timelinePrefix) {
431 ConsoleHelper helper(info); 333 ConsoleHelper helper(info);
432 if (V8InspectorClient* client = helper.ensureDebuggerClient()) { 334 V8InspectorClient* client = helper.inspector()->client();
433 String16 protocolTitle = helper.firstArgToString("default"); 335 String16 protocolTitle = helper.firstArgToString("default");
434 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; 336 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'";
435 client->consoleTimeEnd(toStringView(protocolTitle)); 337 client->consoleTimeEnd(toStringView(protocolTitle));
436 338 double elapsed = helper.consoleMessageStorage()->timeEnd(helper.contextId(),
437 v8::Local<v8::Map> timeMap; 339 protocolTitle);
438 if (!helper.privateMap("V8Console#timeMap").ToLocal(&timeMap)) return; 340 String16 message =
439 double elapsed = client->currentTimeMS() - 341 protocolTitle + ": " + String16::fromDouble(elapsed) + "ms";
440 helper.getDoubleFromMap(timeMap, protocolTitle, 0.0); 342 helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message);
441 String16 message =
442 protocolTitle + ": " + String16::fromDouble(elapsed) + "ms";
443 helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message);
444 }
445 } 343 }
446 344
447 void V8Console::timelineCallback( 345 void V8Console::timelineCallback(
448 const v8::FunctionCallbackInfo<v8::Value>& info) { 346 const v8::FunctionCallbackInfo<v8::Value>& info) {
449 ConsoleHelper(info).reportDeprecatedCall( 347 ConsoleHelper(info).reportDeprecatedCall(
450 "V8Console#timeline", 348 "V8Console#timeline",
451 "'console.timeline' is deprecated. Please use 'console.time' instead."); 349 "'console.timeline' is deprecated. Please use 'console.time' instead.");
452 timeFunction(info, true); 350 timeFunction(info, true);
453 } 351 }
454 352
(...skipping 11 matching lines...) Expand all
466 } 364 }
467 365
468 void V8Console::timeEndCallback( 366 void V8Console::timeEndCallback(
469 const v8::FunctionCallbackInfo<v8::Value>& info) { 367 const v8::FunctionCallbackInfo<v8::Value>& info) {
470 timeEndFunction(info, false); 368 timeEndFunction(info, false);
471 } 369 }
472 370
473 void V8Console::timeStampCallback( 371 void V8Console::timeStampCallback(
474 const v8::FunctionCallbackInfo<v8::Value>& info) { 372 const v8::FunctionCallbackInfo<v8::Value>& info) {
475 ConsoleHelper helper(info); 373 ConsoleHelper helper(info);
476 if (V8InspectorClient* client = helper.ensureDebuggerClient()) { 374 String16 title = helper.firstArgToString(String16());
477 String16 title = helper.firstArgToString(String16()); 375 helper.inspector()->client()->consoleTimeStamp(toStringView(title));
478 client->consoleTimeStamp(toStringView(title));
479 }
480 } 376 }
481 377
482 void V8Console::memoryGetterCallback( 378 void V8Console::memoryGetterCallback(
483 const v8::FunctionCallbackInfo<v8::Value>& info) { 379 const v8::FunctionCallbackInfo<v8::Value>& info) {
484 if (V8InspectorClient* client = ConsoleHelper(info).ensureDebuggerClient()) { 380 V8InspectorClient* client = ConsoleHelper(info).inspector()->client();
485 v8::Local<v8::Value> memoryValue; 381 v8::Local<v8::Value> memoryValue;
486 if (!client 382 if (!client
487 ->memoryInfo(info.GetIsolate(), 383 ->memoryInfo(info.GetIsolate(),
488 info.GetIsolate()->GetCurrentContext()) 384 info.GetIsolate()->GetCurrentContext())
489 .ToLocal(&memoryValue)) 385 .ToLocal(&memoryValue))
490 return; 386 return;
491 info.GetReturnValue().Set(memoryValue); 387 info.GetReturnValue().Set(memoryValue);
492 }
493 } 388 }
494 389
495 void V8Console::memorySetterCallback( 390 void V8Console::memorySetterCallback(
496 const v8::FunctionCallbackInfo<v8::Value>& info) { 391 const v8::FunctionCallbackInfo<v8::Value>& info) {
497 // We can't make the attribute readonly as it breaks existing code that relies 392 // We can't make the attribute readonly as it breaks existing code that relies
498 // on being able to assign to console.memory in strict mode. Instead, the 393 // on being able to assign to console.memory in strict mode. Instead, the
499 // setter just ignores the passed value. http://crbug.com/468611 394 // setter just ignores the passed value. http://crbug.com/468611
500 } 395 }
501 396
502 void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 397 void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 v8::Local<v8::Function> function; 498 v8::Local<v8::Function> function;
604 if (!helper.firstArgAsFunction().ToLocal(&function)) return; 499 if (!helper.firstArgAsFunction().ToLocal(&function)) return;
605 setFunctionBreakpoint(helper, function, 500 setFunctionBreakpoint(helper, function,
606 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, 501 V8DebuggerAgentImpl::MonitorCommandBreakpointSource,
607 String16(), false); 502 String16(), false);
608 } 503 }
609 504
610 void V8Console::lastEvaluationResultCallback( 505 void V8Console::lastEvaluationResultCallback(
611 const v8::FunctionCallbackInfo<v8::Value>& info) { 506 const v8::FunctionCallbackInfo<v8::Value>& info) {
612 ConsoleHelper helper(info); 507 ConsoleHelper helper(info);
613 InspectedContext* context = helper.ensureInspectedContext(); 508 InjectedScript* injectedScript = helper.injectedScript();
614 if (!context) return; 509 if (!injectedScript) return;
615 if (InjectedScript* injectedScript = context->getInjectedScript()) 510 info.GetReturnValue().Set(injectedScript->lastEvaluationResult());
616 info.GetReturnValue().Set(injectedScript->lastEvaluationResult());
617 } 511 }
618 512
619 static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info, 513 static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
620 bool copyToClipboard) { 514 bool copyToClipboard) {
621 if (info.Length() < 1) return; 515 if (info.Length() < 1) return;
622 if (!copyToClipboard) info.GetReturnValue().Set(info[0]); 516 if (!copyToClipboard) info.GetReturnValue().Set(info[0]);
623 517
624 ConsoleHelper helper(info); 518 ConsoleHelper helper(info);
625 InspectedContext* context = helper.ensureInspectedContext(); 519 InjectedScript* injectedScript = helper.injectedScript();
626 if (!context) return;
627 InjectedScript* injectedScript = context->getInjectedScript();
628 if (!injectedScript) return; 520 if (!injectedScript) return;
629 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject; 521 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject;
630 protocol::Response response = 522 protocol::Response response =
631 injectedScript->wrapObject(info[0], "", false /** forceValueType */, 523 injectedScript->wrapObject(info[0], "", false /** forceValueType */,
632 false /** generatePreview */, &wrappedObject); 524 false /** generatePreview */, &wrappedObject);
633 if (!response.isSuccess()) return; 525 if (!response.isSuccess()) return;
634 526
635 std::unique_ptr<protocol::DictionaryValue> hints = 527 std::unique_ptr<protocol::DictionaryValue> hints =
636 protocol::DictionaryValue::create(); 528 protocol::DictionaryValue::create();
637 if (copyToClipboard) hints->setBoolean("copyToClipboard", true); 529 if (copyToClipboard) hints->setBoolean("copyToClipboard", true);
638 if (V8InspectorSessionImpl* session = helper.currentSession()) 530 if (V8InspectorSessionImpl* session = helper.currentSession()) {
639 session->runtimeAgent()->inspect(std::move(wrappedObject), 531 session->runtimeAgent()->inspect(std::move(wrappedObject),
640 std::move(hints)); 532 std::move(hints));
533 }
641 } 534 }
642 535
643 void V8Console::inspectCallback( 536 void V8Console::inspectCallback(
644 const v8::FunctionCallbackInfo<v8::Value>& info) { 537 const v8::FunctionCallbackInfo<v8::Value>& info) {
645 inspectImpl(info, false); 538 inspectImpl(info, false);
646 } 539 }
647 540
648 void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 541 void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
649 inspectImpl(info, true); 542 inspectImpl(info, true);
650 } 543 }
(...skipping 19 matching lines...) Expand all
670 v8::Isolate* isolate = context->GetIsolate(); 563 v8::Isolate* isolate = context->GetIsolate();
671 v8::MicrotasksScope microtasksScope(isolate, 564 v8::MicrotasksScope microtasksScope(isolate,
672 v8::MicrotasksScope::kDoNotRunMicrotasks); 565 v8::MicrotasksScope::kDoNotRunMicrotasks);
673 566
674 v8::Local<v8::Object> console = v8::Object::New(isolate); 567 v8::Local<v8::Object> console = v8::Object::New(isolate);
675 bool success = 568 bool success =
676 console->SetPrototype(context, v8::Object::New(isolate)).FromMaybe(false); 569 console->SetPrototype(context, v8::Object::New(isolate)).FromMaybe(false);
677 DCHECK(success); 570 DCHECK(success);
678 USE(success); 571 USE(success);
679 572
680 createBoundFunctionProperty(context, console, "debug", 573 v8::Local<v8::External> data =
574 v8::External::New(isolate, inspectedContext->inspector());
575 createBoundFunctionProperty(context, console, data, "debug",
681 V8Console::debugCallback); 576 V8Console::debugCallback);
682 createBoundFunctionProperty(context, console, "error", 577 createBoundFunctionProperty(context, console, data, "error",
683 V8Console::errorCallback); 578 V8Console::errorCallback);
684 createBoundFunctionProperty(context, console, "info", 579 createBoundFunctionProperty(context, console, data, "info",
685 V8Console::infoCallback); 580 V8Console::infoCallback);
686 createBoundFunctionProperty(context, console, "log", V8Console::logCallback); 581 createBoundFunctionProperty(context, console, data, "log",
687 createBoundFunctionProperty(context, console, "warn", 582 V8Console::logCallback);
583 createBoundFunctionProperty(context, console, data, "warn",
688 V8Console::warnCallback); 584 V8Console::warnCallback);
689 createBoundFunctionProperty(context, console, "dir", V8Console::dirCallback); 585 createBoundFunctionProperty(context, console, data, "dir",
690 createBoundFunctionProperty(context, console, "dirxml", 586 V8Console::dirCallback);
587 createBoundFunctionProperty(context, console, data, "dirxml",
691 V8Console::dirxmlCallback); 588 V8Console::dirxmlCallback);
692 createBoundFunctionProperty(context, console, "table", 589 createBoundFunctionProperty(context, console, data, "table",
693 V8Console::tableCallback); 590 V8Console::tableCallback);
694 createBoundFunctionProperty(context, console, "trace", 591 createBoundFunctionProperty(context, console, data, "trace",
695 V8Console::traceCallback); 592 V8Console::traceCallback);
696 createBoundFunctionProperty(context, console, "group", 593 createBoundFunctionProperty(context, console, data, "group",
697 V8Console::groupCallback); 594 V8Console::groupCallback);
698 createBoundFunctionProperty(context, console, "groupCollapsed", 595 createBoundFunctionProperty(context, console, data, "groupCollapsed",
699 V8Console::groupCollapsedCallback); 596 V8Console::groupCollapsedCallback);
700 createBoundFunctionProperty(context, console, "groupEnd", 597 createBoundFunctionProperty(context, console, data, "groupEnd",
701 V8Console::groupEndCallback); 598 V8Console::groupEndCallback);
702 createBoundFunctionProperty(context, console, "clear", 599 createBoundFunctionProperty(context, console, data, "clear",
703 V8Console::clearCallback); 600 V8Console::clearCallback);
704 createBoundFunctionProperty(context, console, "count", 601 createBoundFunctionProperty(context, console, data, "count",
705 V8Console::countCallback); 602 V8Console::countCallback);
706 createBoundFunctionProperty(context, console, "assert", 603 createBoundFunctionProperty(context, console, data, "assert",
707 V8Console::assertCallback); 604 V8Console::assertCallback);
708 createBoundFunctionProperty(context, console, "markTimeline", 605 createBoundFunctionProperty(context, console, data, "markTimeline",
709 V8Console::markTimelineCallback); 606 V8Console::markTimelineCallback);
710 createBoundFunctionProperty(context, console, "profile", 607 createBoundFunctionProperty(context, console, data, "profile",
711 V8Console::profileCallback); 608 V8Console::profileCallback);
712 createBoundFunctionProperty(context, console, "profileEnd", 609 createBoundFunctionProperty(context, console, data, "profileEnd",
713 V8Console::profileEndCallback); 610 V8Console::profileEndCallback);
714 createBoundFunctionProperty(context, console, "timeline", 611 createBoundFunctionProperty(context, console, data, "timeline",
715 V8Console::timelineCallback); 612 V8Console::timelineCallback);
716 createBoundFunctionProperty(context, console, "timelineEnd", 613 createBoundFunctionProperty(context, console, data, "timelineEnd",
717 V8Console::timelineEndCallback); 614 V8Console::timelineEndCallback);
718 createBoundFunctionProperty(context, console, "time", 615 createBoundFunctionProperty(context, console, data, "time",
719 V8Console::timeCallback); 616 V8Console::timeCallback);
720 createBoundFunctionProperty(context, console, "timeEnd", 617 createBoundFunctionProperty(context, console, data, "timeEnd",
721 V8Console::timeEndCallback); 618 V8Console::timeEndCallback);
722 createBoundFunctionProperty(context, console, "timeStamp", 619 createBoundFunctionProperty(context, console, data, "timeStamp",
723 V8Console::timeStampCallback); 620 V8Console::timeStampCallback);
724 621
725 const char* jsConsoleAssert = 622 const char* jsConsoleAssert =
726 "(function(){\n" 623 "(function(){\n"
727 " var originAssert = this.assert;\n" 624 " var originAssert = this.assert;\n"
728 " originAssert.apply = Function.prototype.apply;\n" 625 " originAssert.apply = Function.prototype.apply;\n"
729 " this.assert = assertWrapper;\n" 626 " this.assert = assertWrapper;\n"
730 " assertWrapper.toString = () => originAssert.toString();\n" 627 " assertWrapper.toString = () => originAssert.toString();\n"
731 " function assertWrapper(){\n" 628 " function assertWrapper(){\n"
732 " if (!!arguments[0]) return;\n" 629 " if (!!arguments[0]) return;\n"
733 " originAssert.apply(null, arguments);\n" 630 " originAssert.apply(null, arguments);\n"
734 " }\n" 631 " }\n"
735 "})"; 632 "})";
736 633
737 v8::Local<v8::String> assertSource = toV8String(isolate, jsConsoleAssert); 634 v8::Local<v8::String> assertSource = toV8String(isolate, jsConsoleAssert);
738 V8InspectorImpl* inspector = inspectedContext->inspector(); 635 V8InspectorImpl* inspector = inspectedContext->inspector();
739 v8::Local<v8::Value> setupFunction; 636 v8::Local<v8::Value> setupFunction;
740 if (inspector->compileAndRunInternalScript(context, assertSource) 637 if (inspector->compileAndRunInternalScript(context, assertSource)
741 .ToLocal(&setupFunction) && 638 .ToLocal(&setupFunction) &&
742 setupFunction->IsFunction()) { 639 setupFunction->IsFunction()) {
743 v8::MicrotasksScope microtasksScope( 640 v8::MicrotasksScope microtasksScope(
744 isolate, v8::MicrotasksScope::kDoNotRunMicrotasks); 641 isolate, v8::MicrotasksScope::kDoNotRunMicrotasks);
745 v8::MaybeLocal<v8::Value> result; 642 v8::MaybeLocal<v8::Value> result;
746 result = v8::Local<v8::Function>::Cast(setupFunction) 643 result = v8::Local<v8::Function>::Cast(setupFunction)
747 ->Call(context, console, 0, nullptr); 644 ->Call(context, console, 0, nullptr);
748 } 645 }
749 646
750 if (hasMemoryAttribute) 647 if (hasMemoryAttribute) {
751 console->SetAccessorProperty( 648 console->SetAccessorProperty(
752 toV8StringInternalized(isolate, "memory"), 649 toV8StringInternalized(isolate, "memory"),
753 v8::Function::New(context, V8Console::memoryGetterCallback, console, 0, 650 v8::Function::New(context, V8Console::memoryGetterCallback, data, 0,
754 v8::ConstructorBehavior::kThrow) 651 v8::ConstructorBehavior::kThrow)
755 .ToLocalChecked(), 652 .ToLocalChecked(),
756 v8::Function::New(context, V8Console::memorySetterCallback, 653 v8::Function::New(context, V8Console::memorySetterCallback, data, 0,
757 v8::Local<v8::Value>(), 0,
758 v8::ConstructorBehavior::kThrow) 654 v8::ConstructorBehavior::kThrow)
759 .ToLocalChecked(), 655 .ToLocalChecked(),
760 static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT); 656 static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT);
657 }
761 658
762 console->SetPrivate(context, inspectedContextPrivateKey(isolate),
763 v8::External::New(isolate, inspectedContext));
764 return console; 659 return console;
765 } 660 }
766 661
767 void V8Console::clearInspectedContextIfNeeded(v8::Local<v8::Context> context,
768 v8::Local<v8::Object> console) {
769 v8::Isolate* isolate = context->GetIsolate();
770 console->SetPrivate(context, inspectedContextPrivateKey(isolate),
771 v8::External::New(isolate, nullptr));
772 }
773
774 v8::Local<v8::Object> V8Console::createCommandLineAPI( 662 v8::Local<v8::Object> V8Console::createCommandLineAPI(
775 InspectedContext* inspectedContext) { 663 InspectedContext* inspectedContext) {
776 v8::Local<v8::Context> context = inspectedContext->context(); 664 v8::Local<v8::Context> context = inspectedContext->context();
777 v8::Isolate* isolate = context->GetIsolate(); 665 v8::Isolate* isolate = context->GetIsolate();
778 v8::MicrotasksScope microtasksScope(isolate, 666 v8::MicrotasksScope microtasksScope(isolate,
779 v8::MicrotasksScope::kDoNotRunMicrotasks); 667 v8::MicrotasksScope::kDoNotRunMicrotasks);
780 668
781 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate); 669 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate);
782 bool success = 670 bool success =
783 commandLineAPI->SetPrototype(context, v8::Null(isolate)).FromMaybe(false); 671 commandLineAPI->SetPrototype(context, v8::Null(isolate)).FromMaybe(false);
784 DCHECK(success); 672 DCHECK(success);
785 USE(success); 673 USE(success);
786 674
787 createBoundFunctionProperty(context, commandLineAPI, "dir", 675 v8::Local<v8::External> data =
676 v8::External::New(isolate, inspectedContext->inspector());
677 createBoundFunctionProperty(context, commandLineAPI, data, "dir",
788 V8Console::dirCallback, 678 V8Console::dirCallback,
789 "function dir(value) { [Command Line API] }"); 679 "function dir(value) { [Command Line API] }");
790 createBoundFunctionProperty(context, commandLineAPI, "dirxml", 680 createBoundFunctionProperty(context, commandLineAPI, data, "dirxml",
791 V8Console::dirxmlCallback, 681 V8Console::dirxmlCallback,
792 "function dirxml(value) { [Command Line API] }"); 682 "function dirxml(value) { [Command Line API] }");
793 createBoundFunctionProperty(context, commandLineAPI, "profile", 683 createBoundFunctionProperty(context, commandLineAPI, data, "profile",
794 V8Console::profileCallback, 684 V8Console::profileCallback,
795 "function profile(title) { [Command Line API] }"); 685 "function profile(title) { [Command Line API] }");
796 createBoundFunctionProperty( 686 createBoundFunctionProperty(
797 context, commandLineAPI, "profileEnd", V8Console::profileEndCallback, 687 context, commandLineAPI, data, "profileEnd",
688 V8Console::profileEndCallback,
798 "function profileEnd(title) { [Command Line API] }"); 689 "function profileEnd(title) { [Command Line API] }");
799 createBoundFunctionProperty(context, commandLineAPI, "clear", 690 createBoundFunctionProperty(context, commandLineAPI, data, "clear",
800 V8Console::clearCallback, 691 V8Console::clearCallback,
801 "function clear() { [Command Line API] }"); 692 "function clear() { [Command Line API] }");
802 createBoundFunctionProperty( 693 createBoundFunctionProperty(
803 context, commandLineAPI, "table", V8Console::tableCallback, 694 context, commandLineAPI, data, "table", V8Console::tableCallback,
804 "function table(data, [columns]) { [Command Line API] }"); 695 "function table(data, [columns]) { [Command Line API] }");
805 696
806 createBoundFunctionProperty(context, commandLineAPI, "keys", 697 createBoundFunctionProperty(context, commandLineAPI, data, "keys",
807 V8Console::keysCallback, 698 V8Console::keysCallback,
808 "function keys(object) { [Command Line API] }"); 699 "function keys(object) { [Command Line API] }");
809 createBoundFunctionProperty(context, commandLineAPI, "values", 700 createBoundFunctionProperty(context, commandLineAPI, data, "values",
810 V8Console::valuesCallback, 701 V8Console::valuesCallback,
811 "function values(object) { [Command Line API] }"); 702 "function values(object) { [Command Line API] }");
812 createBoundFunctionProperty( 703 createBoundFunctionProperty(
813 context, commandLineAPI, "debug", V8Console::debugFunctionCallback, 704 context, commandLineAPI, data, "debug", V8Console::debugFunctionCallback,
814 "function debug(function) { [Command Line API] }"); 705 "function debug(function) { [Command Line API] }");
815 createBoundFunctionProperty( 706 createBoundFunctionProperty(
816 context, commandLineAPI, "undebug", V8Console::undebugFunctionCallback, 707 context, commandLineAPI, data, "undebug",
708 V8Console::undebugFunctionCallback,
817 "function undebug(function) { [Command Line API] }"); 709 "function undebug(function) { [Command Line API] }");
818 createBoundFunctionProperty( 710 createBoundFunctionProperty(
819 context, commandLineAPI, "monitor", V8Console::monitorFunctionCallback, 711 context, commandLineAPI, data, "monitor",
712 V8Console::monitorFunctionCallback,
820 "function monitor(function) { [Command Line API] }"); 713 "function monitor(function) { [Command Line API] }");
821 createBoundFunctionProperty( 714 createBoundFunctionProperty(
822 context, commandLineAPI, "unmonitor", 715 context, commandLineAPI, data, "unmonitor",
823 V8Console::unmonitorFunctionCallback, 716 V8Console::unmonitorFunctionCallback,
824 "function unmonitor(function) { [Command Line API] }"); 717 "function unmonitor(function) { [Command Line API] }");
825 createBoundFunctionProperty( 718 createBoundFunctionProperty(
826 context, commandLineAPI, "inspect", V8Console::inspectCallback, 719 context, commandLineAPI, data, "inspect", V8Console::inspectCallback,
827 "function inspect(object) { [Command Line API] }"); 720 "function inspect(object) { [Command Line API] }");
828 createBoundFunctionProperty(context, commandLineAPI, "copy", 721 createBoundFunctionProperty(context, commandLineAPI, data, "copy",
829 V8Console::copyCallback, 722 V8Console::copyCallback,
830 "function copy(value) { [Command Line API] }"); 723 "function copy(value) { [Command Line API] }");
831 createBoundFunctionProperty(context, commandLineAPI, "$_", 724 createBoundFunctionProperty(context, commandLineAPI, data, "$_",
832 V8Console::lastEvaluationResultCallback); 725 V8Console::lastEvaluationResultCallback);
833 createBoundFunctionProperty(context, commandLineAPI, "$0", 726 createBoundFunctionProperty(context, commandLineAPI, data, "$0",
834 V8Console::inspectedObject0); 727 V8Console::inspectedObject0);
835 createBoundFunctionProperty(context, commandLineAPI, "$1", 728 createBoundFunctionProperty(context, commandLineAPI, data, "$1",
836 V8Console::inspectedObject1); 729 V8Console::inspectedObject1);
837 createBoundFunctionProperty(context, commandLineAPI, "$2", 730 createBoundFunctionProperty(context, commandLineAPI, data, "$2",
838 V8Console::inspectedObject2); 731 V8Console::inspectedObject2);
839 createBoundFunctionProperty(context, commandLineAPI, "$3", 732 createBoundFunctionProperty(context, commandLineAPI, data, "$3",
840 V8Console::inspectedObject3); 733 V8Console::inspectedObject3);
841 createBoundFunctionProperty(context, commandLineAPI, "$4", 734 createBoundFunctionProperty(context, commandLineAPI, data, "$4",
842 V8Console::inspectedObject4); 735 V8Console::inspectedObject4);
843 736
844 inspectedContext->inspector()->client()->installAdditionalCommandLineAPI( 737 inspectedContext->inspector()->client()->installAdditionalCommandLineAPI(
845 context, commandLineAPI); 738 context, commandLineAPI);
846
847 commandLineAPI->SetPrivate(context, inspectedContextPrivateKey(isolate),
848 v8::External::New(isolate, inspectedContext));
849 return commandLineAPI; 739 return commandLineAPI;
850 } 740 }
851 741
852 static bool isCommandLineAPIGetter(const String16& name) { 742 static bool isCommandLineAPIGetter(const String16& name) {
853 if (name.length() != 2) return false; 743 if (name.length() != 2) return false;
854 // $0 ... $4, $_ 744 // $0 ... $4, $_
855 return name[0] == '$' && 745 return name[0] == '$' &&
856 ((name[1] >= '0' && name[1] <= '4') || name[1] == '_'); 746 ((name[1] >= '0' && name[1] <= '4') || name[1] == '_');
857 } 747 }
858 748
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 ->GetOwnPropertyDescriptor( 835 ->GetOwnPropertyDescriptor(
946 m_context, v8::Local<v8::String>::Cast(name)) 836 m_context, v8::Local<v8::String>::Cast(name))
947 .ToLocal(&descriptor); 837 .ToLocal(&descriptor);
948 DCHECK(success); 838 DCHECK(success);
949 USE(success); 839 USE(success);
950 } 840 }
951 } 841 }
952 } 842 }
953 843
954 } // namespace v8_inspector 844 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/v8-console.h ('k') | src/inspector/v8-console-message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698