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

Side by Side Diff: Source/core/inspector/InjectedScriptBase.cpp

Issue 369333002: DevTools: Added error message when the command is invoked from the console with exception (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@add-evaluate-exception-details
Patch Set: Created 6 years, 5 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
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 21 matching lines...) Expand all
32 32
33 33
34 #include "core/inspector/InjectedScriptBase.h" 34 #include "core/inspector/InjectedScriptBase.h"
35 35
36 #include "bindings/core/v8/ScriptFunctionCall.h" 36 #include "bindings/core/v8/ScriptFunctionCall.h"
37 #include "core/inspector/InspectorInstrumentation.h" 37 #include "core/inspector/InspectorInstrumentation.h"
38 #include "core/inspector/InspectorTraceEvents.h" 38 #include "core/inspector/InspectorTraceEvents.h"
39 #include "platform/JSONValues.h" 39 #include "platform/JSONValues.h"
40 #include "wtf/text/WTFString.h" 40 #include "wtf/text/WTFString.h"
41 41
42 using WebCore::TypeBuilder::Array;
42 using WebCore::TypeBuilder::Runtime::RemoteObject; 43 using WebCore::TypeBuilder::Runtime::RemoteObject;
43 44
44 namespace WebCore { 45 namespace WebCore {
45 46
46 InjectedScriptBase::InjectedScriptBase(const String& name) 47 InjectedScriptBase::InjectedScriptBase(const String& name)
47 : m_name(name) 48 : m_name(name)
48 , m_inspectedStateAccessCheck(0) 49 , m_inspectedStateAccessCheck(0)
49 { 50 {
50 } 51 }
51 52
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 ASSERT(!hadException); 115 ASSERT(!hadException);
115 if (!hadException) { 116 if (!hadException) {
116 *result = resultValue.toJSONValue(m_injectedScriptObject.scriptState()); 117 *result = resultValue.toJSONValue(m_injectedScriptObject.scriptState());
117 if (!*result) 118 if (!*result)
118 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth)); 119 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth));
119 } else { 120 } else {
120 *result = JSONString::create("Exception while making a call."); 121 *result = JSONString::create("Exception while making a call.");
121 } 122 }
122 } 123 }
123 124
124 void InjectedScriptBase::makeEvalCall(ErrorString* errorString, ScriptFunctionCa ll& function, RefPtr<TypeBuilder::Runtime::RemoteObject>* objectResult, TypeBuil der::OptOutput<bool>* wasThrown) 125 void InjectedScriptBase::makeEvalCall(ErrorString* errorString, ScriptFunctionCa ll& function, RefPtr<TypeBuilder::Runtime::RemoteObject>* objectResult, TypeBuil der::OptOutput<bool>* wasThrown, RefPtr<TypeBuilder::Debugger::ExceptionDetails> * objectExceptionDetails)
125 { 126 {
126 RefPtr<JSONValue> result; 127 RefPtr<JSONValue> result;
127 makeCall(function, &result); 128 makeCall(function, &result);
128 if (!result) { 129 if (!result) {
129 *errorString = "Internal error: result value is empty"; 130 *errorString = "Internal error: result value is empty";
130 return; 131 return;
131 } 132 }
132 if (result->type() == JSONValue::TypeString) { 133 if (result->type() == JSONValue::TypeString) {
133 result->asString(errorString); 134 result->asString(errorString);
134 ASSERT(errorString->length()); 135 ASSERT(errorString->length());
135 return; 136 return;
136 } 137 }
137 RefPtr<JSONObject> resultPair = result->asObject(); 138 RefPtr<JSONObject> resultPair = result->asObject();
138 if (!resultPair) { 139 if (!resultPair) {
139 *errorString = "Internal error: result is not an Object"; 140 *errorString = "Internal error: result is not an Object";
140 return; 141 return;
141 } 142 }
142 RefPtr<JSONObject> resultObj = resultPair->getObject("result"); 143 RefPtr<JSONObject> resultObj = resultPair->getObject("result");
143 bool wasThrownVal = false; 144 bool wasThrownVal = false;
144 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { 145 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) {
145 *errorString = "Internal error: result is not a pair of value and wasThr own flag"; 146 *errorString = "Internal error: result is not a pair of value and wasThr own flag";
146 return; 147 return;
147 } 148 }
149 if (wasThrownVal) {
150 RefPtr<JSONObject> exceptionDetails = resultPair->getObject("exceptionDe tails");
vsevik 2014/07/15 16:14:33 Let's extract a method.
kozyatinskiy1 2014/07/16 13:15:47 Done.
151 if (objectExceptionDetails && exceptionDetails) {
152 String exceptionDetailsText;
153 if (exceptionDetails->getString("text", &exceptionDetailsText)) {
154 RefPtr<TypeBuilder::Debugger::ExceptionDetails> outputExceptionD etails = TypeBuilder::Debugger::ExceptionDetails::create().setText(exceptionDeta ilsText);
155 String url;
156 if (exceptionDetails->getString("url", &url))
157 outputExceptionDetails->setUrl(url);
158 int line = 0;
159 if (exceptionDetails->getNumber("line", &line))
160 outputExceptionDetails->setLine(line);
161 int column = 0;
162 if (exceptionDetails->getNumber("column", &column))
163 outputExceptionDetails->setColumn(column);
164 RefPtr<JSONArray> stackTrace = exceptionDetails->getArray("stack Trace");
165 if (stackTrace && stackTrace->length() > 0) {
166 RefPtr<TypeBuilder::Array<TypeBuilder::Console::CallFrame> > frames = TypeBuilder::Array<TypeBuilder::Console::CallFrame>::create();
167 for (unsigned i = 0; i < stackTrace->length(); ++i) {
168 RefPtr<JSONObject> stackFrame = stackTrace->get(i)->asOb ject();
169 int lineNumber = 0;
170 stackFrame->getNumber("lineNumber", &lineNumber);
171 int column = 0;
172 stackFrame->getNumber("column", &column);
173 int scriptId = 0;
174 stackFrame->getNumber("scriptId", &scriptId);
175 String sourceURL;
176 stackFrame->getString("scriptNameOrSourceURL", &sourceUR L);
177 String functionName;
178 stackFrame->getString("functionName", &functionName);
179
180 RefPtr<TypeBuilder::Console::CallFrame> callFrame = Type Builder::Console::CallFrame::create()
181 .setFunctionName(functionName)
182 .setScriptId(String::number(scriptId))
183 .setUrl(sourceURL)
184 .setLineNumber(lineNumber)
185 .setColumnNumber(column);
186
187 frames->addItem(callFrame);
188 }
189 outputExceptionDetails->setStackTrace(frames);
190 }
191 *objectExceptionDetails = outputExceptionDetails;
192 }
193 }
194 }
148 *objectResult = TypeBuilder::Runtime::RemoteObject::runtimeCast(resultObj); 195 *objectResult = TypeBuilder::Runtime::RemoteObject::runtimeCast(resultObj);
149 *wasThrown = wasThrownVal; 196 *wasThrown = wasThrownVal;
150 } 197 }
151 198
152 } // namespace WebCore 199 } // namespace WebCore
153 200
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698