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

Side by Side Diff: src/uri.h

Issue 15691017: Make assertion scopes thread safe. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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
« src/api.cc ('K') | « src/type-info.cc ('k') | src/v8.h » ('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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 86 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
87 -0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, 87 -0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
88 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, 88 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
89 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 89 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
90 -1, 10, 11, 12, 13, 14, 15 }; 90 -1, 10, 11, 12, 13, 14, 15 };
91 91
92 92
93 template<typename Char> 93 template<typename Char>
94 Handle<String> URIUnescape::Unescape(Isolate* isolate, Handle<String> source) { 94 Handle<String> URIUnescape::Unescape(Isolate* isolate, Handle<String> source) {
95 int index; 95 int index;
96 { AssertNoAllocation no_allocation; 96 { DisallowHeapAllocation no_allocation;
97 StringSearch<uint8_t, Char> search(isolate, STATIC_ASCII_VECTOR("%")); 97 StringSearch<uint8_t, Char> search(isolate, STATIC_ASCII_VECTOR("%"));
98 index = search.Search(GetCharVector<Char>(source), 0); 98 index = search.Search(GetCharVector<Char>(source), 0);
99 if (index < 0) return source; 99 if (index < 0) return source;
100 } 100 }
101 return UnescapeSlow<Char>(isolate, source, index); 101 return UnescapeSlow<Char>(isolate, source, index);
102 } 102 }
103 103
104 104
105 template <typename Char> 105 template <typename Char>
106 Handle<String> URIUnescape::UnescapeSlow( 106 Handle<String> URIUnescape::UnescapeSlow(
107 Isolate* isolate, Handle<String> string, int start_index) { 107 Isolate* isolate, Handle<String> string, int start_index) {
108 bool one_byte = true; 108 bool one_byte = true;
109 int length = string->length(); 109 int length = string->length();
110 110
111 int unescaped_length = 0; 111 int unescaped_length = 0;
112 { AssertNoAllocation no_allocation; 112 { DisallowHeapAllocation no_allocation;
113 Vector<const Char> vector = GetCharVector<Char>(string); 113 Vector<const Char> vector = GetCharVector<Char>(string);
114 for (int i = start_index; i < length; unescaped_length++) { 114 for (int i = start_index; i < length; unescaped_length++) {
115 int step; 115 int step;
116 if (UnescapeChar(vector, i, length, &step) > 116 if (UnescapeChar(vector, i, length, &step) >
117 String::kMaxOneByteCharCode) { 117 String::kMaxOneByteCharCode) {
118 one_byte = false; 118 one_byte = false;
119 } 119 }
120 i += step; 120 i += step;
121 } 121 }
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 if (one_byte) { 130 if (one_byte) {
131 Handle<SeqOneByteString> dest = 131 Handle<SeqOneByteString> dest =
132 isolate->factory()->NewRawOneByteString(unescaped_length); 132 isolate->factory()->NewRawOneByteString(unescaped_length);
133 AssertNoAllocation no_allocation; 133 DisallowHeapAllocation no_allocation;
134 Vector<const Char> vector = GetCharVector<Char>(string); 134 Vector<const Char> vector = GetCharVector<Char>(string);
135 for (int i = start_index; i < length; dest_position++) { 135 for (int i = start_index; i < length; dest_position++) {
136 int step; 136 int step;
137 dest->SeqOneByteStringSet(dest_position, 137 dest->SeqOneByteStringSet(dest_position,
138 UnescapeChar(vector, i, length, &step)); 138 UnescapeChar(vector, i, length, &step));
139 i += step; 139 i += step;
140 } 140 }
141 second_part = dest; 141 second_part = dest;
142 } else { 142 } else {
143 Handle<SeqTwoByteString> dest = 143 Handle<SeqTwoByteString> dest =
144 isolate->factory()->NewRawTwoByteString(unescaped_length); 144 isolate->factory()->NewRawTwoByteString(unescaped_length);
145 AssertNoAllocation no_allocation; 145 DisallowHeapAllocation no_allocation;
146 Vector<const Char> vector = GetCharVector<Char>(string); 146 Vector<const Char> vector = GetCharVector<Char>(string);
147 for (int i = start_index; i < length; dest_position++) { 147 for (int i = start_index; i < length; dest_position++) {
148 int step; 148 int step;
149 dest->SeqTwoByteStringSet(dest_position, 149 dest->SeqTwoByteStringSet(dest_position,
150 UnescapeChar(vector, i, length, &step)); 150 UnescapeChar(vector, i, length, &step));
151 i += step; 151 i += step;
152 } 152 }
153 second_part = dest; 153 second_part = dest;
154 } 154 }
155 return isolate->factory()->NewConsString(first_part, second_part); 155 return isolate->factory()->NewConsString(first_part, second_part);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 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,
243 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 };
244 244
245 245
246 template<typename Char> 246 template<typename Char>
247 Handle<String> URIEscape::Escape(Isolate* isolate, Handle<String> string) { 247 Handle<String> URIEscape::Escape(Isolate* isolate, Handle<String> string) {
248 ASSERT(string->IsFlat()); 248 ASSERT(string->IsFlat());
249 int escaped_length = 0; 249 int escaped_length = 0;
250 int length = string->length(); 250 int length = string->length();
251 251
252 { AssertNoAllocation no_allocation; 252 { DisallowHeapAllocation no_allocation;
253 Vector<const Char> vector = GetCharVector<Char>(string); 253 Vector<const Char> vector = GetCharVector<Char>(string);
254 for (int i = 0; i < length; i++) { 254 for (int i = 0; i < length; i++) {
255 uint16_t c = vector[i]; 255 uint16_t c = vector[i];
256 if (c >= 256) { 256 if (c >= 256) {
257 escaped_length += 6; 257 escaped_length += 6;
258 } else if (IsNotEscaped(c)) { 258 } else if (IsNotEscaped(c)) {
259 escaped_length++; 259 escaped_length++;
260 } else { 260 } else {
261 escaped_length += 3; 261 escaped_length += 3;
262 } 262 }
263 263
264 // We don't allow strings that are longer than a maximal length. 264 // We don't allow strings that are longer than a maximal length.
265 ASSERT(String::kMaxLength < 0x7fffffff - 6); // Cannot overflow. 265 ASSERT(String::kMaxLength < 0x7fffffff - 6); // Cannot overflow.
266 if (escaped_length > String::kMaxLength) { 266 if (escaped_length > String::kMaxLength) {
267 isolate->context()->mark_out_of_memory(); 267 isolate->context()->mark_out_of_memory();
268 return Handle<String>::null(); 268 return Handle<String>::null();
269 } 269 }
270 } 270 }
271 } 271 }
272 272
273 // No length change implies no change. Return original string if no change. 273 // No length change implies no change. Return original string if no change.
274 if (escaped_length == length) return string; 274 if (escaped_length == length) return string;
275 275
276 Handle<SeqOneByteString> dest = 276 Handle<SeqOneByteString> dest =
277 isolate->factory()->NewRawOneByteString(escaped_length); 277 isolate->factory()->NewRawOneByteString(escaped_length);
278 int dest_position = 0; 278 int dest_position = 0;
279 279
280 { AssertNoAllocation no_allocation; 280 { DisallowHeapAllocation no_allocation;
281 Vector<const Char> vector = GetCharVector<Char>(string); 281 Vector<const Char> vector = GetCharVector<Char>(string);
282 for (int i = 0; i < length; i++) { 282 for (int i = 0; i < length; i++) {
283 uint16_t c = vector[i]; 283 uint16_t c = vector[i];
284 if (c >= 256) { 284 if (c >= 256) {
285 dest->SeqOneByteStringSet(dest_position, '%'); 285 dest->SeqOneByteStringSet(dest_position, '%');
286 dest->SeqOneByteStringSet(dest_position+1, 'u'); 286 dest->SeqOneByteStringSet(dest_position+1, 'u');
287 dest->SeqOneByteStringSet(dest_position+2, kHexChars[c >> 12]); 287 dest->SeqOneByteStringSet(dest_position+2, kHexChars[c >> 12]);
288 dest->SeqOneByteStringSet(dest_position+3, kHexChars[(c >> 8) & 0xf]); 288 dest->SeqOneByteStringSet(dest_position+3, kHexChars[(c >> 8) & 0xf]);
289 dest->SeqOneByteStringSet(dest_position+4, kHexChars[(c >> 4) & 0xf]); 289 dest->SeqOneByteStringSet(dest_position+4, kHexChars[(c >> 4) & 0xf]);
290 dest->SeqOneByteStringSet(dest_position+5, kHexChars[c & 0xf]); 290 dest->SeqOneByteStringSet(dest_position+5, kHexChars[c & 0xf]);
291 dest_position += 6; 291 dest_position += 6;
292 } else if (IsNotEscaped(c)) { 292 } else if (IsNotEscaped(c)) {
293 dest->SeqOneByteStringSet(dest_position, c); 293 dest->SeqOneByteStringSet(dest_position, c);
294 dest_position++; 294 dest_position++;
295 } else { 295 } else {
296 dest->SeqOneByteStringSet(dest_position, '%'); 296 dest->SeqOneByteStringSet(dest_position, '%');
297 dest->SeqOneByteStringSet(dest_position+1, kHexChars[c >> 4]); 297 dest->SeqOneByteStringSet(dest_position+1, kHexChars[c >> 4]);
298 dest->SeqOneByteStringSet(dest_position+2, kHexChars[c & 0xf]); 298 dest->SeqOneByteStringSet(dest_position+2, kHexChars[c & 0xf]);
299 dest_position += 3; 299 dest_position += 3;
300 } 300 }
301 } 301 }
302 } 302 }
303 303
304 return dest; 304 return dest;
305 } 305 }
306 306
307 } } // namespace v8::internal 307 } } // namespace v8::internal
308 308
309 #endif // V8_URI_H_ 309 #endif // V8_URI_H_
OLDNEW
« src/api.cc ('K') | « src/type-info.cc ('k') | src/v8.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698