| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium 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 "platform/v8_inspector/V8StringUtil.h" | 5 #include "platform/v8_inspector/V8StringUtil.h" |
| 6 | 6 |
| 7 #include "platform/inspector_protocol/String16.h" | 7 #include "platform/inspector_protocol/String16.h" |
| 8 #include "platform/v8_inspector/V8DebuggerImpl.h" | 8 #include "platform/v8_inspector/V8DebuggerImpl.h" |
| 9 #include "platform/v8_inspector/V8InspectorSessionImpl.h" | 9 #include "platform/v8_inspector/V8InspectorSessionImpl.h" |
| 10 #include "platform/v8_inspector/V8Regex.h" | 10 #include "platform/v8_inspector/V8Regex.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 while (start < text.length()) { | 103 while (start < text.length()) { |
| 104 size_t lineEnd = text.find('\n', start); | 104 size_t lineEnd = text.find('\n', start); |
| 105 if (lineEnd == kNotFound) | 105 if (lineEnd == kNotFound) |
| 106 break; | 106 break; |
| 107 | 107 |
| 108 result->append(static_cast<unsigned>(lineEnd)); | 108 result->append(static_cast<unsigned>(lineEnd)); |
| 109 start = lineEnd + 1; | 109 start = lineEnd + 1; |
| 110 } | 110 } |
| 111 result->append(text.length()); | 111 result->append(text.length()); |
| 112 | 112 |
| 113 return result.release(); | 113 return result; |
| 114 } | 114 } |
| 115 | 115 |
| 116 protocol::Vector<std::pair<int, String16>> scriptRegexpMatchesByLines(const V8Re
gex& regex, const String16& text) | 116 protocol::Vector<std::pair<int, String16>> scriptRegexpMatchesByLines(const V8Re
gex& regex, const String16& text) |
| 117 { | 117 { |
| 118 protocol::Vector<std::pair<int, String16>> result; | 118 protocol::Vector<std::pair<int, String16>> result; |
| 119 if (text.isEmpty()) | 119 if (text.isEmpty()) |
| 120 return result; | 120 return result; |
| 121 | 121 |
| 122 OwnPtr<protocol::Vector<unsigned>> endings(lineEndings(text)); | 122 OwnPtr<protocol::Vector<unsigned>> endings(lineEndings(text)); |
| 123 unsigned size = endings->size(); | 123 unsigned size = endings->size(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 197 |
| 198 PassOwnPtr<protocol::Array<protocol::Debugger::SearchMatch>> searchInTextByLines
(V8InspectorSession* session, const String16& text, const String16& query, const
bool caseSensitive, const bool isRegex) | 198 PassOwnPtr<protocol::Array<protocol::Debugger::SearchMatch>> searchInTextByLines
(V8InspectorSession* session, const String16& text, const String16& query, const
bool caseSensitive, const bool isRegex) |
| 199 { | 199 { |
| 200 OwnPtr<protocol::Array<protocol::Debugger::SearchMatch>> result = protocol::
Array<protocol::Debugger::SearchMatch>::create(); | 200 OwnPtr<protocol::Array<protocol::Debugger::SearchMatch>> result = protocol::
Array<protocol::Debugger::SearchMatch>::create(); |
| 201 OwnPtr<V8Regex> regex = createSearchRegex(static_cast<V8InspectorSessionImpl
*>(session)->debugger(), query, caseSensitive, isRegex); | 201 OwnPtr<V8Regex> regex = createSearchRegex(static_cast<V8InspectorSessionImpl
*>(session)->debugger(), query, caseSensitive, isRegex); |
| 202 protocol::Vector<std::pair<int, String16>> matches = scriptRegexpMatchesByLi
nes(*regex.get(), text); | 202 protocol::Vector<std::pair<int, String16>> matches = scriptRegexpMatchesByLi
nes(*regex.get(), text); |
| 203 | 203 |
| 204 for (const auto& match : matches) | 204 for (const auto& match : matches) |
| 205 result->addItem(buildObjectForSearchMatch(match.first, match.second)); | 205 result->addItem(buildObjectForSearchMatch(match.first, match.second)); |
| 206 | 206 |
| 207 return result.release(); | 207 return result; |
| 208 } | 208 } |
| 209 | 209 |
| 210 } // namespace V8ContentSearchUtil | 210 } // namespace V8ContentSearchUtil |
| 211 | 211 |
| 212 PassOwnPtr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context, v8::
Local<v8::Value> value, int maxDepth) | 212 PassOwnPtr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context, v8::
Local<v8::Value> value, int maxDepth) |
| 213 { | 213 { |
| 214 if (value.IsEmpty()) { | 214 if (value.IsEmpty()) { |
| 215 ASSERT_NOT_REACHED(); | 215 ASSERT_NOT_REACHED(); |
| 216 return nullptr; | 216 return nullptr; |
| 217 } | 217 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 232 v8::Local<v8::Array> array = value.As<v8::Array>(); | 232 v8::Local<v8::Array> array = value.As<v8::Array>(); |
| 233 OwnPtr<protocol::ListValue> inspectorArray = protocol::ListValue::create
(); | 233 OwnPtr<protocol::ListValue> inspectorArray = protocol::ListValue::create
(); |
| 234 uint32_t length = array->Length(); | 234 uint32_t length = array->Length(); |
| 235 for (uint32_t i = 0; i < length; i++) { | 235 for (uint32_t i = 0; i < length; i++) { |
| 236 v8::Local<v8::Value> value; | 236 v8::Local<v8::Value> value; |
| 237 if (!array->Get(context, i).ToLocal(&value)) | 237 if (!array->Get(context, i).ToLocal(&value)) |
| 238 return nullptr; | 238 return nullptr; |
| 239 OwnPtr<protocol::Value> element = toProtocolValue(context, value, ma
xDepth); | 239 OwnPtr<protocol::Value> element = toProtocolValue(context, value, ma
xDepth); |
| 240 if (!element) | 240 if (!element) |
| 241 return nullptr; | 241 return nullptr; |
| 242 inspectorArray->pushValue(element.release()); | 242 inspectorArray->pushValue(std::move(element)); |
| 243 } | 243 } |
| 244 return inspectorArray.release(); | 244 return std::move(inspectorArray); |
| 245 } | 245 } |
| 246 if (value->IsObject()) { | 246 if (value->IsObject()) { |
| 247 OwnPtr<protocol::DictionaryValue> jsonObject = protocol::DictionaryValue
::create(); | 247 OwnPtr<protocol::DictionaryValue> jsonObject = protocol::DictionaryValue
::create(); |
| 248 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); | 248 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); |
| 249 v8::Local<v8::Array> propertyNames; | 249 v8::Local<v8::Array> propertyNames; |
| 250 if (!object->GetPropertyNames(context).ToLocal(&propertyNames)) | 250 if (!object->GetPropertyNames(context).ToLocal(&propertyNames)) |
| 251 return nullptr; | 251 return nullptr; |
| 252 uint32_t length = propertyNames->Length(); | 252 uint32_t length = propertyNames->Length(); |
| 253 for (uint32_t i = 0; i < length; i++) { | 253 for (uint32_t i = 0; i < length; i++) { |
| 254 v8::Local<v8::Value> name; | 254 v8::Local<v8::Value> name; |
| 255 if (!propertyNames->Get(context, i).ToLocal(&name)) | 255 if (!propertyNames->Get(context, i).ToLocal(&name)) |
| 256 return nullptr; | 256 return nullptr; |
| 257 // FIXME(yurys): v8::Object should support GetOwnPropertyNames | 257 // FIXME(yurys): v8::Object should support GetOwnPropertyNames |
| 258 if (name->IsString()) { | 258 if (name->IsString()) { |
| 259 v8::Maybe<bool> hasRealNamedProperty = object->HasRealNamedPrope
rty(context, v8::Local<v8::String>::Cast(name)); | 259 v8::Maybe<bool> hasRealNamedProperty = object->HasRealNamedPrope
rty(context, v8::Local<v8::String>::Cast(name)); |
| 260 if (!hasRealNamedProperty.IsJust() || !hasRealNamedProperty.From
Just()) | 260 if (!hasRealNamedProperty.IsJust() || !hasRealNamedProperty.From
Just()) |
| 261 continue; | 261 continue; |
| 262 } | 262 } |
| 263 v8::Local<v8::String> propertyName; | 263 v8::Local<v8::String> propertyName; |
| 264 if (!name->ToString(context).ToLocal(&propertyName)) | 264 if (!name->ToString(context).ToLocal(&propertyName)) |
| 265 continue; | 265 continue; |
| 266 v8::Local<v8::Value> property; | 266 v8::Local<v8::Value> property; |
| 267 if (!object->Get(context, name).ToLocal(&property)) | 267 if (!object->Get(context, name).ToLocal(&property)) |
| 268 return nullptr; | 268 return nullptr; |
| 269 OwnPtr<protocol::Value> propertyValue = toProtocolValue(context, pro
perty, maxDepth); | 269 OwnPtr<protocol::Value> propertyValue = toProtocolValue(context, pro
perty, maxDepth); |
| 270 if (!propertyValue) | 270 if (!propertyValue) |
| 271 return nullptr; | 271 return nullptr; |
| 272 jsonObject->setValue(toProtocolString(propertyName), propertyValue.r
elease()); | 272 jsonObject->setValue(toProtocolString(propertyName), std::move(prope
rtyValue)); |
| 273 } | 273 } |
| 274 return jsonObject.release(); | 274 return std::move(jsonObject); |
| 275 } | 275 } |
| 276 ASSERT_NOT_REACHED(); | 276 ASSERT_NOT_REACHED(); |
| 277 return nullptr; | 277 return nullptr; |
| 278 } | 278 } |
| 279 | 279 |
| 280 } // namespace blink | 280 } // namespace blink |
| OLD | NEW |