[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}
This commit is contained in:
kozyatinskiy 2016-09-19 09:10:26 -07:00 committed by Commit bot
parent 04c8a36849
commit 072c694336
15 changed files with 272 additions and 132 deletions

View File

@ -26,8 +26,7 @@ void InjectedScriptNative::setOnInjectedScriptHost(
}
InjectedScriptNative* InjectedScriptNative::fromInjectedScriptHost(
v8::Local<v8::Object> injectedScriptObject) {
v8::Isolate* isolate = injectedScriptObject->GetIsolate();
v8::Isolate* isolate, v8::Local<v8::Object> injectedScriptObject) {
v8::HandleScope handleScope(isolate);
v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::Local<v8::Private> privateKey = v8::Private::ForApi(

View File

@ -19,7 +19,8 @@ class InjectedScriptNative final {
~InjectedScriptNative();
void setOnInjectedScriptHost(v8::Local<v8::Object>);
static InjectedScriptNative* fromInjectedScriptHost(v8::Local<v8::Object>);
static InjectedScriptNative* fromInjectedScriptHost(v8::Isolate* isolate,
v8::Local<v8::Object>);
int bind(v8::Local<v8::Value>, const String16& groupName);
void unbind(int id);

View File

@ -53,7 +53,8 @@ int JavaScriptCallFrame::callV8FunctionReturnInt(const char* name) const {
v8::Local<v8::Object> callFrame =
v8::Local<v8::Object>::New(m_isolate, m_callFrame);
v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(
callFrame->Get(toV8StringInternalized(m_isolate, name)));
callFrame->Get(context, toV8StringInternalized(m_isolate, name))
.ToLocalChecked());
v8::Local<v8::Value> 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<v8::Value> result =
v8::Local<v8::Object>::New(m_isolate, m_callFrame)
->Get(toV8StringInternalized(m_isolate, "isAtReturn"));
if (result.IsEmpty() || !result->IsBoolean()) return false;
return result->BooleanValue();
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(m_isolate, m_debuggerContext);
v8::Local<v8::Object> callFrame =
v8::Local<v8::Object>::New(m_isolate, m_callFrame);
v8::Local<v8::Value> result;
if (!callFrame->Get(context, toV8StringInternalized(m_isolate, "isAtReturn"))
.ToLocal(&result) ||
!result->IsBoolean())
return false;
return result.As<v8::Boolean>()->BooleanValue(context).FromMaybe(false);
}
v8::Local<v8::Object> JavaScriptCallFrame::details() const {
v8::MicrotasksScope microtasks(m_isolate,
v8::MicrotasksScope::kDoNotRunMicrotasks);
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(m_isolate, m_debuggerContext);
v8::Local<v8::Object> callFrame =
v8::Local<v8::Object>::New(m_isolate, m_callFrame);
v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(
callFrame->Get(toV8StringInternalized(m_isolate, "details")));
return v8::Local<v8::Object>::Cast(
func->Call(m_debuggerContext.Get(m_isolate), callFrame, 0, nullptr)
callFrame->Get(context, toV8StringInternalized(m_isolate, "details"))
.ToLocalChecked());
return v8::Local<v8::Object>::Cast(
func->Call(context, callFrame, 0, nullptr).ToLocalChecked());
}
v8::MaybeLocal<v8::Value> JavaScriptCallFrame::evaluate(
v8::Local<v8::Value> expression) {
v8::MicrotasksScope microtasks(m_isolate,
v8::MicrotasksScope::kRunMicrotasks);
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(m_isolate, m_debuggerContext);
v8::Local<v8::Object> callFrame =
v8::Local<v8::Object>::New(m_isolate, m_callFrame);
v8::Local<v8::Function> evalFunction = v8::Local<v8::Function>::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<v8::Value> JavaScriptCallFrame::restart() {
v8::MicrotasksScope microtasks(m_isolate,
v8::MicrotasksScope::kDoNotRunMicrotasks);
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(m_isolate, m_debuggerContext);
v8::Local<v8::Object> callFrame =
v8::Local<v8::Object>::New(m_isolate, m_callFrame);
v8::Local<v8::Function> restartFunction = v8::Local<v8::Function>::Cast(
callFrame->Get(toV8StringInternalized(m_isolate, "restart")));
callFrame->Get(context, toV8StringInternalized(m_isolate, "restart"))
.ToLocalChecked());
v8::Debug::SetLiveEditEnabled(m_isolate, true);
v8::MaybeLocal<v8::Value> result = restartFunction->Call(
m_debuggerContext.Get(m_isolate), callFrame, 0, nullptr);
@ -129,16 +142,20 @@ v8::MaybeLocal<v8::Value> JavaScriptCallFrame::setVariableValue(
v8::Local<v8::Value> newValue) {
v8::MicrotasksScope microtasks(m_isolate,
v8::MicrotasksScope::kDoNotRunMicrotasks);
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(m_isolate, m_debuggerContext);
v8::Local<v8::Object> callFrame =
v8::Local<v8::Object>::New(m_isolate, m_callFrame);
v8::Local<v8::Function> setVariableValueFunction =
v8::Local<v8::Function>::Cast(callFrame->Get(
toV8StringInternalized(m_isolate, "setVariableValue")));
v8::Local<v8::Function>::Cast(
callFrame
->Get(context,
toV8StringInternalized(m_isolate, "setVariableValue"))
.ToLocalChecked());
v8::Local<v8::Value> argv[] = {
v8::Local<v8::Value>(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);
}

View File

@ -63,8 +63,9 @@ const unsigned maxStackDepthLimit = 32;
class V8ValueStringBuilder {
public:
static String16 toString(v8::Local<v8::Value> value, v8::Isolate* isolate) {
V8ValueStringBuilder builder(isolate);
static String16 toString(v8::Local<v8::Value> value,
v8::Local<v8::Context> 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<v8::Context> 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<v8::Value> 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<v8::Value> 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<v8::Local<v8::Array>> m_visitedArrays;
v8::TryCatch m_tryCatch;
v8::Local<v8::Context> m_context;
};
} // namespace
@ -336,11 +341,13 @@ ConsoleAPIType V8ConsoleMessage::type() const { return m_type; }
std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForConsoleAPI(
double timestamp, ConsoleAPIType type,
const std::vector<v8::Local<v8::Value>>& arguments,
std::unique_ptr<V8StackTraceImpl> stackTrace, InspectedContext* context) {
v8::Isolate* isolate = context->isolate();
int contextId = context->contextId();
int contextGroupId = context->contextGroupId();
V8InspectorImpl* inspector = context->inspector();
std::unique_ptr<V8StackTraceImpl> stackTrace,
InspectedContext* inspectedContext) {
v8::Isolate* isolate = inspectedContext->isolate();
int contextId = inspectedContext->contextId();
int contextGroupId = inspectedContext->contextGroupId();
V8InspectorImpl* inspector = inspectedContext->inspector();
v8::Local<v8::Context> context = inspectedContext->context();
std::unique_ptr<V8ConsoleMessage> message = wrapUnique(
new V8ConsoleMessage(V8MessageOrigin::kConsole, timestamp, String16()));
@ -356,7 +363,7 @@ std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForConsoleAPI(
message->m_arguments.push_back(
wrapUnique(new v8::Global<v8::Value>(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 ||

View File

@ -35,12 +35,14 @@ v8::MaybeLocal<v8::Value> V8Debugger::callDebuggerMethod(
const char* functionName, int argc, v8::Local<v8::Value> argv[]) {
v8::MicrotasksScope microtasks(m_isolate,
v8::MicrotasksScope::kDoNotRunMicrotasks);
DCHECK(m_isolate->InContext());
v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate);
v8::Local<v8::Function> function = v8::Local<v8::Function>::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<v8::Context> context = debuggerContext();
v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate);
DCHECK(!debuggerScript->IsUndefined());
v8::Local<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast(
debuggerScript->Get(toV8StringInternalized(m_isolate, "getScripts")));
debuggerScript
->Get(context, toV8StringInternalized(m_isolate, "getScripts"))
.ToLocalChecked());
v8::Local<v8::Value> argv[] = {v8::Integer::New(m_isolate, contextGroupId)};
v8::Local<v8::Value> 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<v8::Object> scriptObject = v8::Local<v8::Object>::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<v8::Context> context = debuggerContext();
v8::Context::Scope contextScope(context);
v8::Local<v8::Object> 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<v8::Function> setBreakpointFunction =
v8::Local<v8::Function>::Cast(m_debuggerScript.Get(m_isolate)->Get(
toV8StringInternalized(m_isolate, "setBreakpoint")));
v8::Local<v8::Function> setBreakpointFunction = v8::Local<v8::Function>::Cast(
m_debuggerScript.Get(m_isolate)
->Get(context, toV8StringInternalized(m_isolate, "setBreakpoint"))
.ToLocalChecked());
v8::Local<v8::Value> 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<v8::String>());
}
void V8Debugger::removeBreakpoint(const String16& breakpointId) {
v8::HandleScope scope(m_isolate);
v8::Context::Scope contextScope(debuggerContext());
v8::Local<v8::Context> context = debuggerContext();
v8::Context::Scope contextScope(context);
v8::Local<v8::Object> 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<v8::Function> removeBreakpointFunction =
v8::Local<v8::Function>::Cast(m_debuggerScript.Get(m_isolate)->Get(
toV8StringInternalized(m_isolate, "removeBreakpoint")));
v8::Local<v8::Function>::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<v8::Context> context = debuggerContext();
v8::Context::Scope contextScope(context);
v8::Local<v8::Function> clearBreakpoints =
v8::Local<v8::Function>::Cast(m_debuggerScript.Get(m_isolate)->Get(
toV8StringInternalized(m_isolate, "clearBreakpoints")));
v8::Local<v8::Function> clearBreakpoints = v8::Local<v8::Function>::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<v8::Context> context = debuggerContext();
v8::Context::Scope contextScope(context);
v8::Local<v8::Object> 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<v8::Function> setBreakpointsActivated =
v8::Local<v8::Function>::Cast(m_debuggerScript.Get(m_isolate)->Get(
toV8StringInternalized(m_isolate, "setBreakpointsActivated")));
v8::Local<v8::Function>::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<v8::Context> context = debuggerContext();
v8::Context::Scope contextScope(context);
v8::Local<v8::Value> argv[] = {v8::Undefined(m_isolate)};
v8::Local<v8::Value> result =
callDebuggerMethod("pauseOnExceptionsState", 0, argv).ToLocalChecked();
return static_cast<V8Debugger::PauseOnExceptionsState>(result->Int32Value());
return static_cast<V8Debugger::PauseOnExceptionsState>(
result->Int32Value(context).FromJust());
}
void V8Debugger::setPauseOnExceptionsState(
@ -357,12 +399,20 @@ bool V8Debugger::setScriptSource(
v8result = maybeResult.ToLocalChecked();
}
DCHECK(!v8result.IsEmpty());
v8::Local<v8::Object> resultTuple = v8result->ToObject(m_isolate);
int code =
static_cast<int>(resultTuple->Get(0)->ToInteger(m_isolate)->Value());
v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
v8::Local<v8::Object> resultTuple =
v8result->ToObject(context).ToLocalChecked();
int code = static_cast<int>(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<v8::Value> currentCallFramesV8;
if (m_executionState.IsEmpty()) {
v8::Local<v8::Function> currentCallFramesFunction =
v8::Local<v8::Function>::Cast(m_debuggerScript.Get(m_isolate)->Get(
toV8StringInternalized(m_isolate, "currentCallFrames")));
v8::Local<v8::Function>::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<v8::Context> pausedContext,
if (!hitBreakpointNumbers.IsEmpty()) {
breakpointIds.reserve(hitBreakpointNumbers->Length());
for (size_t i = 0; i < hitBreakpointNumbers->Length(); i++) {
v8::Local<v8::Value> hitBreakpointNumber = hitBreakpointNumbers->Get(i);
DCHECK(!hitBreakpointNumber.IsEmpty() && hitBreakpointNumber->IsInt32());
breakpointIds.push_back(
String16::fromInteger(hitBreakpointNumber->Int32Value()));
v8::Local<v8::Value> hitBreakpointNumber =
hitBreakpointNumbers->Get(debuggerContext(), i).ToLocalChecked();
DCHECK(hitBreakpointNumber->IsInt32());
breakpointIds.push_back(String16::fromInteger(
hitBreakpointNumber->Int32Value(debuggerContext()).FromJust()));
}
}
@ -507,7 +570,10 @@ v8::Local<v8::Value> V8Debugger::callInternalGetterFunction(
v8::MicrotasksScope microtasks(m_isolate,
v8::MicrotasksScope::kDoNotRunMicrotasks);
v8::Local<v8::Value> 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<v8::Function>::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<v8::Object> scriptObject = v8::Local<v8::Object>::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<v8::Object> eventData = eventDetails.GetEventData();
v8::Local<v8::Value> exception =
@ -580,7 +647,8 @@ void V8Debugger::handleV8AsyncTaskEvent(v8::Local<v8::Context> 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.".

View File

@ -100,6 +100,8 @@ class V8Debugger {
void muteScriptParsedEvents();
void unmuteScriptParsedEvents();
V8InspectorImpl* inspector() { return m_inspector; }
private:
void compileDebuggerScript();
v8::MaybeLocal<v8::Value> callDebuggerMethod(const char* functionName,

View File

@ -67,44 +67,50 @@ static String16 calculateHash(const String16& str) {
return hash.toString();
}
V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate,
static v8::Local<v8::Value> GetChecked(v8::Local<v8::Context> context,
v8::Local<v8::Object> object,
const char* name) {
return object
->Get(context, toV8StringInternalized(context->GetIsolate(), name))
.ToLocalChecked();
}
static int64_t GetCheckedInt(v8::Local<v8::Context> context,
v8::Local<v8::Object> object, const char* name) {
return GetChecked(context, object, name)
->ToInteger(context)
.ToLocalChecked()
->Value();
}
V8DebuggerScript::V8DebuggerScript(v8::Local<v8::Context> context,
v8::Local<v8::Object> object,
bool isLiveEdit) {
v8::Local<v8::Value> idValue =
object->Get(toV8StringInternalized(isolate, "id"));
v8::Isolate* isolate = context->GetIsolate();
v8::Local<v8::Value> 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<v8::Value> sourceValue =
object->Get(toV8StringInternalized(isolate, "source"));
if (!sourceValue.IsEmpty() && sourceValue->IsString())
setSource(isolate, sourceValue.As<v8::String>());
v8::Local<v8::Value> sourceValue;
if (!object->Get(context, toV8StringInternalized(isolate, "source"))
.ToLocal(&sourceValue) ||
!sourceValue->IsString())
return;
setSource(isolate, sourceValue.As<v8::String>());
}
V8DebuggerScript::~V8DebuggerScript() {}

View File

@ -41,7 +41,8 @@ class V8DebuggerScript {
V8_INSPECTOR_DISALLOW_COPY(V8DebuggerScript);
public:
V8DebuggerScript(v8::Isolate*, v8::Local<v8::Object>, bool isLiveEdit);
V8DebuggerScript(v8::Local<v8::Context>, v8::Local<v8::Object>,
bool isLiveEdit);
~V8DebuggerScript();
const String16& scriptId() const { return m_id; }

View File

@ -189,10 +189,13 @@ void V8InjectedScriptHost::bindCallback(
const v8::FunctionCallbackInfo<v8::Value>& 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<v8::String> v8groupName = info[1]->ToString(info.GetIsolate());
v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
v8::Local<v8::String> v8groupName =
info[1]->ToString(context).ToLocalChecked();
String16 groupName = toProtocolStringWithTypeCheck(v8groupName);
int id = injectedScriptNative->bind(info[0], groupName);
info.GetReturnValue().Set(id);

View File

@ -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> 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<v8::Value> V8InspectorImpl::runCompiledScript(
v8::Local<v8::Context> context, v8::Local<v8::Script> script) {
v8::MicrotasksScope microtasksScope(m_isolate,
@ -271,11 +277,15 @@ void V8InspectorImpl::didExecuteScript(v8::Local<v8::Context> 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(

View File

@ -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;

View File

@ -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

View File

@ -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();

View File

@ -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> V8StackTraceImpl::capture(
v8::HandleScope handleScope(isolate);
v8::Local<v8::StackTrace> 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);
}

View File

@ -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', {