OLD | NEW |
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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 bool isOk = false; | 109 bool isOk = false; |
110 m_executionContextId = executionContextId.toInteger(&isOk); | 110 m_executionContextId = executionContextId.toInteger(&isOk); |
111 if (!isOk) m_executionContextId = 0; | 111 if (!isOk) m_executionContextId = 0; |
112 m_executionContextAuxData = contextData.substring(secondComma + 1); | 112 m_executionContextAuxData = contextData.substring(secondComma + 1); |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 m_isLiveEdit = isLiveEdit; | 116 m_isLiveEdit = isLiveEdit; |
117 | 117 |
118 if (script->Source().ToLocal(&tmp)) { | 118 if (script->Source().ToLocal(&tmp)) { |
119 m_source.Reset(m_isolate, tmp); | 119 m_sourceObj.Reset(m_isolate, tmp); |
120 String16 source = toProtocolString(tmp); | 120 String16 source = toProtocolString(tmp); |
121 m_hash = calculateHash(source); | |
122 // V8 will not count last line if script source ends with \n. | 121 // V8 will not count last line if script source ends with \n. |
123 if (source.length() > 1 && source[source.length() - 1] == '\n') { | 122 if (source.length() > 1 && source[source.length() - 1] == '\n') { |
124 m_endLine++; | 123 m_endLine++; |
125 m_endColumn = 0; | 124 m_endColumn = 0; |
126 } | 125 } |
127 } | 126 } |
128 | 127 |
129 m_script.Reset(m_isolate, script); | 128 m_script.Reset(m_isolate, script); |
130 } | 129 } |
131 | 130 |
| 131 V8DebuggerScript::V8DebuggerScript(String16 id, String16 url, String16 source) |
| 132 : m_id(std::move(id)), m_url(std::move(url)), m_source(std::move(source)) { |
| 133 int num_lines = 0; |
| 134 int last_newline = -1; |
| 135 size_t next_newline = m_source.find('\n', last_newline + 1); |
| 136 while (next_newline != String16::kNotFound) { |
| 137 last_newline = static_cast<int>(next_newline); |
| 138 next_newline = m_source.find('\n', last_newline + 1); |
| 139 ++num_lines; |
| 140 } |
| 141 m_endLine = num_lines; |
| 142 m_endColumn = static_cast<int>(m_source.length()) - last_newline - 1; |
| 143 } |
| 144 |
132 V8DebuggerScript::~V8DebuggerScript() {} | 145 V8DebuggerScript::~V8DebuggerScript() {} |
133 | 146 |
134 const String16& V8DebuggerScript::sourceURL() const { | 147 const String16& V8DebuggerScript::sourceURL() const { |
135 return m_sourceURL.isEmpty() ? m_url : m_sourceURL; | 148 return m_sourceURL.isEmpty() ? m_url : m_sourceURL; |
136 } | 149 } |
137 | 150 |
138 v8::Local<v8::String> V8DebuggerScript::source(v8::Isolate* isolate) const { | 151 String16 V8DebuggerScript::source(v8::Isolate* isolate) const { |
139 return m_source.Get(isolate); | 152 if (m_sourceObj.IsEmpty()) return m_source; |
| 153 return toProtocolString(m_sourceObj.Get(isolate)); |
| 154 } |
| 155 |
| 156 const String16& V8DebuggerScript::hash(v8::Isolate* isolate) const { |
| 157 if (m_hash.isEmpty()) m_hash = calculateHash(source(isolate)); |
| 158 DCHECK(!m_hash.isEmpty()); |
| 159 return m_hash; |
140 } | 160 } |
141 | 161 |
142 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { | 162 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { |
143 m_sourceURL = sourceURL; | 163 m_sourceURL = sourceURL; |
144 } | 164 } |
145 | 165 |
146 void V8DebuggerScript::setSourceMappingURL(const String16& sourceMappingURL) { | 166 void V8DebuggerScript::setSourceMappingURL(const String16& sourceMappingURL) { |
147 m_sourceMappingURL = sourceMappingURL; | 167 m_sourceMappingURL = sourceMappingURL; |
148 } | 168 } |
149 | 169 |
150 void V8DebuggerScript::setSource(v8::Local<v8::String> source) { | 170 void V8DebuggerScript::setSource(v8::Local<v8::String> source) { |
151 m_source.Reset(m_isolate, source); | 171 m_source = String16(); |
152 m_hash = calculateHash(toProtocolString(source)); | 172 m_sourceObj.Reset(m_isolate, source); |
| 173 m_hash = String16(); |
153 } | 174 } |
154 | 175 |
155 bool V8DebuggerScript::getPossibleBreakpoints( | 176 bool V8DebuggerScript::getPossibleBreakpoints( |
156 const v8::DebugInterface::Location& start, | 177 const v8::DebugInterface::Location& start, |
157 const v8::DebugInterface::Location& end, | 178 const v8::DebugInterface::Location& end, |
158 std::vector<v8::DebugInterface::Location>* locations) { | 179 std::vector<v8::DebugInterface::Location>* locations) { |
159 v8::HandleScope scope(m_isolate); | 180 v8::HandleScope scope(m_isolate); |
160 v8::Local<v8::DebugInterface::Script> script = m_script.Get(m_isolate); | 181 v8::Local<v8::DebugInterface::Script> script = m_script.Get(m_isolate); |
161 return script->GetPossibleBreakpoints(start, end, locations); | 182 return script->GetPossibleBreakpoints(start, end, locations); |
162 } | 183 } |
163 | 184 |
164 } // namespace v8_inspector | 185 } // namespace v8_inspector |
OLD | NEW |