OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010-2011 Google Inc. All rights reserved. | 2 * Copyright (c) 2010-2011 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 if (!agent->enabled()) | 170 if (!agent->enabled()) |
171 return nullptr; | 171 return nullptr; |
172 return agent; | 172 return agent; |
173 } | 173 } |
174 | 174 |
175 V8DebuggerAgentImpl* V8DebuggerImpl::findEnabledDebuggerAgent(v8::Local<v8::Cont
ext> context) | 175 V8DebuggerAgentImpl* V8DebuggerImpl::findEnabledDebuggerAgent(v8::Local<v8::Cont
ext> context) |
176 { | 176 { |
177 return findEnabledDebuggerAgent(getGroupId(context)); | 177 return findEnabledDebuggerAgent(getGroupId(context)); |
178 } | 178 } |
179 | 179 |
180 void V8DebuggerImpl::getCompiledScripts(int contextGroupId, std::vector<V8Debugg
erParsedScript>& result) | 180 void V8DebuggerImpl::getCompiledScripts(int contextGroupId, std::vector<std::uni
que_ptr<V8DebuggerScript>>& result) |
181 { | 181 { |
182 v8::HandleScope scope(m_isolate); | 182 v8::HandleScope scope(m_isolate); |
183 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicr
otasks); | 183 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicr
otasks); |
184 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); | 184 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); |
185 DCHECK(!debuggerScript->IsUndefined()); | 185 DCHECK(!debuggerScript->IsUndefined()); |
186 v8::Local<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast(d
ebuggerScript->Get(v8InternalizedString("getScripts"))); | 186 v8::Local<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast(d
ebuggerScript->Get(v8InternalizedString("getScripts"))); |
187 v8::Local<v8::Value> argv[] = { v8::Integer::New(m_isolate, contextGroupId)
}; | 187 v8::Local<v8::Value> argv[] = { v8::Integer::New(m_isolate, contextGroupId)
}; |
188 v8::Local<v8::Value> value; | 188 v8::Local<v8::Value> value; |
189 if (!getScriptsFunction->Call(debuggerContext(), debuggerScript, PROTOCOL_AR
RAY_LENGTH(argv), argv).ToLocal(&value)) | 189 if (!getScriptsFunction->Call(debuggerContext(), debuggerScript, PROTOCOL_AR
RAY_LENGTH(argv), argv).ToLocal(&value)) |
190 return; | 190 return; |
191 DCHECK(value->IsArray()); | 191 DCHECK(value->IsArray()); |
192 v8::Local<v8::Array> scriptsArray = v8::Local<v8::Array>::Cast(value); | 192 v8::Local<v8::Array> scriptsArray = v8::Local<v8::Array>::Cast(value); |
193 result.resize(scriptsArray->Length()); | 193 result.reserve(scriptsArray->Length()); |
194 for (unsigned i = 0; i < scriptsArray->Length(); ++i) | 194 for (unsigned i = 0; i < scriptsArray->Length(); ++i) { |
195 result[i] = createParsedScript(v8::Local<v8::Object>::Cast(scriptsArray-
>Get(v8::Integer::New(m_isolate, i))), true); | 195 v8::Local<v8::Object> scriptObject = v8::Local<v8::Object>::Cast(scripts
Array->Get(v8::Integer::New(m_isolate, i))); |
| 196 result.push_back(wrapUnique(new V8DebuggerScript(m_isolate, scriptObject
, inLiveEditScope))); |
| 197 } |
196 } | 198 } |
197 | 199 |
198 String16 V8DebuggerImpl::setBreakpoint(const String16& sourceID, const ScriptBre
akpoint& scriptBreakpoint, int* actualLineNumber, int* actualColumnNumber, bool
interstatementLocation) | 200 String16 V8DebuggerImpl::setBreakpoint(const String16& sourceID, const ScriptBre
akpoint& scriptBreakpoint, int* actualLineNumber, int* actualColumnNumber, bool
interstatementLocation) |
199 { | 201 { |
200 v8::HandleScope scope(m_isolate); | 202 v8::HandleScope scope(m_isolate); |
201 v8::Context::Scope contextScope(debuggerContext()); | 203 v8::Context::Scope contextScope(debuggerContext()); |
202 | 204 |
203 v8::Local<v8::Object> info = v8::Object::New(m_isolate); | 205 v8::Local<v8::Object> info = v8::Object::New(m_isolate); |
204 info->Set(v8InternalizedString("sourceID"), toV8String(m_isolate, sourceID))
; | 206 info->Set(v8InternalizedString("sourceID"), toV8String(m_isolate, sourceID))
; |
205 info->Set(v8InternalizedString("lineNumber"), v8::Integer::New(m_isolate, sc
riptBreakpoint.lineNumber)); | 207 info->Set(v8InternalizedString("lineNumber"), v8::Integer::New(m_isolate, sc
riptBreakpoint.lineNumber)); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 void V8DebuggerImpl::clearStepping() | 355 void V8DebuggerImpl::clearStepping() |
354 { | 356 { |
355 DCHECK(enabled()); | 357 DCHECK(enabled()); |
356 v8::HandleScope scope(m_isolate); | 358 v8::HandleScope scope(m_isolate); |
357 v8::Context::Scope contextScope(debuggerContext()); | 359 v8::Context::Scope contextScope(debuggerContext()); |
358 | 360 |
359 v8::Local<v8::Value> argv[] = { v8::Undefined(m_isolate) }; | 361 v8::Local<v8::Value> argv[] = { v8::Undefined(m_isolate) }; |
360 callDebuggerMethod("clearStepping", 0, argv); | 362 callDebuggerMethod("clearStepping", 0, argv); |
361 } | 363 } |
362 | 364 |
363 bool V8DebuggerImpl::setScriptSource(const String16& sourceID, const String16& n
ewContent, bool preview, ErrorString* error, Maybe<protocol::Debugger::SetScript
SourceError>* errorData, JavaScriptCallFrames* newCallFrames, Maybe<bool>* stack
Changed) | 365 bool V8DebuggerImpl::setScriptSource(const String16& sourceID, v8::Local<v8::Str
ing> newSource, bool preview, ErrorString* error, Maybe<protocol::Debugger::SetS
criptSourceError>* errorData, JavaScriptCallFrames* newCallFrames, Maybe<bool>*
stackChanged) |
364 { | 366 { |
365 class EnableLiveEditScope { | 367 class EnableLiveEditScope { |
366 public: | 368 public: |
367 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate) | 369 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate) |
368 { | 370 { |
369 v8::Debug::SetLiveEditEnabled(m_isolate, true); | 371 v8::Debug::SetLiveEditEnabled(m_isolate, true); |
370 inLiveEditScope = true; | 372 inLiveEditScope = true; |
371 } | 373 } |
372 ~EnableLiveEditScope() | 374 ~EnableLiveEditScope() |
373 { | 375 { |
374 v8::Debug::SetLiveEditEnabled(m_isolate, false); | 376 v8::Debug::SetLiveEditEnabled(m_isolate, false); |
375 inLiveEditScope = false; | 377 inLiveEditScope = false; |
376 } | 378 } |
377 private: | 379 private: |
378 v8::Isolate* m_isolate; | 380 v8::Isolate* m_isolate; |
379 }; | 381 }; |
380 | 382 |
381 DCHECK(enabled()); | 383 DCHECK(enabled()); |
382 v8::HandleScope scope(m_isolate); | 384 v8::HandleScope scope(m_isolate); |
383 | 385 |
384 std::unique_ptr<v8::Context::Scope> contextScope; | 386 std::unique_ptr<v8::Context::Scope> contextScope; |
385 if (!isPaused()) | 387 if (!isPaused()) |
386 contextScope = wrapUnique(new v8::Context::Scope(debuggerContext())); | 388 contextScope = wrapUnique(new v8::Context::Scope(debuggerContext())); |
387 | 389 |
388 v8::Local<v8::Value> argv[] = { toV8String(m_isolate, sourceID), toV8String(
m_isolate, newContent), v8Boolean(preview, m_isolate) }; | 390 v8::Local<v8::Value> argv[] = { toV8String(m_isolate, sourceID), newSource,
v8Boolean(preview, m_isolate) }; |
389 | 391 |
390 v8::Local<v8::Value> v8result; | 392 v8::Local<v8::Value> v8result; |
391 { | 393 { |
392 EnableLiveEditScope enableLiveEditScope(m_isolate); | 394 EnableLiveEditScope enableLiveEditScope(m_isolate); |
393 v8::TryCatch tryCatch(m_isolate); | 395 v8::TryCatch tryCatch(m_isolate); |
394 tryCatch.SetVerbose(false); | 396 tryCatch.SetVerbose(false); |
395 v8::MaybeLocal<v8::Value> maybeResult = callDebuggerMethod("liveEditScri
ptSource", 3, argv); | 397 v8::MaybeLocal<v8::Value> maybeResult = callDebuggerMethod("liveEditScri
ptSource", 3, argv); |
396 if (tryCatch.HasCaught()) { | 398 if (tryCatch.HasCaught()) { |
397 v8::Local<v8::Message> message = tryCatch.Message(); | 399 v8::Local<v8::Message> message = tryCatch.Message(); |
398 if (!message.IsEmpty()) | 400 if (!message.IsEmpty()) |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 } | 559 } |
558 | 560 |
559 V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(eventContext); | 561 V8DebuggerAgentImpl* agent = findEnabledDebuggerAgent(eventContext); |
560 if (agent) { | 562 if (agent) { |
561 v8::HandleScope scope(m_isolate); | 563 v8::HandleScope scope(m_isolate); |
562 if (event == v8::AfterCompile || event == v8::CompileError) { | 564 if (event == v8::AfterCompile || event == v8::CompileError) { |
563 v8::Context::Scope contextScope(debuggerContext()); | 565 v8::Context::Scope contextScope(debuggerContext()); |
564 v8::Local<v8::Value> argv[] = { eventDetails.GetEventData() }; | 566 v8::Local<v8::Value> argv[] = { eventDetails.GetEventData() }; |
565 v8::Local<v8::Value> value = callDebuggerMethod("getAfterCompileScri
pt", 1, argv).ToLocalChecked(); | 567 v8::Local<v8::Value> value = callDebuggerMethod("getAfterCompileScri
pt", 1, argv).ToLocalChecked(); |
566 DCHECK(value->IsObject()); | 568 DCHECK(value->IsObject()); |
567 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); | 569 v8::Local<v8::Object> scriptObject = v8::Local<v8::Object>::Cast(val
ue); |
568 agent->didParseSource(createParsedScript(object, event == v8::AfterC
ompile)); | 570 agent->didParseSource(wrapUnique(new V8DebuggerScript(m_isolate, scr
iptObject, inLiveEditScope)), event == v8::AfterCompile); |
569 } else if (event == v8::Exception) { | 571 } else if (event == v8::Exception) { |
570 v8::Local<v8::Object> eventData = eventDetails.GetEventData(); | 572 v8::Local<v8::Object> eventData = eventDetails.GetEventData(); |
571 v8::Local<v8::Value> exception = callInternalGetterFunction(eventDat
a, "exception"); | 573 v8::Local<v8::Value> exception = callInternalGetterFunction(eventDat
a, "exception"); |
572 v8::Local<v8::Value> promise = callInternalGetterFunction(eventData,
"promise"); | 574 v8::Local<v8::Value> promise = callInternalGetterFunction(eventData,
"promise"); |
573 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject(); | 575 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject(); |
574 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), e
xception, v8::Local<v8::Array>(), isPromiseRejection); | 576 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), e
xception, v8::Local<v8::Array>(), isPromiseRejection); |
575 } else if (event == v8::Break) { | 577 } else if (event == v8::Break) { |
576 v8::Local<v8::Value> argv[] = { eventDetails.GetEventData() }; | 578 v8::Local<v8::Value> argv[] = { eventDetails.GetEventData() }; |
577 v8::Local<v8::Value> hitBreakpoints = callDebuggerMethod("getBreakpo
intNumbers", 1, argv).ToLocalChecked(); | 579 v8::Local<v8::Value> hitBreakpoints = callDebuggerMethod("getBreakpo
intNumbers", 1, argv).ToLocalChecked(); |
578 DCHECK(hitBreakpoints->IsArray()); | 580 DCHECK(hitBreakpoints->IsArray()); |
(...skipping 22 matching lines...) Expand all Loading... |
601 NOTREACHED(); | 603 NOTREACHED(); |
602 } | 604 } |
603 | 605 |
604 V8StackTraceImpl* V8DebuggerImpl::currentAsyncCallChain() | 606 V8StackTraceImpl* V8DebuggerImpl::currentAsyncCallChain() |
605 { | 607 { |
606 if (!m_currentStacks.size()) | 608 if (!m_currentStacks.size()) |
607 return nullptr; | 609 return nullptr; |
608 return m_currentStacks.back().get(); | 610 return m_currentStacks.back().get(); |
609 } | 611 } |
610 | 612 |
611 V8DebuggerParsedScript V8DebuggerImpl::createParsedScript(v8::Local<v8::Object>
object, bool success) | |
612 { | |
613 v8::Local<v8::Value> id = object->Get(v8InternalizedString("id")); | |
614 DCHECK(!id.IsEmpty() && id->IsInt32()); | |
615 | |
616 V8DebuggerParsedScript parsedScript; | |
617 parsedScript.scriptId = String16::number(id->Int32Value()); | |
618 parsedScript.script.setURL(toProtocolStringWithTypeCheck(object->Get(v8Inter
nalizedString("name")))) | |
619 .setSourceURL(toProtocolStringWithTypeCheck(object->Get(v8InternalizedSt
ring("sourceURL")))) | |
620 .setSourceMappingURL(toProtocolStringWithTypeCheck(object->Get(v8Interna
lizedString("sourceMappingURL")))) | |
621 .setSource(toProtocolStringWithTypeCheck(object->Get(v8InternalizedStrin
g("source")))) | |
622 .setStartLine(object->Get(v8InternalizedString("startLine"))->ToInteger(
m_isolate)->Value()) | |
623 .setStartColumn(object->Get(v8InternalizedString("startColumn"))->ToInte
ger(m_isolate)->Value()) | |
624 .setEndLine(object->Get(v8InternalizedString("endLine"))->ToInteger(m_is
olate)->Value()) | |
625 .setEndColumn(object->Get(v8InternalizedString("endColumn"))->ToInteger(
m_isolate)->Value()) | |
626 .setIsContentScript(object->Get(v8InternalizedString("isContentScript"))
->ToBoolean(m_isolate)->Value()) | |
627 .setIsInternalScript(object->Get(v8InternalizedString("isInternalScript"
))->ToBoolean(m_isolate)->Value()) | |
628 .setExecutionContextId(object->Get(v8InternalizedString("executionContex
tId"))->ToInteger(m_isolate)->Value()) | |
629 .setIsLiveEdit(inLiveEditScope); | |
630 parsedScript.success = success; | |
631 return parsedScript; | |
632 } | |
633 | |
634 void V8DebuggerImpl::compileDebuggerScript() | 613 void V8DebuggerImpl::compileDebuggerScript() |
635 { | 614 { |
636 if (!m_debuggerScript.IsEmpty()) { | 615 if (!m_debuggerScript.IsEmpty()) { |
637 NOTREACHED(); | 616 NOTREACHED(); |
638 return; | 617 return; |
639 } | 618 } |
640 | 619 |
641 v8::HandleScope scope(m_isolate); | 620 v8::HandleScope scope(m_isolate); |
642 v8::Context::Scope contextScope(debuggerContext()); | 621 v8::Context::Scope contextScope(debuggerContext()); |
643 | 622 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 | 992 |
1014 V8InspectorSessionImpl* V8DebuggerImpl::sessionForContextGroup(int contextGroupI
d) | 993 V8InspectorSessionImpl* V8DebuggerImpl::sessionForContextGroup(int contextGroupI
d) |
1015 { | 994 { |
1016 if (!contextGroupId) | 995 if (!contextGroupId) |
1017 return nullptr; | 996 return nullptr; |
1018 SessionMap::iterator iter = m_sessions.find(contextGroupId); | 997 SessionMap::iterator iter = m_sessions.find(contextGroupId); |
1019 return iter == m_sessions.end() ? nullptr : iter->second; | 998 return iter == m_sessions.end() ? nullptr : iter->second; |
1020 } | 999 } |
1021 | 1000 |
1022 } // namespace blink | 1001 } // namespace blink |
OLD | NEW |