| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 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 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 } | 702 } |
| 703 fail: | 703 fail: |
| 704 ASSERT(exception); | 704 ASSERT(exception); |
| 705 packageResult(exception, DartDebuggerObject::Error, objectGroup, errorString
, returnByValue, generatePreview, result, wasThrown); | 705 packageResult(exception, DartDebuggerObject::Error, objectGroup, errorString
, returnByValue, generatePreview, result, wasThrown); |
| 706 | 706 |
| 707 | 707 |
| 708 } | 708 } |
| 709 | 709 |
| 710 void DartInjectedScript::evaluateOnCallFrame(ErrorString* errorString, const Sta
ckTrace& callFrames, const Vector<StackTrace>& asyncCallStacks, const String& ca
llFrameId, const String& expression, const String& objectGroup, bool includeComm
andLineAPI, bool returnByValue, bool generatePreview, RefPtr<RemoteObject>* resu
lt, TypeBuilder::OptOutput<bool>* wasThrown) | 710 void DartInjectedScript::evaluateOnCallFrame(ErrorString* errorString, const Sta
ckTrace& callFrames, const Vector<StackTrace>& asyncCallStacks, const String& ca
llFrameId, const String& expression, const String& objectGroup, bool includeComm
andLineAPI, bool returnByValue, bool generatePreview, RefPtr<RemoteObject>* resu
lt, TypeBuilder::OptOutput<bool>* wasThrown) |
| 711 { | 711 { |
| 712 ASSERT(!callFrames.isJavaScript()); | 712 ASSERT(callFrames.hasDart()); |
| 713 if (!m_scriptState) { | 713 if (!m_scriptState) { |
| 714 *errorString = "Invalid DartInjectedScript"; | 714 *errorString = "Invalid DartInjectedScript"; |
| 715 return; | 715 return; |
| 716 } | 716 } |
| 717 DartIsolateScope scope(m_scriptState->isolate()); | 717 DartIsolateScope scope(m_scriptState->isolate()); |
| 718 DartApiScope apiScope; | 718 DartApiScope apiScope; |
| 719 // FIXMEDART: add v8Scope calls elsewhere. | 719 // FIXMEDART: add v8Scope calls elsewhere. |
| 720 V8Scope v8scope(DartDOMData::current()); | 720 V8Scope v8scope(DartDOMData::current()); |
| 721 | 721 |
| 722 Dart_ActivationFrame frame = callFrameForId(callFrames, asyncCallStacks, cal
lFrameId); | 722 Dart_ActivationFrame frame = callFrameForId(callFrames, asyncCallStacks, cal
lFrameId); |
| 723 ASSERT(frame); | 723 ASSERT(frame); |
| 724 if (!frame) { | 724 if (!frame) { |
| 725 *errorString = "Call frame not found"; | 725 *errorString = "Call frame not found"; |
| 726 return; | 726 return; |
| 727 } | 727 } |
| 728 | 728 |
| 729 Dart_Handle function = 0; | 729 Dart_Handle function = 0; |
| 730 Dart_ActivationFrameGetLocation(frame, 0, &function, 0); | 730 Dart_ActivationFrameGetLocation(frame, 0, &function, 0); |
| 731 ASSERT(function); | 731 ASSERT(function); |
| 732 Dart_Handle localVariables = Dart_GetLocalVariables(frame); | 732 Dart_Handle localVariables = Dart_GetLocalVariables(frame); |
| 733 Dart_Handle thisHandle = findReceiver(localVariables); | 733 Dart_Handle thisHandle = findReceiver(localVariables); |
| 734 Dart_Handle context = thisHandle ? thisHandle : lookupEnclosingType(function
); | 734 Dart_Handle context = thisHandle ? thisHandle : lookupEnclosingType(function
); |
| 735 evaluateAndPackageResult(context, expression, localVariables, includeCommand
LineAPI, objectGroup, errorString, returnByValue, generatePreview, result, wasTh
rown); | 735 evaluateAndPackageResult(context, expression, localVariables, includeCommand
LineAPI, objectGroup, errorString, returnByValue, generatePreview, result, wasTh
rown); |
| 736 } | 736 } |
| 737 | 737 |
| 738 void DartInjectedScript::restartFrame(ErrorString* errorString, const StackTrace
& callFrames, const String& callFrameId, RefPtr<JSONObject>* result) | 738 void DartInjectedScript::restartFrame(ErrorString* errorString, const StackTrace
& callFrames, const String& callFrameId, RefPtr<JSONObject>* result) |
| 739 { | 739 { |
| 740 ASSERT(!callFrames.isJavaScript()); | 740 ASSERT(callFrames.hasDart()); |
| 741 *errorString = "Dart does not yet support restarting call frames"; | 741 *errorString = "Dart does not yet support restarting call frames"; |
| 742 return; | 742 return; |
| 743 } | 743 } |
| 744 | 744 |
| 745 void DartInjectedScript::getStepInPositions(ErrorString* errorString, const Stac
kTrace& callFrames, const String& callFrameId, RefPtr<Array<TypeBuilder::Debugge
r::Location> >& positions) | 745 void DartInjectedScript::getStepInPositions(ErrorString* errorString, const Stac
kTrace& callFrames, const String& callFrameId, RefPtr<Array<TypeBuilder::Debugge
r::Location> >& positions) |
| 746 { | 746 { |
| 747 ASSERT(!callFrames.isJavaScript()); | 747 ASSERT(callFrames.hasDart()); |
| 748 if (!m_scriptState) { | 748 if (!m_scriptState) { |
| 749 *errorString = "Invalid DartInjectedScript"; | 749 *errorString = "Invalid DartInjectedScript"; |
| 750 return; | 750 return; |
| 751 } | 751 } |
| 752 DartIsolateScope scope(m_scriptState->isolate()); | 752 DartIsolateScope scope(m_scriptState->isolate()); |
| 753 DartApiScope apiScope; | 753 DartApiScope apiScope; |
| 754 *errorString = "FIXME: support dart."; | 754 *errorString = "FIXME: support dart."; |
| 755 return; | 755 return; |
| 756 } | 756 } |
| 757 | 757 |
| 758 void DartInjectedScript::setVariableValue(ErrorString* errorString, const StackT
race& callFrames, const String* callFrameIdOpt, const String* functionObjectIdOp
t, int scopeNumber, const String& variableName, const String& newValueStr) | 758 void DartInjectedScript::setVariableValue(ErrorString* errorString, const StackT
race& callFrames, const String* callFrameIdOpt, const String* functionObjectIdOp
t, int scopeNumber, const String& variableName, const String& newValueStr) |
| 759 { | 759 { |
| 760 ASSERT(callFrames.hasDart()); |
| 760 if (!m_scriptState) { | 761 if (!m_scriptState) { |
| 761 *errorString = "Invalid DartInjectedScript"; | 762 *errorString = "Invalid DartInjectedScript"; |
| 762 return; | 763 return; |
| 763 } | 764 } |
| 764 DartIsolateScope scope(m_scriptState->isolate()); | 765 DartIsolateScope scope(m_scriptState->isolate()); |
| 765 DartApiScope apiScope; | 766 DartApiScope apiScope; |
| 766 ASSERT(!callFrames.isJavaScript()); | |
| 767 *errorString = "Not supported by Dart."; | 767 *errorString = "Not supported by Dart."; |
| 768 return; | 768 return; |
| 769 } | 769 } |
| 770 | 770 |
| 771 void DartInjectedScript::getFunctionDetails(ErrorString* errorString, const Stri
ng& functionId, RefPtr<FunctionDetails>* result) | 771 void DartInjectedScript::getFunctionDetails(ErrorString* errorString, const Stri
ng& functionId, RefPtr<FunctionDetails>* result) |
| 772 { | 772 { |
| 773 if (!m_scriptState) { | 773 if (!m_scriptState) { |
| 774 *errorString = "Invalid DartInjectedScript"; | 774 *errorString = "Invalid DartInjectedScript"; |
| 775 return; | 775 return; |
| 776 } | 776 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 { | 836 { |
| 837 ASSERT(Dart_IsList(completions)); | 837 ASSERT(Dart_IsList(completions)); |
| 838 intptr_t length = 0; | 838 intptr_t length = 0; |
| 839 Dart_ListLength(completions, &length); | 839 Dart_ListLength(completions, &length); |
| 840 for (intptr_t i = 0; i < length; ++i) | 840 for (intptr_t i = 0; i < length; ++i) |
| 841 (*result)->addItem(DartUtilities::toString(Dart_ListGetAt(completions, i
))); | 841 (*result)->addItem(DartUtilities::toString(Dart_ListGetAt(completions, i
))); |
| 842 } | 842 } |
| 843 | 843 |
| 844 void DartInjectedScript::getCompletionsOnCallFrame(ErrorString* errorString, con
st StackTrace& callFrames, const Vector<StackTrace>& asyncCallStacks, const Stri
ng& callFrameId, const String& expression, RefPtr<TypeBuilder::Array<String> >*
result) | 844 void DartInjectedScript::getCompletionsOnCallFrame(ErrorString* errorString, con
st StackTrace& callFrames, const Vector<StackTrace>& asyncCallStacks, const Stri
ng& callFrameId, const String& expression, RefPtr<TypeBuilder::Array<String> >*
result) |
| 845 { | 845 { |
| 846 ASSERT(!callFrames.isJavaScript()); | 846 ASSERT(callFrames.hasDart()); |
| 847 *result = TypeBuilder::Array<String>::create(); | 847 *result = TypeBuilder::Array<String>::create(); |
| 848 if (!m_scriptState) { | 848 if (!m_scriptState) { |
| 849 *errorString = "Invalid DartInjectedScript"; | 849 *errorString = "Invalid DartInjectedScript"; |
| 850 return; | 850 return; |
| 851 } | 851 } |
| 852 DartIsolateScope scope(m_scriptState->isolate()); | 852 DartIsolateScope scope(m_scriptState->isolate()); |
| 853 DartApiScope apiScope; | 853 DartApiScope apiScope; |
| 854 V8Scope v8scope(DartDOMData::current()); | 854 V8Scope v8scope(DartDOMData::current()); |
| 855 | 855 |
| 856 Dart_ActivationFrame frame = callFrameForId(callFrames, asyncCallStacks, cal
lFrameId); | 856 Dart_ActivationFrame frame = callFrameForId(callFrames, asyncCallStacks, cal
lFrameId); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 | 1187 |
| 1188 String DartInjectedScript::getCallFrameId(int ordinal, int asyncOrdinal) | 1188 String DartInjectedScript::getCallFrameId(int ordinal, int asyncOrdinal) |
| 1189 { | 1189 { |
| 1190 // FIXME: what if the stack trace contains frames from multiple | 1190 // FIXME: what if the stack trace contains frames from multiple |
| 1191 // injectedScripts? | 1191 // injectedScripts? |
| 1192 return String::format("{\"ordinal\":%d,\"injectedScriptId\":%d,\"asyncOrdina
l\":%d}", ordinal, m_injectedScriptId, asyncOrdinal); | 1192 return String::format("{\"ordinal\":%d,\"injectedScriptId\":%d,\"asyncOrdina
l\":%d}", ordinal, m_injectedScriptId, asyncOrdinal); |
| 1193 } | 1193 } |
| 1194 | 1194 |
| 1195 Dart_ActivationFrame DartInjectedScript::callFrameForId(const StackTrace& callFr
ames, const Vector<StackTrace>& asyncCallStacks, const String& callFrameId) | 1195 Dart_ActivationFrame DartInjectedScript::callFrameForId(const StackTrace& callFr
ames, const Vector<StackTrace>& asyncCallStacks, const String& callFrameId) |
| 1196 { | 1196 { |
| 1197 ASSERT(!callFrames.isJavaScript()); | 1197 ASSERT(callFrames.hasDart()); |
| 1198 if (callFrames.isJavaScript()) | 1198 if (!callFrames.hasDart()) |
| 1199 return 0; | 1199 return 0; |
| 1200 Dart_StackTrace trace = callFrames.asDart(); | 1200 Dart_StackTrace trace = callFrames.asDart(); |
| 1201 Dart_ActivationFrame frame = 0; | 1201 Dart_ActivationFrame frame = 0; |
| 1202 int ordinal = 0; | 1202 int ordinal = 0; |
| 1203 int asyncOrdinal = 0; | 1203 int asyncOrdinal = 0; |
| 1204 RefPtr<JSONValue> json = parseJSON(callFrameId); | 1204 RefPtr<JSONValue> json = parseJSON(callFrameId); |
| 1205 if (json && json->type() == JSONValue::TypeObject) { | 1205 if (json && json->type() == JSONValue::TypeObject) { |
| 1206 bool ALLOW_UNUSED success = json->asObject()->getNumber("ordinal", &ordi
nal); | 1206 bool ALLOW_UNUSED success = json->asObject()->getNumber("ordinal", &ordi
nal); |
| 1207 ASSERT(success); | 1207 ASSERT(success); |
| 1208 success = json->asObject()->getNumber("asyncOrdinal", &asyncOrdinal); | 1208 success = json->asObject()->getNumber("asyncOrdinal", &asyncOrdinal); |
| 1209 ASSERT(success); | 1209 ASSERT(success); |
| 1210 } else { | 1210 } else { |
| 1211 ASSERT(json && json->type() == JSONValue::TypeObject); | 1211 ASSERT(json && json->type() == JSONValue::TypeObject); |
| 1212 return 0; | 1212 return 0; |
| 1213 } | 1213 } |
| 1214 Dart_Handle ALLOW_UNUSED result; | 1214 Dart_Handle ALLOW_UNUSED result; |
| 1215 if (asyncOrdinal > 0) { // 1-based index | 1215 if (asyncOrdinal > 0) { // 1-based index |
| 1216 ASSERT(asyncOrdinal <= (int)asyncCallStacks.size()); | 1216 ASSERT(asyncOrdinal <= (int)asyncCallStacks.size()); |
| 1217 if (asyncOrdinal <= (int)asyncCallStacks.size()) { | 1217 if (asyncOrdinal <= (int)asyncCallStacks.size()) { |
| 1218 ASSERT(!asyncCallStacks[asyncOrdinal-1].isJavaScript()); | 1218 StackTrace asyncCallStack = asyncCallStacks[asyncOrdinal-1]; |
| 1219 result = Dart_GetActivationFrame(asyncCallStacks[asyncOrdinal-1].asD
art(), ordinal, &frame); | 1219 ASSERT(asyncCallStack.hasDart()); |
| 1220 result = Dart_GetActivationFrame(asyncCallStack.asDart(), ordinal, &
frame); |
| 1220 } else { | 1221 } else { |
| 1221 return 0; | 1222 return 0; |
| 1222 } | 1223 } |
| 1223 } else { | 1224 } else { |
| 1224 result = Dart_GetActivationFrame(trace, ordinal, &frame); | 1225 result = Dart_GetActivationFrame(trace, ordinal, &frame); |
| 1225 } | 1226 } |
| 1226 ASSERT(result); | 1227 ASSERT(result); |
| 1227 return frame; | 1228 return frame; |
| 1228 } | 1229 } |
| 1229 | 1230 |
| 1230 PassRefPtr<Array<CallFrame> > DartInjectedScript::wrapCallFrames(const StackTrac
e& callFrames, int asyncOrdinal) | 1231 PassRefPtr<Array<CallFrame> > DartInjectedScript::wrapCallFrames(const StackTrac
e& callFrames, int asyncOrdinal) |
| 1231 { | 1232 { |
| 1232 ASSERT(!callFrames.isJavaScript()); | 1233 ASSERT(callFrames.hasDart()); |
| 1233 if (callFrames.isJavaScript()) | 1234 if (!callFrames.hasDart()) |
| 1234 return nullptr; | 1235 return nullptr; |
| 1236 DartIsolateScope scope(m_scriptState->isolate()); |
| 1237 DartApiScope apiScope; |
| 1235 Dart_StackTrace trace = callFrames.asDart(); | 1238 Dart_StackTrace trace = callFrames.asDart(); |
| 1236 intptr_t length = 0; | 1239 intptr_t length = 0; |
| 1237 Dart_Handle ALLOW_UNUSED result; | 1240 Dart_Handle ALLOW_UNUSED result; |
| 1238 RefPtr<Array<CallFrame> > ret = Array<CallFrame>::create(); | 1241 RefPtr<Array<CallFrame> > ret = Array<CallFrame>::create(); |
| 1239 result = Dart_StackTraceLength(trace, &length); | 1242 result = Dart_StackTraceLength(trace, &length); |
| 1240 ASSERT(!Dart_IsError(result)); | 1243 ASSERT(!Dart_IsError(result)); |
| 1241 DartScriptDebugServer& debugServer = DartScriptDebugServer::shared(); | 1244 DartScriptDebugServer& debugServer = DartScriptDebugServer::shared(); |
| 1242 Dart_Handle libraries = Dart_GetLibraryIds(); | 1245 Dart_Handle libraries = Dart_GetLibraryIds(); |
| 1246 |
| 1247 DartDOMData* domData = DartDOMData::current(); |
| 1248 StackTraceTimestampTracker* timestampTracker = domData->stackTraceTimestampT
racker(); |
| 1243 for (intptr_t i = 0; i < length; i++) { | 1249 for (intptr_t i = 0; i < length; i++) { |
| 1250 int64_t timestamp = timestampTracker->getTimestamp(length - i - 1); |
| 1244 Dart_ActivationFrame frame = 0; | 1251 Dart_ActivationFrame frame = 0; |
| 1245 result = Dart_GetActivationFrame(trace, i, &frame); | 1252 result = Dart_GetActivationFrame(trace, i, &frame); |
| 1246 ASSERT(!Dart_IsError(result)); | 1253 ASSERT(!Dart_IsError(result)); |
| 1247 Dart_Handle functionName = 0; | 1254 Dart_Handle functionName = 0; |
| 1248 Dart_Handle function = 0; | 1255 Dart_Handle function = 0; |
| 1249 Dart_CodeLocation location; | 1256 Dart_CodeLocation location; |
| 1250 Dart_ActivationFrameGetLocation(frame, &functionName, &function, &locati
on); | 1257 Dart_ActivationFrameGetLocation(frame, &functionName, &function, &locati
on); |
| 1251 const String& url = DartUtilities::toString(location.script_url); | 1258 const String& url = DartUtilities::toString(location.script_url); |
| 1252 intptr_t line = 0; | 1259 intptr_t line = 0; |
| 1253 intptr_t column = 0; | 1260 intptr_t column = 0; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1295 .setType(Scope::Type::Library) | 1302 .setType(Scope::Type::Library) |
| 1296 .setObject(wrapDartHandle(library, DartDebuggerObject::CurrentLi
brary, "backtrace", false)) | 1303 .setObject(wrapDartHandle(library, DartDebuggerObject::CurrentLi
brary, "backtrace", false)) |
| 1297 .release()); | 1304 .release()); |
| 1298 } | 1305 } |
| 1299 | 1306 |
| 1300 scopeChain->addItem(Scope::create() | 1307 scopeChain->addItem(Scope::create() |
| 1301 .setType(Scope::Type::Isolate) | 1308 .setType(Scope::Type::Isolate) |
| 1302 .setObject(wrapDartHandle(libraries, DartDebuggerObject::Isolate, "b
acktrace", false)) | 1309 .setObject(wrapDartHandle(libraries, DartDebuggerObject::Isolate, "b
acktrace", false)) |
| 1303 .release()); | 1310 .release()); |
| 1304 | 1311 |
| 1305 ret->addItem(CallFrame::create() | 1312 RefPtr<CallFrame> callFrame = CallFrame::create() |
| 1306 .setCallFrameId(getCallFrameId(i, asyncOrdinal)) | 1313 .setCallFrameId(getCallFrameId(i, asyncOrdinal)) |
| 1307 .setFunctionName(DartUtilities::toString(functionName)) | 1314 .setFunctionName(DartUtilities::toString(functionName)) |
| 1308 .setLocation(locationJson) | 1315 .setLocation(locationJson) |
| 1309 .setScopeChain(scopeChain) | 1316 .setScopeChain(scopeChain) |
| 1310 .setThis(thisObject) | 1317 .setThis(thisObject) |
| 1311 .release()); | 1318 .release(); |
| 1319 callFrame->setTimestamp(timestamp); |
| 1320 ret->addItem(callFrame); |
| 1312 } | 1321 } |
| 1313 return ret; | 1322 return ret; |
| 1314 } | 1323 } |
| 1315 | 1324 |
| 1316 DartDebuggerObject::Kind DartInjectedScript::inferKind(Dart_Handle handle) | 1325 DartDebuggerObject::Kind DartInjectedScript::inferKind(Dart_Handle handle) |
| 1317 { | 1326 { |
| 1318 DartDOMData* domData = DartDOMData::current(); | 1327 DartDOMData* domData = DartDOMData::current(); |
| 1319 ASSERT(domData); | 1328 ASSERT(domData); |
| 1320 if (Dart_IsType(handle)) | 1329 if (Dart_IsType(handle)) |
| 1321 return DartDebuggerObject::Class; | 1330 return DartDebuggerObject::Class; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1412 } | 1421 } |
| 1413 | 1422 |
| 1414 DartDebuggerObject* DartInjectedScript::lookupObject(const String& objectId) | 1423 DartDebuggerObject* DartInjectedScript::lookupObject(const String& objectId) |
| 1415 { | 1424 { |
| 1416 ASSERT(validateObjectId(objectId)); | 1425 ASSERT(validateObjectId(objectId)); |
| 1417 DebuggerObjectMap::iterator it = m_objects.find(objectId); | 1426 DebuggerObjectMap::iterator it = m_objects.find(objectId); |
| 1418 return it != m_objects.end() ? it->value : 0; | 1427 return it != m_objects.end() ? it->value : 0; |
| 1419 } | 1428 } |
| 1420 | 1429 |
| 1421 } // namespace WebCore | 1430 } // namespace WebCore |
| OLD | NEW |