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

Side by Side Diff: src/inspector/v8-debugger-script.cc

Issue 2449213002: [inspector] migrate scriptParsed and getCompiledScripts to native (Closed)
Patch Set: fixed compilation Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/inspector/v8-debugger-script.h" 5 #include "src/inspector/v8-debugger-script.h"
6 6
7 #include "src/inspector/protocol-platform.h" 7 #include "src/inspector/protocol-platform.h"
8 #include "src/inspector/string-util.h" 8 #include "src/inspector/string-util.h"
9 9
10 namespace v8_inspector { 10 namespace v8_inspector {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 61
62 for (size_t i = 0; i < hashesSize; ++i) 62 for (size_t i = 0; i < hashesSize; ++i)
63 hashes[i] = (hashes[i] + zi[i] * (prime[i] - 1)) % prime[i]; 63 hashes[i] = (hashes[i] + zi[i] * (prime[i] - 1)) % prime[i];
64 64
65 String16Builder hash; 65 String16Builder hash;
66 for (size_t i = 0; i < hashesSize; ++i) appendUnsignedAsHex(hashes[i], &hash); 66 for (size_t i = 0; i < hashesSize; ++i) appendUnsignedAsHex(hashes[i], &hash);
67 return hash.toString(); 67 return hash.toString();
68 } 68 }
69 69
70 static v8::Local<v8::Value> GetChecked(v8::Local<v8::Context> context, 70 V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate,
71 v8::Local<v8::Object> object, 71 v8::Local<v8::DebugInterface::Script> script,
72 const char* name) { 72 bool isLiveEdit) {
73 return object 73 m_id = String16::fromInteger(script->Id());
74 ->Get(context, toV8StringInternalized(context->GetIsolate(), name)) 74 v8::Local<v8::String> tmp;
75 .ToLocalChecked(); 75 if (script->Name().ToLocal(&tmp)) m_url = toProtocolString(tmp);
76 } 76 if (script->SourceURL().ToLocal(&tmp)) {
77 m_sourceURL = toProtocolString(tmp);
78 if (m_url.isEmpty()) m_url = toProtocolString(tmp);
79 }
80 if (script->SourceMappingURL().ToLocal(&tmp))
81 m_sourceMappingURL = toProtocolString(tmp);
82 m_startLine = script->LineOffset();
83 m_startColumn = script->ColumnOffset();
84 std::vector<int> lineEnds = script->LineEnds();
85 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.
86 m_endLine = static_cast<int>(lineEnds.size()) + m_startLine - 1;
87 if (lineEnds.size() > 1) {
88 m_endColumn =
89 lineEnds[lineEnds.size() - 1] - lineEnds[lineEnds.size() - 2] - 1;
90 } else {
91 m_endColumn = lineEnds[lineEnds.size() - 1] + m_startColumn;
92 }
93 } else {
94 m_endLine = m_startLine;
95 m_endColumn = m_startColumn;
96 }
77 97
78 static int GetCheckedInt(v8::Local<v8::Context> context, 98 if (script->ContextData().ToLocal(&tmp)) {
79 v8::Local<v8::Object> object, const char* name) { 99 String16 contextData = toProtocolString(tmp);
80 return static_cast<int>(GetChecked(context, object, name) 100 size_t firstComma = contextData.find(",", 0);
81 ->ToInteger(context) 101 size_t secondComma = firstComma != String16::kNotFound
82 .ToLocalChecked() 102 ? contextData.find(",", firstComma + 1)
83 ->Value()); 103 : String16::kNotFound;
84 } 104 if (secondComma != String16::kNotFound) {
105 String16 executionContextId =
106 contextData.substring(firstComma + 1, secondComma - firstComma - 1);
107 bool isOk = false;
108 m_executionContextId = executionContextId.toInteger(&isOk);
109 if (!isOk) m_executionContextId = 0;
110 m_executionContextAuxData = contextData.substring(secondComma + 1);
111 }
112 }
85 113
86 V8DebuggerScript::V8DebuggerScript(v8::Local<v8::Context> context,
87 v8::Local<v8::Object> object,
88 bool isLiveEdit) {
89 v8::Isolate* isolate = context->GetIsolate();
90 v8::Local<v8::Value> idValue = GetChecked(context, object, "id");
91 DCHECK(!idValue.IsEmpty() && idValue->IsInt32());
92 m_id = String16::fromInteger(idValue->Int32Value(context).FromJust());
93
94 m_url = toProtocolStringWithTypeCheck(GetChecked(context, object, "name"));
95 m_sourceURL =
96 toProtocolStringWithTypeCheck(GetChecked(context, object, "sourceURL"));
97 m_sourceMappingURL = toProtocolStringWithTypeCheck(
98 GetChecked(context, object, "sourceMappingURL"));
99 m_startLine = GetCheckedInt(context, object, "startLine");
100 m_startColumn = GetCheckedInt(context, object, "startColumn");
101 m_endLine = GetCheckedInt(context, object, "endLine");
102 m_endColumn = GetCheckedInt(context, object, "endColumn");
103 m_executionContextAuxData = toProtocolStringWithTypeCheck(
104 GetChecked(context, object, "executionContextAuxData"));
105 m_executionContextId = GetCheckedInt(context, object, "executionContextId");
106 m_isLiveEdit = isLiveEdit; 114 m_isLiveEdit = isLiveEdit;
107 115 if (script->Source().ToLocal(&tmp)) {
108 v8::Local<v8::Value> sourceValue; 116 m_source.Reset(isolate, tmp);
109 if (!object->Get(context, toV8StringInternalized(isolate, "source")) 117 String16 source = toProtocolString(tmp);
110 .ToLocal(&sourceValue) || 118 m_hash = calculateHash(source);
111 !sourceValue->IsString()) 119 // V8 will not count last line if script source ends with \n.
112 return; 120 if (source.length() > 1 && source[source.length() - 1] == '\n') {
113 setSource(isolate, sourceValue.As<v8::String>()); 121 m_endLine++;
122 m_endColumn = 0;
123 }
124 }
114 } 125 }
115 126
116 V8DebuggerScript::~V8DebuggerScript() {} 127 V8DebuggerScript::~V8DebuggerScript() {}
117 128
118 const String16& V8DebuggerScript::sourceURL() const { 129 const String16& V8DebuggerScript::sourceURL() const {
119 return m_sourceURL.isEmpty() ? m_url : m_sourceURL; 130 return m_sourceURL.isEmpty() ? m_url : m_sourceURL;
120 } 131 }
121 132
122 v8::Local<v8::String> V8DebuggerScript::source(v8::Isolate* isolate) const { 133 v8::Local<v8::String> V8DebuggerScript::source(v8::Isolate* isolate) const {
123 return m_source.Get(isolate); 134 return m_source.Get(isolate);
124 } 135 }
125 136
126 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { 137 void V8DebuggerScript::setSourceURL(const String16& sourceURL) {
127 m_sourceURL = sourceURL; 138 m_sourceURL = sourceURL;
128 } 139 }
129 140
130 void V8DebuggerScript::setSourceMappingURL(const String16& sourceMappingURL) { 141 void V8DebuggerScript::setSourceMappingURL(const String16& sourceMappingURL) {
131 m_sourceMappingURL = sourceMappingURL; 142 m_sourceMappingURL = sourceMappingURL;
132 } 143 }
133 144
134 void V8DebuggerScript::setSource(v8::Isolate* isolate, 145 void V8DebuggerScript::setSource(v8::Isolate* isolate,
135 v8::Local<v8::String> source) { 146 v8::Local<v8::String> source) {
136 m_source.Reset(isolate, source); 147 m_source.Reset(isolate, source);
137 m_hash = calculateHash(toProtocolString(source)); 148 m_hash = calculateHash(toProtocolString(source));
138 } 149 }
139 150
140 } // namespace v8_inspector 151 } // namespace v8_inspector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698