| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef V8_URI_H_ | |
| 6 #define V8_URI_H_ | |
| 7 | |
| 8 #include "src/v8.h" | 5 #include "src/v8.h" |
| 9 | 6 |
| 7 #include "src/arguments.h" |
| 10 #include "src/conversions.h" | 8 #include "src/conversions.h" |
| 9 #include "src/runtime/runtime.h" |
| 10 #include "src/runtime/runtime-utils.h" |
| 11 #include "src/string-search.h" | 11 #include "src/string-search.h" |
| 12 #include "src/utils.h" | 12 #include "src/utils.h" |
| 13 | 13 |
| 14 |
| 14 namespace v8 { | 15 namespace v8 { |
| 15 namespace internal { | 16 namespace internal { |
| 16 | 17 |
| 17 | |
| 18 template <typename Char> | 18 template <typename Char> |
| 19 static INLINE(Vector<const Char> GetCharVector(Handle<String> string)); | 19 static INLINE(Vector<const Char> GetCharVector(Handle<String> string)); |
| 20 | 20 |
| 21 | 21 |
| 22 template <> | 22 template <> |
| 23 Vector<const uint8_t> GetCharVector(Handle<String> string) { | 23 Vector<const uint8_t> GetCharVector(Handle<String> string) { |
| 24 String::FlatContent flat = string->GetFlatContent(); | 24 String::FlatContent flat = string->GetFlatContent(); |
| 25 DCHECK(flat.IsOneByte()); | 25 DCHECK(flat.IsOneByte()); |
| 26 return flat.ToOneByteVector(); | 26 return flat.ToOneByteVector(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 | 29 |
| 30 template <> | 30 template <> |
| 31 Vector<const uc16> GetCharVector(Handle<String> string) { | 31 Vector<const uc16> GetCharVector(Handle<String> string) { |
| 32 String::FlatContent flat = string->GetFlatContent(); | 32 String::FlatContent flat = string->GetFlatContent(); |
| 33 DCHECK(flat.IsTwoByte()); | 33 DCHECK(flat.IsTwoByte()); |
| 34 return flat.ToUC16Vector(); | 34 return flat.ToUC16Vector(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 | 37 |
| 38 class URIUnescape : public AllStatic { | 38 class URIUnescape : public AllStatic { |
| 39 public: | 39 public: |
| 40 template<typename Char> | 40 template <typename Char> |
| 41 MUST_USE_RESULT static MaybeHandle<String> Unescape(Isolate* isolate, | 41 MUST_USE_RESULT static MaybeHandle<String> Unescape(Isolate* isolate, |
| 42 Handle<String> source); | 42 Handle<String> source); |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 static const signed char kHexValue['g']; | 45 static const signed char kHexValue['g']; |
| 46 | 46 |
| 47 template<typename Char> | 47 template <typename Char> |
| 48 MUST_USE_RESULT static MaybeHandle<String> UnescapeSlow( | 48 MUST_USE_RESULT static MaybeHandle<String> UnescapeSlow(Isolate* isolate, |
| 49 Isolate* isolate, Handle<String> string, int start_index); | 49 Handle<String> string, |
| 50 int start_index); |
| 50 | 51 |
| 51 static INLINE(int TwoDigitHex(uint16_t character1, uint16_t character2)); | 52 static INLINE(int TwoDigitHex(uint16_t character1, uint16_t character2)); |
| 52 | 53 |
| 53 template <typename Char> | 54 template <typename Char> |
| 54 static INLINE(int UnescapeChar(Vector<const Char> vector, | 55 static INLINE(int UnescapeChar(Vector<const Char> vector, int i, int length, |
| 55 int i, | |
| 56 int length, | |
| 57 int* step)); | 56 int* step)); |
| 58 }; | 57 }; |
| 59 | 58 |
| 60 | 59 |
| 61 const signed char URIUnescape::kHexValue[] = { | 60 const signed char URIUnescape::kHexValue[] = { |
| 62 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | 61 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 63 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | 62 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 64 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | 63 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -0, 1, 2, 3, 4, 5, |
| 65 -0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, | 64 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, |
| 66 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, | 65 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 67 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | 66 -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15}; |
| 68 -1, 10, 11, 12, 13, 14, 15 }; | |
| 69 | 67 |
| 70 | 68 |
| 71 template<typename Char> | 69 template <typename Char> |
| 72 MaybeHandle<String> URIUnescape::Unescape(Isolate* isolate, | 70 MaybeHandle<String> URIUnescape::Unescape(Isolate* isolate, |
| 73 Handle<String> source) { | 71 Handle<String> source) { |
| 74 int index; | 72 int index; |
| 75 { DisallowHeapAllocation no_allocation; | 73 { |
| 74 DisallowHeapAllocation no_allocation; |
| 76 StringSearch<uint8_t, Char> search(isolate, STATIC_CHAR_VECTOR("%")); | 75 StringSearch<uint8_t, Char> search(isolate, STATIC_CHAR_VECTOR("%")); |
| 77 index = search.Search(GetCharVector<Char>(source), 0); | 76 index = search.Search(GetCharVector<Char>(source), 0); |
| 78 if (index < 0) return source; | 77 if (index < 0) return source; |
| 79 } | 78 } |
| 80 return UnescapeSlow<Char>(isolate, source, index); | 79 return UnescapeSlow<Char>(isolate, source, index); |
| 81 } | 80 } |
| 82 | 81 |
| 83 | 82 |
| 84 template <typename Char> | 83 template <typename Char> |
| 85 MaybeHandle<String> URIUnescape::UnescapeSlow( | 84 MaybeHandle<String> URIUnescape::UnescapeSlow(Isolate* isolate, |
| 86 Isolate* isolate, Handle<String> string, int start_index) { | 85 Handle<String> string, |
| 86 int start_index) { |
| 87 bool one_byte = true; | 87 bool one_byte = true; |
| 88 int length = string->length(); | 88 int length = string->length(); |
| 89 | 89 |
| 90 int unescaped_length = 0; | 90 int unescaped_length = 0; |
| 91 { DisallowHeapAllocation no_allocation; | 91 { |
| 92 DisallowHeapAllocation no_allocation; |
| 92 Vector<const Char> vector = GetCharVector<Char>(string); | 93 Vector<const Char> vector = GetCharVector<Char>(string); |
| 93 for (int i = start_index; i < length; unescaped_length++) { | 94 for (int i = start_index; i < length; unescaped_length++) { |
| 94 int step; | 95 int step; |
| 95 if (UnescapeChar(vector, i, length, &step) > | 96 if (UnescapeChar(vector, i, length, &step) > |
| 96 String::kMaxOneByteCharCode) { | 97 String::kMaxOneByteCharCode) { |
| 97 one_byte = false; | 98 one_byte = false; |
| 98 } | 99 } |
| 99 i += step; | 100 i += step; |
| 100 } | 101 } |
| 101 } | 102 } |
| 102 | 103 |
| 103 DCHECK(start_index < length); | 104 DCHECK(start_index < length); |
| 104 Handle<String> first_part = | 105 Handle<String> first_part = |
| 105 isolate->factory()->NewProperSubString(string, 0, start_index); | 106 isolate->factory()->NewProperSubString(string, 0, start_index); |
| 106 | 107 |
| 107 int dest_position = 0; | 108 int dest_position = 0; |
| 108 Handle<String> second_part; | 109 Handle<String> second_part; |
| 109 DCHECK(unescaped_length <= String::kMaxLength); | 110 DCHECK(unescaped_length <= String::kMaxLength); |
| 110 if (one_byte) { | 111 if (one_byte) { |
| 111 Handle<SeqOneByteString> dest = isolate->factory()->NewRawOneByteString( | 112 Handle<SeqOneByteString> dest = isolate->factory() |
| 112 unescaped_length).ToHandleChecked(); | 113 ->NewRawOneByteString(unescaped_length) |
| 114 .ToHandleChecked(); |
| 113 DisallowHeapAllocation no_allocation; | 115 DisallowHeapAllocation no_allocation; |
| 114 Vector<const Char> vector = GetCharVector<Char>(string); | 116 Vector<const Char> vector = GetCharVector<Char>(string); |
| 115 for (int i = start_index; i < length; dest_position++) { | 117 for (int i = start_index; i < length; dest_position++) { |
| 116 int step; | 118 int step; |
| 117 dest->SeqOneByteStringSet(dest_position, | 119 dest->SeqOneByteStringSet(dest_position, |
| 118 UnescapeChar(vector, i, length, &step)); | 120 UnescapeChar(vector, i, length, &step)); |
| 119 i += step; | 121 i += step; |
| 120 } | 122 } |
| 121 second_part = dest; | 123 second_part = dest; |
| 122 } else { | 124 } else { |
| 123 Handle<SeqTwoByteString> dest = isolate->factory()->NewRawTwoByteString( | 125 Handle<SeqTwoByteString> dest = isolate->factory() |
| 124 unescaped_length).ToHandleChecked(); | 126 ->NewRawTwoByteString(unescaped_length) |
| 127 .ToHandleChecked(); |
| 125 DisallowHeapAllocation no_allocation; | 128 DisallowHeapAllocation no_allocation; |
| 126 Vector<const Char> vector = GetCharVector<Char>(string); | 129 Vector<const Char> vector = GetCharVector<Char>(string); |
| 127 for (int i = start_index; i < length; dest_position++) { | 130 for (int i = start_index; i < length; dest_position++) { |
| 128 int step; | 131 int step; |
| 129 dest->SeqTwoByteStringSet(dest_position, | 132 dest->SeqTwoByteStringSet(dest_position, |
| 130 UnescapeChar(vector, i, length, &step)); | 133 UnescapeChar(vector, i, length, &step)); |
| 131 i += step; | 134 i += step; |
| 132 } | 135 } |
| 133 second_part = dest; | 136 second_part = dest; |
| 134 } | 137 } |
| 135 return isolate->factory()->NewConsString(first_part, second_part); | 138 return isolate->factory()->NewConsString(first_part, second_part); |
| 136 } | 139 } |
| 137 | 140 |
| 138 | 141 |
| 139 int URIUnescape::TwoDigitHex(uint16_t character1, uint16_t character2) { | 142 int URIUnescape::TwoDigitHex(uint16_t character1, uint16_t character2) { |
| 140 if (character1 > 'f') return -1; | 143 if (character1 > 'f') return -1; |
| 141 int hi = kHexValue[character1]; | 144 int hi = kHexValue[character1]; |
| 142 if (hi == -1) return -1; | 145 if (hi == -1) return -1; |
| 143 if (character2 > 'f') return -1; | 146 if (character2 > 'f') return -1; |
| 144 int lo = kHexValue[character2]; | 147 int lo = kHexValue[character2]; |
| 145 if (lo == -1) return -1; | 148 if (lo == -1) return -1; |
| 146 return (hi << 4) + lo; | 149 return (hi << 4) + lo; |
| 147 } | 150 } |
| 148 | 151 |
| 149 | 152 |
| 150 template <typename Char> | 153 template <typename Char> |
| 151 int URIUnescape::UnescapeChar(Vector<const Char> vector, | 154 int URIUnescape::UnescapeChar(Vector<const Char> vector, int i, int length, |
| 152 int i, | |
| 153 int length, | |
| 154 int* step) { | 155 int* step) { |
| 155 uint16_t character = vector[i]; | 156 uint16_t character = vector[i]; |
| 156 int32_t hi = 0; | 157 int32_t hi = 0; |
| 157 int32_t lo = 0; | 158 int32_t lo = 0; |
| 158 if (character == '%' && | 159 if (character == '%' && i <= length - 6 && vector[i + 1] == 'u' && |
| 159 i <= length - 6 && | 160 (hi = TwoDigitHex(vector[i + 2], vector[i + 3])) != -1 && |
| 160 vector[i + 1] == 'u' && | 161 (lo = TwoDigitHex(vector[i + 4], vector[i + 5])) != -1) { |
| 161 (hi = TwoDigitHex(vector[i + 2], | |
| 162 vector[i + 3])) != -1 && | |
| 163 (lo = TwoDigitHex(vector[i + 4], | |
| 164 vector[i + 5])) != -1) { | |
| 165 *step = 6; | 162 *step = 6; |
| 166 return (hi << 8) + lo; | 163 return (hi << 8) + lo; |
| 167 } else if (character == '%' && | 164 } else if (character == '%' && i <= length - 3 && |
| 168 i <= length - 3 && | 165 (lo = TwoDigitHex(vector[i + 1], vector[i + 2])) != -1) { |
| 169 (lo = TwoDigitHex(vector[i + 1], | |
| 170 vector[i + 2])) != -1) { | |
| 171 *step = 3; | 166 *step = 3; |
| 172 return lo; | 167 return lo; |
| 173 } else { | 168 } else { |
| 174 *step = 1; | 169 *step = 1; |
| 175 return character; | 170 return character; |
| 176 } | 171 } |
| 177 } | 172 } |
| 178 | 173 |
| 179 | 174 |
| 180 class URIEscape : public AllStatic { | 175 class URIEscape : public AllStatic { |
| 181 public: | 176 public: |
| 182 template<typename Char> | 177 template <typename Char> |
| 183 MUST_USE_RESULT static MaybeHandle<String> Escape(Isolate* isolate, | 178 MUST_USE_RESULT static MaybeHandle<String> Escape(Isolate* isolate, |
| 184 Handle<String> string); | 179 Handle<String> string); |
| 185 | 180 |
| 186 private: | 181 private: |
| 187 static const char kHexChars[17]; | 182 static const char kHexChars[17]; |
| 188 static const char kNotEscaped[256]; | 183 static const char kNotEscaped[256]; |
| 189 | 184 |
| 190 static bool IsNotEscaped(uint16_t c) { return kNotEscaped[c] != 0; } | 185 static bool IsNotEscaped(uint16_t c) { return kNotEscaped[c] != 0; } |
| 191 }; | 186 }; |
| 192 | 187 |
| 193 | 188 |
| 194 const char URIEscape::kHexChars[] = "0123456789ABCDEF"; | 189 const char URIEscape::kHexChars[] = "0123456789ABCDEF"; |
| 195 | 190 |
| 196 | 191 |
| 197 // kNotEscaped is generated by the following: | 192 // kNotEscaped is generated by the following: |
| 198 // | 193 // |
| 199 // #!/bin/perl | 194 // #!/bin/perl |
| 200 // for (my $i = 0; $i < 256; $i++) { | 195 // for (my $i = 0; $i < 256; $i++) { |
| 201 // print "\n" if $i % 16 == 0; | 196 // print "\n" if $i % 16 == 0; |
| 202 // my $c = chr($i); | 197 // my $c = chr($i); |
| 203 // my $escaped = 1; | 198 // my $escaped = 1; |
| 204 // $escaped = 0 if $c =~ m#[A-Za-z0-9@*_+./-]#; | 199 // $escaped = 0 if $c =~ m#[A-Za-z0-9@*_+./-]#; |
| 205 // print $escaped ? "0, " : "1, "; | 200 // print $escaped ? "0, " : "1, "; |
| 206 // } | 201 // } |
| 207 | 202 |
| 208 const char URIEscape::kNotEscaped[] = { | 203 const char URIEscape::kNotEscaped[] = { |
| 209 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 204 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 210 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 205 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, |
| 211 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, | 206 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, |
| 212 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, | 207 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, |
| 213 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | 208 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 214 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, | 209 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 215 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | 210 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 216 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, | 211 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 217 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 212 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 218 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 213 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 219 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 214 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 220 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 221 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 222 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 223 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 224 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | |
| 225 | 215 |
| 226 | 216 |
| 227 template<typename Char> | 217 template <typename Char> |
| 228 MaybeHandle<String> URIEscape::Escape(Isolate* isolate, Handle<String> string) { | 218 MaybeHandle<String> URIEscape::Escape(Isolate* isolate, Handle<String> string) { |
| 229 DCHECK(string->IsFlat()); | 219 DCHECK(string->IsFlat()); |
| 230 int escaped_length = 0; | 220 int escaped_length = 0; |
| 231 int length = string->length(); | 221 int length = string->length(); |
| 232 | 222 |
| 233 { DisallowHeapAllocation no_allocation; | 223 { |
| 224 DisallowHeapAllocation no_allocation; |
| 234 Vector<const Char> vector = GetCharVector<Char>(string); | 225 Vector<const Char> vector = GetCharVector<Char>(string); |
| 235 for (int i = 0; i < length; i++) { | 226 for (int i = 0; i < length; i++) { |
| 236 uint16_t c = vector[i]; | 227 uint16_t c = vector[i]; |
| 237 if (c >= 256) { | 228 if (c >= 256) { |
| 238 escaped_length += 6; | 229 escaped_length += 6; |
| 239 } else if (IsNotEscaped(c)) { | 230 } else if (IsNotEscaped(c)) { |
| 240 escaped_length++; | 231 escaped_length++; |
| 241 } else { | 232 } else { |
| 242 escaped_length += 3; | 233 escaped_length += 3; |
| 243 } | 234 } |
| 244 | 235 |
| 245 // We don't allow strings that are longer than a maximal length. | 236 // We don't allow strings that are longer than a maximal length. |
| 246 DCHECK(String::kMaxLength < 0x7fffffff - 6); // Cannot overflow. | 237 DCHECK(String::kMaxLength < 0x7fffffff - 6); // Cannot overflow. |
| 247 if (escaped_length > String::kMaxLength) break; // Provoke exception. | 238 if (escaped_length > String::kMaxLength) break; // Provoke exception. |
| 248 } | 239 } |
| 249 } | 240 } |
| 250 | 241 |
| 251 // No length change implies no change. Return original string if no change. | 242 // No length change implies no change. Return original string if no change. |
| 252 if (escaped_length == length) return string; | 243 if (escaped_length == length) return string; |
| 253 | 244 |
| 254 Handle<SeqOneByteString> dest; | 245 Handle<SeqOneByteString> dest; |
| 255 ASSIGN_RETURN_ON_EXCEPTION( | 246 ASSIGN_RETURN_ON_EXCEPTION( |
| 256 isolate, dest, | 247 isolate, dest, isolate->factory()->NewRawOneByteString(escaped_length), |
| 257 isolate->factory()->NewRawOneByteString(escaped_length), | |
| 258 String); | 248 String); |
| 259 int dest_position = 0; | 249 int dest_position = 0; |
| 260 | 250 |
| 261 { DisallowHeapAllocation no_allocation; | 251 { |
| 252 DisallowHeapAllocation no_allocation; |
| 262 Vector<const Char> vector = GetCharVector<Char>(string); | 253 Vector<const Char> vector = GetCharVector<Char>(string); |
| 263 for (int i = 0; i < length; i++) { | 254 for (int i = 0; i < length; i++) { |
| 264 uint16_t c = vector[i]; | 255 uint16_t c = vector[i]; |
| 265 if (c >= 256) { | 256 if (c >= 256) { |
| 266 dest->SeqOneByteStringSet(dest_position, '%'); | 257 dest->SeqOneByteStringSet(dest_position, '%'); |
| 267 dest->SeqOneByteStringSet(dest_position+1, 'u'); | 258 dest->SeqOneByteStringSet(dest_position + 1, 'u'); |
| 268 dest->SeqOneByteStringSet(dest_position+2, kHexChars[c >> 12]); | 259 dest->SeqOneByteStringSet(dest_position + 2, kHexChars[c >> 12]); |
| 269 dest->SeqOneByteStringSet(dest_position+3, kHexChars[(c >> 8) & 0xf]); | 260 dest->SeqOneByteStringSet(dest_position + 3, kHexChars[(c >> 8) & 0xf]); |
| 270 dest->SeqOneByteStringSet(dest_position+4, kHexChars[(c >> 4) & 0xf]); | 261 dest->SeqOneByteStringSet(dest_position + 4, kHexChars[(c >> 4) & 0xf]); |
| 271 dest->SeqOneByteStringSet(dest_position+5, kHexChars[c & 0xf]); | 262 dest->SeqOneByteStringSet(dest_position + 5, kHexChars[c & 0xf]); |
| 272 dest_position += 6; | 263 dest_position += 6; |
| 273 } else if (IsNotEscaped(c)) { | 264 } else if (IsNotEscaped(c)) { |
| 274 dest->SeqOneByteStringSet(dest_position, c); | 265 dest->SeqOneByteStringSet(dest_position, c); |
| 275 dest_position++; | 266 dest_position++; |
| 276 } else { | 267 } else { |
| 277 dest->SeqOneByteStringSet(dest_position, '%'); | 268 dest->SeqOneByteStringSet(dest_position, '%'); |
| 278 dest->SeqOneByteStringSet(dest_position+1, kHexChars[c >> 4]); | 269 dest->SeqOneByteStringSet(dest_position + 1, kHexChars[c >> 4]); |
| 279 dest->SeqOneByteStringSet(dest_position+2, kHexChars[c & 0xf]); | 270 dest->SeqOneByteStringSet(dest_position + 2, kHexChars[c & 0xf]); |
| 280 dest_position += 3; | 271 dest_position += 3; |
| 281 } | 272 } |
| 282 } | 273 } |
| 283 } | 274 } |
| 284 | 275 |
| 285 return dest; | 276 return dest; |
| 286 } | 277 } |
| 287 | 278 |
| 288 } } // namespace v8::internal | |
| 289 | 279 |
| 290 #endif // V8_URI_H_ | 280 RUNTIME_FUNCTION(Runtime_URIEscape) { |
| 281 HandleScope scope(isolate); |
| 282 DCHECK(args.length() == 1); |
| 283 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); |
| 284 Handle<String> string = String::Flatten(source); |
| 285 DCHECK(string->IsFlat()); |
| 286 Handle<String> result; |
| 287 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 288 isolate, result, string->IsOneByteRepresentationUnderneath() |
| 289 ? URIEscape::Escape<uint8_t>(isolate, source) |
| 290 : URIEscape::Escape<uc16>(isolate, source)); |
| 291 return *result; |
| 292 } |
| 293 |
| 294 |
| 295 RUNTIME_FUNCTION(Runtime_URIUnescape) { |
| 296 HandleScope scope(isolate); |
| 297 DCHECK(args.length() == 1); |
| 298 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); |
| 299 Handle<String> string = String::Flatten(source); |
| 300 DCHECK(string->IsFlat()); |
| 301 Handle<String> result; |
| 302 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 303 isolate, result, string->IsOneByteRepresentationUnderneath() |
| 304 ? URIUnescape::Unescape<uint8_t>(isolate, source) |
| 305 : URIUnescape::Unescape<uc16>(isolate, source)); |
| 306 return *result; |
| 307 } |
| 308 } |
| 309 } // namespace v8::internal |
| OLD | NEW |