| OLD | NEW |
| 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 Loading... |
| 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 |
| 47 static PassRefPtr<TypeBuilder::Debugger::ExceptionDetails> toExceptionDetails(Pa
ssRefPtr<JSONObject> object) |
| 48 { |
| 49 String text; |
| 50 if (!object->getString("text", &text)) |
| 51 return nullptr; |
| 52 |
| 53 RefPtr<TypeBuilder::Debugger::ExceptionDetails> exceptionDetails = TypeBuild
er::Debugger::ExceptionDetails::create().setText(text); |
| 54 String url; |
| 55 if (object->getString("url", &url)) |
| 56 exceptionDetails->setUrl(url); |
| 57 int line = 0; |
| 58 if (object->getNumber("line", &line)) |
| 59 exceptionDetails->setLine(line); |
| 60 int column = 0; |
| 61 if (object->getNumber("column", &column)) |
| 62 exceptionDetails->setColumn(column); |
| 63 RefPtr<JSONArray> stackTrace = object->getArray("stackTrace"); |
| 64 if (stackTrace && stackTrace->length() > 0) { |
| 65 RefPtr<TypeBuilder::Array<TypeBuilder::Console::CallFrame> > frames = Ty
peBuilder::Array<TypeBuilder::Console::CallFrame>::create(); |
| 66 for (unsigned i = 0; i < stackTrace->length(); ++i) { |
| 67 RefPtr<JSONObject> stackFrame = stackTrace->get(i)->asObject(); |
| 68 int lineNumber = 0; |
| 69 stackFrame->getNumber("lineNumber", &lineNumber); |
| 70 int column = 0; |
| 71 stackFrame->getNumber("column", &column); |
| 72 int scriptId = 0; |
| 73 stackFrame->getNumber("scriptId", &scriptId); |
| 74 String sourceURL; |
| 75 stackFrame->getString("scriptNameOrSourceURL", &sourceURL); |
| 76 String functionName; |
| 77 stackFrame->getString("functionName", &functionName); |
| 78 |
| 79 RefPtr<TypeBuilder::Console::CallFrame> callFrame = TypeBuilder::Con
sole::CallFrame::create() |
| 80 .setFunctionName(functionName) |
| 81 .setScriptId(String::number(scriptId)) |
| 82 .setUrl(sourceURL) |
| 83 .setLineNumber(lineNumber) |
| 84 .setColumnNumber(column); |
| 85 |
| 86 frames->addItem(callFrame.release()); |
| 87 } |
| 88 exceptionDetails->setStackTrace(frames.release()); |
| 89 } |
| 90 return exceptionDetails.release(); |
| 91 } |
| 92 |
| 46 InjectedScriptBase::InjectedScriptBase(const String& name) | 93 InjectedScriptBase::InjectedScriptBase(const String& name) |
| 47 : m_name(name) | 94 : m_name(name) |
| 48 , m_inspectedStateAccessCheck(0) | 95 , m_inspectedStateAccessCheck(0) |
| 49 { | 96 { |
| 50 } | 97 } |
| 51 | 98 |
| 52 InjectedScriptBase::InjectedScriptBase(const String& name, ScriptValue injectedS
criptObject, InspectedStateAccessCheck accessCheck) | 99 InjectedScriptBase::InjectedScriptBase(const String& name, ScriptValue injectedS
criptObject, InspectedStateAccessCheck accessCheck) |
| 53 : m_name(name) | 100 : m_name(name) |
| 54 , m_injectedScriptObject(injectedScriptObject) | 101 , m_injectedScriptObject(injectedScriptObject) |
| 55 , m_inspectedStateAccessCheck(accessCheck) | 102 , m_inspectedStateAccessCheck(accessCheck) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 ASSERT(!hadException); | 161 ASSERT(!hadException); |
| 115 if (!hadException) { | 162 if (!hadException) { |
| 116 *result = resultValue.toJSONValue(m_injectedScriptObject.scriptState()); | 163 *result = resultValue.toJSONValue(m_injectedScriptObject.scriptState()); |
| 117 if (!*result) | 164 if (!*result) |
| 118 *result = JSONString::create(String::format("Object has too long ref
erence chain(must not be longer than %d)", JSONValue::maxDepth)); | 165 *result = JSONString::create(String::format("Object has too long ref
erence chain(must not be longer than %d)", JSONValue::maxDepth)); |
| 119 } else { | 166 } else { |
| 120 *result = JSONString::create("Exception while making a call."); | 167 *result = JSONString::create("Exception while making a call."); |
| 121 } | 168 } |
| 122 } | 169 } |
| 123 | 170 |
| 124 void InjectedScriptBase::makeEvalCall(ErrorString* errorString, ScriptFunctionCa
ll& function, RefPtr<TypeBuilder::Runtime::RemoteObject>* objectResult, TypeBuil
der::OptOutput<bool>* wasThrown) | 171 void InjectedScriptBase::makeEvalCall(ErrorString* errorString, ScriptFunctionCa
ll& function, RefPtr<TypeBuilder::Runtime::RemoteObject>* objectResult, TypeBuil
der::OptOutput<bool>* wasThrown, RefPtr<TypeBuilder::Debugger::ExceptionDetails>
* exceptionDetails) |
| 125 { | 172 { |
| 126 RefPtr<JSONValue> result; | 173 RefPtr<JSONValue> result; |
| 127 makeCall(function, &result); | 174 makeCall(function, &result); |
| 128 if (!result) { | 175 if (!result) { |
| 129 *errorString = "Internal error: result value is empty"; | 176 *errorString = "Internal error: result value is empty"; |
| 130 return; | 177 return; |
| 131 } | 178 } |
| 132 if (result->type() == JSONValue::TypeString) { | 179 if (result->type() == JSONValue::TypeString) { |
| 133 result->asString(errorString); | 180 result->asString(errorString); |
| 134 ASSERT(errorString->length()); | 181 ASSERT(errorString->length()); |
| 135 return; | 182 return; |
| 136 } | 183 } |
| 137 RefPtr<JSONObject> resultPair = result->asObject(); | 184 RefPtr<JSONObject> resultPair = result->asObject(); |
| 138 if (!resultPair) { | 185 if (!resultPair) { |
| 139 *errorString = "Internal error: result is not an Object"; | 186 *errorString = "Internal error: result is not an Object"; |
| 140 return; | 187 return; |
| 141 } | 188 } |
| 142 RefPtr<JSONObject> resultObj = resultPair->getObject("result"); | 189 RefPtr<JSONObject> resultObj = resultPair->getObject("result"); |
| 143 bool wasThrownVal = false; | 190 bool wasThrownVal = false; |
| 144 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { | 191 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { |
| 145 *errorString = "Internal error: result is not a pair of value and wasThr
own flag"; | 192 *errorString = "Internal error: result is not a pair of value and wasThr
own flag"; |
| 146 return; | 193 return; |
| 147 } | 194 } |
| 195 if (wasThrownVal) { |
| 196 RefPtr<JSONObject> objectExceptionDetails = resultPair->getObject("excep
tionDetails"); |
| 197 if (objectExceptionDetails) |
| 198 *exceptionDetails = toExceptionDetails(objectExceptionDetails.releas
e()); |
| 199 } |
| 148 *objectResult = TypeBuilder::Runtime::RemoteObject::runtimeCast(resultObj); | 200 *objectResult = TypeBuilder::Runtime::RemoteObject::runtimeCast(resultObj); |
| 149 *wasThrown = wasThrownVal; | 201 *wasThrown = wasThrownVal; |
| 150 } | 202 } |
| 151 | 203 |
| 152 } // namespace WebCore | 204 } // namespace WebCore |
| 153 | 205 |
| OLD | NEW |