From 072c6943367828657e36f11bbfbbbd95a54d3431 Mon Sep 17 00:00:00 2001 From: kozyatinskiy Date: Mon, 19 Sep 2016 09:10:26 -0700 Subject: [PATCH] [inspector] fixed all deprecated calls BUG=chromium:635948 R=dgozman@chromium.org,alph@chromium.org Review-Url: https://codereview.chromium.org/2332243002 Cr-Commit-Position: refs/heads/master@{#39506} --- src/inspector/InjectedScriptNative.cpp | 3 +- src/inspector/InjectedScriptNative.h | 3 +- src/inspector/JavaScriptCallFrame.cpp | 51 ++++--- src/inspector/V8ConsoleMessage.cpp | 31 ++-- src/inspector/V8Debugger.cpp | 188 +++++++++++++++++-------- src/inspector/V8Debugger.h | 2 + src/inspector/V8DebuggerScript.cpp | 66 +++++---- src/inspector/V8DebuggerScript.h | 3 +- src/inspector/V8InjectedScriptHost.cpp | 7 +- src/inspector/V8InspectorImpl.cpp | 18 ++- src/inspector/V8InspectorImpl.h | 2 + src/inspector/V8ProfilerAgentImpl.cpp | 14 ++ src/inspector/V8ProfilerAgentImpl.h | 5 + src/inspector/V8StackTraceImpl.cpp | 9 +- src/v8.gyp | 2 - 15 files changed, 272 insertions(+), 132 deletions(-) diff --git a/src/inspector/InjectedScriptNative.cpp b/src/inspector/InjectedScriptNative.cpp index c5b7fa0cde..173716c1c4 100644 --- a/src/inspector/InjectedScriptNative.cpp +++ b/src/inspector/InjectedScriptNative.cpp @@ -26,8 +26,7 @@ void InjectedScriptNative::setOnInjectedScriptHost( } InjectedScriptNative* InjectedScriptNative::fromInjectedScriptHost( - v8::Local injectedScriptObject) { - v8::Isolate* isolate = injectedScriptObject->GetIsolate(); + v8::Isolate* isolate, v8::Local injectedScriptObject) { v8::HandleScope handleScope(isolate); v8::Local context = isolate->GetCurrentContext(); v8::Local privateKey = v8::Private::ForApi( diff --git a/src/inspector/InjectedScriptNative.h b/src/inspector/InjectedScriptNative.h index 90edc422dc..b91d0148da 100644 --- a/src/inspector/InjectedScriptNative.h +++ b/src/inspector/InjectedScriptNative.h @@ -19,7 +19,8 @@ class InjectedScriptNative final { ~InjectedScriptNative(); void setOnInjectedScriptHost(v8::Local); - static InjectedScriptNative* fromInjectedScriptHost(v8::Local); + static InjectedScriptNative* fromInjectedScriptHost(v8::Isolate* isolate, + v8::Local); int bind(v8::Local, const String16& groupName); void unbind(int id); diff --git a/src/inspector/JavaScriptCallFrame.cpp b/src/inspector/JavaScriptCallFrame.cpp index 5d7d390107..6ee803899c 100644 --- a/src/inspector/JavaScriptCallFrame.cpp +++ b/src/inspector/JavaScriptCallFrame.cpp @@ -53,7 +53,8 @@ int JavaScriptCallFrame::callV8FunctionReturnInt(const char* name) const { v8::Local callFrame = v8::Local::New(m_isolate, m_callFrame); v8::Local func = v8::Local::Cast( - callFrame->Get(toV8StringInternalized(m_isolate, name))); + callFrame->Get(context, toV8StringInternalized(m_isolate, name)) + .ToLocalChecked()); v8::Local result; if (!func->Call(context, callFrame, 0, nullptr).ToLocal(&result) || !result->IsInt32()) @@ -79,44 +80,56 @@ int JavaScriptCallFrame::contextId() const { bool JavaScriptCallFrame::isAtReturn() const { v8::HandleScope handleScope(m_isolate); - v8::Local result = - v8::Local::New(m_isolate, m_callFrame) - ->Get(toV8StringInternalized(m_isolate, "isAtReturn")); - if (result.IsEmpty() || !result->IsBoolean()) return false; - return result->BooleanValue(); + v8::Local context = + v8::Local::New(m_isolate, m_debuggerContext); + v8::Local callFrame = + v8::Local::New(m_isolate, m_callFrame); + v8::Local result; + if (!callFrame->Get(context, toV8StringInternalized(m_isolate, "isAtReturn")) + .ToLocal(&result) || + !result->IsBoolean()) + return false; + return result.As()->BooleanValue(context).FromMaybe(false); } v8::Local JavaScriptCallFrame::details() const { v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicrotasks); + v8::Local context = + v8::Local::New(m_isolate, m_debuggerContext); v8::Local callFrame = v8::Local::New(m_isolate, m_callFrame); v8::Local func = v8::Local::Cast( - callFrame->Get(toV8StringInternalized(m_isolate, "details"))); - return v8::Local::Cast( - func->Call(m_debuggerContext.Get(m_isolate), callFrame, 0, nullptr) + callFrame->Get(context, toV8StringInternalized(m_isolate, "details")) .ToLocalChecked()); + return v8::Local::Cast( + func->Call(context, callFrame, 0, nullptr).ToLocalChecked()); } v8::MaybeLocal JavaScriptCallFrame::evaluate( v8::Local expression) { v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kRunMicrotasks); + v8::Local context = + v8::Local::New(m_isolate, m_debuggerContext); v8::Local callFrame = v8::Local::New(m_isolate, m_callFrame); v8::Local evalFunction = v8::Local::Cast( - callFrame->Get(toV8StringInternalized(m_isolate, "evaluate"))); - return evalFunction->Call(m_debuggerContext.Get(m_isolate), callFrame, 1, - &expression); + callFrame->Get(context, toV8StringInternalized(m_isolate, "evaluate")) + .ToLocalChecked()); + return evalFunction->Call(context, callFrame, 1, &expression); } v8::MaybeLocal JavaScriptCallFrame::restart() { v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicrotasks); + v8::Local context = + v8::Local::New(m_isolate, m_debuggerContext); v8::Local callFrame = v8::Local::New(m_isolate, m_callFrame); v8::Local restartFunction = v8::Local::Cast( - callFrame->Get(toV8StringInternalized(m_isolate, "restart"))); + callFrame->Get(context, toV8StringInternalized(m_isolate, "restart")) + .ToLocalChecked()); v8::Debug::SetLiveEditEnabled(m_isolate, true); v8::MaybeLocal result = restartFunction->Call( m_debuggerContext.Get(m_isolate), callFrame, 0, nullptr); @@ -129,16 +142,20 @@ v8::MaybeLocal JavaScriptCallFrame::setVariableValue( v8::Local newValue) { v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicrotasks); + v8::Local context = + v8::Local::New(m_isolate, m_debuggerContext); v8::Local callFrame = v8::Local::New(m_isolate, m_callFrame); v8::Local setVariableValueFunction = - v8::Local::Cast(callFrame->Get( - toV8StringInternalized(m_isolate, "setVariableValue"))); + v8::Local::Cast( + callFrame + ->Get(context, + toV8StringInternalized(m_isolate, "setVariableValue")) + .ToLocalChecked()); v8::Local argv[] = { v8::Local(v8::Integer::New(m_isolate, scopeNumber)), variableName, newValue}; - return setVariableValueFunction->Call(m_debuggerContext.Get(m_isolate), - callFrame, + return setVariableValueFunction->Call(context, callFrame, V8_INSPECTOR_ARRAY_LENGTH(argv), argv); } diff --git a/src/inspector/V8ConsoleMessage.cpp b/src/inspector/V8ConsoleMessage.cpp index 606c7fd1f6..354a689eab 100644 --- a/src/inspector/V8ConsoleMessage.cpp +++ b/src/inspector/V8ConsoleMessage.cpp @@ -63,8 +63,9 @@ const unsigned maxStackDepthLimit = 32; class V8ValueStringBuilder { public: - static String16 toString(v8::Local value, v8::Isolate* isolate) { - V8ValueStringBuilder builder(isolate); + static String16 toString(v8::Local value, + v8::Local context) { + V8ValueStringBuilder builder(context); if (!builder.append(value)) return String16(); return builder.toString(); } @@ -75,10 +76,11 @@ class V8ValueStringBuilder { IgnoreUndefined = 1 << 1, }; - V8ValueStringBuilder(v8::Isolate* isolate) + V8ValueStringBuilder(v8::Local context) : m_arrayLimit(maxArrayItemsLimit), - m_isolate(isolate), - m_tryCatch(isolate) {} + m_isolate(context->GetIsolate()), + m_tryCatch(context->GetIsolate()), + m_context(context) {} bool append(v8::Local value, unsigned ignoreOptions = 0) { if (value.IsEmpty()) return true; @@ -133,7 +135,9 @@ class V8ValueStringBuilder { m_visitedArrays.push_back(array); for (uint32_t i = 0; i < length; ++i) { if (i) m_builder.append(','); - if (!append(array->Get(i), IgnoreNull | IgnoreUndefined)) { + v8::Local value; + if (!array->Get(m_context, i).ToLocal(&value)) continue; + if (!append(value, IgnoreNull | IgnoreUndefined)) { result = false; break; } @@ -165,6 +169,7 @@ class V8ValueStringBuilder { String16Builder m_builder; std::vector> m_visitedArrays; v8::TryCatch m_tryCatch; + v8::Local m_context; }; } // namespace @@ -336,11 +341,13 @@ ConsoleAPIType V8ConsoleMessage::type() const { return m_type; } std::unique_ptr V8ConsoleMessage::createForConsoleAPI( double timestamp, ConsoleAPIType type, const std::vector>& arguments, - std::unique_ptr stackTrace, InspectedContext* context) { - v8::Isolate* isolate = context->isolate(); - int contextId = context->contextId(); - int contextGroupId = context->contextGroupId(); - V8InspectorImpl* inspector = context->inspector(); + std::unique_ptr stackTrace, + InspectedContext* inspectedContext) { + v8::Isolate* isolate = inspectedContext->isolate(); + int contextId = inspectedContext->contextId(); + int contextGroupId = inspectedContext->contextGroupId(); + V8InspectorImpl* inspector = inspectedContext->inspector(); + v8::Local context = inspectedContext->context(); std::unique_ptr message = wrapUnique( new V8ConsoleMessage(V8MessageOrigin::kConsole, timestamp, String16())); @@ -356,7 +363,7 @@ std::unique_ptr V8ConsoleMessage::createForConsoleAPI( message->m_arguments.push_back( wrapUnique(new v8::Global(isolate, arguments.at(i)))); if (arguments.size()) - message->m_message = V8ValueStringBuilder::toString(arguments[0], isolate); + message->m_message = V8ValueStringBuilder::toString(arguments[0], context); V8ConsoleAPIType clientType = V8ConsoleAPIType::kLog; if (type == ConsoleAPIType::kDebug || type == ConsoleAPIType::kCount || diff --git a/src/inspector/V8Debugger.cpp b/src/inspector/V8Debugger.cpp index 1d4217cf93..675623de34 100644 --- a/src/inspector/V8Debugger.cpp +++ b/src/inspector/V8Debugger.cpp @@ -35,12 +35,14 @@ v8::MaybeLocal V8Debugger::callDebuggerMethod( const char* functionName, int argc, v8::Local argv[]) { v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicrotasks); + DCHECK(m_isolate->InContext()); + v8::Local context = m_isolate->GetCurrentContext(); v8::Local debuggerScript = m_debuggerScript.Get(m_isolate); v8::Local function = v8::Local::Cast( - debuggerScript->Get(toV8StringInternalized(m_isolate, functionName))); - DCHECK(m_isolate->InContext()); - return function->Call(m_isolate->GetCurrentContext(), debuggerScript, argc, - argv); + debuggerScript + ->Get(context, toV8StringInternalized(m_isolate, functionName)) + .ToLocalChecked()); + return function->Call(context, debuggerScript, argc, argv); } V8Debugger::V8Debugger(v8::Isolate* isolate, V8InspectorImpl* inspector) @@ -110,15 +112,18 @@ void V8Debugger::getCompiledScripts( v8::HandleScope scope(m_isolate); v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicrotasks); + v8::Local context = debuggerContext(); v8::Local debuggerScript = m_debuggerScript.Get(m_isolate); DCHECK(!debuggerScript->IsUndefined()); v8::Local getScriptsFunction = v8::Local::Cast( - debuggerScript->Get(toV8StringInternalized(m_isolate, "getScripts"))); + debuggerScript + ->Get(context, toV8StringInternalized(m_isolate, "getScripts")) + .ToLocalChecked()); v8::Local argv[] = {v8::Integer::New(m_isolate, contextGroupId)}; v8::Local value; if (!getScriptsFunction - ->Call(debuggerContext(), debuggerScript, - V8_INSPECTOR_ARRAY_LENGTH(argv), argv) + ->Call(context, debuggerScript, V8_INSPECTOR_ARRAY_LENGTH(argv), + argv) .ToLocal(&value)) return; DCHECK(value->IsArray()); @@ -126,9 +131,10 @@ void V8Debugger::getCompiledScripts( result.reserve(scriptsArray->Length()); for (unsigned i = 0; i < scriptsArray->Length(); ++i) { v8::Local scriptObject = v8::Local::Cast( - scriptsArray->Get(v8::Integer::New(m_isolate, i))); + scriptsArray->Get(context, v8::Integer::New(m_isolate, i)) + .ToLocalChecked()); result.push_back(wrapUnique( - new V8DebuggerScript(m_isolate, scriptObject, inLiveEditScope))); + new V8DebuggerScript(context, scriptObject, inLiveEditScope))); } } @@ -137,55 +143,82 @@ String16 V8Debugger::setBreakpoint(const String16& sourceID, int* actualLineNumber, int* actualColumnNumber) { v8::HandleScope scope(m_isolate); - v8::Context::Scope contextScope(debuggerContext()); + v8::Local context = debuggerContext(); + v8::Context::Scope contextScope(context); v8::Local info = v8::Object::New(m_isolate); - info->Set(toV8StringInternalized(m_isolate, "sourceID"), - toV8String(m_isolate, sourceID)); - info->Set(toV8StringInternalized(m_isolate, "lineNumber"), - v8::Integer::New(m_isolate, scriptBreakpoint.lineNumber)); - info->Set(toV8StringInternalized(m_isolate, "columnNumber"), - v8::Integer::New(m_isolate, scriptBreakpoint.columnNumber)); - info->Set(toV8StringInternalized(m_isolate, "condition"), - toV8String(m_isolate, scriptBreakpoint.condition)); + bool success = false; + success = info->Set(context, toV8StringInternalized(m_isolate, "sourceID"), + toV8String(m_isolate, sourceID)) + .FromMaybe(false); + DCHECK(success); + success = info->Set(context, toV8StringInternalized(m_isolate, "lineNumber"), + v8::Integer::New(m_isolate, scriptBreakpoint.lineNumber)) + .FromMaybe(false); + DCHECK(success); + success = + info->Set(context, toV8StringInternalized(m_isolate, "columnNumber"), + v8::Integer::New(m_isolate, scriptBreakpoint.columnNumber)) + .FromMaybe(false); + DCHECK(success); + success = info->Set(context, toV8StringInternalized(m_isolate, "condition"), + toV8String(m_isolate, scriptBreakpoint.condition)) + .FromMaybe(false); + DCHECK(success); - v8::Local setBreakpointFunction = - v8::Local::Cast(m_debuggerScript.Get(m_isolate)->Get( - toV8StringInternalized(m_isolate, "setBreakpoint"))); + v8::Local setBreakpointFunction = v8::Local::Cast( + m_debuggerScript.Get(m_isolate) + ->Get(context, toV8StringInternalized(m_isolate, "setBreakpoint")) + .ToLocalChecked()); v8::Local breakpointId = v8::Debug::Call(debuggerContext(), setBreakpointFunction, info) .ToLocalChecked(); if (!breakpointId->IsString()) return ""; *actualLineNumber = - info->Get(toV8StringInternalized(m_isolate, "lineNumber"))->Int32Value(); + info->Get(context, toV8StringInternalized(m_isolate, "lineNumber")) + .ToLocalChecked() + ->Int32Value(context) + .FromJust(); *actualColumnNumber = - info->Get(toV8StringInternalized(m_isolate, "columnNumber")) - ->Int32Value(); + info->Get(context, toV8StringInternalized(m_isolate, "columnNumber")) + .ToLocalChecked() + ->Int32Value(context) + .FromJust(); return toProtocolString(breakpointId.As()); } void V8Debugger::removeBreakpoint(const String16& breakpointId) { v8::HandleScope scope(m_isolate); - v8::Context::Scope contextScope(debuggerContext()); + v8::Local context = debuggerContext(); + v8::Context::Scope contextScope(context); v8::Local info = v8::Object::New(m_isolate); - info->Set(toV8StringInternalized(m_isolate, "breakpointId"), - toV8String(m_isolate, breakpointId)); + bool success = false; + success = + info->Set(context, toV8StringInternalized(m_isolate, "breakpointId"), + toV8String(m_isolate, breakpointId)) + .FromMaybe(false); + DCHECK(success); v8::Local removeBreakpointFunction = - v8::Local::Cast(m_debuggerScript.Get(m_isolate)->Get( - toV8StringInternalized(m_isolate, "removeBreakpoint"))); + v8::Local::Cast( + m_debuggerScript.Get(m_isolate) + ->Get(context, + toV8StringInternalized(m_isolate, "removeBreakpoint")) + .ToLocalChecked()); v8::Debug::Call(debuggerContext(), removeBreakpointFunction, info) .ToLocalChecked(); } void V8Debugger::clearBreakpoints() { v8::HandleScope scope(m_isolate); - v8::Context::Scope contextScope(debuggerContext()); + v8::Local context = debuggerContext(); + v8::Context::Scope contextScope(context); - v8::Local clearBreakpoints = - v8::Local::Cast(m_debuggerScript.Get(m_isolate)->Get( - toV8StringInternalized(m_isolate, "clearBreakpoints"))); + v8::Local clearBreakpoints = v8::Local::Cast( + m_debuggerScript.Get(m_isolate) + ->Get(context, toV8StringInternalized(m_isolate, "clearBreakpoints")) + .ToLocalChecked()); v8::Debug::Call(debuggerContext(), clearBreakpoints).ToLocalChecked(); } @@ -195,14 +228,21 @@ void V8Debugger::setBreakpointsActivated(bool activated) { return; } v8::HandleScope scope(m_isolate); - v8::Context::Scope contextScope(debuggerContext()); + v8::Local context = debuggerContext(); + v8::Context::Scope contextScope(context); v8::Local info = v8::Object::New(m_isolate); - info->Set(toV8StringInternalized(m_isolate, "enabled"), - v8::Boolean::New(m_isolate, activated)); + bool success = false; + success = info->Set(context, toV8StringInternalized(m_isolate, "enabled"), + v8::Boolean::New(m_isolate, activated)) + .FromMaybe(false); + DCHECK(success); v8::Local setBreakpointsActivated = - v8::Local::Cast(m_debuggerScript.Get(m_isolate)->Get( - toV8StringInternalized(m_isolate, "setBreakpointsActivated"))); + v8::Local::Cast( + m_debuggerScript.Get(m_isolate) + ->Get(context, toV8StringInternalized(m_isolate, + "setBreakpointsActivated")) + .ToLocalChecked()); v8::Debug::Call(debuggerContext(), setBreakpointsActivated, info) .ToLocalChecked(); @@ -212,12 +252,14 @@ void V8Debugger::setBreakpointsActivated(bool activated) { V8Debugger::PauseOnExceptionsState V8Debugger::getPauseOnExceptionsState() { DCHECK(enabled()); v8::HandleScope scope(m_isolate); - v8::Context::Scope contextScope(debuggerContext()); + v8::Local context = debuggerContext(); + v8::Context::Scope contextScope(context); v8::Local argv[] = {v8::Undefined(m_isolate)}; v8::Local result = callDebuggerMethod("pauseOnExceptionsState", 0, argv).ToLocalChecked(); - return static_cast(result->Int32Value()); + return static_cast( + result->Int32Value(context).FromJust()); } void V8Debugger::setPauseOnExceptionsState( @@ -357,12 +399,20 @@ bool V8Debugger::setScriptSource( v8result = maybeResult.ToLocalChecked(); } DCHECK(!v8result.IsEmpty()); - v8::Local resultTuple = v8result->ToObject(m_isolate); - int code = - static_cast(resultTuple->Get(0)->ToInteger(m_isolate)->Value()); + v8::Local context = m_isolate->GetCurrentContext(); + v8::Local resultTuple = + v8result->ToObject(context).ToLocalChecked(); + int code = static_cast(resultTuple->Get(context, 0) + .ToLocalChecked() + ->ToInteger(context) + .ToLocalChecked() + ->Value()); switch (code) { case 0: { - *stackChanged = resultTuple->Get(1)->BooleanValue(); + *stackChanged = resultTuple->Get(context, 1) + .ToLocalChecked() + ->BooleanValue(context) + .FromJust(); // Call stack may have changed after if the edited function was on the // stack. if (!dryRun && isPaused()) { @@ -376,11 +426,20 @@ bool V8Debugger::setScriptSource( *exceptionDetails = protocol::Runtime::ExceptionDetails::create() .setExceptionId(m_inspector->nextExceptionId()) - .setText(toProtocolStringWithTypeCheck(resultTuple->Get(2))) - .setLineNumber( - resultTuple->Get(3)->ToInteger(m_isolate)->Value() - 1) - .setColumnNumber( - resultTuple->Get(4)->ToInteger(m_isolate)->Value() - 1) + .setText(toProtocolStringWithTypeCheck( + resultTuple->Get(context, 2).ToLocalChecked())) + .setLineNumber(resultTuple->Get(context, 3) + .ToLocalChecked() + ->ToInteger(context) + .ToLocalChecked() + ->Value() - + 1) + .setColumnNumber(resultTuple->Get(context, 4) + .ToLocalChecked() + ->ToInteger(context) + .ToLocalChecked() + ->Value() - + 1) .build(); return false; } @@ -394,8 +453,11 @@ JavaScriptCallFrames V8Debugger::currentCallFrames(int limit) { v8::Local currentCallFramesV8; if (m_executionState.IsEmpty()) { v8::Local currentCallFramesFunction = - v8::Local::Cast(m_debuggerScript.Get(m_isolate)->Get( - toV8StringInternalized(m_isolate, "currentCallFrames"))); + v8::Local::Cast( + m_debuggerScript.Get(m_isolate) + ->Get(debuggerContext(), + toV8StringInternalized(m_isolate, "currentCallFrames")) + .ToLocalChecked()); currentCallFramesV8 = v8::Debug::Call(debuggerContext(), currentCallFramesFunction, v8::Integer::New(m_isolate, limit)) @@ -459,10 +521,11 @@ void V8Debugger::handleProgramBreak(v8::Local pausedContext, if (!hitBreakpointNumbers.IsEmpty()) { breakpointIds.reserve(hitBreakpointNumbers->Length()); for (size_t i = 0; i < hitBreakpointNumbers->Length(); i++) { - v8::Local hitBreakpointNumber = hitBreakpointNumbers->Get(i); - DCHECK(!hitBreakpointNumber.IsEmpty() && hitBreakpointNumber->IsInt32()); - breakpointIds.push_back( - String16::fromInteger(hitBreakpointNumber->Int32Value())); + v8::Local hitBreakpointNumber = + hitBreakpointNumbers->Get(debuggerContext(), i).ToLocalChecked(); + DCHECK(hitBreakpointNumber->IsInt32()); + breakpointIds.push_back(String16::fromInteger( + hitBreakpointNumber->Int32Value(debuggerContext()).FromJust())); } } @@ -507,7 +570,10 @@ v8::Local V8Debugger::callInternalGetterFunction( v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicrotasks); v8::Local getterValue = - object->Get(toV8StringInternalized(m_isolate, functionName)); + object + ->Get(m_isolate->GetCurrentContext(), + toV8StringInternalized(m_isolate, functionName)) + .ToLocalChecked(); DCHECK(!getterValue.IsEmpty() && getterValue->IsFunction()); return v8::Local::Cast(getterValue) ->Call(m_isolate->GetCurrentContext(), object, 0, 0) @@ -546,9 +612,10 @@ void V8Debugger::handleV8DebugEvent( if (value->IsNull()) return; DCHECK(value->IsObject()); v8::Local scriptObject = v8::Local::Cast(value); - agent->didParseSource(wrapUnique(new V8DebuggerScript( - m_isolate, scriptObject, inLiveEditScope)), - event == v8::AfterCompile); + agent->didParseSource( + wrapUnique(new V8DebuggerScript(debuggerContext(), scriptObject, + inLiveEditScope)), + event == v8::AfterCompile); } else if (event == v8::Exception) { v8::Local eventData = eventDetails.GetEventData(); v8::Local exception = @@ -580,7 +647,8 @@ void V8Debugger::handleV8AsyncTaskEvent(v8::Local context, String16 name = toProtocolStringWithTypeCheck( callInternalGetterFunction(eventData, "name")); int id = callInternalGetterFunction(eventData, "id") - ->ToInteger(m_isolate) + ->ToInteger(context) + .ToLocalChecked() ->Value(); // The scopes for the ids are defined by the eventData.name namespaces. There // are currently two namespaces: "Object." and "Promise.". diff --git a/src/inspector/V8Debugger.h b/src/inspector/V8Debugger.h index c4221b39ef..ca12a76b4f 100644 --- a/src/inspector/V8Debugger.h +++ b/src/inspector/V8Debugger.h @@ -100,6 +100,8 @@ class V8Debugger { void muteScriptParsedEvents(); void unmuteScriptParsedEvents(); + V8InspectorImpl* inspector() { return m_inspector; } + private: void compileDebuggerScript(); v8::MaybeLocal callDebuggerMethod(const char* functionName, diff --git a/src/inspector/V8DebuggerScript.cpp b/src/inspector/V8DebuggerScript.cpp index a7d018a553..cc6f8c82fd 100644 --- a/src/inspector/V8DebuggerScript.cpp +++ b/src/inspector/V8DebuggerScript.cpp @@ -67,44 +67,50 @@ static String16 calculateHash(const String16& str) { return hash.toString(); } -V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, +static v8::Local GetChecked(v8::Local context, + v8::Local object, + const char* name) { + return object + ->Get(context, toV8StringInternalized(context->GetIsolate(), name)) + .ToLocalChecked(); +} + +static int64_t GetCheckedInt(v8::Local context, + v8::Local object, const char* name) { + return GetChecked(context, object, name) + ->ToInteger(context) + .ToLocalChecked() + ->Value(); +} + +V8DebuggerScript::V8DebuggerScript(v8::Local context, v8::Local object, bool isLiveEdit) { - v8::Local idValue = - object->Get(toV8StringInternalized(isolate, "id")); + v8::Isolate* isolate = context->GetIsolate(); + v8::Local idValue = GetChecked(context, object, "id"); DCHECK(!idValue.IsEmpty() && idValue->IsInt32()); - m_id = String16::fromInteger(idValue->Int32Value()); + m_id = String16::fromInteger(idValue->Int32Value(context).FromJust()); - m_url = toProtocolStringWithTypeCheck( - object->Get(toV8StringInternalized(isolate, "name"))); - m_sourceURL = toProtocolStringWithTypeCheck( - object->Get(toV8StringInternalized(isolate, "sourceURL"))); + m_url = toProtocolStringWithTypeCheck(GetChecked(context, object, "name")); + m_sourceURL = + toProtocolStringWithTypeCheck(GetChecked(context, object, "sourceURL")); m_sourceMappingURL = toProtocolStringWithTypeCheck( - object->Get(toV8StringInternalized(isolate, "sourceMappingURL"))); - m_startLine = object->Get(toV8StringInternalized(isolate, "startLine")) - ->ToInteger(isolate) - ->Value(); - m_startColumn = object->Get(toV8StringInternalized(isolate, "startColumn")) - ->ToInteger(isolate) - ->Value(); - m_endLine = object->Get(toV8StringInternalized(isolate, "endLine")) - ->ToInteger(isolate) - ->Value(); - m_endColumn = object->Get(toV8StringInternalized(isolate, "endColumn")) - ->ToInteger(isolate) - ->Value(); + GetChecked(context, object, "sourceMappingURL")); + m_startLine = GetCheckedInt(context, object, "startLine"); + m_startColumn = GetCheckedInt(context, object, "startColumn"); + m_endLine = GetCheckedInt(context, object, "endLine"); + m_endColumn = GetCheckedInt(context, object, "endColumn"); m_executionContextAuxData = toProtocolStringWithTypeCheck( - object->Get(toV8StringInternalized(isolate, "executionContextAuxData"))); - m_executionContextId = - object->Get(toV8StringInternalized(isolate, "executionContextId")) - ->ToInteger(isolate) - ->Value(); + GetChecked(context, object, "executionContextAuxData")); + m_executionContextId = GetCheckedInt(context, object, "executionContextId"); m_isLiveEdit = isLiveEdit; - v8::Local sourceValue = - object->Get(toV8StringInternalized(isolate, "source")); - if (!sourceValue.IsEmpty() && sourceValue->IsString()) - setSource(isolate, sourceValue.As()); + v8::Local sourceValue; + if (!object->Get(context, toV8StringInternalized(isolate, "source")) + .ToLocal(&sourceValue) || + !sourceValue->IsString()) + return; + setSource(isolate, sourceValue.As()); } V8DebuggerScript::~V8DebuggerScript() {} diff --git a/src/inspector/V8DebuggerScript.h b/src/inspector/V8DebuggerScript.h index e3fc00562f..bfc24f4b62 100644 --- a/src/inspector/V8DebuggerScript.h +++ b/src/inspector/V8DebuggerScript.h @@ -41,7 +41,8 @@ class V8DebuggerScript { V8_INSPECTOR_DISALLOW_COPY(V8DebuggerScript); public: - V8DebuggerScript(v8::Isolate*, v8::Local, bool isLiveEdit); + V8DebuggerScript(v8::Local, v8::Local, + bool isLiveEdit); ~V8DebuggerScript(); const String16& scriptId() const { return m_id; } diff --git a/src/inspector/V8InjectedScriptHost.cpp b/src/inspector/V8InjectedScriptHost.cpp index 376a8f58ce..3ccf31e2b4 100644 --- a/src/inspector/V8InjectedScriptHost.cpp +++ b/src/inspector/V8InjectedScriptHost.cpp @@ -189,10 +189,13 @@ void V8InjectedScriptHost::bindCallback( const v8::FunctionCallbackInfo& info) { if (info.Length() < 2 || !info[1]->IsString()) return; InjectedScriptNative* injectedScriptNative = - InjectedScriptNative::fromInjectedScriptHost(info.Holder()); + InjectedScriptNative::fromInjectedScriptHost(info.GetIsolate(), + info.Holder()); if (!injectedScriptNative) return; - v8::Local v8groupName = info[1]->ToString(info.GetIsolate()); + v8::Local context = info.GetIsolate()->GetCurrentContext(); + v8::Local v8groupName = + info[1]->ToString(context).ToLocalChecked(); String16 groupName = toProtocolStringWithTypeCheck(v8groupName); int id = injectedScriptNative->bind(info[0], groupName); info.GetReturnValue().Set(id); diff --git a/src/inspector/V8InspectorImpl.cpp b/src/inspector/V8InspectorImpl.cpp index c501302140..f631473fad 100644 --- a/src/inspector/V8InspectorImpl.cpp +++ b/src/inspector/V8InspectorImpl.cpp @@ -37,12 +37,11 @@ #include "src/inspector/V8Debugger.h" #include "src/inspector/V8DebuggerAgentImpl.h" #include "src/inspector/V8InspectorSessionImpl.h" +#include "src/inspector/V8ProfilerAgentImpl.h" #include "src/inspector/V8RuntimeAgentImpl.h" #include "src/inspector/V8StackTraceImpl.h" #include "src/inspector/protocol/Protocol.h" -#include "include/v8-profiler.h" - namespace v8_inspector { std::unique_ptr V8Inspector::create(v8::Isolate* isolate, @@ -74,6 +73,13 @@ V8RuntimeAgentImpl* V8InspectorImpl::enabledRuntimeAgentForGroup( return agent && agent->enabled() ? agent : nullptr; } +V8ProfilerAgentImpl* V8InspectorImpl::enabledProfilerAgentForGroup( + int contextGroupId) { + V8InspectorSessionImpl* session = sessionForContextGroup(contextGroupId); + V8ProfilerAgentImpl* agent = session ? session->profilerAgent() : nullptr; + return agent && agent->enabled() ? agent : nullptr; +} + v8::MaybeLocal V8InspectorImpl::runCompiledScript( v8::Local context, v8::Local script) { v8::MicrotasksScope microtasksScope(m_isolate, @@ -271,11 +277,15 @@ void V8InspectorImpl::didExecuteScript(v8::Local context) { } void V8InspectorImpl::idleStarted() { - m_isolate->GetCpuProfiler()->SetIdle(true); + for (auto it = m_sessions.begin(); it != m_sessions.end(); ++it) { + if (it->second->profilerAgent()->idleStarted()) return; + } } void V8InspectorImpl::idleFinished() { - m_isolate->GetCpuProfiler()->SetIdle(false); + for (auto it = m_sessions.begin(); it != m_sessions.end(); ++it) { + if (it->second->profilerAgent()->idleFinished()) return; + } } unsigned V8InspectorImpl::exceptionThrown( diff --git a/src/inspector/V8InspectorImpl.h b/src/inspector/V8InspectorImpl.h index 053aeab1f8..c617f32109 100644 --- a/src/inspector/V8InspectorImpl.h +++ b/src/inspector/V8InspectorImpl.h @@ -46,6 +46,7 @@ class V8ConsoleMessageStorage; class V8Debugger; class V8DebuggerAgentImpl; class V8InspectorSessionImpl; +class V8ProfilerAgentImpl; class V8RuntimeAgentImpl; class V8StackTraceImpl; @@ -119,6 +120,7 @@ class V8InspectorImpl : public V8Inspector { InspectedContext* getContext(int groupId, int contextId) const; V8DebuggerAgentImpl* enabledDebuggerAgentForGroup(int contextGroupId); V8RuntimeAgentImpl* enabledRuntimeAgentForGroup(int contextGroupId); + V8ProfilerAgentImpl* enabledProfilerAgentForGroup(int contextGroupId); private: v8::Isolate* m_isolate; diff --git a/src/inspector/V8ProfilerAgentImpl.cpp b/src/inspector/V8ProfilerAgentImpl.cpp index 11a18a0cbe..dcf4418c65 100644 --- a/src/inspector/V8ProfilerAgentImpl.cpp +++ b/src/inspector/V8ProfilerAgentImpl.cpp @@ -304,4 +304,18 @@ bool V8ProfilerAgentImpl::isRecording() const { return m_recordingCPUProfile || !m_startedProfiles.empty(); } +bool V8ProfilerAgentImpl::idleStarted() { + if (m_profiler) m_profiler->SetIdle(true); + return m_profiler; +} + +bool V8ProfilerAgentImpl::idleFinished() { + if (m_profiler) m_profiler->SetIdle(false); + return m_profiler; +} + +void V8ProfilerAgentImpl::collectSample() { + if (m_profiler) m_profiler->CollectSample(); +} + } // namespace v8_inspector diff --git a/src/inspector/V8ProfilerAgentImpl.h b/src/inspector/V8ProfilerAgentImpl.h index d2c4c15397..de2db02184 100644 --- a/src/inspector/V8ProfilerAgentImpl.h +++ b/src/inspector/V8ProfilerAgentImpl.h @@ -43,6 +43,11 @@ class V8ProfilerAgentImpl : public protocol::Profiler::Backend { void consoleProfile(const String16& title); void consoleProfileEnd(const String16& title); + bool idleStarted(); + bool idleFinished(); + + void collectSample(); + private: String16 nextProfileId(); diff --git a/src/inspector/V8StackTraceImpl.cpp b/src/inspector/V8StackTraceImpl.cpp index 25a0e7caf7..972f2d28e8 100644 --- a/src/inspector/V8StackTraceImpl.cpp +++ b/src/inspector/V8StackTraceImpl.cpp @@ -6,6 +6,8 @@ #include "src/inspector/StringUtil.h" #include "src/inspector/V8Debugger.h" +#include "src/inspector/V8InspectorImpl.h" +#include "src/inspector/V8ProfilerAgentImpl.h" #include "src/inspector/protocol/Protocol.h" #include "include/v8-debug.h" @@ -158,7 +160,12 @@ std::unique_ptr V8StackTraceImpl::capture( v8::HandleScope handleScope(isolate); v8::Local stackTrace; if (isolate->InContext()) { - isolate->GetCpuProfiler()->CollectSample(); + if (debugger) { + V8InspectorImpl* inspector = debugger->inspector(); + V8ProfilerAgentImpl* profilerAgent = + inspector->enabledProfilerAgentForGroup(contextGroupId); + if (profilerAgent) profilerAgent->collectSample(); + } stackTrace = v8::StackTrace::CurrentStackTrace(isolate, maxStackSize, stackTraceOptions); } diff --git a/src/v8.gyp b/src/v8.gyp index 0598c99eec..2a3028b24a 100644 --- a/src/v8.gyp +++ b/src/v8.gyp @@ -1753,11 +1753,9 @@ 4324, # Struct padded due to declspec(align). 4714, # Function marked forceinline not inlined. 4800, # Value forced to bool. - 4996, # Deprecated function call. ], 'cflags': [ '-Wno-shorten-64-to-32', - '-Wno-deprecated-declarations', ], }], ['OS=="win" and v8_enable_i18n_support==1', {