OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 "use strict"; | 5 "use strict"; |
6 | 6 |
7 // This file relies on the fact that the following declaration has been made | 7 // This file relies on the fact that the following declaration has been made |
8 // in runtime.js: | 8 // in runtime.js: |
9 // var $Array = global.Array; | 9 // var $Array = global.Array; |
10 | 10 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 return result; | 210 return result; |
211 } | 211 } |
212 | 212 |
213 // ECMA-262, section 15.1.3 | 213 // ECMA-262, section 15.1.3 |
214 function Decode(uri, reserved) { | 214 function Decode(uri, reserved) { |
215 var uriLength = uri.length; | 215 var uriLength = uri.length; |
216 var one_byte = %NewString(uriLength, NEW_ONE_BYTE_STRING); | 216 var one_byte = %NewString(uriLength, NEW_ONE_BYTE_STRING); |
217 var index = 0; | 217 var index = 0; |
218 var k = 0; | 218 var k = 0; |
219 | 219 |
220 // Optimistically assume ascii string. | 220 // Optimistically assume one-byte string. |
221 for ( ; k < uriLength; k++) { | 221 for ( ; k < uriLength; k++) { |
222 var code = uri.charCodeAt(k); | 222 var code = uri.charCodeAt(k); |
223 if (code == 37) { // '%' | 223 if (code == 37) { // '%' |
224 if (k + 2 >= uriLength) throw new $URIError("URI malformed"); | 224 if (k + 2 >= uriLength) throw new $URIError("URI malformed"); |
225 var cc = URIHexCharsToCharCode(uri.charCodeAt(k+1), uri.charCodeAt(k+2))
; | 225 var cc = URIHexCharsToCharCode(uri.charCodeAt(k+1), uri.charCodeAt(k+2))
; |
226 if (cc >> 7) break; // Assumption wrong, two byte string. | 226 if (cc >> 7) break; // Assumption wrong, two-byte string. |
227 if (reserved(cc)) { | 227 if (reserved(cc)) { |
228 %_OneByteSeqStringSetChar(one_byte, index++, 37); // '%'. | 228 %_OneByteSeqStringSetChar(one_byte, index++, 37); // '%'. |
229 %_OneByteSeqStringSetChar(one_byte, index++, uri.charCodeAt(k+1)); | 229 %_OneByteSeqStringSetChar(one_byte, index++, uri.charCodeAt(k+1)); |
230 %_OneByteSeqStringSetChar(one_byte, index++, uri.charCodeAt(k+2)); | 230 %_OneByteSeqStringSetChar(one_byte, index++, uri.charCodeAt(k+2)); |
231 } else { | 231 } else { |
232 %_OneByteSeqStringSetChar(one_byte, index++, cc); | 232 %_OneByteSeqStringSetChar(one_byte, index++, cc); |
233 } | 233 } |
234 k += 2; | 234 k += 2; |
235 } else { | 235 } else { |
236 if (code > 0x7f) break; // Assumption wrong, two byte string. | 236 if (code > 0x7f) break; // Assumption wrong, two-byte string. |
237 %_OneByteSeqStringSetChar(one_byte, index++, code); | 237 %_OneByteSeqStringSetChar(one_byte, index++, code); |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 one_byte = %TruncateString(one_byte, index); | 241 one_byte = %TruncateString(one_byte, index); |
242 if (k == uriLength) return one_byte; | 242 if (k == uriLength) return one_byte; |
243 | 243 |
244 // Write into two byte string. | 244 // Write into two byte string. |
245 var two_byte = %NewString(uriLength - k, NEW_TWO_BYTE_STRING); | 245 var two_byte = %NewString(uriLength - k, NEW_TWO_BYTE_STRING); |
246 index = 0; | 246 index = 0; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 InstallFunctions(global, DONT_ENUM, $Array( | 383 InstallFunctions(global, DONT_ENUM, $Array( |
384 "escape", URIEscapeJS, | 384 "escape", URIEscapeJS, |
385 "unescape", URIUnescapeJS, | 385 "unescape", URIUnescapeJS, |
386 "decodeURI", URIDecode, | 386 "decodeURI", URIDecode, |
387 "decodeURIComponent", URIDecodeComponent, | 387 "decodeURIComponent", URIDecodeComponent, |
388 "encodeURI", URIEncode, | 388 "encodeURI", URIEncode, |
389 "encodeURIComponent", URIEncodeComponent | 389 "encodeURIComponent", URIEncodeComponent |
390 )); | 390 )); |
391 | 391 |
392 })(); | 392 })(); |
OLD | NEW |