| OLD | NEW |
| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 ASSERT(unescaped_length <= String::kMaxLength); | |
| 131 if (one_byte) { | 130 if (one_byte) { |
| 132 Handle<SeqOneByteString> dest = | 131 Handle<SeqOneByteString> dest = |
| 133 isolate->factory()->NewRawOneByteString(unescaped_length); | 132 isolate->factory()->NewRawOneByteString(unescaped_length); |
| 134 ASSERT(!dest.is_null()); | |
| 135 DisallowHeapAllocation no_allocation; | 133 DisallowHeapAllocation no_allocation; |
| 136 Vector<const Char> vector = GetCharVector<Char>(string); | 134 Vector<const Char> vector = GetCharVector<Char>(string); |
| 137 for (int i = start_index; i < length; dest_position++) { | 135 for (int i = start_index; i < length; dest_position++) { |
| 138 int step; | 136 int step; |
| 139 dest->SeqOneByteStringSet(dest_position, | 137 dest->SeqOneByteStringSet(dest_position, |
| 140 UnescapeChar(vector, i, length, &step)); | 138 UnescapeChar(vector, i, length, &step)); |
| 141 i += step; | 139 i += step; |
| 142 } | 140 } |
| 143 second_part = dest; | 141 second_part = dest; |
| 144 } else { | 142 } else { |
| 145 Handle<SeqTwoByteString> dest = | 143 Handle<SeqTwoByteString> dest = |
| 146 isolate->factory()->NewRawTwoByteString(unescaped_length); | 144 isolate->factory()->NewRawTwoByteString(unescaped_length); |
| 147 ASSERT(!dest.is_null()); | |
| 148 DisallowHeapAllocation no_allocation; | 145 DisallowHeapAllocation no_allocation; |
| 149 Vector<const Char> vector = GetCharVector<Char>(string); | 146 Vector<const Char> vector = GetCharVector<Char>(string); |
| 150 for (int i = start_index; i < length; dest_position++) { | 147 for (int i = start_index; i < length; dest_position++) { |
| 151 int step; | 148 int step; |
| 152 dest->SeqTwoByteStringSet(dest_position, | 149 dest->SeqTwoByteStringSet(dest_position, |
| 153 UnescapeChar(vector, i, length, &step)); | 150 UnescapeChar(vector, i, length, &step)); |
| 154 i += step; | 151 i += step; |
| 155 } | 152 } |
| 156 second_part = dest; | 153 second_part = dest; |
| 157 } | 154 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 if (c >= 256) { | 256 if (c >= 256) { |
| 260 escaped_length += 6; | 257 escaped_length += 6; |
| 261 } else if (IsNotEscaped(c)) { | 258 } else if (IsNotEscaped(c)) { |
| 262 escaped_length++; | 259 escaped_length++; |
| 263 } else { | 260 } else { |
| 264 escaped_length += 3; | 261 escaped_length += 3; |
| 265 } | 262 } |
| 266 | 263 |
| 267 // 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. |
| 268 ASSERT(String::kMaxLength < 0x7fffffff - 6); // Cannot overflow. | 265 ASSERT(String::kMaxLength < 0x7fffffff - 6); // Cannot overflow. |
| 269 if (escaped_length > String::kMaxLength) break; // Provoke exception. | 266 if (escaped_length > String::kMaxLength) { |
| 267 AllowHeapAllocation allocate_error_and_return; |
| 268 isolate->ThrowInvalidStringLength(); |
| 269 return Handle<String>::null(); |
| 270 } |
| 270 } | 271 } |
| 271 } | 272 } |
| 272 | 273 |
| 273 // No length change implies no change. Return original string if no change. | 274 // No length change implies no change. Return original string if no change. |
| 274 if (escaped_length == length) return string; | 275 if (escaped_length == length) return string; |
| 275 | 276 |
| 276 Handle<SeqOneByteString> dest = | 277 Handle<SeqOneByteString> dest = |
| 277 isolate->factory()->NewRawOneByteString(escaped_length); | 278 isolate->factory()->NewRawOneByteString(escaped_length); |
| 278 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, dest, Handle<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 Loading... |
| 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_ |
| OLD | NEW |