OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/v8_inspector/V8InjectedScriptHost.h" | 5 #include "platform/v8_inspector/V8InjectedScriptHost.h" |
6 | 6 |
7 #include "platform/inspector_protocol/String16.h" | 7 #include "platform/inspector_protocol/String16.h" |
8 #include "platform/inspector_protocol/Values.h" | 8 #include "platform/inspector_protocol/Values.h" |
9 #include "platform/v8_inspector/InjectedScript.h" | 9 #include "platform/v8_inspector/InjectedScript.h" |
10 #include "platform/v8_inspector/InjectedScriptHost.h" | 10 #include "platform/v8_inspector/InjectedScriptHost.h" |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(isolate->GetCurrentC
ontext(), info.Holder()); | 280 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(isolate->GetCurrentC
ontext(), info.Holder()); |
281 if (!host->debugger()) | 281 if (!host->debugger()) |
282 return; | 282 return; |
283 if (!host->debugger()->compileAndRunInternalScript(isolate->GetCurrentContex
t(), expression).ToLocal(&result)) { | 283 if (!host->debugger()->compileAndRunInternalScript(isolate->GetCurrentContex
t(), expression).ToLocal(&result)) { |
284 v8SetReturnValue(info, tryCatch.ReThrow()); | 284 v8SetReturnValue(info, tryCatch.ReThrow()); |
285 return; | 285 return; |
286 } | 286 } |
287 v8SetReturnValue(info, result); | 287 v8SetReturnValue(info, result); |
288 } | 288 } |
289 | 289 |
290 static void setExceptionAsReturnValue(const v8::FunctionCallbackInfo<v8::Value>&
info, v8::Local<v8::Object> returnValue, v8::TryCatch& tryCatch) | |
291 { | |
292 v8::Isolate* isolate = info.GetIsolate(); | |
293 returnValue->Set(v8::String::NewFromUtf8(isolate, "result"), tryCatch.Except
ion()); | |
294 returnValue->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), JavaS
criptCallFrame::createExceptionDetails(isolate, tryCatch.Message())); | |
295 v8SetReturnValue(info, returnValue); | |
296 } | |
297 | |
298 void V8InjectedScriptHost::evaluateWithExceptionDetailsCallback(const v8::Functi
onCallbackInfo<v8::Value>& info) | |
299 { | |
300 v8::Isolate* isolate = info.GetIsolate(); | |
301 if (info.Length() < 1) { | |
302 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "One argument expected."))); | |
303 return; | |
304 } | |
305 | |
306 v8::Local<v8::String> expression = info[0]->ToString(isolate); | |
307 if (expression.IsEmpty()) { | |
308 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "The argument must be a string."))); | |
309 return; | |
310 } | |
311 | |
312 ASSERT(isolate->InContext()); | |
313 v8::Local<v8::Object> wrappedResult = v8::Object::New(isolate); | |
314 if (wrappedResult.IsEmpty()) | |
315 return; | |
316 | |
317 v8::TryCatch tryCatch(isolate); | |
318 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
319 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(context, info.Holder
()); | |
320 if (!host->debugger()) | |
321 return; | |
322 | |
323 v8::Local<v8::Script> script = host->debugger()->compileInternalScript(conte
xt, expression, String16()); | |
324 if (script.IsEmpty()) { | |
325 setExceptionAsReturnValue(info, wrappedResult, tryCatch); | |
326 return; | |
327 } | |
328 | |
329 v8::Local<v8::Symbol> scopeExtensionSymbolValue = V8Debugger::scopeExtension
Symbol(isolate); | |
330 v8::Local<v8::Object> global = context->Global(); | |
331 if (info.Length() >= 2 && info[1]->IsObject()) { | |
332 v8::Local<v8::Object> commandLineAPI = info[1]->ToObject(isolate); | |
333 global->Set(scopeExtensionSymbolValue, commandLineAPI); | |
334 } | |
335 | |
336 v8::MaybeLocal<v8::Value> result = host->debugger()->runCompiledScript(conte
xt, script); | |
337 if (result.IsEmpty()) { | |
338 global->Delete(context, scopeExtensionSymbolValue); | |
339 setExceptionAsReturnValue(info, wrappedResult, tryCatch); | |
340 return; | |
341 } | |
342 | |
343 global->Delete(context, scopeExtensionSymbolValue); | |
344 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), result.ToLoca
lChecked()); | |
345 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), v8:
:Undefined(isolate)); | |
346 v8SetReturnValue(info, wrappedResult); | |
347 } | |
348 | |
349 static bool getFunctionLocation(const v8::FunctionCallbackInfo<v8::Value>& info,
String16* scriptId, int* lineNumber, int* columnNumber) | 290 static bool getFunctionLocation(const v8::FunctionCallbackInfo<v8::Value>& info,
String16* scriptId, int* lineNumber, int* columnNumber) |
350 { | 291 { |
351 if (info.Length() < 1 || !info[0]->IsFunction()) | 292 if (info.Length() < 1 || !info[0]->IsFunction()) |
352 return false; | 293 return false; |
353 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]); | 294 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]); |
354 *lineNumber = function->GetScriptLineNumber(); | 295 *lineNumber = function->GetScriptLineNumber(); |
355 *columnNumber = function->GetScriptColumnNumber(); | 296 *columnNumber = function->GetScriptColumnNumber(); |
356 if (*lineNumber == v8::Function::kLineOffsetNotFound || *columnNumber == v8:
:Function::kLineOffsetNotFound) | 297 if (*lineNumber == v8::Function::kLineOffsetNotFound || *columnNumber == v8:
:Function::kLineOffsetNotFound) |
357 return false; | 298 return false; |
358 *scriptId = String16::number(function->ScriptId()); | 299 *scriptId = String16::number(function->ScriptId()); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 {"inspectedObject", V8InjectedScriptHost::inspectedObjectCallback}, | 491 {"inspectedObject", V8InjectedScriptHost::inspectedObjectCallback}, |
551 {"internalConstructorName", V8InjectedScriptHost::internalConstructorNameCal
lback}, | 492 {"internalConstructorName", V8InjectedScriptHost::internalConstructorNameCal
lback}, |
552 {"formatAccessorsAsProperties", V8InjectedScriptHost::formatAccessorsAsPrope
rties}, | 493 {"formatAccessorsAsProperties", V8InjectedScriptHost::formatAccessorsAsPrope
rties}, |
553 {"isTypedArray", V8InjectedScriptHost::isTypedArrayCallback}, | 494 {"isTypedArray", V8InjectedScriptHost::isTypedArrayCallback}, |
554 {"subtype", V8InjectedScriptHost::subtypeCallback}, | 495 {"subtype", V8InjectedScriptHost::subtypeCallback}, |
555 {"functionDetails", V8InjectedScriptHost::functionDetailsCallback}, | 496 {"functionDetails", V8InjectedScriptHost::functionDetailsCallback}, |
556 {"collectionEntries", V8InjectedScriptHost::collectionEntriesCallback}, | 497 {"collectionEntries", V8InjectedScriptHost::collectionEntriesCallback}, |
557 {"getInternalProperties", V8InjectedScriptHost::getInternalPropertiesCallbac
k}, | 498 {"getInternalProperties", V8InjectedScriptHost::getInternalPropertiesCallbac
k}, |
558 {"getEventListeners", V8InjectedScriptHost::getEventListenersCallback}, | 499 {"getEventListeners", V8InjectedScriptHost::getEventListenersCallback}, |
559 {"eval", V8InjectedScriptHost::evalCallback}, | 500 {"eval", V8InjectedScriptHost::evalCallback}, |
560 {"evaluateWithExceptionDetails", V8InjectedScriptHost::evaluateWithException
DetailsCallback}, | |
561 {"debugFunction", V8InjectedScriptHost::debugFunctionCallback}, | 501 {"debugFunction", V8InjectedScriptHost::debugFunctionCallback}, |
562 {"undebugFunction", V8InjectedScriptHost::undebugFunctionCallback}, | 502 {"undebugFunction", V8InjectedScriptHost::undebugFunctionCallback}, |
563 {"monitorFunction", V8InjectedScriptHost::monitorFunctionCallback}, | 503 {"monitorFunction", V8InjectedScriptHost::monitorFunctionCallback}, |
564 {"unmonitorFunction", V8InjectedScriptHost::unmonitorFunctionCallback}, | 504 {"unmonitorFunction", V8InjectedScriptHost::unmonitorFunctionCallback}, |
565 {"callFunction", V8InjectedScriptHost::callFunctionCallback}, | 505 {"callFunction", V8InjectedScriptHost::callFunctionCallback}, |
566 {"suppressWarningsAndCallFunction", V8InjectedScriptHost::suppressWarningsAn
dCallFunctionCallback}, | 506 {"suppressWarningsAndCallFunction", V8InjectedScriptHost::suppressWarningsAn
dCallFunctionCallback}, |
567 {"setNonEnumProperty", V8InjectedScriptHost::setNonEnumPropertyCallback}, | 507 {"setNonEnumProperty", V8InjectedScriptHost::setNonEnumPropertyCallback}, |
568 {"bind", V8InjectedScriptHost::bindCallback}, | 508 {"bind", V8InjectedScriptHost::bindCallback}, |
569 {"objectForId", V8InjectedScriptHost::objectForIdCallback}, | 509 {"objectForId", V8InjectedScriptHost::objectForIdCallback}, |
570 {"idToObjectGroupName", V8InjectedScriptHost::idToObjectGroupNameCallback}, | 510 {"idToObjectGroupName", V8InjectedScriptHost::idToObjectGroupNameCallback}, |
(...skipping 13 matching lines...) Expand all Loading... |
584 { | 524 { |
585 return InjectedScriptHostWrapper::wrap(constructorTemplate, context, host); | 525 return InjectedScriptHostWrapper::wrap(constructorTemplate, context, host); |
586 } | 526 } |
587 | 527 |
588 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context,
v8::Local<v8::Object> object) | 528 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context,
v8::Local<v8::Object> object) |
589 { | 529 { |
590 return InjectedScriptHostWrapper::unwrap(context, object); | 530 return InjectedScriptHostWrapper::unwrap(context, object); |
591 } | 531 } |
592 | 532 |
593 } // namespace blink | 533 } // namespace blink |
OLD | NEW |