Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Unified Diff: src/inspector/v8-debugger-script.cc

Issue 2449213002: [inspector] migrate scriptParsed and getCompiledScripts to native (Closed)
Patch Set: addressed comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/inspector/v8-debugger-script.h ('k') | test/inspector/debugger/script-on-after-compile.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..2da169c8323ce44a81bfd7a1435ad21386235b51 100644
--- a/src/inspector/v8-debugger-script.cc
+++ b/src/inspector/v8-debugger-script.cc
@@ -67,50 +67,62 @@ 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();
+ CHECK(lineEnds.size());
+ int source_length = lineEnds[lineEnds.size() - 1];
+ if (lineEnds.size()) {
+ m_endLine = static_cast<int>(lineEnds.size()) + m_startLine - 1;
+ if (lineEnds.size() > 1) {
+ m_endColumn = source_length - lineEnds[lineEnds.size() - 2] - 1;
+ } else {
+ m_endColumn = source_length + m_startColumn;
+ }
+ } else {
jgruber 2016/11/02 08:39:07 Sorry for the late comment; I've been reading a co
kozy 2016/11/03 00:18:36 Yes, it's dead code, thanks! For vector - I think
+ 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() {}
« no previous file with comments | « src/inspector/v8-debugger-script.h ('k') | test/inspector/debugger/script-on-after-compile.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698