OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #include "platform/v8_inspector/V8StringUtil.h" | 43 #include "platform/v8_inspector/V8StringUtil.h" |
44 #include "platform/v8_inspector/public/V8InspectorClient.h" | 44 #include "platform/v8_inspector/public/V8InspectorClient.h" |
45 | 45 |
46 namespace v8_inspector { | 46 namespace v8_inspector { |
47 | 47 |
48 namespace V8RuntimeAgentImplState { | 48 namespace V8RuntimeAgentImplState { |
49 static const char customObjectFormatterEnabled[] = "customObjectFormatterEnabled
"; | 49 static const char customObjectFormatterEnabled[] = "customObjectFormatterEnabled
"; |
50 static const char runtimeEnabled[] = "runtimeEnabled"; | 50 static const char runtimeEnabled[] = "runtimeEnabled"; |
51 }; | 51 }; |
52 | 52 |
53 using protocol::Runtime::ExceptionDetails; | |
54 using protocol::Runtime::RemoteObject; | 53 using protocol::Runtime::RemoteObject; |
55 | 54 |
56 static bool hasInternalError(ErrorString* errorString, bool hasError) | 55 static bool hasInternalError(ErrorString* errorString, bool hasError) |
57 { | 56 { |
58 if (hasError) | 57 if (hasError) |
59 *errorString = "Internal error"; | 58 *errorString = "Internal error"; |
60 return hasError; | 59 return hasError; |
61 } | 60 } |
62 | 61 |
63 namespace { | 62 namespace { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 v8::Local<v8::Value> value = info.Length() > 0 ? info[0] : v8::Local<v8:
:Value>::Cast(v8::Undefined(info.GetIsolate())); | 98 v8::Local<v8::Value> value = info.Length() > 0 ? info[0] : v8::Local<v8:
:Value>::Cast(v8::Undefined(info.GetIsolate())); |
100 handler->m_callback->sendSuccess(handler->wrapObject(value), Maybe<proto
col::Runtime::ExceptionDetails>()); | 99 handler->m_callback->sendSuccess(handler->wrapObject(value), Maybe<proto
col::Runtime::ExceptionDetails>()); |
101 } | 100 } |
102 | 101 |
103 static void catchCallback(const v8::FunctionCallbackInfo<v8::Value>& info) | 102 static void catchCallback(const v8::FunctionCallbackInfo<v8::Value>& info) |
104 { | 103 { |
105 ProtocolPromiseHandler<Callback>* handler = static_cast<ProtocolPromiseH
andler<Callback>*>(info.Data().As<v8::External>()->Value()); | 104 ProtocolPromiseHandler<Callback>* handler = static_cast<ProtocolPromiseH
andler<Callback>*>(info.Data().As<v8::External>()->Value()); |
106 DCHECK(handler); | 105 DCHECK(handler); |
107 v8::Local<v8::Value> value = info.Length() > 0 ? info[0] : v8::Local<v8:
:Value>::Cast(v8::Undefined(info.GetIsolate())); | 106 v8::Local<v8::Value> value = info.Length() > 0 ? info[0] : v8::Local<v8:
:Value>::Cast(v8::Undefined(info.GetIsolate())); |
108 | 107 |
109 std::unique_ptr<protocol::Runtime::ExceptionDetails> exceptionDetails; | |
110 std::unique_ptr<V8StackTraceImpl> stack = handler->m_inspector->debugger
()->captureStackTrace(true); | 108 std::unique_ptr<V8StackTraceImpl> stack = handler->m_inspector->debugger
()->captureStackTrace(true); |
111 if (stack) { | 109 std::unique_ptr<protocol::Runtime::ExceptionDetails> exceptionDetails =
protocol::Runtime::ExceptionDetails::create() |
112 exceptionDetails = protocol::Runtime::ExceptionDetails::create() | 110 .setExceptionId(handler->m_inspector->nextExceptionId()) |
113 .setText("Promise was rejected") | 111 .setText("Uncaught (in promise)") |
114 .setLineNumber(!stack->isEmpty() ? stack->topLineNumber() : 0) | 112 .setLineNumber(stack && !stack->isEmpty() ? stack->topLineNumber() :
0) |
115 .setColumnNumber(!stack->isEmpty() ? stack->topColumnNumber() :
0) | 113 .setColumnNumber(stack && !stack->isEmpty() ? stack->topColumnNumber
() : 0) |
116 .setScriptId(!stack->isEmpty() ? stack->topScriptId() : String16
()) | 114 .setException(handler->wrapObject(value)) |
117 .setStackTrace(stack->buildInspectorObjectImpl()) | 115 .build(); |
118 .build(); | 116 if (stack) |
119 } | 117 exceptionDetails->setStackTrace(stack->buildInspectorObjectImpl()); |
| 118 if (stack && !stack->isEmpty()) |
| 119 exceptionDetails->setScriptId(stack->topScriptId()); |
120 handler->m_callback->sendSuccess(handler->wrapObject(value), std::move(e
xceptionDetails)); | 120 handler->m_callback->sendSuccess(handler->wrapObject(value), std::move(e
xceptionDetails)); |
121 } | 121 } |
122 | 122 |
123 ProtocolPromiseHandler(V8InspectorImpl* inspector, int contextGroupId, int e
xecutionContextId, const String16& objectGroup, bool returnByValue, bool generat
ePreview, std::unique_ptr<Callback> callback) | 123 ProtocolPromiseHandler(V8InspectorImpl* inspector, int contextGroupId, int e
xecutionContextId, const String16& objectGroup, bool returnByValue, bool generat
ePreview, std::unique_ptr<Callback> callback) |
124 : m_inspector(inspector) | 124 : m_inspector(inspector) |
125 , m_contextGroupId(contextGroupId) | 125 , m_contextGroupId(contextGroupId) |
126 , m_executionContextId(executionContextId) | 126 , m_executionContextId(executionContextId) |
127 , m_objectGroup(objectGroup) | 127 , m_objectGroup(objectGroup) |
128 , m_returnByValue(returnByValue) | 128 , m_returnByValue(returnByValue) |
129 , m_generatePreview(generatePreview) | 129 , m_generatePreview(generatePreview) |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 } | 404 } |
405 | 405 |
406 void V8RuntimeAgentImpl::getProperties( | 406 void V8RuntimeAgentImpl::getProperties( |
407 ErrorString* errorString, | 407 ErrorString* errorString, |
408 const String16& objectId, | 408 const String16& objectId, |
409 const Maybe<bool>& ownProperties, | 409 const Maybe<bool>& ownProperties, |
410 const Maybe<bool>& accessorPropertiesOnly, | 410 const Maybe<bool>& accessorPropertiesOnly, |
411 const Maybe<bool>& generatePreview, | 411 const Maybe<bool>& generatePreview, |
412 std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* res
ult, | 412 std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* res
ult, |
413 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter
nalProperties, | 413 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter
nalProperties, |
414 Maybe<ExceptionDetails>* exceptionDetails) | 414 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) |
415 { | 415 { |
416 using protocol::Runtime::InternalPropertyDescriptor; | 416 using protocol::Runtime::InternalPropertyDescriptor; |
417 | 417 |
418 InjectedScript::ObjectScope scope(errorString, m_inspector, m_session->conte
xtGroupId(), objectId); | 418 InjectedScript::ObjectScope scope(errorString, m_inspector, m_session->conte
xtGroupId(), objectId); |
419 if (!scope.initialize()) | 419 if (!scope.initialize()) |
420 return; | 420 return; |
421 | 421 |
422 scope.ignoreExceptionsAndMuteConsole(); | 422 scope.ignoreExceptionsAndMuteConsole(); |
423 if (!scope.object()->IsObject()) { | 423 if (!scope.object()->IsObject()) { |
424 *errorString = "Value with given id is not an object"; | 424 *errorString = "Value with given id is not an object"; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 V8ConsoleMessageStorage* storage = m_inspector->ensureConsoleMessageStorage(
m_session->contextGroupId()); | 481 V8ConsoleMessageStorage* storage = m_inspector->ensureConsoleMessageStorage(
m_session->contextGroupId()); |
482 storage->clear(); | 482 storage->clear(); |
483 } | 483 } |
484 | 484 |
485 void V8RuntimeAgentImpl::compileScript(ErrorString* errorString, | 485 void V8RuntimeAgentImpl::compileScript(ErrorString* errorString, |
486 const String16& expression, | 486 const String16& expression, |
487 const String16& sourceURL, | 487 const String16& sourceURL, |
488 bool persistScript, | 488 bool persistScript, |
489 const Maybe<int>& executionContextId, | 489 const Maybe<int>& executionContextId, |
490 Maybe<String16>* scriptId, | 490 Maybe<String16>* scriptId, |
491 Maybe<ExceptionDetails>* exceptionDetails) | 491 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) |
492 { | 492 { |
493 if (!m_enabled) { | 493 if (!m_enabled) { |
494 *errorString = "Runtime agent is not enabled"; | 494 *errorString = "Runtime agent is not enabled"; |
495 return; | 495 return; |
496 } | 496 } |
497 int contextId = ensureContext(errorString, m_inspector, m_session->contextGr
oupId(), executionContextId); | 497 int contextId = ensureContext(errorString, m_inspector, m_session->contextGr
oupId(), executionContextId); |
498 if (!errorString->isEmpty()) | 498 if (!errorString->isEmpty()) |
499 return; | 499 return; |
500 InjectedScript::ContextScope scope(errorString, m_inspector, m_session->cont
extGroupId(), contextId); | 500 InjectedScript::ContextScope scope(errorString, m_inspector, m_session->cont
extGroupId(), contextId); |
501 if (!scope.initialize()) | 501 if (!scope.initialize()) |
502 return; | 502 return; |
503 | 503 |
504 if (!persistScript) | 504 if (!persistScript) |
505 m_inspector->debugger()->muteScriptParsedEvents(); | 505 m_inspector->debugger()->muteScriptParsedEvents(); |
506 v8::Local<v8::Script> script = m_inspector->compileScript(scope.context(), t
oV8String(m_inspector->isolate(), expression), sourceURL, false); | 506 v8::Local<v8::Script> script = m_inspector->compileScript(scope.context(), t
oV8String(m_inspector->isolate(), expression), sourceURL, false); |
507 if (!persistScript) | 507 if (!persistScript) |
508 m_inspector->debugger()->unmuteScriptParsedEvents(); | 508 m_inspector->debugger()->unmuteScriptParsedEvents(); |
509 if (script.IsEmpty()) { | 509 if (script.IsEmpty()) { |
510 v8::Local<v8::Message> message = scope.tryCatch().Message(); | 510 if (scope.tryCatch().HasCaught()) |
511 if (!message.IsEmpty()) | 511 *exceptionDetails = scope.injectedScript()->createExceptionDetails(e
rrorString, scope.tryCatch(), String16(), false); |
512 *exceptionDetails = scope.injectedScript()->createExceptionDetails(m
essage); | |
513 else | 512 else |
514 *errorString = "Script compilation failed"; | 513 *errorString = "Script compilation failed"; |
515 return; | 514 return; |
516 } | 515 } |
517 | 516 |
518 if (!persistScript) | 517 if (!persistScript) |
519 return; | 518 return; |
520 | 519 |
521 String16 scriptValueId = String16::fromInteger(script->GetUnboundScript()->G
etId()); | 520 String16 scriptValueId = String16::fromInteger(script->GetUnboundScript()->G
etId()); |
522 std::unique_ptr<v8::Global<v8::Script>> global(new v8::Global<v8::Script>(m_
inspector->isolate(), script)); | 521 std::unique_ptr<v8::Global<v8::Script>> global(new v8::Global<v8::Script>(m_
inspector->isolate(), script)); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 reportMessage(message, true); | 678 reportMessage(message, true); |
680 } | 679 } |
681 | 680 |
682 void V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, bool generateP
review) | 681 void V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, bool generateP
review) |
683 { | 682 { |
684 message->reportToFrontend(&m_frontend, m_session, generatePreview); | 683 message->reportToFrontend(&m_frontend, m_session, generatePreview); |
685 m_frontend.flush(); | 684 m_frontend.flush(); |
686 } | 685 } |
687 | 686 |
688 } // namespace v8_inspector | 687 } // namespace v8_inspector |
OLD | NEW |