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::Local<v8::Context> context, |
71 v8::Local<v8::Object> object, | 71 v8::Local<v8::DebugInterface::Script> script, |
72 const char* name) { | 72 bool isLiveEdit) { |
73 return object | 73 v8::HandleScope scope(context->GetIsolate()); |
74 ->Get(context, toV8StringInternalized(context->GetIsolate(), name)) | 74 m_id = String16::fromInteger(script->Id()); |
75 .ToLocalChecked(); | 75 v8::Local<v8::String> tmp; |
76 } | 76 if (script->Name(context).ToLocal(&tmp)) m_url = toProtocolString(tmp); |
77 if (script->SourceURL(context).ToLocal(&tmp)) { | |
78 m_sourceURL = toProtocolString(tmp); | |
79 if (m_url.isEmpty()) m_url = toProtocolString(tmp); | |
80 } | |
81 if (script->SourceMappingURL(context).ToLocal(&tmp)) | |
82 m_sourceMappingURL = toProtocolString(tmp); | |
83 m_startLine = script->LineOffset(); | |
84 m_startColumn = script->ColumnOffset(); | |
85 v8::Local<v8::Array> lineEnds; | |
86 if (script->LineEnds(context).ToLocal(&lineEnds) && lineEnds->Length()) { | |
87 m_endLine = static_cast<int>(lineEnds->Length()) + m_startLine - 1; | |
77 | 88 |
78 static int GetCheckedInt(v8::Local<v8::Context> context, | 89 v8::Local<v8::Value> lastLineLengthValue; |
79 v8::Local<v8::Object> object, const char* name) { | 90 if (lineEnds->Get(context, lineEnds->Length() - 1) |
80 return static_cast<int>(GetChecked(context, object, name) | 91 .ToLocal(&lastLineLengthValue) && |
81 ->ToInteger(context) | 92 lastLineLengthValue->IsInt32()) { |
82 .ToLocalChecked() | 93 int32_t lastLineLength = lastLineLengthValue.As<v8::Int32>()->Value(); |
83 ->Value()); | 94 if (lineEnds->Length() > 1) { |
84 } | 95 v8::Local<v8::Value> lengthValue; |
96 if (lineEnds->Get(context, lineEnds->Length() - 2) | |
97 .ToLocal(&lengthValue) && | |
98 lengthValue->IsInt32()) { | |
99 m_endColumn = | |
100 lastLineLength - lengthValue.As<v8::Int32>()->Value() - 1; | |
101 } | |
102 } else { | |
103 m_endColumn = lastLineLength + m_startColumn; | |
104 } | |
105 } | |
106 } else { | |
107 m_endLine = 0; | |
108 m_endColumn = 0; | |
109 } | |
85 | 110 |
86 V8DebuggerScript::V8DebuggerScript(v8::Local<v8::Context> context, | 111 if (script->ContextData(context).ToLocal(&tmp)) { |
87 v8::Local<v8::Object> object, | 112 String16 contextData = toProtocolString(tmp); |
88 bool isLiveEdit) { | 113 size_t firstComma = contextData.find(",", 0); |
89 v8::Isolate* isolate = context->GetIsolate(); | 114 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.
| |
90 v8::Local<v8::Value> idValue = GetChecked(context, object, "id"); | 115 if (firstComma != String16::kNotFound && |
91 DCHECK(!idValue.IsEmpty() && idValue->IsInt32()); | 116 secondComma != String16::kNotFound) { |
92 m_id = String16::fromInteger(idValue->Int32Value(context).FromJust()); | 117 String16 executionContextId = |
118 contextData.substring(firstComma + 1, secondComma - firstComma - 1); | |
119 bool isOk = false; | |
120 m_executionContextId = executionContextId.toInteger(&isOk); | |
121 if (!isOk) m_executionContextId = 0; | |
122 m_executionContextAuxData = contextData.substring(secondComma + 1); | |
123 } | |
124 } | |
93 | 125 |
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; | 126 m_isLiveEdit = isLiveEdit; |
107 | 127 if (script->Source(context).ToLocal(&tmp)) { |
108 v8::Local<v8::Value> sourceValue; | 128 m_source.Reset(context->GetIsolate(), tmp); |
109 if (!object->Get(context, toV8StringInternalized(isolate, "source")) | 129 String16 source = toProtocolString(tmp); |
110 .ToLocal(&sourceValue) || | 130 m_hash = calculateHash(source); |
111 !sourceValue->IsString()) | 131 // V8 will not count last line if script source ends with \n. |
112 return; | 132 if (source.length() > 1 && source[source.length() - 1] == '\n') { |
113 setSource(isolate, sourceValue.As<v8::String>()); | 133 m_endLine++; |
134 m_endColumn = 0; | |
135 } | |
136 } | |
114 } | 137 } |
115 | 138 |
116 V8DebuggerScript::~V8DebuggerScript() {} | 139 V8DebuggerScript::~V8DebuggerScript() {} |
117 | 140 |
118 const String16& V8DebuggerScript::sourceURL() const { | 141 const String16& V8DebuggerScript::sourceURL() const { |
119 return m_sourceURL.isEmpty() ? m_url : m_sourceURL; | 142 return m_sourceURL.isEmpty() ? m_url : m_sourceURL; |
120 } | 143 } |
121 | 144 |
122 v8::Local<v8::String> V8DebuggerScript::source(v8::Isolate* isolate) const { | 145 v8::Local<v8::String> V8DebuggerScript::source(v8::Isolate* isolate) const { |
123 return m_source.Get(isolate); | 146 return m_source.Get(isolate); |
124 } | 147 } |
125 | 148 |
126 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { | 149 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { |
127 m_sourceURL = sourceURL; | 150 m_sourceURL = sourceURL; |
128 } | 151 } |
129 | 152 |
130 void V8DebuggerScript::setSourceMappingURL(const String16& sourceMappingURL) { | 153 void V8DebuggerScript::setSourceMappingURL(const String16& sourceMappingURL) { |
131 m_sourceMappingURL = sourceMappingURL; | 154 m_sourceMappingURL = sourceMappingURL; |
132 } | 155 } |
133 | 156 |
134 void V8DebuggerScript::setSource(v8::Isolate* isolate, | 157 void V8DebuggerScript::setSource(v8::Isolate* isolate, |
135 v8::Local<v8::String> source) { | 158 v8::Local<v8::String> source) { |
136 m_source.Reset(isolate, source); | 159 m_source.Reset(isolate, source); |
137 m_hash = calculateHash(toProtocolString(source)); | 160 m_hash = calculateHash(toProtocolString(source)); |
138 } | 161 } |
139 | 162 |
140 } // namespace v8_inspector | 163 } // namespace v8_inspector |
OLD | NEW |