Commit e6ca9c67 authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[Cleanup] Avoid deprecated methods in inspector/string-util.cc.

Use the new Isolate version of the methods.

BUG=v8:7754

Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Id4f10d23927d6ae50cb458b5cac744617fa83e53
Reviewed-on: https://chromium-review.googlesource.com/1145387Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54613}
parent 2d0a7649
......@@ -204,6 +204,7 @@ class InjectedScript::ProtocolPromiseHandler {
v8::Isolate* isolate = session->inspector()->isolate();
if (result->IsNativeError()) {
message = " " + toProtocolString(
isolate,
result->ToDetailString(isolate->GetCurrentContext())
.ToLocalChecked());
v8::Local<v8::StackTrace> stackTrace = v8::debug::GetDetailedStackTrace(
......@@ -564,7 +565,9 @@ Response InjectedScript::createExceptionDetails(
v8::Local<v8::Message> message = tryCatch.Message();
v8::Local<v8::Value> exception = tryCatch.Exception();
String16 messageText =
message.IsEmpty() ? String16() : toProtocolString(message->Get());
message.IsEmpty()
? String16()
: toProtocolString(m_context->isolate(), message->Get());
std::unique_ptr<protocol::Runtime::ExceptionDetails> exceptionDetails =
protocol::Runtime::ExceptionDetails::create()
.setExceptionId(m_context->inspector()->nextExceptionId())
......
......@@ -52,16 +52,18 @@ v8::Local<v8::String> toV8String(v8::Isolate* isolate,
.ToLocalChecked();
}
String16 toProtocolString(v8::Local<v8::String> value) {
String16 toProtocolString(v8::Isolate* isolate, v8::Local<v8::String> value) {
if (value.IsEmpty() || value->IsNullOrUndefined()) return String16();
std::unique_ptr<UChar[]> buffer(new UChar[value->Length()]);
value->Write(reinterpret_cast<uint16_t*>(buffer.get()), 0, value->Length());
value->Write(isolate, reinterpret_cast<uint16_t*>(buffer.get()), 0,
value->Length());
return String16(buffer.get(), value->Length());
}
String16 toProtocolStringWithTypeCheck(v8::Local<v8::Value> value) {
String16 toProtocolStringWithTypeCheck(v8::Isolate* isolate,
v8::Local<v8::Value> value) {
if (value.IsEmpty() || !value->IsString()) return String16();
return toProtocolString(value.As<v8::String>());
return toProtocolString(isolate, value.As<v8::String>());
}
String16 toString16(const StringView& string) {
......
......@@ -67,8 +67,8 @@ v8::Local<v8::String> toV8StringInternalized(v8::Isolate*, const String16&);
v8::Local<v8::String> toV8StringInternalized(v8::Isolate*, const char*);
v8::Local<v8::String> toV8String(v8::Isolate*, const StringView&);
// TODO(dgozman): rename to toString16.
String16 toProtocolString(v8::Local<v8::String>);
String16 toProtocolStringWithTypeCheck(v8::Local<v8::Value>);
String16 toProtocolString(v8::Isolate*, v8::Local<v8::String>);
String16 toProtocolStringWithTypeCheck(v8::Isolate*, v8::Local<v8::Value>);
String16 toString16(const StringView&);
StringView toStringView(const String16&);
bool stringViewStartsWith(const StringView&, const char*);
......
......@@ -168,7 +168,9 @@ class V8ValueStringBuilder {
bool append(v8::Local<v8::String> string) {
if (m_tryCatch.HasCaught()) return false;
if (!string.IsEmpty()) m_builder.append(toProtocolString(string));
if (!string.IsEmpty()) {
m_builder.append(toProtocolString(m_isolate, string));
}
return true;
}
......
......@@ -24,9 +24,9 @@ namespace v8_inspector {
namespace {
String16 consoleContextToString(
const v8::debug::ConsoleContext& consoleContext) {
v8::Isolate* isolate, const v8::debug::ConsoleContext& consoleContext) {
if (consoleContext.id() == 0) return String16();
return toProtocolString(consoleContext.name()) + "#" +
return toProtocolString(isolate, consoleContext.name()) + "#" +
String16::fromInteger(consoleContext.id());
}
......@@ -88,7 +88,7 @@ class ConsoleHelper {
V8ConsoleMessage::createForConsoleAPI(
m_context, m_contextId, m_groupId, m_inspector,
m_inspector->client()->currentTimeMS(), type, arguments,
consoleContextToString(m_consoleContext),
consoleContextToString(m_isolate, m_consoleContext),
m_inspector->debugger()->captureStackTrace(false));
consoleMessageStorage()->addMessage(std::move(message));
}
......@@ -124,7 +124,7 @@ class ConsoleHelper {
if (!m_info[0]->ToString(m_context).ToLocal(&titleValue))
return defaultValue;
}
return toProtocolString(titleValue);
return toProtocolString(m_context->GetIsolate(), titleValue);
}
v8::MaybeLocal<v8::Object> firstArgAsObject() {
......@@ -297,7 +297,8 @@ static String16 identifierFromTitleOrStackTrace(
} else {
identifier = title + "@";
}
identifier = consoleContextToString(consoleContext) + "@" + identifier;
identifier = consoleContextToString(inspector->isolate(), consoleContext) +
"@" + identifier;
return identifier;
}
......@@ -370,7 +371,8 @@ static void timeFunction(const v8::debug::ConsoleCallArguments& info,
String16 protocolTitle = helper.firstArgToString("default", false);
if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'";
const String16& timerId =
protocolTitle + "@" + consoleContextToString(consoleContext);
protocolTitle + "@" +
consoleContextToString(inspector->isolate(), consoleContext);
if (helper.consoleMessageStorage()->hasTimer(helper.contextId(), timerId)) {
helper.reportCallWithArgument(
ConsoleAPIType::kWarning,
......@@ -388,7 +390,8 @@ static void timeEndFunction(const v8::debug::ConsoleCallArguments& info,
String16 protocolTitle = helper.firstArgToString("default", false);
if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'";
const String16& timerId =
protocolTitle + "@" + consoleContextToString(consoleContext);
protocolTitle + "@" +
consoleContextToString(inspector->isolate(), consoleContext);
if (!helper.consoleMessageStorage()->hasTimer(helper.contextId(), timerId)) {
helper.reportCallWithArgument(
ConsoleAPIType::kWarning,
......@@ -398,7 +401,8 @@ static void timeEndFunction(const v8::debug::ConsoleCallArguments& info,
inspector->client()->consoleTimeEnd(toStringView(protocolTitle));
double elapsed = helper.consoleMessageStorage()->timeEnd(
helper.contextId(),
protocolTitle + "@" + consoleContextToString(consoleContext));
protocolTitle + "@" +
consoleContextToString(inspector->isolate(), consoleContext));
String16 message =
protocolTitle + ": " + String16::fromDouble(elapsed) + "ms";
helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message);
......@@ -527,7 +531,8 @@ void V8Console::monitorFunctionCallback(
v8::Local<v8::Value> name = function->GetName();
if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length())
name = function->GetInferredName();
String16 functionName = toProtocolStringWithTypeCheck(name);
String16 functionName =
toProtocolStringWithTypeCheck(info.GetIsolate(), name);
String16Builder builder;
builder.append("console.log(\"function ");
if (functionName.isEmpty())
......@@ -779,7 +784,8 @@ void V8Console::CommandLineAPIScope::accessorGetterCallback(
v8::Local<v8::Value> value;
if (!commandLineAPI->Get(context, name).ToLocal(&value)) return;
if (isCommandLineAPIGetter(toProtocolStringWithTypeCheck(name))) {
if (isCommandLineAPIGetter(
toProtocolStringWithTypeCheck(info.GetIsolate(), name))) {
DCHECK(value->IsFunction());
v8::MicrotasksScope microtasks(info.GetIsolate(),
v8::MicrotasksScope::kDoNotRunMicrotasks);
......
......@@ -250,7 +250,7 @@ String16 scopeType(v8::debug::ScopeIterator::ScopeType type) {
namespace {
Response buildScopes(v8::debug::ScopeIterator* iterator,
Response buildScopes(v8::Isolate* isolate, v8::debug::ScopeIterator* iterator,
InjectedScript* injectedScript,
std::unique_ptr<Array<Scope>>* scopes) {
*scopes = Array<Scope>::create();
......@@ -270,8 +270,8 @@ Response buildScopes(v8::debug::ScopeIterator* iterator,
.setObject(std::move(object))
.build();
String16 name =
toProtocolStringWithTypeCheck(iterator->GetFunctionDebugName());
String16 name = toProtocolStringWithTypeCheck(
isolate, iterator->GetFunctionDebugName());
if (!name.isEmpty()) scope->setName(name);
if (iterator->HasLocationInfo()) {
......@@ -878,7 +878,7 @@ Response V8DebuggerAgentImpl::setScriptSource(
*optOutCompileError =
protocol::Runtime::ExceptionDetails::create()
.setExceptionId(m_inspector->nextExceptionId())
.setText(toProtocolString(result.message))
.setText(toProtocolString(m_isolate, result.message))
.setLineNumber(result.line_number != -1 ? result.line_number - 1
: 0)
.setColumnNumber(result.column_number != -1 ? result.column_number
......@@ -1265,7 +1265,8 @@ Response V8DebuggerAgentImpl::currentCallFrames(
std::unique_ptr<Array<Scope>> scopes;
auto scopeIterator = iterator->GetScopeIterator();
Response res = buildScopes(scopeIterator.get(), injectedScript, &scopes);
Response res =
buildScopes(m_isolate, scopeIterator.get(), injectedScript, &scopes);
if (!res.isSuccess()) return res;
std::unique_ptr<RemoteObject> protocolReceiver;
......@@ -1300,15 +1301,15 @@ Response V8DebuggerAgentImpl::currentCallFrames(
url = scriptIterator->second->sourceURL();
}
auto frame =
CallFrame::create()
.setCallFrameId(callFrameId)
.setFunctionName(toProtocolString(iterator->GetFunctionDebugName()))
.setLocation(std::move(location))
.setUrl(url)
.setScopeChain(std::move(scopes))
.setThis(std::move(protocolReceiver))
.build();
auto frame = CallFrame::create()
.setCallFrameId(callFrameId)
.setFunctionName(toProtocolString(
m_isolate, iterator->GetFunctionDebugName()))
.setLocation(std::move(location))
.setUrl(url)
.setScopeChain(std::move(scopes))
.setThis(std::move(protocolReceiver))
.build();
v8::Local<v8::Function> func = iterator->GetFunction();
if (!func.IsEmpty()) {
......
......@@ -112,7 +112,7 @@ class ActualScript : public V8DebuggerScript {
ActualScript(v8::Isolate* isolate, v8::Local<v8::debug::Script> script,
bool isLiveEdit)
: V8DebuggerScript(isolate, String16::fromInteger(script->Id()),
GetNameOrSourceUrl(script)),
GetNameOrSourceUrl(isolate, script)),
m_isLiveEdit(isLiveEdit) {
Initialize(script);
}
......@@ -218,10 +218,11 @@ class ActualScript : public V8DebuggerScript {
}
private:
String16 GetNameOrSourceUrl(v8::Local<v8::debug::Script> script) {
String16 GetNameOrSourceUrl(v8::Isolate* isolate,
v8::Local<v8::debug::Script> script) {
v8::Local<v8::String> name;
if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name))
return toProtocolString(name);
return toProtocolString(isolate, name);
return String16();
}
......@@ -231,9 +232,10 @@ class ActualScript : public V8DebuggerScript {
void Initialize(v8::Local<v8::debug::Script> script) {
v8::Local<v8::String> tmp;
if (script->SourceURL().ToLocal(&tmp)) m_sourceURL = toProtocolString(tmp);
if (script->SourceURL().ToLocal(&tmp))
m_sourceURL = toProtocolString(m_isolate, tmp);
if (script->SourceMappingURL().ToLocal(&tmp))
m_sourceMappingURL = toProtocolString(tmp);
m_sourceMappingURL = toProtocolString(m_isolate, tmp);
m_startLine = script->LineOffset();
m_startColumn = script->ColumnOffset();
std::vector<int> lineEnds = script->LineEnds();
......@@ -254,7 +256,7 @@ class ActualScript : public V8DebuggerScript {
USE(script->ContextId().To(&m_executionContextId));
if (script->Source().ToLocal(&tmp)) {
m_source = toProtocolString(tmp);
m_source = toProtocolString(m_isolate, tmp);
}
m_isModule = script->IsModule();
......
......@@ -719,7 +719,7 @@ v8::MaybeLocal<v8::Value> V8Debugger::getTargetScopes(
String16 name;
v8::Local<v8::Value> maybe_name = iterator->GetFunctionDebugName();
if (!maybe_name->IsUndefined()) {
name = toProtocolStringWithTypeCheck(maybe_name);
name = toProtocolStringWithTypeCheck(m_isolate, maybe_name);
}
v8::Local<v8::Object> object = iterator->GetObject();
createDataProperty(context, scope,
......@@ -1131,7 +1131,7 @@ std::shared_ptr<StackFrame> V8Debugger::symbolize(
if (it != m_framesCache.end() && !it->second.expired()) {
return std::shared_ptr<StackFrame>(it->second);
}
std::shared_ptr<StackFrame> frame(new StackFrame(v8Frame));
std::shared_ptr<StackFrame> frame(new StackFrame(isolate(), v8Frame));
// TODO(clemensh): Figure out a way to do this translation only right before
// sending the stack trace over wire.
if (v8Frame->IsWasm()) frame->translate(&m_wasmTranslation);
......
......@@ -335,19 +335,20 @@ Response V8HeapProfilerAgentImpl::startSampling(
namespace {
std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfileNode>
buildSampingHeapProfileNode(const v8::AllocationProfile::Node* node) {
buildSampingHeapProfileNode(v8::Isolate* isolate,
const v8::AllocationProfile::Node* node) {
auto children = protocol::Array<
protocol::HeapProfiler::SamplingHeapProfileNode>::create();
for (const auto* child : node->children)
children->addItem(buildSampingHeapProfileNode(child));
children->addItem(buildSampingHeapProfileNode(isolate, child));
size_t selfSize = 0;
for (const auto& allocation : node->allocations)
selfSize += allocation.size * allocation.count;
std::unique_ptr<protocol::Runtime::CallFrame> callFrame =
protocol::Runtime::CallFrame::create()
.setFunctionName(toProtocolString(node->name))
.setFunctionName(toProtocolString(isolate, node->name))
.setScriptId(String16::fromInteger(node->script_id))
.setUrl(toProtocolString(node->script_name))
.setUrl(toProtocolString(isolate, node->script_name))
.setLineNumber(node->line_number - 1)
.setColumnNumber(node->column_number - 1)
.build();
......@@ -383,7 +384,7 @@ Response V8HeapProfilerAgentImpl::getSamplingProfile(
return Response::Error("V8 sampling heap profiler was not started.");
v8::AllocationProfile::Node* root = v8Profile->GetRootNode();
*profile = protocol::HeapProfiler::SamplingHeapProfile::create()
.setHead(buildSampingHeapProfileNode(root))
.setHead(buildSampingHeapProfileNode(m_isolate, root))
.build();
return Response::OK();
}
......
......@@ -299,7 +299,7 @@ void V8InjectedScriptHost::getInternalPropertiesCallback(
tryCatch.Reset();
continue;
}
String16 keyString = toProtocolStringWithTypeCheck(key);
String16 keyString = toProtocolStringWithTypeCheck(isolate, key);
if (keyString.isEmpty() ||
allowedProperties.find(keyString) == allowedProperties.end())
continue;
......@@ -337,7 +337,8 @@ void V8InjectedScriptHost::bindCallback(
v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
v8::Local<v8::String> v8groupName =
info[1]->ToString(context).ToLocalChecked();
String16 groupName = toProtocolStringWithTypeCheck(v8groupName);
String16 groupName =
toProtocolStringWithTypeCheck(info.GetIsolate(), v8groupName);
int id = injectedScript->bindObject(info[0], groupName);
info.GetReturnValue().Set(id);
}
......
......@@ -55,9 +55,9 @@ std::unique_ptr<protocol::Profiler::ProfileNode> buildInspectorObjectFor(
v8::HandleScope handleScope(isolate);
auto callFrame =
protocol::Runtime::CallFrame::create()
.setFunctionName(toProtocolString(node->GetFunctionName()))
.setFunctionName(toProtocolString(isolate, node->GetFunctionName()))
.setScriptId(String16::fromInteger(node->GetScriptId()))
.setUrl(toProtocolString(node->GetScriptResourceName()))
.setUrl(toProtocolString(isolate, node->GetScriptResourceName()))
.setLineNumber(node->GetLineNumber() - 1)
.setColumnNumber(node->GetColumnNumber() - 1)
.build();
......@@ -354,6 +354,7 @@ Response coverageToProtocol(
functions->addItem(
protocol::Profiler::FunctionCoverage::create()
.setFunctionName(toProtocolString(
isolate,
function_data.Name().FromMaybe(v8::Local<v8::String>())))
.setRanges(std::move(ranges))
.setIsBlockCoverage(function_data.HasBlockCoverage())
......@@ -362,7 +363,7 @@ Response coverageToProtocol(
String16 url;
v8::Local<v8::String> name;
if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name)) {
url = toProtocolString(name);
url = toProtocolString(isolate, name);
}
result->addItem(protocol::Profiler::ScriptCoverage::create()
.setScriptId(String16::fromInteger(script->Id()))
......@@ -414,10 +415,11 @@ typeProfileToProtocol(v8::Isolate* isolate,
std::unique_ptr<protocol::Array<protocol::Profiler::TypeObject>> types =
protocol::Array<protocol::Profiler::TypeObject>::create();
for (const auto& type : entry.Types()) {
types->addItem(protocol::Profiler::TypeObject::create()
.setName(toProtocolString(
type.FromMaybe(v8::Local<v8::String>())))
.build());
types->addItem(
protocol::Profiler::TypeObject::create()
.setName(toProtocolString(
isolate, type.FromMaybe(v8::Local<v8::String>())))
.build());
}
entries->addItem(protocol::Profiler::TypeProfileEntry::create()
.setOffset(entry.SourcePosition())
......@@ -427,7 +429,7 @@ typeProfileToProtocol(v8::Isolate* isolate,
String16 url;
v8::Local<v8::String> name;
if (script->Name().ToLocal(&name) || script->SourceURL().ToLocal(&name)) {
url = toProtocolString(name);
url = toProtocolString(isolate, name);
}
result->addItem(protocol::Profiler::ScriptTypeProfile::create()
.setScriptId(String16::fromInteger(script->Id()))
......
......@@ -32,7 +32,7 @@ V8Regex::V8Regex(V8InspectorImpl* inspector, const String16& pattern,
.ToLocal(&regex))
m_regex.Reset(isolate, regex);
else if (tryCatch.HasCaught())
m_errorMessage = toProtocolString(tryCatch.Message()->Get());
m_errorMessage = toProtocolString(isolate, tryCatch.Message()->Get());
else
m_errorMessage = "Internal error";
}
......
......@@ -426,7 +426,8 @@ Response V8RuntimeAgentImpl::getProperties(
if (!response.isSuccess()) return response;
propertiesProtocolArray->addItem(
InternalPropertyDescriptor::create()
.setName(toProtocolString(name.As<v8::String>()))
.setName(
toProtocolString(m_inspector->isolate(), name.As<v8::String>()))
.setValue(std::move(wrappedValue))
.build());
}
......@@ -622,7 +623,8 @@ Response V8RuntimeAgentImpl::globalLexicalScopeNames(
v8::debug::GlobalLexicalScopeNames(scope.context(), &names);
*outNames = protocol::Array<String16>::create();
for (size_t i = 0; i < names.Size(); ++i) {
(*outNames)->addItem(toProtocolString(names.Get(i)));
(*outNames)->addItem(
toProtocolString(m_inspector->isolate(), names.Get(i)));
}
return Response::OK();
}
......@@ -690,8 +692,10 @@ void V8RuntimeAgentImpl::bindingCallback(
int contextId = InspectedContext::contextId(isolate->GetCurrentContext());
int contextGroupId = inspector->contextGroupId(contextId);
String16 name = toProtocolString(v8::Local<v8::String>::Cast(info.Data()));
String16 payload = toProtocolString(v8::Local<v8::String>::Cast(info[0]));
String16 name =
toProtocolString(isolate, v8::Local<v8::String>::Cast(info.Data()));
String16 payload =
toProtocolString(isolate, v8::Local<v8::String>::Cast(info[0]));
inspector->forEachSession(
contextGroupId,
......
......@@ -112,10 +112,11 @@ V8StackTraceId::V8StackTraceId(uintptr_t id,
bool V8StackTraceId::IsInvalid() const { return !id; }
StackFrame::StackFrame(v8::Local<v8::StackFrame> v8Frame)
: m_functionName(toProtocolString(v8Frame->GetFunctionName())),
StackFrame::StackFrame(v8::Isolate* isolate, v8::Local<v8::StackFrame> v8Frame)
: m_functionName(toProtocolString(isolate, v8Frame->GetFunctionName())),
m_scriptId(String16::fromInteger(v8Frame->GetScriptId())),
m_sourceURL(toProtocolString(v8Frame->GetScriptNameOrSourceURL())),
m_sourceURL(
toProtocolString(isolate, v8Frame->GetScriptNameOrSourceURL())),
m_lineNumber(v8Frame->GetLineNumber() - 1),
m_columnNumber(v8Frame->GetColumn() - 1) {
DCHECK_NE(v8::Message::kNoLineNumberInfo, m_lineNumber + 1);
......
......@@ -23,7 +23,7 @@ struct V8StackTraceId;
class StackFrame {
public:
explicit StackFrame(v8::Local<v8::StackFrame> frame);
explicit StackFrame(v8::Isolate* isolate, v8::Local<v8::StackFrame> frame);
~StackFrame() = default;
void translate(WasmTranslation* wasmTranslation);
......
......@@ -39,8 +39,8 @@ protocol::Response toProtocolValue(v8::Local<v8::Context> context,
return Response::OK();
}
if (value->IsString()) {
*result =
protocol::StringValue::create(toProtocolString(value.As<v8::String>()));
*result = protocol::StringValue::create(
toProtocolString(context->GetIsolate(), value.As<v8::String>()));
return Response::OK();
}
if (value->IsArray()) {
......@@ -90,8 +90,9 @@ protocol::Response toProtocolValue(v8::Local<v8::Context> context,
Response response =
toProtocolValue(context, property, maxDepth, &propertyValue);
if (!response.isSuccess()) return response;
jsonObject->setValue(toProtocolString(propertyName),
std::move(propertyValue));
jsonObject->setValue(
toProtocolString(context->GetIsolate(), propertyName),
std::move(propertyValue));
}
*result = std::move(jsonObject);
return Response::OK();
......
......@@ -219,7 +219,8 @@ class WasmTranslation::TranslatorImpl::DisassemblingTranslator
private:
String16 GetFakeScriptUrl(v8::Isolate* isolate, int func_index) {
v8::Local<v8::debug::WasmScript> script = script_.Get(isolate);
String16 script_name = toProtocolString(script->Name().ToLocalChecked());
String16 script_name =
toProtocolString(isolate, script->Name().ToLocalChecked());
int numFunctions = script->NumFunctions();
int numImported = script->NumImportedFunctions();
String16Builder builder;
......
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