| 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 12 matching lines...) Expand all Loading... |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "platform/v8_inspector/InjectedScript.h" | 31 #include "platform/v8_inspector/InjectedScript.h" |
| 32 | 32 |
| 33 #include "platform/JSONParser.h" | 33 #include "platform/inspector_protocol/Parser.h" |
| 34 #include "platform/JSONValues.h" | 34 #include "platform/inspector_protocol/Values.h" |
| 35 #include "platform/JSONValuesForV8.h" | |
| 36 #include "platform/v8_inspector/InjectedScriptHost.h" | 35 #include "platform/v8_inspector/InjectedScriptHost.h" |
| 37 #include "platform/v8_inspector/InjectedScriptManager.h" | 36 #include "platform/v8_inspector/InjectedScriptManager.h" |
| 38 #include "platform/v8_inspector/RemoteObjectId.h" | 37 #include "platform/v8_inspector/RemoteObjectId.h" |
| 39 #include "platform/v8_inspector/V8FunctionCall.h" | 38 #include "platform/v8_inspector/V8FunctionCall.h" |
| 40 #include "platform/v8_inspector/V8StringUtil.h" | 39 #include "platform/v8_inspector/V8StringUtil.h" |
| 41 #include "platform/v8_inspector/public/V8Debugger.h" | 40 #include "platform/v8_inspector/public/V8Debugger.h" |
| 42 #include "platform/v8_inspector/public/V8DebuggerClient.h" | 41 #include "platform/v8_inspector/public/V8DebuggerClient.h" |
| 42 #include "platform/v8_inspector/public/V8ToProtocolValue.h" |
| 43 #include "wtf/text/WTFString.h" | 43 #include "wtf/text/WTFString.h" |
| 44 | 44 |
| 45 using blink::protocol::Array; | 45 using blink::protocol::Array; |
| 46 using blink::protocol::Debugger::CallFrame; | 46 using blink::protocol::Debugger::CallFrame; |
| 47 using blink::protocol::Debugger::CollectionEntry; | 47 using blink::protocol::Debugger::CollectionEntry; |
| 48 using blink::protocol::Debugger::FunctionDetails; | 48 using blink::protocol::Debugger::FunctionDetails; |
| 49 using blink::protocol::Debugger::GeneratorObjectDetails; | 49 using blink::protocol::Debugger::GeneratorObjectDetails; |
| 50 using blink::protocol::Runtime::PropertyDescriptor; | 50 using blink::protocol::Runtime::PropertyDescriptor; |
| 51 using blink::protocol::Runtime::InternalPropertyDescriptor; | 51 using blink::protocol::Runtime::InternalPropertyDescriptor; |
| 52 using blink::protocol::Runtime::RemoteObject; | 52 using blink::protocol::Runtime::RemoteObject; |
| 53 using blink::protocol::Maybe; | 53 using blink::protocol::Maybe; |
| 54 | 54 |
| 55 namespace blink { | 55 namespace blink { |
| 56 | 56 |
| 57 static PassOwnPtr<protocol::Runtime::ExceptionDetails> toExceptionDetails(PassRe
fPtr<JSONObject> object) | 57 static PassOwnPtr<protocol::Runtime::ExceptionDetails> toExceptionDetails(PassRe
fPtr<protocol::DictionaryValue> object) |
| 58 { | 58 { |
| 59 String text; | 59 String text; |
| 60 if (!object->getString("text", &text)) | 60 if (!object->getString("text", &text)) |
| 61 return nullptr; | 61 return nullptr; |
| 62 | 62 |
| 63 OwnPtr<protocol::Runtime::ExceptionDetails> exceptionDetails = protocol::Run
time::ExceptionDetails::create().setText(text).build(); | 63 OwnPtr<protocol::Runtime::ExceptionDetails> exceptionDetails = protocol::Run
time::ExceptionDetails::create().setText(text).build(); |
| 64 String url; | 64 String url; |
| 65 if (object->getString("url", &url)) | 65 if (object->getString("url", &url)) |
| 66 exceptionDetails->setUrl(url); | 66 exceptionDetails->setUrl(url); |
| 67 int line = 0; | 67 int line = 0; |
| 68 if (object->getNumber("line", &line)) | 68 if (object->getNumber("line", &line)) |
| 69 exceptionDetails->setLine(line); | 69 exceptionDetails->setLine(line); |
| 70 int column = 0; | 70 int column = 0; |
| 71 if (object->getNumber("column", &column)) | 71 if (object->getNumber("column", &column)) |
| 72 exceptionDetails->setColumn(column); | 72 exceptionDetails->setColumn(column); |
| 73 int originScriptId = 0; | 73 int originScriptId = 0; |
| 74 object->getNumber("scriptId", &originScriptId); | 74 object->getNumber("scriptId", &originScriptId); |
| 75 | 75 |
| 76 RefPtr<JSONArray> stackTrace = object->getArray("stackTrace"); | 76 RefPtr<protocol::ListValue> stackTrace = object->getArray("stackTrace"); |
| 77 if (stackTrace && stackTrace->length() > 0) { | 77 if (stackTrace && stackTrace->length() > 0) { |
| 78 OwnPtr<protocol::Array<protocol::Runtime::CallFrame>> frames = protocol:
:Array<protocol::Runtime::CallFrame>::create(); | 78 OwnPtr<protocol::Array<protocol::Runtime::CallFrame>> frames = protocol:
:Array<protocol::Runtime::CallFrame>::create(); |
| 79 for (unsigned i = 0; i < stackTrace->length(); ++i) { | 79 for (unsigned i = 0; i < stackTrace->length(); ++i) { |
| 80 RefPtr<JSONObject> stackFrame = JSONObject::cast(stackTrace->get(i))
; | 80 RefPtr<protocol::DictionaryValue> stackFrame = protocol::DictionaryV
alue::cast(stackTrace->get(i)); |
| 81 int lineNumber = 0; | 81 int lineNumber = 0; |
| 82 stackFrame->getNumber("lineNumber", &lineNumber); | 82 stackFrame->getNumber("lineNumber", &lineNumber); |
| 83 int column = 0; | 83 int column = 0; |
| 84 stackFrame->getNumber("column", &column); | 84 stackFrame->getNumber("column", &column); |
| 85 int scriptId = 0; | 85 int scriptId = 0; |
| 86 stackFrame->getNumber("scriptId", &scriptId); | 86 stackFrame->getNumber("scriptId", &scriptId); |
| 87 if (i == 0 && scriptId == originScriptId) | 87 if (i == 0 && scriptId == originScriptId) |
| 88 originScriptId = 0; | 88 originScriptId = 0; |
| 89 | 89 |
| 90 String sourceURL; | 90 String sourceURL; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 function.appendArgument(generatePreview); | 169 function.appendArgument(generatePreview); |
| 170 makeEvalCall(errorString, function, result, wasThrown, exceptionDetails); | 170 makeEvalCall(errorString, function, result, wasThrown, exceptionDetails); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void InjectedScript::restartFrame(ErrorString* errorString, v8::Local<v8::Object
> callFrames, const String& callFrameId) | 173 void InjectedScript::restartFrame(ErrorString* errorString, v8::Local<v8::Object
> callFrames, const String& callFrameId) |
| 174 { | 174 { |
| 175 v8::HandleScope handles(m_isolate); | 175 v8::HandleScope handles(m_isolate); |
| 176 V8FunctionCall function(m_client, context(), v8Value(), "restartFrame"); | 176 V8FunctionCall function(m_client, context(), v8Value(), "restartFrame"); |
| 177 function.appendArgument(callFrames); | 177 function.appendArgument(callFrames); |
| 178 function.appendArgument(callFrameId); | 178 function.appendArgument(callFrameId); |
| 179 RefPtr<JSONValue> resultValue; | 179 RefPtr<protocol::Value> resultValue; |
| 180 makeCall(function, &resultValue); | 180 makeCall(function, &resultValue); |
| 181 if (resultValue) { | 181 if (resultValue) { |
| 182 if (resultValue->type() == JSONValue::TypeString) { | 182 if (resultValue->type() == protocol::Value::TypeString) { |
| 183 resultValue->asString(errorString); | 183 resultValue->asString(errorString); |
| 184 } else { | 184 } else { |
| 185 bool value; | 185 bool value; |
| 186 ASSERT_UNUSED(value, resultValue->asBoolean(&value) && value); | 186 ASSERT_UNUSED(value, resultValue->asBoolean(&value) && value); |
| 187 } | 187 } |
| 188 return; | 188 return; |
| 189 } | 189 } |
| 190 *errorString = "Internal error"; | 190 *errorString = "Internal error"; |
| 191 } | 191 } |
| 192 | 192 |
| 193 void InjectedScript::getStepInPositions(ErrorString* errorString, v8::Local<v8::
Object> callFrames, const String& callFrameId, Maybe<Array<protocol::Debugger::L
ocation>>* positions) | 193 void InjectedScript::getStepInPositions(ErrorString* errorString, v8::Local<v8::
Object> callFrames, const String& callFrameId, Maybe<Array<protocol::Debugger::L
ocation>>* positions) |
| 194 { | 194 { |
| 195 v8::HandleScope handles(m_isolate); | 195 v8::HandleScope handles(m_isolate); |
| 196 V8FunctionCall function(m_client, context(), v8Value(), "getStepInPositions"
); | 196 V8FunctionCall function(m_client, context(), v8Value(), "getStepInPositions"
); |
| 197 function.appendArgument(callFrames); | 197 function.appendArgument(callFrames); |
| 198 function.appendArgument(callFrameId); | 198 function.appendArgument(callFrameId); |
| 199 RefPtr<JSONValue> resultValue; | 199 RefPtr<protocol::Value> resultValue; |
| 200 makeCall(function, &resultValue); | 200 makeCall(function, &resultValue); |
| 201 if (resultValue) { | 201 if (resultValue) { |
| 202 if (resultValue->type() == JSONValue::TypeString) { | 202 if (resultValue->type() == protocol::Value::TypeString) { |
| 203 resultValue->asString(errorString); | 203 resultValue->asString(errorString); |
| 204 return; | 204 return; |
| 205 } | 205 } |
| 206 if (resultValue->type() == JSONValue::TypeArray) { | 206 if (resultValue->type() == protocol::Value::TypeArray) { |
| 207 protocol::ErrorSupport errors(errorString); | 207 protocol::ErrorSupport errors(errorString); |
| 208 *positions = Array<protocol::Debugger::Location>::parse(resultValue.
release(), &errors); | 208 *positions = Array<protocol::Debugger::Location>::parse(resultValue.
release(), &errors); |
| 209 return; | 209 return; |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 *errorString = "Internal error"; | 212 *errorString = "Internal error"; |
| 213 } | 213 } |
| 214 | 214 |
| 215 void InjectedScript::setVariableValue(ErrorString* errorString, | 215 void InjectedScript::setVariableValue(ErrorString* errorString, |
| 216 v8::Local<v8::Object> callFrames, | 216 v8::Local<v8::Object> callFrames, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 229 function.appendArgument(false); | 229 function.appendArgument(false); |
| 230 function.appendArgument(false); | 230 function.appendArgument(false); |
| 231 } | 231 } |
| 232 if (functionObjectIdOpt.isJust()) | 232 if (functionObjectIdOpt.isJust()) |
| 233 function.appendArgument(functionObjectIdOpt.fromJust()); | 233 function.appendArgument(functionObjectIdOpt.fromJust()); |
| 234 else | 234 else |
| 235 function.appendArgument(false); | 235 function.appendArgument(false); |
| 236 function.appendArgument(scopeNumber); | 236 function.appendArgument(scopeNumber); |
| 237 function.appendArgument(variableName); | 237 function.appendArgument(variableName); |
| 238 function.appendArgument(newValueStr); | 238 function.appendArgument(newValueStr); |
| 239 RefPtr<JSONValue> resultValue; | 239 RefPtr<protocol::Value> resultValue; |
| 240 makeCall(function, &resultValue); | 240 makeCall(function, &resultValue); |
| 241 if (!resultValue) { | 241 if (!resultValue) { |
| 242 *errorString = "Internal error"; | 242 *errorString = "Internal error"; |
| 243 return; | 243 return; |
| 244 } | 244 } |
| 245 if (resultValue->type() == JSONValue::TypeString) { | 245 if (resultValue->type() == protocol::Value::TypeString) { |
| 246 resultValue->asString(errorString); | 246 resultValue->asString(errorString); |
| 247 return; | 247 return; |
| 248 } | 248 } |
| 249 // Normal return. | 249 // Normal return. |
| 250 } | 250 } |
| 251 | 251 |
| 252 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String&
functionId, OwnPtr<FunctionDetails>* result) | 252 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String&
functionId, OwnPtr<FunctionDetails>* result) |
| 253 { | 253 { |
| 254 v8::HandleScope handles(m_isolate); | 254 v8::HandleScope handles(m_isolate); |
| 255 V8FunctionCall function(m_client, context(), v8Value(), "getFunctionDetails"
); | 255 V8FunctionCall function(m_client, context(), v8Value(), "getFunctionDetails"
); |
| 256 function.appendArgument(functionId); | 256 function.appendArgument(functionId); |
| 257 RefPtr<JSONValue> resultValue; | 257 RefPtr<protocol::Value> resultValue; |
| 258 makeCall(function, &resultValue); | 258 makeCall(function, &resultValue); |
| 259 protocol::ErrorSupport errors(errorString); | 259 protocol::ErrorSupport errors(errorString); |
| 260 *result = FunctionDetails::parse(resultValue, &errors); | 260 *result = FunctionDetails::parse(resultValue, &errors); |
| 261 } | 261 } |
| 262 | 262 |
| 263 void InjectedScript::getGeneratorObjectDetails(ErrorString* errorString, const S
tring& objectId, OwnPtr<GeneratorObjectDetails>* result) | 263 void InjectedScript::getGeneratorObjectDetails(ErrorString* errorString, const S
tring& objectId, OwnPtr<GeneratorObjectDetails>* result) |
| 264 { | 264 { |
| 265 v8::HandleScope handles(m_isolate); | 265 v8::HandleScope handles(m_isolate); |
| 266 V8FunctionCall function(m_client, context(), v8Value(), "getGeneratorObjectD
etails"); | 266 V8FunctionCall function(m_client, context(), v8Value(), "getGeneratorObjectD
etails"); |
| 267 function.appendArgument(objectId); | 267 function.appendArgument(objectId); |
| 268 RefPtr<JSONValue> resultValue; | 268 RefPtr<protocol::Value> resultValue; |
| 269 makeCall(function, &resultValue); | 269 makeCall(function, &resultValue); |
| 270 protocol::ErrorSupport errors(errorString); | 270 protocol::ErrorSupport errors(errorString); |
| 271 *result = GeneratorObjectDetails::parse(resultValue, &errors); | 271 *result = GeneratorObjectDetails::parse(resultValue, &errors); |
| 272 } | 272 } |
| 273 | 273 |
| 274 void InjectedScript::getCollectionEntries(ErrorString* errorString, const String
& objectId, OwnPtr<Array<CollectionEntry>>* result) | 274 void InjectedScript::getCollectionEntries(ErrorString* errorString, const String
& objectId, OwnPtr<Array<CollectionEntry>>* result) |
| 275 { | 275 { |
| 276 v8::HandleScope handles(m_isolate); | 276 v8::HandleScope handles(m_isolate); |
| 277 V8FunctionCall function(m_client, context(), v8Value(), "getCollectionEntrie
s"); | 277 V8FunctionCall function(m_client, context(), v8Value(), "getCollectionEntrie
s"); |
| 278 function.appendArgument(objectId); | 278 function.appendArgument(objectId); |
| 279 RefPtr<JSONValue> resultValue; | 279 RefPtr<protocol::Value> resultValue; |
| 280 makeCall(function, &resultValue); | 280 makeCall(function, &resultValue); |
| 281 protocol::ErrorSupport errors(errorString); | 281 protocol::ErrorSupport errors(errorString); |
| 282 *result = Array<CollectionEntry>::parse(resultValue, &errors); | 282 *result = Array<CollectionEntry>::parse(resultValue, &errors); |
| 283 } | 283 } |
| 284 | 284 |
| 285 void InjectedScript::getProperties(ErrorString* errorString, const String& objec
tId, bool ownProperties, bool accessorPropertiesOnly, bool generatePreview, OwnP
tr<Array<PropertyDescriptor>>* properties, Maybe<protocol::Runtime::ExceptionDet
ails>* exceptionDetails) | 285 void InjectedScript::getProperties(ErrorString* errorString, const String& objec
tId, bool ownProperties, bool accessorPropertiesOnly, bool generatePreview, OwnP
tr<Array<PropertyDescriptor>>* properties, Maybe<protocol::Runtime::ExceptionDet
ails>* exceptionDetails) |
| 286 { | 286 { |
| 287 v8::HandleScope handles(m_isolate); | 287 v8::HandleScope handles(m_isolate); |
| 288 V8FunctionCall function(m_client, context(), v8Value(), "getProperties"); | 288 V8FunctionCall function(m_client, context(), v8Value(), "getProperties"); |
| 289 function.appendArgument(objectId); | 289 function.appendArgument(objectId); |
| 290 function.appendArgument(ownProperties); | 290 function.appendArgument(ownProperties); |
| 291 function.appendArgument(accessorPropertiesOnly); | 291 function.appendArgument(accessorPropertiesOnly); |
| 292 function.appendArgument(generatePreview); | 292 function.appendArgument(generatePreview); |
| 293 | 293 |
| 294 RefPtr<JSONValue> result; | 294 RefPtr<protocol::Value> result; |
| 295 makeCallWithExceptionDetails(function, &result, exceptionDetails); | 295 makeCallWithExceptionDetails(function, &result, exceptionDetails); |
| 296 if (exceptionDetails->isJust()) { | 296 if (exceptionDetails->isJust()) { |
| 297 // FIXME: make properties optional | 297 // FIXME: make properties optional |
| 298 *properties = Array<PropertyDescriptor>::create(); | 298 *properties = Array<PropertyDescriptor>::create(); |
| 299 return; | 299 return; |
| 300 } | 300 } |
| 301 protocol::ErrorSupport errors(errorString); | 301 protocol::ErrorSupport errors(errorString); |
| 302 *properties = Array<PropertyDescriptor>::parse(result.release(), &errors); | 302 *properties = Array<PropertyDescriptor>::parse(result.release(), &errors); |
| 303 } | 303 } |
| 304 | 304 |
| 305 void InjectedScript::getInternalProperties(ErrorString* errorString, const Strin
g& objectId, Maybe<Array<InternalPropertyDescriptor>>* properties, Maybe<protoco
l::Runtime::ExceptionDetails>* exceptionDetails) | 305 void InjectedScript::getInternalProperties(ErrorString* errorString, const Strin
g& objectId, Maybe<Array<InternalPropertyDescriptor>>* properties, Maybe<protoco
l::Runtime::ExceptionDetails>* exceptionDetails) |
| 306 { | 306 { |
| 307 v8::HandleScope handles(m_isolate); | 307 v8::HandleScope handles(m_isolate); |
| 308 V8FunctionCall function(m_client, context(), v8Value(), "getInternalProperti
es"); | 308 V8FunctionCall function(m_client, context(), v8Value(), "getInternalProperti
es"); |
| 309 function.appendArgument(objectId); | 309 function.appendArgument(objectId); |
| 310 | 310 |
| 311 RefPtr<JSONValue> result; | 311 RefPtr<protocol::Value> result; |
| 312 makeCallWithExceptionDetails(function, &result, exceptionDetails); | 312 makeCallWithExceptionDetails(function, &result, exceptionDetails); |
| 313 if (exceptionDetails->isJust()) | 313 if (exceptionDetails->isJust()) |
| 314 return; | 314 return; |
| 315 protocol::ErrorSupport errors(errorString); | 315 protocol::ErrorSupport errors(errorString); |
| 316 OwnPtr<Array<InternalPropertyDescriptor>> array = Array<InternalPropertyDesc
riptor>::parse(result.release(), &errors); | 316 OwnPtr<Array<InternalPropertyDescriptor>> array = Array<InternalPropertyDesc
riptor>::parse(result.release(), &errors); |
| 317 if (!errors.hasErrors() && array->length() > 0) | 317 if (!errors.hasErrors() && array->length() > 0) |
| 318 *properties = array.release(); | 318 *properties = array.release(); |
| 319 } | 319 } |
| 320 | 320 |
| 321 void InjectedScript::releaseObject(const String& objectId) | 321 void InjectedScript::releaseObject(const String& objectId) |
| 322 { | 322 { |
| 323 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId); | 323 RefPtr<protocol::Value> parsedObjectId = protocol::parseJSON(objectId); |
| 324 if (!parsedObjectId) | 324 if (!parsedObjectId) |
| 325 return; | 325 return; |
| 326 RefPtr<JSONObject> object = JSONObject::cast(parsedObjectId); | 326 RefPtr<protocol::DictionaryValue> object = protocol::DictionaryValue::cast(p
arsedObjectId); |
| 327 if (!object) | 327 if (!object) |
| 328 return; | 328 return; |
| 329 int boundId = 0; | 329 int boundId = 0; |
| 330 if (!object->getNumber("id", &boundId)) | 330 if (!object->getNumber("id", &boundId)) |
| 331 return; | 331 return; |
| 332 m_native->unbind(boundId); | 332 m_native->unbind(boundId); |
| 333 } | 333 } |
| 334 | 334 |
| 335 v8::MaybeLocal<v8::Value> InjectedScript::runCompiledScript(v8::Local<v8::Script
> script, bool includeCommandLineAPI) | 335 v8::MaybeLocal<v8::Value> InjectedScript::runCompiledScript(v8::Local<v8::Script
> script, bool includeCommandLineAPI) |
| 336 { | 336 { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 353 | 353 |
| 354 PassOwnPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object
> callFrames, int asyncOrdinal) | 354 PassOwnPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object
> callFrames, int asyncOrdinal) |
| 355 { | 355 { |
| 356 v8::HandleScope handles(m_isolate); | 356 v8::HandleScope handles(m_isolate); |
| 357 V8FunctionCall function(m_client, context(), v8Value(), "wrapCallFrames"); | 357 V8FunctionCall function(m_client, context(), v8Value(), "wrapCallFrames"); |
| 358 function.appendArgument(callFrames); | 358 function.appendArgument(callFrames); |
| 359 function.appendArgument(asyncOrdinal); | 359 function.appendArgument(asyncOrdinal); |
| 360 bool hadException = false; | 360 bool hadException = false; |
| 361 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function,
hadException); | 361 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function,
hadException); |
| 362 ASSERT(!hadException); | 362 ASSERT(!hadException); |
| 363 RefPtr<JSONValue> result = toJSONValue(context(), callFramesValue); | 363 RefPtr<protocol::Value> result = toProtocolValue(context(), callFramesValue)
; |
| 364 protocol::ErrorSupport errors; | 364 protocol::ErrorSupport errors; |
| 365 if (result && result->type() == JSONValue::TypeArray) | 365 if (result && result->type() == protocol::Value::TypeArray) |
| 366 return Array<CallFrame>::parse(result.release(), &errors); | 366 return Array<CallFrame>::parse(result.release(), &errors); |
| 367 return Array<CallFrame>::create(); | 367 return Array<CallFrame>::create(); |
| 368 } | 368 } |
| 369 | 369 |
| 370 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(v8::Local
<v8::Value> value, const String& groupName, bool generatePreview) const | 370 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(v8::Local
<v8::Value> value, const String& groupName, bool generatePreview) const |
| 371 { | 371 { |
| 372 v8::HandleScope handles(m_isolate); | 372 v8::HandleScope handles(m_isolate); |
| 373 V8FunctionCall function(m_client, context(), v8Value(), "wrapObject"); | 373 V8FunctionCall function(m_client, context(), v8Value(), "wrapObject"); |
| 374 function.appendArgument(value); | 374 function.appendArgument(value); |
| 375 function.appendArgument(groupName); | 375 function.appendArgument(groupName); |
| 376 function.appendArgument(canAccessInspectedWindow()); | 376 function.appendArgument(canAccessInspectedWindow()); |
| 377 function.appendArgument(generatePreview); | 377 function.appendArgument(generatePreview); |
| 378 bool hadException = false; | 378 bool hadException = false; |
| 379 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException)
; | 379 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException)
; |
| 380 if (hadException) | 380 if (hadException) |
| 381 return nullptr; | 381 return nullptr; |
| 382 protocol::ErrorSupport errors; | 382 protocol::ErrorSupport errors; |
| 383 return protocol::Runtime::RemoteObject::parse(toJSONValue(context(), r), &er
rors); | 383 return protocol::Runtime::RemoteObject::parse(toProtocolValue(context(), r),
&errors); |
| 384 } | 384 } |
| 385 | 385 |
| 386 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Local<
v8::Value> table, v8::Local<v8::Value> columns) const | 386 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Local<
v8::Value> table, v8::Local<v8::Value> columns) const |
| 387 { | 387 { |
| 388 v8::HandleScope handles(m_isolate); | 388 v8::HandleScope handles(m_isolate); |
| 389 V8FunctionCall function(m_client, context(), v8Value(), "wrapTable"); | 389 V8FunctionCall function(m_client, context(), v8Value(), "wrapTable"); |
| 390 function.appendArgument(canAccessInspectedWindow()); | 390 function.appendArgument(canAccessInspectedWindow()); |
| 391 function.appendArgument(table); | 391 function.appendArgument(table); |
| 392 if (columns.IsEmpty()) | 392 if (columns.IsEmpty()) |
| 393 function.appendArgument(false); | 393 function.appendArgument(false); |
| 394 else | 394 else |
| 395 function.appendArgument(columns); | 395 function.appendArgument(columns); |
| 396 bool hadException = false; | 396 bool hadException = false; |
| 397 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException
); | 397 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException
); |
| 398 if (hadException) | 398 if (hadException) |
| 399 return nullptr; | 399 return nullptr; |
| 400 protocol::ErrorSupport errors; | 400 protocol::ErrorSupport errors; |
| 401 return protocol::Runtime::RemoteObject::parse(toJSONValue(context(), r), &er
rors); | 401 return protocol::Runtime::RemoteObject::parse(toProtocolValue(context(), r),
&errors); |
| 402 } | 402 } |
| 403 | 403 |
| 404 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId)
const | 404 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId)
const |
| 405 { | 405 { |
| 406 return m_native->objectForId(objectId.id()); | 406 return m_native->objectForId(objectId.id()); |
| 407 } | 407 } |
| 408 | 408 |
| 409 String InjectedScript::objectGroupName(const RemoteObjectId& objectId) const | 409 String InjectedScript::objectGroupName(const RemoteObjectId& objectId) const |
| 410 { | 410 { |
| 411 return m_native->groupName(objectId.id()); | 411 return m_native->groupName(objectId.id()); |
| 412 } | 412 } |
| 413 | 413 |
| 414 void InjectedScript::releaseObjectGroup(const String& objectGroup) | 414 void InjectedScript::releaseObjectGroup(const String& objectGroup) |
| 415 { | 415 { |
| 416 v8::HandleScope handles(m_isolate); | 416 v8::HandleScope handles(m_isolate); |
| 417 m_native->releaseObjectGroup(objectGroup); | 417 m_native->releaseObjectGroup(objectGroup); |
| 418 if (objectGroup == "console") { | 418 if (objectGroup == "console") { |
| 419 V8FunctionCall function(m_client, context(), v8Value(), "clearLastEvalua
tionResult"); | 419 V8FunctionCall function(m_client, context(), v8Value(), "clearLastEvalua
tionResult"); |
| 420 bool hadException = false; | 420 bool hadException = false; |
| 421 callFunctionWithEvalEnabled(function, hadException); | 421 callFunctionWithEvalEnabled(function, hadException); |
| 422 ASSERT(!hadException); | 422 ASSERT(!hadException); |
| 423 } | 423 } |
| 424 } | 424 } |
| 425 | 425 |
| 426 void InjectedScript::setCustomObjectFormatterEnabled(bool enabled) | 426 void InjectedScript::setCustomObjectFormatterEnabled(bool enabled) |
| 427 { | 427 { |
| 428 v8::HandleScope handles(m_isolate); | 428 v8::HandleScope handles(m_isolate); |
| 429 V8FunctionCall function(m_client, context(), v8Value(), "setCustomObjectForm
atterEnabled"); | 429 V8FunctionCall function(m_client, context(), v8Value(), "setCustomObjectForm
atterEnabled"); |
| 430 function.appendArgument(enabled); | 430 function.appendArgument(enabled); |
| 431 RefPtr<JSONValue> result; | 431 RefPtr<protocol::Value> result; |
| 432 makeCall(function, &result); | 432 makeCall(function, &result); |
| 433 } | 433 } |
| 434 | 434 |
| 435 bool InjectedScript::canAccessInspectedWindow() const | 435 bool InjectedScript::canAccessInspectedWindow() const |
| 436 { | 436 { |
| 437 v8::Local<v8::Context> callingContext = m_isolate->GetCallingContext(); | 437 v8::Local<v8::Context> callingContext = m_isolate->GetCallingContext(); |
| 438 if (callingContext.IsEmpty()) | 438 if (callingContext.IsEmpty()) |
| 439 return true; | 439 return true; |
| 440 return m_client->callingContextCanAccessContext(callingContext, context()); | 440 return m_client->callingContextCanAccessContext(callingContext, context()); |
| 441 } | 441 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 457 bool evalIsDisabled = !localContext->IsCodeGenerationFromStringsAllowed(); | 457 bool evalIsDisabled = !localContext->IsCodeGenerationFromStringsAllowed(); |
| 458 // Temporarily enable allow evals for inspector. | 458 // Temporarily enable allow evals for inspector. |
| 459 if (evalIsDisabled) | 459 if (evalIsDisabled) |
| 460 localContext->AllowCodeGenerationFromStrings(true); | 460 localContext->AllowCodeGenerationFromStrings(true); |
| 461 v8::Local<v8::Value> resultValue = function.call(hadException); | 461 v8::Local<v8::Value> resultValue = function.call(hadException); |
| 462 if (evalIsDisabled) | 462 if (evalIsDisabled) |
| 463 localContext->AllowCodeGenerationFromStrings(false); | 463 localContext->AllowCodeGenerationFromStrings(false); |
| 464 return resultValue; | 464 return resultValue; |
| 465 } | 465 } |
| 466 | 466 |
| 467 void InjectedScript::makeCall(V8FunctionCall& function, RefPtr<JSONValue>* resul
t) | 467 void InjectedScript::makeCall(V8FunctionCall& function, RefPtr<protocol::Value>*
result) |
| 468 { | 468 { |
| 469 if (!canAccessInspectedWindow()) { | 469 if (!canAccessInspectedWindow()) { |
| 470 *result = JSONString::create("Can not access given context."); | 470 *result = protocol::StringValue::create("Can not access given context.")
; |
| 471 return; | 471 return; |
| 472 } | 472 } |
| 473 | 473 |
| 474 bool hadException = false; | 474 bool hadException = false; |
| 475 v8::Local<v8::Value> resultValue = callFunctionWithEvalEnabled(function, had
Exception); | 475 v8::Local<v8::Value> resultValue = callFunctionWithEvalEnabled(function, had
Exception); |
| 476 | 476 |
| 477 ASSERT(!hadException); | 477 ASSERT(!hadException); |
| 478 if (!hadException) { | 478 if (!hadException) { |
| 479 *result = toJSONValue(function.context(), resultValue); | 479 *result = toProtocolValue(function.context(), resultValue); |
| 480 if (!*result) | 480 if (!*result) |
| 481 *result = JSONString::create(String::format("Object has too long ref
erence chain(must not be longer than %d)", JSONValue::maxDepth)); | 481 *result = protocol::StringValue::create(String::format("Object has t
oo long reference chain(must not be longer than %d)", protocol::Value::maxDepth)
); |
| 482 } else { | 482 } else { |
| 483 *result = JSONString::create("Exception while making a call."); | 483 *result = protocol::StringValue::create("Exception while making a call."
); |
| 484 } | 484 } |
| 485 } | 485 } |
| 486 | 486 |
| 487 void InjectedScript::makeEvalCall(ErrorString* errorString, V8FunctionCall& func
tion, OwnPtr<protocol::Runtime::RemoteObject>* objectResult, Maybe<bool>* wasThr
own, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) | 487 void InjectedScript::makeEvalCall(ErrorString* errorString, V8FunctionCall& func
tion, OwnPtr<protocol::Runtime::RemoteObject>* objectResult, Maybe<bool>* wasThr
own, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) |
| 488 { | 488 { |
| 489 RefPtr<JSONValue> result; | 489 RefPtr<protocol::Value> result; |
| 490 makeCall(function, &result); | 490 makeCall(function, &result); |
| 491 if (!result) { | 491 if (!result) { |
| 492 *errorString = "Internal error: result value is empty"; | 492 *errorString = "Internal error: result value is empty"; |
| 493 return; | 493 return; |
| 494 } | 494 } |
| 495 if (result->type() == JSONValue::TypeString) { | 495 if (result->type() == protocol::Value::TypeString) { |
| 496 result->asString(errorString); | 496 result->asString(errorString); |
| 497 ASSERT(errorString->length()); | 497 ASSERT(errorString->length()); |
| 498 return; | 498 return; |
| 499 } | 499 } |
| 500 RefPtr<JSONObject> resultPair = JSONObject::cast(result); | 500 RefPtr<protocol::DictionaryValue> resultPair = protocol::DictionaryValue::ca
st(result); |
| 501 if (!resultPair) { | 501 if (!resultPair) { |
| 502 *errorString = "Internal error: result is not an Object"; | 502 *errorString = "Internal error: result is not an Object"; |
| 503 return; | 503 return; |
| 504 } | 504 } |
| 505 RefPtr<JSONObject> resultObj = resultPair->getObject("result"); | 505 RefPtr<protocol::DictionaryValue> resultObj = resultPair->getObject("result"
); |
| 506 bool wasThrownVal = false; | 506 bool wasThrownVal = false; |
| 507 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { | 507 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { |
| 508 *errorString = "Internal error: result is not a pair of value and wasThr
own flag"; | 508 *errorString = "Internal error: result is not a pair of value and wasThr
own flag"; |
| 509 return; | 509 return; |
| 510 } | 510 } |
| 511 if (wasThrownVal) { | 511 if (wasThrownVal) { |
| 512 RefPtr<JSONObject> objectExceptionDetails = resultPair->getObject("excep
tionDetails"); | 512 RefPtr<protocol::DictionaryValue> objectExceptionDetails = resultPair->g
etObject("exceptionDetails"); |
| 513 if (objectExceptionDetails) | 513 if (objectExceptionDetails) |
| 514 *exceptionDetails = toExceptionDetails(objectExceptionDetails.releas
e()); | 514 *exceptionDetails = toExceptionDetails(objectExceptionDetails.releas
e()); |
| 515 } | 515 } |
| 516 protocol::ErrorSupport errors(errorString); | 516 protocol::ErrorSupport errors(errorString); |
| 517 *objectResult = protocol::Runtime::RemoteObject::parse(resultObj, &errors); | 517 *objectResult = protocol::Runtime::RemoteObject::parse(resultObj, &errors); |
| 518 *wasThrown = wasThrownVal; | 518 *wasThrown = wasThrownVal; |
| 519 } | 519 } |
| 520 | 520 |
| 521 void InjectedScript::makeCallWithExceptionDetails(V8FunctionCall& function, RefP
tr<JSONValue>* result, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDeta
ils) | 521 void InjectedScript::makeCallWithExceptionDetails(V8FunctionCall& function, RefP
tr<protocol::Value>* result, Maybe<protocol::Runtime::ExceptionDetails>* excepti
onDetails) |
| 522 { | 522 { |
| 523 v8::HandleScope handles(m_isolate); | 523 v8::HandleScope handles(m_isolate); |
| 524 v8::Context::Scope scope(context()); | 524 v8::Context::Scope scope(context()); |
| 525 v8::TryCatch tryCatch(m_isolate); | 525 v8::TryCatch tryCatch(m_isolate); |
| 526 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); | 526 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); |
| 527 if (tryCatch.HasCaught()) { | 527 if (tryCatch.HasCaught()) { |
| 528 v8::Local<v8::Message> message = tryCatch.Message(); | 528 v8::Local<v8::Message> message = tryCatch.Message(); |
| 529 String text = !message.IsEmpty() ? toWTFStringWithTypeCheck(message->Get
()) : "Internal error"; | 529 String text = !message.IsEmpty() ? toWTFStringWithTypeCheck(message->Get
()) : "Internal error"; |
| 530 *exceptionDetails = protocol::Runtime::ExceptionDetails::create().setTex
t(text).build(); | 530 *exceptionDetails = protocol::Runtime::ExceptionDetails::create().setTex
t(text).build(); |
| 531 } else { | 531 } else { |
| 532 *result = toJSONValue(function.context(), resultValue); | 532 *result = toProtocolValue(function.context(), resultValue); |
| 533 if (!*result) | 533 if (!*result) |
| 534 *result = JSONString::create(String::format("Object has too long ref
erence chain(must not be longer than %d)", JSONValue::maxDepth)); | 534 *result = protocol::StringValue::create(String::format("Object has t
oo long reference chain(must not be longer than %d)", protocol::Value::maxDepth)
); |
| 535 } | 535 } |
| 536 } | 536 } |
| 537 | 537 |
| 538 void InjectedScript::dispose() | 538 void InjectedScript::dispose() |
| 539 { | 539 { |
| 540 m_manager->discardInjectedScript(m_contextId); | 540 m_manager->discardInjectedScript(m_contextId); |
| 541 } | 541 } |
| 542 | 542 |
| 543 } // namespace blink | 543 } // namespace blink |
| OLD | NEW |