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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 CHECK(lineEnds.size()); | |
86 int source_length = lineEnds[lineEnds.size() - 1]; | |
87 if (lineEnds.size()) { | |
88 m_endLine = static_cast<int>(lineEnds.size()) + m_startLine - 1; | |
89 if (lineEnds.size() > 1) { | |
90 m_endColumn = source_length - lineEnds[lineEnds.size() - 2] - 1; | |
91 } else { | |
92 m_endColumn = source_length + m_startColumn; | |
93 } | |
94 } 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
| |
95 m_endLine = m_startLine; | |
96 m_endColumn = m_startColumn; | |
97 } | |
77 | 98 |
78 static int GetCheckedInt(v8::Local<v8::Context> context, | 99 if (script->ContextData().ToLocal(&tmp)) { |
79 v8::Local<v8::Object> object, const char* name) { | 100 String16 contextData = toProtocolString(tmp); |
80 return static_cast<int>(GetChecked(context, object, name) | 101 size_t firstComma = contextData.find(",", 0); |
81 ->ToInteger(context) | 102 size_t secondComma = firstComma != String16::kNotFound |
82 .ToLocalChecked() | 103 ? contextData.find(",", firstComma + 1) |
83 ->Value()); | 104 : String16::kNotFound; |
84 } | 105 if (secondComma != String16::kNotFound) { |
106 String16 executionContextId = | |
107 contextData.substring(firstComma + 1, secondComma - firstComma - 1); | |
108 bool isOk = false; | |
109 m_executionContextId = executionContextId.toInteger(&isOk); | |
110 if (!isOk) m_executionContextId = 0; | |
111 m_executionContextAuxData = contextData.substring(secondComma + 1); | |
112 } | |
113 } | |
85 | 114 |
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; | 115 m_isLiveEdit = isLiveEdit; |
107 | 116 if (script->Source().ToLocal(&tmp)) { |
108 v8::Local<v8::Value> sourceValue; | 117 m_source.Reset(isolate, tmp); |
109 if (!object->Get(context, toV8StringInternalized(isolate, "source")) | 118 String16 source = toProtocolString(tmp); |
110 .ToLocal(&sourceValue) || | 119 m_hash = calculateHash(source); |
111 !sourceValue->IsString()) | 120 // V8 will not count last line if script source ends with \n. |
112 return; | 121 if (source.length() > 1 && source[source.length() - 1] == '\n') { |
113 setSource(isolate, sourceValue.As<v8::String>()); | 122 m_endLine++; |
123 m_endColumn = 0; | |
124 } | |
125 } | |
114 } | 126 } |
115 | 127 |
116 V8DebuggerScript::~V8DebuggerScript() {} | 128 V8DebuggerScript::~V8DebuggerScript() {} |
117 | 129 |
118 const String16& V8DebuggerScript::sourceURL() const { | 130 const String16& V8DebuggerScript::sourceURL() const { |
119 return m_sourceURL.isEmpty() ? m_url : m_sourceURL; | 131 return m_sourceURL.isEmpty() ? m_url : m_sourceURL; |
120 } | 132 } |
121 | 133 |
122 v8::Local<v8::String> V8DebuggerScript::source(v8::Isolate* isolate) const { | 134 v8::Local<v8::String> V8DebuggerScript::source(v8::Isolate* isolate) const { |
123 return m_source.Get(isolate); | 135 return m_source.Get(isolate); |
124 } | 136 } |
125 | 137 |
126 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { | 138 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { |
127 m_sourceURL = sourceURL; | 139 m_sourceURL = sourceURL; |
128 } | 140 } |
129 | 141 |
130 void V8DebuggerScript::setSourceMappingURL(const String16& sourceMappingURL) { | 142 void V8DebuggerScript::setSourceMappingURL(const String16& sourceMappingURL) { |
131 m_sourceMappingURL = sourceMappingURL; | 143 m_sourceMappingURL = sourceMappingURL; |
132 } | 144 } |
133 | 145 |
134 void V8DebuggerScript::setSource(v8::Isolate* isolate, | 146 void V8DebuggerScript::setSource(v8::Isolate* isolate, |
135 v8::Local<v8::String> source) { | 147 v8::Local<v8::String> source) { |
136 m_source.Reset(isolate, source); | 148 m_source.Reset(isolate, source); |
137 m_hash = calculateHash(toProtocolString(source)); | 149 m_hash = calculateHash(toProtocolString(source)); |
138 } | 150 } |
139 | 151 |
140 } // namespace v8_inspector | 152 } // namespace v8_inspector |
OLD | NEW |