Chromium Code Reviews| Index: src/inspector/v8-debugger-script.cc |
| diff --git a/src/inspector/v8-debugger-script.cc b/src/inspector/v8-debugger-script.cc |
| index 485188a48f4eaca4d8ad47268073ef2cb0cc52b1..58e15a79d4a9f89dddc3a4966f680b048fe4de32 100644 |
| --- a/src/inspector/v8-debugger-script.cc |
| +++ b/src/inspector/v8-debugger-script.cc |
| @@ -67,50 +67,61 @@ static String16 calculateHash(const String16& str) { |
| return hash.toString(); |
| } |
| -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(); |
| -} |
| +V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, |
| + v8::Local<v8::DebugInterface::Script> script, |
| + bool isLiveEdit) { |
| + m_id = String16::fromInteger(script->Id()); |
| + v8::Local<v8::String> tmp; |
| + if (script->Name().ToLocal(&tmp)) m_url = toProtocolString(tmp); |
| + if (script->SourceURL().ToLocal(&tmp)) { |
| + m_sourceURL = toProtocolString(tmp); |
| + if (m_url.isEmpty()) m_url = toProtocolString(tmp); |
| + } |
| + if (script->SourceMappingURL().ToLocal(&tmp)) |
| + m_sourceMappingURL = toProtocolString(tmp); |
| + m_startLine = script->LineOffset(); |
| + m_startColumn = script->ColumnOffset(); |
| + std::vector<int> lineEnds = script->LineEnds(); |
| + if (lineEnds.size()) { |
|
dgozman
2016/10/28 22:52:51
CHECK(!lineEnds.empty());
int source_length = line
kozy
2016/10/29 01:26:06
Done.
|
| + m_endLine = static_cast<int>(lineEnds.size()) + m_startLine - 1; |
| + if (lineEnds.size() > 1) { |
| + m_endColumn = |
| + lineEnds[lineEnds.size() - 1] - lineEnds[lineEnds.size() - 2] - 1; |
| + } else { |
| + m_endColumn = lineEnds[lineEnds.size() - 1] + m_startColumn; |
| + } |
| + } else { |
| + m_endLine = m_startLine; |
| + m_endColumn = m_startColumn; |
| + } |
| -static int GetCheckedInt(v8::Local<v8::Context> context, |
| - v8::Local<v8::Object> object, const char* name) { |
| - return static_cast<int>(GetChecked(context, object, name) |
| - ->ToInteger(context) |
| - .ToLocalChecked() |
| - ->Value()); |
| -} |
| + if (script->ContextData().ToLocal(&tmp)) { |
| + String16 contextData = toProtocolString(tmp); |
| + size_t firstComma = contextData.find(",", 0); |
| + size_t secondComma = firstComma != String16::kNotFound |
| + ? contextData.find(",", firstComma + 1) |
| + : String16::kNotFound; |
| + if (secondComma != String16::kNotFound) { |
| + String16 executionContextId = |
| + contextData.substring(firstComma + 1, secondComma - firstComma - 1); |
| + bool isOk = false; |
| + m_executionContextId = executionContextId.toInteger(&isOk); |
| + if (!isOk) m_executionContextId = 0; |
| + m_executionContextAuxData = contextData.substring(secondComma + 1); |
| + } |
| + } |
| -V8DebuggerScript::V8DebuggerScript(v8::Local<v8::Context> context, |
| - v8::Local<v8::Object> object, |
| - bool isLiveEdit) { |
| - 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(context).FromJust()); |
| - |
| - m_url = toProtocolStringWithTypeCheck(GetChecked(context, object, "name")); |
| - m_sourceURL = |
| - toProtocolStringWithTypeCheck(GetChecked(context, object, "sourceURL")); |
| - m_sourceMappingURL = toProtocolStringWithTypeCheck( |
| - 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( |
| - GetChecked(context, object, "executionContextAuxData")); |
| - m_executionContextId = GetCheckedInt(context, object, "executionContextId"); |
| m_isLiveEdit = isLiveEdit; |
| - |
| - v8::Local<v8::Value> sourceValue; |
| - if (!object->Get(context, toV8StringInternalized(isolate, "source")) |
| - .ToLocal(&sourceValue) || |
| - !sourceValue->IsString()) |
| - return; |
| - setSource(isolate, sourceValue.As<v8::String>()); |
| + if (script->Source().ToLocal(&tmp)) { |
| + m_source.Reset(isolate, tmp); |
| + String16 source = toProtocolString(tmp); |
| + m_hash = calculateHash(source); |
| + // V8 will not count last line if script source ends with \n. |
| + if (source.length() > 1 && source[source.length() - 1] == '\n') { |
| + m_endLine++; |
| + m_endColumn = 0; |
| + } |
| + } |
| } |
| V8DebuggerScript::~V8DebuggerScript() {} |