| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 using blink::protocol::Debugger::CollectionEntry; | 48 using blink::protocol::Debugger::CollectionEntry; |
| 49 using blink::protocol::Debugger::FunctionDetails; | 49 using blink::protocol::Debugger::FunctionDetails; |
| 50 using blink::protocol::Debugger::GeneratorObjectDetails; | 50 using blink::protocol::Debugger::GeneratorObjectDetails; |
| 51 using blink::protocol::Runtime::PropertyDescriptor; | 51 using blink::protocol::Runtime::PropertyDescriptor; |
| 52 using blink::protocol::Runtime::InternalPropertyDescriptor; | 52 using blink::protocol::Runtime::InternalPropertyDescriptor; |
| 53 using blink::protocol::Runtime::RemoteObject; | 53 using blink::protocol::Runtime::RemoteObject; |
| 54 using blink::protocol::Maybe; | 54 using blink::protocol::Maybe; |
| 55 | 55 |
| 56 namespace blink { | 56 namespace blink { |
| 57 | 57 |
| 58 static PassOwnPtr<protocol::Runtime::ExceptionDetails> toExceptionDetails(protoc
ol::DictionaryValue* object) | |
| 59 { | |
| 60 String16 text; | |
| 61 if (!object->getString("text", &text)) | |
| 62 return nullptr; | |
| 63 | |
| 64 OwnPtr<protocol::Runtime::ExceptionDetails> exceptionDetails = protocol::Run
time::ExceptionDetails::create().setText(text).build(); | |
| 65 String16 url; | |
| 66 if (object->getString("url", &url)) | |
| 67 exceptionDetails->setUrl(url); | |
| 68 int line = 0; | |
| 69 if (object->getNumber("line", &line)) | |
| 70 exceptionDetails->setLine(line); | |
| 71 int column = 0; | |
| 72 if (object->getNumber("column", &column)) | |
| 73 exceptionDetails->setColumn(column); | |
| 74 int originScriptId = 0; | |
| 75 object->getNumber("scriptId", &originScriptId); | |
| 76 | |
| 77 protocol::ListValue* stackTrace = object->getArray("stackTrace"); | |
| 78 if (stackTrace && stackTrace->size() > 0) { | |
| 79 OwnPtr<protocol::Array<protocol::Runtime::CallFrame>> frames = protocol:
:Array<protocol::Runtime::CallFrame>::create(); | |
| 80 for (unsigned i = 0; i < stackTrace->size(); ++i) { | |
| 81 protocol::DictionaryValue* stackFrame = protocol::DictionaryValue::c
ast(stackTrace->at(i)); | |
| 82 int lineNumber = 0; | |
| 83 stackFrame->getNumber("lineNumber", &lineNumber); | |
| 84 int column = 0; | |
| 85 stackFrame->getNumber("column", &column); | |
| 86 int scriptId = 0; | |
| 87 stackFrame->getNumber("scriptId", &scriptId); | |
| 88 if (i == 0 && scriptId == originScriptId) | |
| 89 originScriptId = 0; | |
| 90 | |
| 91 String16 sourceURL; | |
| 92 stackFrame->getString("scriptNameOrSourceURL", &sourceURL); | |
| 93 String16 functionName; | |
| 94 stackFrame->getString("functionName", &functionName); | |
| 95 | |
| 96 OwnPtr<protocol::Runtime::CallFrame> callFrame = protocol::Runtime::
CallFrame::create() | |
| 97 .setFunctionName(functionName) | |
| 98 .setScriptId(String16::number(scriptId)) | |
| 99 .setUrl(sourceURL) | |
| 100 .setLineNumber(lineNumber) | |
| 101 .setColumnNumber(column).build(); | |
| 102 | |
| 103 frames->addItem(callFrame.release()); | |
| 104 } | |
| 105 OwnPtr<protocol::Runtime::StackTrace> stack = protocol::Runtime::StackTr
ace::create() | |
| 106 .setCallFrames(frames.release()).build(); | |
| 107 exceptionDetails->setStack(stack.release()); | |
| 108 } | |
| 109 if (originScriptId) | |
| 110 exceptionDetails->setScriptId(String16::number(originScriptId)); | |
| 111 return exceptionDetails.release(); | |
| 112 } | |
| 113 | |
| 114 static void weakCallback(const v8::WeakCallbackInfo<InjectedScript>& data) | 58 static void weakCallback(const v8::WeakCallbackInfo<InjectedScript>& data) |
| 115 { | 59 { |
| 116 data.GetParameter()->dispose(); | 60 data.GetParameter()->dispose(); |
| 117 } | 61 } |
| 118 | 62 |
| 119 InjectedScript::InjectedScript(InjectedScriptManager* manager, v8::Local<v8::Con
text> context, v8::Local<v8::Object> object, PassOwnPtr<InjectedScriptNative> in
jectedScriptNative, int contextId) | 63 InjectedScript::InjectedScript(InjectedScriptManager* manager, v8::Local<v8::Con
text> context, v8::Local<v8::Object> object, PassOwnPtr<InjectedScriptNative> in
jectedScriptNative, int contextId) |
| 120 : m_manager(manager) | 64 : m_manager(manager) |
| 121 , m_isolate(context->GetIsolate()) | 65 , m_isolate(context->GetIsolate()) |
| 122 , m_context(m_isolate, context) | 66 , m_context(m_isolate, context) |
| 123 , m_value(m_isolate, object) | 67 , m_value(m_isolate, object) |
| 124 , m_native(injectedScriptNative) | 68 , m_native(injectedScriptNative) |
| 125 , m_contextId(contextId) | 69 , m_contextId(contextId) |
| 126 { | 70 { |
| 127 m_context.SetWeak(this, &weakCallback, v8::WeakCallbackType::kParameter); | 71 m_context.SetWeak(this, &weakCallback, v8::WeakCallbackType::kParameter); |
| 128 } | 72 } |
| 129 | 73 |
| 130 InjectedScript::~InjectedScript() | 74 InjectedScript::~InjectedScript() |
| 131 { | 75 { |
| 132 } | 76 } |
| 133 | 77 |
| 134 void InjectedScript::evaluate(ErrorString* errorString, const String16& expressi
on, const String16& objectGroup, bool includeCommandLineAPI, bool returnByValue,
bool generatePreview, OwnPtr<protocol::Runtime::RemoteObject>* result, Maybe<bo
ol>* wasThrown, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) | |
| 135 { | |
| 136 v8::HandleScope handles(m_isolate); | |
| 137 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "evalua
te"); | |
| 138 function.appendArgument(expression); | |
| 139 function.appendArgument(objectGroup); | |
| 140 function.appendArgument(includeCommandLineAPI); | |
| 141 function.appendArgument(returnByValue); | |
| 142 function.appendArgument(generatePreview); | |
| 143 *result = makeEvalCall(errorString, function, wasThrown, exceptionDetails); | |
| 144 } | |
| 145 | |
| 146 void InjectedScript::callFunctionOn(ErrorString* errorString, const String16& ob
jectId, const String16& expression, const String16& arguments, bool returnByValu
e, bool generatePreview, OwnPtr<protocol::Runtime::RemoteObject>* result, Maybe<
bool>* wasThrown) | 78 void InjectedScript::callFunctionOn(ErrorString* errorString, const String16& ob
jectId, const String16& expression, const String16& arguments, bool returnByValu
e, bool generatePreview, OwnPtr<protocol::Runtime::RemoteObject>* result, Maybe<
bool>* wasThrown) |
| 147 { | 79 { |
| 148 v8::HandleScope handles(m_isolate); | 80 v8::HandleScope handles(m_isolate); |
| 149 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "callFu
nctionOn"); | 81 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "callFu
nctionOn"); |
| 150 function.appendArgument(objectId); | 82 function.appendArgument(objectId); |
| 151 function.appendArgument(expression); | 83 function.appendArgument(expression); |
| 152 function.appendArgument(arguments); | 84 function.appendArgument(arguments); |
| 153 function.appendArgument(returnByValue); | 85 function.appendArgument(returnByValue); |
| 154 function.appendArgument(generatePreview); | 86 function.appendArgument(generatePreview); |
| 155 *result = makeEvalCall(errorString, function, wasThrown); | 87 *result = makeEvalCall(errorString, function, wasThrown); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 if (!hadException) { | 316 if (!hadException) { |
| 385 result = toProtocolValue(function.context(), resultValue); | 317 result = toProtocolValue(function.context(), resultValue); |
| 386 if (!result) | 318 if (!result) |
| 387 result = protocol::StringValue::create("Object has too long referenc
e chain"); | 319 result = protocol::StringValue::create("Object has too long referenc
e chain"); |
| 388 } else { | 320 } else { |
| 389 result = protocol::StringValue::create("Exception while making a call.")
; | 321 result = protocol::StringValue::create("Exception while making a call.")
; |
| 390 } | 322 } |
| 391 return result.release(); | 323 return result.release(); |
| 392 } | 324 } |
| 393 | 325 |
| 394 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::makeEvalCall(ErrorSt
ring* errorString, V8FunctionCall& function, Maybe<bool>* wasThrown, Maybe<proto
col::Runtime::ExceptionDetails>* exceptionDetails) | 326 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::makeEvalCall(ErrorSt
ring* errorString, V8FunctionCall& function, Maybe<bool>* wasThrown) |
| 395 { | 327 { |
| 396 OwnPtr<protocol::Value> result = makeCall(function); | 328 OwnPtr<protocol::Value> result = makeCall(function); |
| 397 if (!result) { | 329 if (!result) { |
| 398 *errorString = "Internal error: result value is empty"; | 330 *errorString = "Internal error: result value is empty"; |
| 399 return nullptr; | 331 return nullptr; |
| 400 } | 332 } |
| 401 if (result->type() == protocol::Value::TypeString) { | 333 if (result->type() == protocol::Value::TypeString) { |
| 402 result->asString(errorString); | 334 result->asString(errorString); |
| 403 ASSERT(errorString->length()); | 335 ASSERT(errorString->length()); |
| 404 return nullptr; | 336 return nullptr; |
| 405 } | 337 } |
| 406 protocol::DictionaryValue* resultPair = protocol::DictionaryValue::cast(resu
lt.get()); | 338 protocol::DictionaryValue* resultPair = protocol::DictionaryValue::cast(resu
lt.get()); |
| 407 if (!resultPair) { | 339 if (!resultPair) { |
| 408 *errorString = "Internal error: result is not an Object"; | 340 *errorString = "Internal error: result is not an Object"; |
| 409 return nullptr; | 341 return nullptr; |
| 410 } | 342 } |
| 411 protocol::DictionaryValue* resultObj = resultPair->getObject("result"); | 343 protocol::DictionaryValue* resultObj = resultPair->getObject("result"); |
| 412 bool wasThrownVal = false; | 344 bool wasThrownVal = false; |
| 413 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { | 345 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { |
| 414 *errorString = "Internal error: result is not a pair of value and wasThr
own flag"; | 346 *errorString = "Internal error: result is not a pair of value and wasThr
own flag"; |
| 415 return nullptr; | 347 return nullptr; |
| 416 } | 348 } |
| 417 if (wasThrownVal) { | |
| 418 protocol::DictionaryValue* objectExceptionDetails = resultPair->getObjec
t("exceptionDetails"); | |
| 419 if (objectExceptionDetails) | |
| 420 *exceptionDetails = toExceptionDetails(objectExceptionDetails); | |
| 421 } | |
| 422 protocol::ErrorSupport errors(errorString); | 349 protocol::ErrorSupport errors(errorString); |
| 423 *wasThrown = wasThrownVal; | 350 *wasThrown = wasThrownVal; |
| 424 return protocol::Runtime::RemoteObject::parse(resultObj, &errors); | 351 return protocol::Runtime::RemoteObject::parse(resultObj, &errors); |
| 425 } | 352 } |
| 426 | 353 |
| 427 PassOwnPtr<protocol::Value> InjectedScript::makeCallWithExceptionDetails(V8Funct
ionCall& function, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) | 354 PassOwnPtr<protocol::Value> InjectedScript::makeCallWithExceptionDetails(V8Funct
ionCall& function, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) |
| 428 { | 355 { |
| 429 OwnPtr<protocol::Value> result; | 356 OwnPtr<protocol::Value> result; |
| 430 v8::HandleScope handles(m_isolate); | 357 v8::HandleScope handles(m_isolate); |
| 431 v8::Context::Scope scope(context()); | 358 v8::Context::Scope scope(context()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 v8::Local<v8::Value> scopeExtensionValue = function.call(hadException, false
); | 424 v8::Local<v8::Value> scopeExtensionValue = function.call(hadException, false
); |
| 498 v8::Local<v8::Object> scopeExtensionObject; | 425 v8::Local<v8::Object> scopeExtensionObject; |
| 499 if (hadException || scopeExtensionValue.IsEmpty() || !scopeExtensionValue->T
oObject(context()).ToLocal(&scopeExtensionObject)) { | 426 if (hadException || scopeExtensionValue.IsEmpty() || !scopeExtensionValue->T
oObject(context()).ToLocal(&scopeExtensionObject)) { |
| 500 *errorString = "Internal error"; | 427 *errorString = "Internal error"; |
| 501 return v8::MaybeLocal<v8::Object>(); | 428 return v8::MaybeLocal<v8::Object>(); |
| 502 } | 429 } |
| 503 return scopeExtensionObject; | 430 return scopeExtensionObject; |
| 504 } | 431 } |
| 505 | 432 |
| 506 } // namespace blink | 433 } // namespace blink |
| OLD | NEW |