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

Side by Side Diff: src/inspector/string-util.cc

Issue 2332163002: [inspector] fixed all shorten-64-to-32 warnings (Closed)
Patch Set: rebased Created 4 years, 2 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
« no previous file with comments | « src/inspector/string-util.h ('k') | src/inspector/v8-console.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/string-util.h" 5 #include "src/inspector/string-util.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
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;
94 if (string.is8Bit()) 98 if (string.is8Bit()) {
95 return protocol::parseJSON(string.characters8(), string.length()); 99 return protocol::parseJSON(string.characters8(),
96 return protocol::parseJSON(string.characters16(), string.length()); 100 static_cast<int>(string.length()));
101 }
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 return protocol::parseJSON(string.characters16(),
109 static_cast<int>(string.length()));
102 } 110 }
103 111
104 } // namespace protocol 112 } // namespace protocol
105 113
106 std::unique_ptr<protocol::Value> toProtocolValue(protocol::String* errorString, 114 std::unique_ptr<protocol::Value> toProtocolValue(protocol::String* errorString,
107 v8::Local<v8::Context> context, 115 v8::Local<v8::Context> context,
108 v8::Local<v8::Value> value, 116 v8::Local<v8::Value> value,
109 int maxDepth) { 117 int maxDepth) {
110 if (value.IsEmpty()) { 118 if (value.IsEmpty()) {
111 UNREACHABLE(); 119 UNREACHABLE();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 std::unique_ptr<StringBufferImpl> StringBufferImpl::adopt(String16& string) { 209 std::unique_ptr<StringBufferImpl> StringBufferImpl::adopt(String16& string) {
202 return wrapUnique(new StringBufferImpl(string)); 210 return wrapUnique(new StringBufferImpl(string));
203 } 211 }
204 212
205 StringBufferImpl::StringBufferImpl(String16& string) { 213 StringBufferImpl::StringBufferImpl(String16& string) {
206 m_owner.swap(string); 214 m_owner.swap(string);
207 m_string = toStringView(m_owner); 215 m_string = toStringView(m_owner);
208 } 216 }
209 217
210 } // namespace v8_inspector 218 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/string-util.h ('k') | src/inspector/v8-console.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698