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

Side by Side Diff: src/uri.h

Issue 223573002: Return MaybeHandle from NewRaw???String. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/runtime.cc ('k') | test/cctest/test-mementos.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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 122 }
123 123
124 ASSERT(start_index < length); 124 ASSERT(start_index < length);
125 Handle<String> first_part = 125 Handle<String> first_part =
126 isolate->factory()->NewProperSubString(string, 0, start_index); 126 isolate->factory()->NewProperSubString(string, 0, start_index);
127 127
128 int dest_position = 0; 128 int dest_position = 0;
129 Handle<String> second_part; 129 Handle<String> second_part;
130 ASSERT(unescaped_length <= String::kMaxLength); 130 ASSERT(unescaped_length <= String::kMaxLength);
131 if (one_byte) { 131 if (one_byte) {
132 Handle<SeqOneByteString> dest = 132 Handle<SeqOneByteString> dest = isolate->factory()->NewRawOneByteString(
133 isolate->factory()->NewRawOneByteString(unescaped_length); 133 unescaped_length).ToHandleChecked();
134 ASSERT(!dest.is_null());
135 DisallowHeapAllocation no_allocation; 134 DisallowHeapAllocation no_allocation;
136 Vector<const Char> vector = GetCharVector<Char>(string); 135 Vector<const Char> vector = GetCharVector<Char>(string);
137 for (int i = start_index; i < length; dest_position++) { 136 for (int i = start_index; i < length; dest_position++) {
138 int step; 137 int step;
139 dest->SeqOneByteStringSet(dest_position, 138 dest->SeqOneByteStringSet(dest_position,
140 UnescapeChar(vector, i, length, &step)); 139 UnescapeChar(vector, i, length, &step));
141 i += step; 140 i += step;
142 } 141 }
143 second_part = dest; 142 second_part = dest;
144 } else { 143 } else {
145 Handle<SeqTwoByteString> dest = 144 Handle<SeqTwoByteString> dest = isolate->factory()->NewRawTwoByteString(
146 isolate->factory()->NewRawTwoByteString(unescaped_length); 145 unescaped_length).ToHandleChecked();
147 ASSERT(!dest.is_null());
148 DisallowHeapAllocation no_allocation; 146 DisallowHeapAllocation no_allocation;
149 Vector<const Char> vector = GetCharVector<Char>(string); 147 Vector<const Char> vector = GetCharVector<Char>(string);
150 for (int i = start_index; i < length; dest_position++) { 148 for (int i = start_index; i < length; dest_position++) {
151 int step; 149 int step;
152 dest->SeqTwoByteStringSet(dest_position, 150 dest->SeqTwoByteStringSet(dest_position,
153 UnescapeChar(vector, i, length, &step)); 151 UnescapeChar(vector, i, length, &step));
154 i += step; 152 i += step;
155 } 153 }
156 second_part = dest; 154 second_part = dest;
157 } 155 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 } else { 194 } else {
197 *step = 1; 195 *step = 1;
198 return character; 196 return character;
199 } 197 }
200 } 198 }
201 199
202 200
203 class URIEscape : public AllStatic { 201 class URIEscape : public AllStatic {
204 public: 202 public:
205 template<typename Char> 203 template<typename Char>
206 static Handle<String> Escape(Isolate* isolate, Handle<String> string); 204 static MaybeHandle<String> Escape(Isolate* isolate, Handle<String> string);
207 205
208 private: 206 private:
209 static const char kHexChars[17]; 207 static const char kHexChars[17];
210 static const char kNotEscaped[256]; 208 static const char kNotEscaped[256];
211 209
212 static bool IsNotEscaped(uint16_t c) { return kNotEscaped[c] != 0; } 210 static bool IsNotEscaped(uint16_t c) { return kNotEscaped[c] != 0; }
213 }; 211 };
214 212
215 213
216 const char URIEscape::kHexChars[] = "0123456789ABCDEF"; 214 const char URIEscape::kHexChars[] = "0123456789ABCDEF";
(...skipping 23 matching lines...) Expand all
240 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 238 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
241 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 239 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
242 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
243 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 241 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
244 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 242 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
245 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 243 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
246 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 244 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
247 245
248 246
249 template<typename Char> 247 template<typename Char>
250 Handle<String> URIEscape::Escape(Isolate* isolate, Handle<String> string) { 248 MaybeHandle<String> URIEscape::Escape(Isolate* isolate, Handle<String> string) {
251 ASSERT(string->IsFlat()); 249 ASSERT(string->IsFlat());
252 int escaped_length = 0; 250 int escaped_length = 0;
253 int length = string->length(); 251 int length = string->length();
254 252
255 { DisallowHeapAllocation no_allocation; 253 { DisallowHeapAllocation no_allocation;
256 Vector<const Char> vector = GetCharVector<Char>(string); 254 Vector<const Char> vector = GetCharVector<Char>(string);
257 for (int i = 0; i < length; i++) { 255 for (int i = 0; i < length; i++) {
258 uint16_t c = vector[i]; 256 uint16_t c = vector[i];
259 if (c >= 256) { 257 if (c >= 256) {
260 escaped_length += 6; 258 escaped_length += 6;
261 } else if (IsNotEscaped(c)) { 259 } else if (IsNotEscaped(c)) {
262 escaped_length++; 260 escaped_length++;
263 } else { 261 } else {
264 escaped_length += 3; 262 escaped_length += 3;
265 } 263 }
266 264
267 // We don't allow strings that are longer than a maximal length. 265 // We don't allow strings that are longer than a maximal length.
268 ASSERT(String::kMaxLength < 0x7fffffff - 6); // Cannot overflow. 266 ASSERT(String::kMaxLength < 0x7fffffff - 6); // Cannot overflow.
269 if (escaped_length > String::kMaxLength) break; // Provoke exception. 267 if (escaped_length > String::kMaxLength) break; // Provoke exception.
270 } 268 }
271 } 269 }
272 270
273 // No length change implies no change. Return original string if no change. 271 // No length change implies no change. Return original string if no change.
274 if (escaped_length == length) return string; 272 if (escaped_length == length) return string;
275 273
276 Handle<SeqOneByteString> dest = 274 Handle<SeqOneByteString> dest;
277 isolate->factory()->NewRawOneByteString(escaped_length); 275 ASSIGN_RETURN_ON_EXCEPTION(
278 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, dest, Handle<String>()); 276 isolate, dest,
277 isolate->factory()->NewRawOneByteString(escaped_length),
278 String);
279 int dest_position = 0; 279 int dest_position = 0;
280 280
281 { DisallowHeapAllocation no_allocation; 281 { DisallowHeapAllocation no_allocation;
282 Vector<const Char> vector = GetCharVector<Char>(string); 282 Vector<const Char> vector = GetCharVector<Char>(string);
283 for (int i = 0; i < length; i++) { 283 for (int i = 0; i < length; i++) {
284 uint16_t c = vector[i]; 284 uint16_t c = vector[i];
285 if (c >= 256) { 285 if (c >= 256) {
286 dest->SeqOneByteStringSet(dest_position, '%'); 286 dest->SeqOneByteStringSet(dest_position, '%');
287 dest->SeqOneByteStringSet(dest_position+1, 'u'); 287 dest->SeqOneByteStringSet(dest_position+1, 'u');
288 dest->SeqOneByteStringSet(dest_position+2, kHexChars[c >> 12]); 288 dest->SeqOneByteStringSet(dest_position+2, kHexChars[c >> 12]);
(...skipping 12 matching lines...) Expand all
301 } 301 }
302 } 302 }
303 } 303 }
304 304
305 return dest; 305 return dest;
306 } 306 }
307 307
308 } } // namespace v8::internal 308 } } // namespace v8::internal
309 309
310 #endif // V8_URI_H_ 310 #endif // V8_URI_H_
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/cctest/test-mementos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698