Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/inspector/StringUtil.cpp

Issue 2332163002: [inspector] fixed all shorten-64-to-32 warnings (Closed)
Patch Set: fixed compilation on linux bot Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <limits>
10
9 namespace v8_inspector { 11 namespace v8_inspector {
10 12
11 v8::Local<v8::String> toV8String(v8::Isolate* isolate, const String16& string) { 13 v8::Local<v8::String> toV8String(v8::Isolate* isolate, const String16& string) {
12 if (string.isEmpty()) return v8::String::Empty(isolate); 14 if (string.isEmpty()) return v8::String::Empty(isolate);
15 DCHECK(string.length() < v8::String::kMaxLength);
13 return v8::String::NewFromTwoByte( 16 return v8::String::NewFromTwoByte(
14 isolate, reinterpret_cast<const uint16_t*>(string.characters16()), 17 isolate, reinterpret_cast<const uint16_t*>(string.characters16()),
15 v8::NewStringType::kNormal, string.length()) 18 v8::NewStringType::kNormal, static_cast<int>(string.length()))
16 .ToLocalChecked(); 19 .ToLocalChecked();
17 } 20 }
18 21
19 v8::Local<v8::String> toV8StringInternalized(v8::Isolate* isolate, 22 v8::Local<v8::String> toV8StringInternalized(v8::Isolate* isolate,
20 const String16& string) { 23 const String16& string) {
21 if (string.isEmpty()) return v8::String::Empty(isolate); 24 if (string.isEmpty()) return v8::String::Empty(isolate);
25 DCHECK(string.length() < v8::String::kMaxLength);
22 return v8::String::NewFromTwoByte( 26 return v8::String::NewFromTwoByte(
23 isolate, reinterpret_cast<const uint16_t*>(string.characters16()), 27 isolate, reinterpret_cast<const uint16_t*>(string.characters16()),
24 v8::NewStringType::kInternalized, string.length()) 28 v8::NewStringType::kInternalized,
29 static_cast<int>(string.length()))
25 .ToLocalChecked(); 30 .ToLocalChecked();
26 } 31 }
27 32
28 v8::Local<v8::String> toV8StringInternalized(v8::Isolate* isolate, 33 v8::Local<v8::String> toV8StringInternalized(v8::Isolate* isolate,
29 const char* str) { 34 const char* str) {
30 return v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kInternalized) 35 return v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kInternalized)
31 .ToLocalChecked(); 36 .ToLocalChecked();
32 } 37 }
33 38
34 v8::Local<v8::String> toV8String(v8::Isolate* isolate, 39 v8::Local<v8::String> toV8String(v8::Isolate* isolate,
35 const StringView& string) { 40 const StringView& string) {
36 if (!string.length()) return v8::String::Empty(isolate); 41 if (!string.length()) return v8::String::Empty(isolate);
42 DCHECK(string.length() < v8::String::kMaxLength);
37 if (string.is8Bit()) 43 if (string.is8Bit())
38 return v8::String::NewFromOneByte( 44 return v8::String::NewFromOneByte(
39 isolate, reinterpret_cast<const uint8_t*>(string.characters8()), 45 isolate, reinterpret_cast<const uint8_t*>(string.characters8()),
40 v8::NewStringType::kNormal, string.length()) 46 v8::NewStringType::kNormal, static_cast<int>(string.length()))
41 .ToLocalChecked(); 47 .ToLocalChecked();
42 return v8::String::NewFromTwoByte( 48 return v8::String::NewFromTwoByte(
43 isolate, reinterpret_cast<const uint16_t*>(string.characters16()), 49 isolate, reinterpret_cast<const uint16_t*>(string.characters16()),
44 v8::NewStringType::kNormal, string.length()) 50 v8::NewStringType::kNormal, static_cast<int>(string.length()))
45 .ToLocalChecked(); 51 .ToLocalChecked();
46 } 52 }
47 53
48 String16 toProtocolString(v8::Local<v8::String> value) { 54 String16 toProtocolString(v8::Local<v8::String> value) {
49 if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) 55 if (value.IsEmpty() || value->IsNull() || value->IsUndefined())
50 return String16(); 56 return String16();
51 std::unique_ptr<UChar[]> buffer(new UChar[value->Length()]); 57 std::unique_ptr<UChar[]> buffer(new UChar[value->Length()]);
52 value->Write(reinterpret_cast<uint16_t*>(buffer.get()), 0, value->Length()); 58 value->Write(reinterpret_cast<uint16_t*>(buffer.get()), 0, value->Length());
53 return String16(buffer.get(), value->Length()); 59 return String16(buffer.get(), value->Length());
54 } 60 }
(...skipping 29 matching lines...) Expand all
84 if (string.characters16()[i] != prefix[j]) return false; 90 if (string.characters16()[i] != prefix[j]) return false;
85 } 91 }
86 } 92 }
87 return true; 93 return true;
88 } 94 }
89 95
90 namespace protocol { 96 namespace protocol {
91 97
92 std::unique_ptr<protocol::Value> parseJSON(const StringView& string) { 98 std::unique_ptr<protocol::Value> parseJSON(const StringView& string) {
93 if (!string.length()) return nullptr; 99 if (!string.length()) return nullptr;
94 if (string.is8Bit()) 100 DCHECK(string.length() <= std::numeric_limits<int>::max());
95 return protocol::parseJSON(string.characters8(), string.length()); 101 if (string.is8Bit()) {
96 return protocol::parseJSON(string.characters16(), string.length()); 102 return protocol::parseJSON(string.characters8(),
103 static_cast<int>(string.length()));
104 }
105 return protocol::parseJSON(string.characters16(),
106 static_cast<int>(string.length()));
97 } 107 }
98 108
99 std::unique_ptr<protocol::Value> parseJSON(const String16& string) { 109 std::unique_ptr<protocol::Value> parseJSON(const String16& string) {
100 if (!string.length()) return nullptr; 110 if (!string.length()) return nullptr;
101 return protocol::parseJSON(string.characters16(), string.length()); 111 DCHECK(string.length() <= std::numeric_limits<int>::max());
112 return protocol::parseJSON(string.characters16(),
113 static_cast<int>(string.length()));
102 } 114 }
103 115
104 } // namespace protocol 116 } // namespace protocol
105 117
106 std::unique_ptr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context, 118 std::unique_ptr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context,
107 v8::Local<v8::Value> value, 119 v8::Local<v8::Value> value,
108 int maxDepth) { 120 int maxDepth) {
109 if (value.IsEmpty()) { 121 if (value.IsEmpty()) {
110 UNREACHABLE(); 122 UNREACHABLE();
111 return nullptr; 123 return nullptr;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 std::unique_ptr<StringBufferImpl> StringBufferImpl::adopt(String16& string) { 198 std::unique_ptr<StringBufferImpl> StringBufferImpl::adopt(String16& string) {
187 return wrapUnique(new StringBufferImpl(string)); 199 return wrapUnique(new StringBufferImpl(string));
188 } 200 }
189 201
190 StringBufferImpl::StringBufferImpl(String16& string) { 202 StringBufferImpl::StringBufferImpl(String16& string) {
191 m_owner.swap(string); 203 m_owner.swap(string);
192 m_string = toStringView(m_owner); 204 m_string = toStringView(m_owner);
193 } 205 }
194 206
195 } // namespace v8_inspector 207 } // namespace v8_inspector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698