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..572a83d80cc75cb9715482654e507e3b7d41ce05 100644 |
| --- a/src/inspector/v8-debugger-script.cc |
| +++ b/src/inspector/v8-debugger-script.cc |
| @@ -67,50 +67,73 @@ 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(); |
| -} |
| - |
| -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()); |
| -} |
| - |
| V8DebuggerScript::V8DebuggerScript(v8::Local<v8::Context> context, |
| - v8::Local<v8::Object> object, |
| + v8::Local<v8::DebugInterface::Script> script, |
| 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::HandleScope scope(context->GetIsolate()); |
| + m_id = String16::fromInteger(script->Id()); |
| + v8::Local<v8::String> tmp; |
| + if (script->Name(context).ToLocal(&tmp)) m_url = toProtocolString(tmp); |
| + if (script->SourceURL(context).ToLocal(&tmp)) { |
| + m_sourceURL = toProtocolString(tmp); |
| + if (m_url.isEmpty()) m_url = toProtocolString(tmp); |
| + } |
| + if (script->SourceMappingURL(context).ToLocal(&tmp)) |
| + m_sourceMappingURL = toProtocolString(tmp); |
| + m_startLine = script->LineOffset(); |
| + m_startColumn = script->ColumnOffset(); |
| + v8::Local<v8::Array> lineEnds; |
| + if (script->LineEnds(context).ToLocal(&lineEnds) && lineEnds->Length()) { |
| + m_endLine = static_cast<int>(lineEnds->Length()) + m_startLine - 1; |
| + |
| + v8::Local<v8::Value> lastLineLengthValue; |
| + if (lineEnds->Get(context, lineEnds->Length() - 1) |
| + .ToLocal(&lastLineLengthValue) && |
| + lastLineLengthValue->IsInt32()) { |
| + int32_t lastLineLength = lastLineLengthValue.As<v8::Int32>()->Value(); |
| + if (lineEnds->Length() > 1) { |
| + v8::Local<v8::Value> lengthValue; |
| + if (lineEnds->Get(context, lineEnds->Length() - 2) |
| + .ToLocal(&lengthValue) && |
| + lengthValue->IsInt32()) { |
| + m_endColumn = |
| + lastLineLength - lengthValue.As<v8::Int32>()->Value() - 1; |
| + } |
| + } else { |
| + m_endColumn = lastLineLength + m_startColumn; |
| + } |
| + } |
| + } else { |
| + m_endLine = 0; |
| + m_endColumn = 0; |
| + } |
| + |
| + if (script->ContextData(context).ToLocal(&tmp)) { |
| + String16 contextData = toProtocolString(tmp); |
| + size_t firstComma = contextData.find(",", 0); |
| + size_t secondComma = contextData.find(",", firstComma + 1); |
|
dgozman
2016/10/28 19:57:15
Let's not call when firstComma is kNotFound.
kozy
2016/10/28 20:59:37
Done.
|
| + if (firstComma != String16::kNotFound && |
| + 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); |
| + } |
| + } |
| - v8::Local<v8::Value> sourceValue; |
| - if (!object->Get(context, toV8StringInternalized(isolate, "source")) |
| - .ToLocal(&sourceValue) || |
| - !sourceValue->IsString()) |
| - return; |
| - setSource(isolate, sourceValue.As<v8::String>()); |
| + m_isLiveEdit = isLiveEdit; |
| + if (script->Source(context).ToLocal(&tmp)) { |
| + m_source.Reset(context->GetIsolate(), 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() {} |