OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project 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 "src/inspector/v8-debugger.h" | 5 #include "src/inspector/v8-debugger.h" |
6 | 6 |
7 #include "src/inspector/debugger-script.h" | 7 #include "src/inspector/debugger-script.h" |
8 #include "src/inspector/protocol/Protocol.h" | 8 #include "src/inspector/protocol/Protocol.h" |
9 #include "src/inspector/script-breakpoint.h" | 9 #include "src/inspector/script-breakpoint.h" |
10 #include "src/inspector/string-util.h" | 10 #include "src/inspector/string-util.h" |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 DCHECK(!m_executionState.IsEmpty()); | 322 DCHECK(!m_executionState.IsEmpty()); |
323 v8::DebugInterface::PrepareStep(m_isolate, v8::DebugInterface::StepOut); | 323 v8::DebugInterface::PrepareStep(m_isolate, v8::DebugInterface::StepOut); |
324 continueProgram(); | 324 continueProgram(); |
325 } | 325 } |
326 | 326 |
327 void V8Debugger::clearStepping() { | 327 void V8Debugger::clearStepping() { |
328 DCHECK(enabled()); | 328 DCHECK(enabled()); |
329 v8::DebugInterface::ClearStepping(m_isolate); | 329 v8::DebugInterface::ClearStepping(m_isolate); |
330 } | 330 } |
331 | 331 |
332 bool V8Debugger::setScriptSource( | 332 Response V8Debugger::setScriptSource( |
333 const String16& sourceID, v8::Local<v8::String> newSource, bool dryRun, | 333 const String16& sourceID, v8::Local<v8::String> newSource, bool dryRun, |
334 ErrorString* error, | |
335 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails, | 334 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails, |
336 JavaScriptCallFrames* newCallFrames, Maybe<bool>* stackChanged) { | 335 JavaScriptCallFrames* newCallFrames, Maybe<bool>* stackChanged, |
| 336 bool* compileError) { |
337 class EnableLiveEditScope { | 337 class EnableLiveEditScope { |
338 public: | 338 public: |
339 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate) { | 339 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate) { |
340 v8::DebugInterface::SetLiveEditEnabled(m_isolate, true); | 340 v8::DebugInterface::SetLiveEditEnabled(m_isolate, true); |
341 inLiveEditScope = true; | 341 inLiveEditScope = true; |
342 } | 342 } |
343 ~EnableLiveEditScope() { | 343 ~EnableLiveEditScope() { |
344 v8::DebugInterface::SetLiveEditEnabled(m_isolate, false); | 344 v8::DebugInterface::SetLiveEditEnabled(m_isolate, false); |
345 inLiveEditScope = false; | 345 inLiveEditScope = false; |
346 } | 346 } |
347 | 347 |
348 private: | 348 private: |
349 v8::Isolate* m_isolate; | 349 v8::Isolate* m_isolate; |
350 }; | 350 }; |
351 | 351 |
| 352 *compileError = false; |
352 DCHECK(enabled()); | 353 DCHECK(enabled()); |
353 v8::HandleScope scope(m_isolate); | 354 v8::HandleScope scope(m_isolate); |
354 | 355 |
355 std::unique_ptr<v8::Context::Scope> contextScope; | 356 std::unique_ptr<v8::Context::Scope> contextScope; |
356 if (!isPaused()) | 357 if (!isPaused()) |
357 contextScope = wrapUnique(new v8::Context::Scope(debuggerContext())); | 358 contextScope = wrapUnique(new v8::Context::Scope(debuggerContext())); |
358 | 359 |
359 v8::Local<v8::Value> argv[] = {toV8String(m_isolate, sourceID), newSource, | 360 v8::Local<v8::Value> argv[] = {toV8String(m_isolate, sourceID), newSource, |
360 v8Boolean(dryRun, m_isolate)}; | 361 v8Boolean(dryRun, m_isolate)}; |
361 | 362 |
362 v8::Local<v8::Value> v8result; | 363 v8::Local<v8::Value> v8result; |
363 { | 364 { |
364 EnableLiveEditScope enableLiveEditScope(m_isolate); | 365 EnableLiveEditScope enableLiveEditScope(m_isolate); |
365 v8::TryCatch tryCatch(m_isolate); | 366 v8::TryCatch tryCatch(m_isolate); |
366 tryCatch.SetVerbose(false); | 367 tryCatch.SetVerbose(false); |
367 v8::MaybeLocal<v8::Value> maybeResult = | 368 v8::MaybeLocal<v8::Value> maybeResult = |
368 callDebuggerMethod("liveEditScriptSource", 3, argv); | 369 callDebuggerMethod("liveEditScriptSource", 3, argv); |
369 if (tryCatch.HasCaught()) { | 370 if (tryCatch.HasCaught()) { |
370 v8::Local<v8::Message> message = tryCatch.Message(); | 371 v8::Local<v8::Message> message = tryCatch.Message(); |
371 if (!message.IsEmpty()) | 372 if (!message.IsEmpty()) |
372 *error = toProtocolStringWithTypeCheck(message->Get()); | 373 return Response::Error(toProtocolStringWithTypeCheck(message->Get())); |
373 else | 374 else |
374 *error = "Unknown error."; | 375 return Response::InternalError(); |
375 return false; | |
376 } | 376 } |
377 v8result = maybeResult.ToLocalChecked(); | 377 v8result = maybeResult.ToLocalChecked(); |
378 } | 378 } |
379 DCHECK(!v8result.IsEmpty()); | 379 DCHECK(!v8result.IsEmpty()); |
380 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); | 380 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); |
381 v8::Local<v8::Object> resultTuple = | 381 v8::Local<v8::Object> resultTuple = |
382 v8result->ToObject(context).ToLocalChecked(); | 382 v8result->ToObject(context).ToLocalChecked(); |
383 int code = static_cast<int>(resultTuple->Get(context, 0) | 383 int code = static_cast<int>(resultTuple->Get(context, 0) |
384 .ToLocalChecked() | 384 .ToLocalChecked() |
385 ->ToInteger(context) | 385 ->ToInteger(context) |
386 .ToLocalChecked() | 386 .ToLocalChecked() |
387 ->Value()); | 387 ->Value()); |
388 switch (code) { | 388 switch (code) { |
389 case 0: { | 389 case 0: { |
390 *stackChanged = resultTuple->Get(context, 1) | 390 *stackChanged = resultTuple->Get(context, 1) |
391 .ToLocalChecked() | 391 .ToLocalChecked() |
392 ->BooleanValue(context) | 392 ->BooleanValue(context) |
393 .FromJust(); | 393 .FromJust(); |
394 // Call stack may have changed after if the edited function was on the | 394 // Call stack may have changed after if the edited function was on the |
395 // stack. | 395 // stack. |
396 if (!dryRun && isPaused()) { | 396 if (!dryRun && isPaused()) { |
397 JavaScriptCallFrames frames = currentCallFrames(); | 397 JavaScriptCallFrames frames = currentCallFrames(); |
398 newCallFrames->swap(frames); | 398 newCallFrames->swap(frames); |
399 } | 399 } |
400 return true; | 400 return Response::OK(); |
401 } | 401 } |
402 // Compile error. | 402 // Compile error. |
403 case 1: { | 403 case 1: { |
404 *exceptionDetails = | 404 *exceptionDetails = |
405 protocol::Runtime::ExceptionDetails::create() | 405 protocol::Runtime::ExceptionDetails::create() |
406 .setExceptionId(m_inspector->nextExceptionId()) | 406 .setExceptionId(m_inspector->nextExceptionId()) |
407 .setText(toProtocolStringWithTypeCheck( | 407 .setText(toProtocolStringWithTypeCheck( |
408 resultTuple->Get(context, 2).ToLocalChecked())) | 408 resultTuple->Get(context, 2).ToLocalChecked())) |
409 .setLineNumber(static_cast<int>(resultTuple->Get(context, 3) | 409 .setLineNumber(static_cast<int>(resultTuple->Get(context, 3) |
410 .ToLocalChecked() | 410 .ToLocalChecked() |
411 ->ToInteger(context) | 411 ->ToInteger(context) |
412 .ToLocalChecked() | 412 .ToLocalChecked() |
413 ->Value()) - | 413 ->Value()) - |
414 1) | 414 1) |
415 .setColumnNumber(static_cast<int>(resultTuple->Get(context, 4) | 415 .setColumnNumber(static_cast<int>(resultTuple->Get(context, 4) |
416 .ToLocalChecked() | 416 .ToLocalChecked() |
417 ->ToInteger(context) | 417 ->ToInteger(context) |
418 .ToLocalChecked() | 418 .ToLocalChecked() |
419 ->Value()) - | 419 ->Value()) - |
420 1) | 420 1) |
421 .build(); | 421 .build(); |
422 return false; | 422 *compileError = true; |
| 423 return Response::OK(); |
423 } | 424 } |
424 } | 425 } |
425 *error = "Unknown error."; | 426 return Response::InternalError(); |
426 return false; | |
427 } | 427 } |
428 | 428 |
429 JavaScriptCallFrames V8Debugger::currentCallFrames(int limit) { | 429 JavaScriptCallFrames V8Debugger::currentCallFrames(int limit) { |
430 if (!m_isolate->InContext()) return JavaScriptCallFrames(); | 430 if (!m_isolate->InContext()) return JavaScriptCallFrames(); |
431 v8::Local<v8::Value> currentCallFramesV8; | 431 v8::Local<v8::Value> currentCallFramesV8; |
432 if (m_executionState.IsEmpty()) { | 432 if (m_executionState.IsEmpty()) { |
433 v8::Local<v8::Function> currentCallFramesFunction = | 433 v8::Local<v8::Function> currentCallFramesFunction = |
434 v8::Local<v8::Function>::Cast( | 434 v8::Local<v8::Function>::Cast( |
435 m_debuggerScript.Get(m_isolate) | 435 m_debuggerScript.Get(m_isolate) |
436 ->Get(debuggerContext(), | 436 ->Get(debuggerContext(), |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 | 973 |
974 size_t stackSize = | 974 size_t stackSize = |
975 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; | 975 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; |
976 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) | 976 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) |
977 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; | 977 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; |
978 | 978 |
979 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); | 979 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); |
980 } | 980 } |
981 | 981 |
982 } // namespace v8_inspector | 982 } // namespace v8_inspector |
OLD | NEW |