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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 using blink::protocol::Debugger::CollectionEntry; | 49 using blink::protocol::Debugger::CollectionEntry; |
50 using blink::protocol::Debugger::FunctionDetails; | 50 using blink::protocol::Debugger::FunctionDetails; |
51 using blink::protocol::Debugger::GeneratorObjectDetails; | 51 using blink::protocol::Debugger::GeneratorObjectDetails; |
52 using blink::protocol::Runtime::PropertyDescriptor; | 52 using blink::protocol::Runtime::PropertyDescriptor; |
53 using blink::protocol::Runtime::InternalPropertyDescriptor; | 53 using blink::protocol::Runtime::InternalPropertyDescriptor; |
54 using blink::protocol::Runtime::RemoteObject; | 54 using blink::protocol::Runtime::RemoteObject; |
55 using blink::protocol::Maybe; | 55 using blink::protocol::Maybe; |
56 | 56 |
57 namespace blink { | 57 namespace blink { |
58 | 58 |
59 static PassOwnPtr<protocol::Runtime::ExceptionDetails> toExceptionDetails(protoc ol::DictionaryValue* object) | |
60 { | |
61 String16 text; | |
62 if (!object->getString("text", &text)) | |
63 return nullptr; | |
64 | |
65 OwnPtr<protocol::Runtime::ExceptionDetails> exceptionDetails = protocol::Run time::ExceptionDetails::create().setText(text).build(); | |
66 String16 url; | |
67 if (object->getString("url", &url)) | |
68 exceptionDetails->setUrl(url); | |
69 int line = 0; | |
70 if (object->getNumber("line", &line)) | |
71 exceptionDetails->setLine(line); | |
72 int column = 0; | |
73 if (object->getNumber("column", &column)) | |
74 exceptionDetails->setColumn(column); | |
75 int originScriptId = 0; | |
76 object->getNumber("scriptId", &originScriptId); | |
77 | |
78 protocol::ListValue* stackTrace = object->getArray("stackTrace"); | |
79 if (stackTrace && stackTrace->size() > 0) { | |
80 OwnPtr<protocol::Array<protocol::Runtime::CallFrame>> frames = protocol: :Array<protocol::Runtime::CallFrame>::create(); | |
81 for (unsigned i = 0; i < stackTrace->size(); ++i) { | |
82 protocol::DictionaryValue* stackFrame = protocol::DictionaryValue::c ast(stackTrace->at(i)); | |
83 int lineNumber = 0; | |
84 stackFrame->getNumber("lineNumber", &lineNumber); | |
85 int column = 0; | |
86 stackFrame->getNumber("column", &column); | |
87 int scriptId = 0; | |
88 stackFrame->getNumber("scriptId", &scriptId); | |
89 if (i == 0 && scriptId == originScriptId) | |
90 originScriptId = 0; | |
91 | |
92 String16 sourceURL; | |
93 stackFrame->getString("scriptNameOrSourceURL", &sourceURL); | |
94 String16 functionName; | |
95 stackFrame->getString("functionName", &functionName); | |
96 | |
97 OwnPtr<protocol::Runtime::CallFrame> callFrame = protocol::Runtime:: CallFrame::create() | |
98 .setFunctionName(functionName) | |
99 .setScriptId(String16::number(scriptId)) | |
100 .setUrl(sourceURL) | |
101 .setLineNumber(lineNumber) | |
102 .setColumnNumber(column).build(); | |
103 | |
104 frames->addItem(callFrame.release()); | |
105 } | |
106 OwnPtr<protocol::Runtime::StackTrace> stack = protocol::Runtime::StackTr ace::create() | |
107 .setCallFrames(frames.release()).build(); | |
108 exceptionDetails->setStack(stack.release()); | |
109 } | |
110 if (originScriptId) | |
111 exceptionDetails->setScriptId(String16::number(originScriptId)); | |
112 return exceptionDetails.release(); | |
113 } | |
114 | |
115 static void weakCallback(const v8::WeakCallbackInfo<InjectedScript>& data) | 59 static void weakCallback(const v8::WeakCallbackInfo<InjectedScript>& data) |
116 { | 60 { |
117 data.GetParameter()->dispose(); | 61 data.GetParameter()->dispose(); |
118 } | 62 } |
119 | 63 |
120 InjectedScript::InjectedScript(InjectedScriptManager* manager, v8::Local<v8::Con text> context, v8::Local<v8::Object> object, PassOwnPtr<InjectedScriptNative> in jectedScriptNative, int contextId) | 64 InjectedScript::InjectedScript(InjectedScriptManager* manager, v8::Local<v8::Con text> context, v8::Local<v8::Object> object, PassOwnPtr<InjectedScriptNative> in jectedScriptNative, int contextId) |
121 : m_manager(manager) | 65 : m_manager(manager) |
122 , m_isolate(context->GetIsolate()) | 66 , m_isolate(context->GetIsolate()) |
123 , m_context(m_isolate, context) | 67 , m_context(m_isolate, context) |
124 , m_value(m_isolate, object) | 68 , m_value(m_isolate, object) |
125 , m_native(injectedScriptNative) | 69 , m_native(injectedScriptNative) |
126 , m_contextId(contextId) | 70 , m_contextId(contextId) |
127 { | 71 { |
128 m_context.SetWeak(this, &weakCallback, v8::WeakCallbackType::kParameter); | 72 m_context.SetWeak(this, &weakCallback, v8::WeakCallbackType::kParameter); |
129 } | 73 } |
130 | 74 |
131 InjectedScript::~InjectedScript() | 75 InjectedScript::~InjectedScript() |
132 { | 76 { |
133 } | 77 } |
134 | 78 |
135 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) | |
136 { | |
137 v8::HandleScope handles(m_isolate); | |
138 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "evalua te"); | |
139 function.appendArgument(expression); | |
140 function.appendArgument(objectGroup); | |
141 function.appendArgument(includeCommandLineAPI); | |
142 function.appendArgument(returnByValue); | |
143 function.appendArgument(generatePreview); | |
144 *result = makeEvalCall(errorString, function, wasThrown, exceptionDetails); | |
145 } | |
146 | |
147 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) | 79 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) |
148 { | 80 { |
149 v8::HandleScope handles(m_isolate); | 81 v8::HandleScope handles(m_isolate); |
150 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "callFu nctionOn"); | 82 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "callFu nctionOn"); |
151 function.appendArgument(objectId); | 83 function.appendArgument(objectId); |
152 function.appendArgument(expression); | 84 function.appendArgument(expression); |
153 function.appendArgument(arguments); | 85 function.appendArgument(arguments); |
154 function.appendArgument(returnByValue); | 86 function.appendArgument(returnByValue); |
155 function.appendArgument(generatePreview); | 87 function.appendArgument(generatePreview); |
156 *result = makeEvalCall(errorString, function, wasThrown); | 88 *result = makeEvalCall(errorString, function, wasThrown); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 if (!hadException) { | 315 if (!hadException) { |
384 result = toProtocolValue(function.context(), resultValue); | 316 result = toProtocolValue(function.context(), resultValue); |
385 if (!result) | 317 if (!result) |
386 result = protocol::StringValue::create("Object has too long referenc e chain"); | 318 result = protocol::StringValue::create("Object has too long referenc e chain"); |
387 } else { | 319 } else { |
388 result = protocol::StringValue::create("Exception while making a call.") ; | 320 result = protocol::StringValue::create("Exception while making a call.") ; |
389 } | 321 } |
390 return result.release(); | 322 return result.release(); |
391 } | 323 } |
392 | 324 |
393 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::makeEvalCall(ErrorSt ring* errorString, V8FunctionCall& function, Maybe<bool>* wasThrown, Maybe<proto col::Runtime::ExceptionDetails>* exceptionDetails) | 325 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::makeEvalCall(ErrorSt ring* errorString, V8FunctionCall& function, Maybe<bool>* wasThrown) |
394 { | 326 { |
395 OwnPtr<protocol::Value> result = makeCall(function); | 327 OwnPtr<protocol::Value> result = makeCall(function); |
396 if (!result) { | 328 if (!result) { |
397 *errorString = "Internal error: result value is empty"; | 329 *errorString = "Internal error: result value is empty"; |
398 return nullptr; | 330 return nullptr; |
399 } | 331 } |
400 if (result->type() == protocol::Value::TypeString) { | 332 if (result->type() == protocol::Value::TypeString) { |
401 result->asString(errorString); | 333 result->asString(errorString); |
402 ASSERT(errorString->length()); | 334 ASSERT(errorString->length()); |
403 return nullptr; | 335 return nullptr; |
404 } | 336 } |
405 protocol::DictionaryValue* resultPair = protocol::DictionaryValue::cast(resu lt.get()); | 337 protocol::DictionaryValue* resultPair = protocol::DictionaryValue::cast(resu lt.get()); |
406 if (!resultPair) { | 338 if (!resultPair) { |
407 *errorString = "Internal error: result is not an Object"; | 339 *errorString = "Internal error: result is not an Object"; |
408 return nullptr; | 340 return nullptr; |
409 } | 341 } |
410 protocol::DictionaryValue* resultObj = resultPair->getObject("result"); | 342 protocol::DictionaryValue* resultObj = resultPair->getObject("result"); |
411 bool wasThrownVal = false; | 343 bool wasThrownVal = false; |
412 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { | 344 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { |
413 *errorString = "Internal error: result is not a pair of value and wasThr own flag"; | 345 *errorString = "Internal error: result is not a pair of value and wasThr own flag"; |
414 return nullptr; | 346 return nullptr; |
415 } | 347 } |
416 if (wasThrownVal) { | |
417 protocol::DictionaryValue* objectExceptionDetails = resultPair->getObjec t("exceptionDetails"); | |
418 if (objectExceptionDetails) | |
419 *exceptionDetails = toExceptionDetails(objectExceptionDetails); | |
420 } | |
421 protocol::ErrorSupport errors(errorString); | 348 protocol::ErrorSupport errors(errorString); |
422 *wasThrown = wasThrownVal; | 349 *wasThrown = wasThrownVal; |
423 return protocol::Runtime::RemoteObject::parse(resultObj, &errors); | 350 return protocol::Runtime::RemoteObject::parse(resultObj, &errors); |
424 } | 351 } |
425 | 352 |
426 PassOwnPtr<protocol::Value> InjectedScript::makeCallWithExceptionDetails(V8Funct ionCall& function, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) | 353 PassOwnPtr<protocol::Value> InjectedScript::makeCallWithExceptionDetails(V8Funct ionCall& function, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) |
427 { | 354 { |
428 OwnPtr<protocol::Value> result; | 355 OwnPtr<protocol::Value> result; |
429 v8::HandleScope handles(m_isolate); | 356 v8::HandleScope handles(m_isolate); |
430 v8::Context::Scope scope(context()); | 357 v8::Context::Scope scope(context()); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 if (!maybeResultValue.ToLocal(&resultValue)) { | 455 if (!maybeResultValue.ToLocal(&resultValue)) { |
529 *errorString = "Internal error"; | 456 *errorString = "Internal error"; |
530 return; | 457 return; |
531 } | 458 } |
532 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, resultValue, objectGroup, returnByValue, generatePreview); | 459 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, resultValue, objectGroup, returnByValue, generatePreview); |
533 if (!remoteObject) | 460 if (!remoteObject) |
534 return; | 461 return; |
535 if (objectGroup == "console" && !setLastEvaluationResult(errorString, re sultValue)) | 462 if (objectGroup == "console" && !setLastEvaluationResult(errorString, re sultValue)) |
536 return; | 463 return; |
537 *result = remoteObject.release(); | 464 *result = remoteObject.release(); |
538 *wasThrown = false; | 465 if (wasThrown) |
dgozman
2016/03/18 00:04:33
Should we kill this entirely and just set this boo
kozy
2016/03/18 00:41:38
There is call sides that has wasThrown and doesn't
| |
466 *wasThrown = false; | |
539 } else { | 467 } else { |
540 v8::Local<v8::Value> exception = tryCatch.Exception(); | 468 v8::Local<v8::Value> exception = tryCatch.Exception(); |
541 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, exception, o bjectGroup, false, generatePreview && !exception->IsNativeError()); | 469 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, exception, o bjectGroup, false, generatePreview && !exception->IsNativeError()); |
542 if (!remoteObject) | 470 if (!remoteObject) |
543 return; | 471 return; |
544 *result = remoteObject.release(); | 472 *result = remoteObject.release(); |
545 *exceptionDetails = createExceptionDetails(tryCatch.Message()); | 473 *exceptionDetails = createExceptionDetails(tryCatch.Message()); |
546 *wasThrown = true; | 474 if (wasThrown) |
475 *wasThrown = true; | |
547 } | 476 } |
548 } | 477 } |
549 | 478 |
550 } // namespace blink | 479 } // namespace blink |
OLD | NEW |