Commit 072c6943 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[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}
parent 04c8a368
......@@ -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(
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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 ||
......
This diff is collapsed.
......@@ -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,
......
......@@ -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() {}
......
......@@ -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; }
......
......@@ -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);
......
......@@ -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(
......
......@@ -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;
......
......@@ -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
......@@ -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();
......
......@@ -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);
}
......
......@@ -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', {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment