Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/StringUtil.h" | 5 #include "src/inspector/StringUtil.h" |
| 6 | 6 |
| 7 #include "src/inspector/protocol/Protocol.h" | 7 #include "src/inspector/protocol/Protocol.h" |
| 8 | 8 |
| 9 namespace v8_inspector { | 9 namespace v8_inspector { |
| 10 | 10 |
| 11 v8::Local<v8::String> toV8String(v8::Isolate* isolate, const String16& string) { | 11 v8::Local<v8::String> toV8String(v8::Isolate* isolate, const String16& string) { |
| 12 if (string.isEmpty()) return v8::String::Empty(isolate); | 12 if (string.isEmpty()) return v8::String::Empty(isolate); |
| 13 DCHECK(string.length() < v8::String::kMaxLength); | |
| 13 return v8::String::NewFromTwoByte( | 14 return v8::String::NewFromTwoByte( |
| 14 isolate, reinterpret_cast<const uint16_t*>(string.characters16()), | 15 isolate, reinterpret_cast<const uint16_t*>(string.characters16()), |
| 15 v8::NewStringType::kNormal, string.length()) | 16 v8::NewStringType::kNormal, static_cast<int>(string.length())) |
| 16 .ToLocalChecked(); | 17 .ToLocalChecked(); |
| 17 } | 18 } |
| 18 | 19 |
| 19 v8::Local<v8::String> toV8StringInternalized(v8::Isolate* isolate, | 20 v8::Local<v8::String> toV8StringInternalized(v8::Isolate* isolate, |
| 20 const String16& string) { | 21 const String16& string) { |
| 21 if (string.isEmpty()) return v8::String::Empty(isolate); | 22 if (string.isEmpty()) return v8::String::Empty(isolate); |
| 23 DCHECK(string.length() < v8::String::kMaxLength); | |
| 22 return v8::String::NewFromTwoByte( | 24 return v8::String::NewFromTwoByte( |
| 23 isolate, reinterpret_cast<const uint16_t*>(string.characters16()), | 25 isolate, reinterpret_cast<const uint16_t*>(string.characters16()), |
| 24 v8::NewStringType::kInternalized, string.length()) | 26 v8::NewStringType::kInternalized, |
| 27 static_cast<int>(string.length())) | |
| 25 .ToLocalChecked(); | 28 .ToLocalChecked(); |
| 26 } | 29 } |
| 27 | 30 |
| 28 v8::Local<v8::String> toV8StringInternalized(v8::Isolate* isolate, | 31 v8::Local<v8::String> toV8StringInternalized(v8::Isolate* isolate, |
| 29 const char* str) { | 32 const char* str) { |
| 30 return v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kInternalized) | 33 return v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kInternalized) |
| 31 .ToLocalChecked(); | 34 .ToLocalChecked(); |
| 32 } | 35 } |
| 33 | 36 |
| 34 v8::Local<v8::String> toV8String(v8::Isolate* isolate, | 37 v8::Local<v8::String> toV8String(v8::Isolate* isolate, |
| 35 const StringView& string) { | 38 const StringView& string) { |
| 36 if (!string.length()) return v8::String::Empty(isolate); | 39 if (!string.length()) return v8::String::Empty(isolate); |
| 40 DCHECK(string.length() < v8::String::kMaxLength); | |
| 37 if (string.is8Bit()) | 41 if (string.is8Bit()) |
| 38 return v8::String::NewFromOneByte( | 42 return v8::String::NewFromOneByte( |
| 39 isolate, reinterpret_cast<const uint8_t*>(string.characters8()), | 43 isolate, reinterpret_cast<const uint8_t*>(string.characters8()), |
| 40 v8::NewStringType::kNormal, string.length()) | 44 v8::NewStringType::kNormal, static_cast<int>(string.length())) |
| 41 .ToLocalChecked(); | 45 .ToLocalChecked(); |
| 42 return v8::String::NewFromTwoByte( | 46 return v8::String::NewFromTwoByte( |
| 43 isolate, reinterpret_cast<const uint16_t*>(string.characters16()), | 47 isolate, reinterpret_cast<const uint16_t*>(string.characters16()), |
| 44 v8::NewStringType::kNormal, string.length()) | 48 v8::NewStringType::kNormal, static_cast<int>(string.length())) |
| 45 .ToLocalChecked(); | 49 .ToLocalChecked(); |
| 46 } | 50 } |
| 47 | 51 |
| 48 String16 toProtocolString(v8::Local<v8::String> value) { | 52 String16 toProtocolString(v8::Local<v8::String> value) { |
| 49 if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) | 53 if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) |
| 50 return String16(); | 54 return String16(); |
| 51 std::unique_ptr<UChar[]> buffer(new UChar[value->Length()]); | 55 std::unique_ptr<UChar[]> buffer(new UChar[value->Length()]); |
| 52 value->Write(reinterpret_cast<uint16_t*>(buffer.get()), 0, value->Length()); | 56 value->Write(reinterpret_cast<uint16_t*>(buffer.get()), 0, value->Length()); |
| 53 return String16(buffer.get(), value->Length()); | 57 return String16(buffer.get(), value->Length()); |
| 54 } | 58 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 84 if (string.characters16()[i] != prefix[j]) return false; | 88 if (string.characters16()[i] != prefix[j]) return false; |
| 85 } | 89 } |
| 86 } | 90 } |
| 87 return true; | 91 return true; |
| 88 } | 92 } |
| 89 | 93 |
| 90 namespace protocol { | 94 namespace protocol { |
| 91 | 95 |
| 92 std::unique_ptr<protocol::Value> parseJSON(const StringView& string) { | 96 std::unique_ptr<protocol::Value> parseJSON(const StringView& string) { |
| 93 if (!string.length()) return nullptr; | 97 if (!string.length()) return nullptr; |
| 98 DCHECK(string.length() <= std::numeric_limits<int>::max()); | |
| 94 if (string.is8Bit()) | 99 if (string.is8Bit()) |
|
dgozman
2016/09/12 22:44:25
{}
kozy
2016/09/12 23:02:59
Done.
| |
| 95 return protocol::parseJSON(string.characters8(), string.length()); | 100 return protocol::parseJSON(string.characters8(), |
| 96 return protocol::parseJSON(string.characters16(), string.length()); | 101 static_cast<int>(string.length())); |
| 102 return protocol::parseJSON(string.characters16(), | |
| 103 static_cast<int>(string.length())); | |
| 97 } | 104 } |
| 98 | 105 |
| 99 std::unique_ptr<protocol::Value> parseJSON(const String16& string) { | 106 std::unique_ptr<protocol::Value> parseJSON(const String16& string) { |
| 100 if (!string.length()) return nullptr; | 107 if (!string.length()) return nullptr; |
| 101 return protocol::parseJSON(string.characters16(), string.length()); | 108 DCHECK(string.length() <= std::numeric_limits<int>::max()); |
| 109 return protocol::parseJSON(string.characters16(), | |
| 110 static_cast<int>(string.length())); | |
| 102 } | 111 } |
| 103 | 112 |
| 104 } // namespace protocol | 113 } // namespace protocol |
| 105 | 114 |
| 106 std::unique_ptr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context, | 115 std::unique_ptr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context, |
| 107 v8::Local<v8::Value> value, | 116 v8::Local<v8::Value> value, |
| 108 int maxDepth) { | 117 int maxDepth) { |
| 109 if (value.IsEmpty()) { | 118 if (value.IsEmpty()) { |
| 110 UNREACHABLE(); | 119 UNREACHABLE(); |
| 111 return nullptr; | 120 return nullptr; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 std::unique_ptr<StringBufferImpl> StringBufferImpl::adopt(String16& string) { | 195 std::unique_ptr<StringBufferImpl> StringBufferImpl::adopt(String16& string) { |
| 187 return wrapUnique(new StringBufferImpl(string)); | 196 return wrapUnique(new StringBufferImpl(string)); |
| 188 } | 197 } |
| 189 | 198 |
| 190 StringBufferImpl::StringBufferImpl(String16& string) { | 199 StringBufferImpl::StringBufferImpl(String16& string) { |
| 191 m_owner.swap(string); | 200 m_owner.swap(string); |
| 192 m_string = toStringView(m_owner); | 201 m_string = toStringView(m_owner); |
| 193 } | 202 } |
| 194 | 203 |
| 195 } // namespace v8_inspector | 204 } // namespace v8_inspector |
| OLD | NEW |