Chromium Code Reviews| 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 // 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 | 83 |
| 84 function URIHexCharsToCharCode(ch1, ch2) { | 84 function URIHexCharsToCharCode(ch1, ch2) { |
| 85 if (HexValueOf(ch1) == -1 || HexValueOf(ch2) == -1) { | 85 if (HexValueOf(ch1) == -1 || HexValueOf(ch2) == -1) { |
| 86 throw new $URIError("URI malformed"); | 86 throw new $URIError("URI malformed"); |
| 87 } | 87 } |
| 88 return HexStrToCharCode(ch1 + ch2); | 88 return HexStrToCharCode(ch1 + ch2); |
| 89 } | 89 } |
| 90 | 90 |
| 91 | 91 |
| 92 function URIDecodeOctets(octets, result, index) { | 92 function URIDecodeOctets(octets, result, index) { |
| 93 if (octets[3]) { | 93 var value; |
|
Lasse Reichstein
2009/03/10 07:25:03
How about assigning octets[0], octets[1] and octet
Christian Plesner Hansen
2009/03/10 07:46:52
You only know if octets[2] exists when you've insp
| |
| 94 var x = (octets[2] >> 4) & 3; | 94 if (octets[0] < 0x80) { |
| 95 var y = octets[2] & 0xF; | 95 value = octets[0]; |
| 96 var z = octets[3] & 63; | 96 } else if (octets[0] < 0xc2) { |
| 97 var v = (((octets[0] & 7) << 2) | ((octets[1] >> 4) & 3)) - 1; | 97 throw new $URIError("URI malformed"); |
| 98 var w = octets[1] & 0xF; | 98 } else if (octets[0] < 0xe0) { |
| 99 result[index++] = 55296 | (v << 6) | (w << 2) | x; | 99 var a = octets[0] & 0x1f; |
| 100 result[index++] = 56320 | (y << 6) | z; | 100 if ((octets[1] < 0x80) || (octets[1] > 0xbf)) |
| 101 throw new $URIError("URI malformed"); | |
| 102 var b = octets[1] & 0x3f; | |
| 103 value = (a << 6) + b; | |
| 104 if (value < 0x80 || value > 0x7ff) | |
| 105 throw new $URIError("URI malformed"); | |
| 106 } else if (octets[0] < 0xf0) { | |
| 107 var a = octets[0] & 0x0f; | |
| 108 if ((octets[1] < 0x80) || (octets[1] > 0xbf)) | |
| 109 throw new $URIError("URI malformed"); | |
| 110 var b = octets[1] & 0x3f; | |
| 111 if ((octets[2] < 0x80) || (octets[2] > 0xbf)) | |
| 112 throw new $URIError("URI malformed"); | |
| 113 var c = octets[2] & 0x3f; | |
| 114 value = (a << 12) + (b << 6) + c; | |
| 115 if ((value < 0x800) || (value > 0xffff)) | |
| 116 throw new $URIError("URI malformed"); | |
| 117 } else if (octets[0] < 0xf8) { | |
| 118 var a = (octets[0] & 0x07); | |
| 119 if ((octets[1] < 0x80) || (octets[1] > 0xbf)) | |
| 120 throw new $URIError("URI malformed"); | |
| 121 var b = (octets[1] & 0x3f); | |
| 122 if ((octets[2] < 0x80) || (octets[2] > 0xbf)) | |
| 123 throw new $URIError("URI malformed"); | |
| 124 var c = (octets[2] & 0x3f); | |
| 125 if ((octets[3] < 0x80) || (octets[3] > 0xbf)) | |
| 126 throw new $URIError("URI malformed"); | |
| 127 var d = (octets[3] & 0x3f); | |
| 128 value = (a << 18) + (b << 12) + (c << 6) + d; | |
| 129 if ((value < 0x10000) || (value > 0x10ffff)) | |
| 130 throw new $URIError("URI malformed"); | |
| 131 } else { | |
| 132 throw new $URIError("URI malformed"); | |
| 133 } | |
| 134 if (value < 0x10000) { | |
| 135 result[index++] = value; | |
| 136 return index; | |
| 137 } else { | |
| 138 result[index++] = (value >> 10) + 0xd7c0; | |
| 139 result[index++] = (value & 0x3ff) + 0xdc00; | |
| 101 return index; | 140 return index; |
| 102 } | 141 } |
| 103 if (octets[2]) { | |
| 104 var x = octets[0] & 0xF; | |
| 105 var y = octets[1] & 63; | |
| 106 var z = octets[2] & 63; | |
| 107 result[index++] = (x << 12) | (y << 6) | z; | |
| 108 return index; | |
| 109 } | |
| 110 var z = octets[1] & 63; | |
| 111 var y = octets[0] & 31; | |
| 112 result[index++] = (y << 6) | z; | |
| 113 return index; | |
| 114 } | 142 } |
| 115 | 143 |
| 116 | 144 |
| 117 // ECMA-262, section 15.1.3 | 145 // ECMA-262, section 15.1.3 |
| 118 function Encode(uri, unescape) { | 146 function Encode(uri, unescape) { |
| 119 var uriLength = uri.length; | 147 var uriLength = uri.length; |
| 120 var result = new $Array(uriLength); | 148 var result = new $Array(uriLength); |
| 121 var index = 0; | 149 var index = 0; |
| 122 for (var k = 0; k < uriLength; k++) { | 150 for (var k = 0; k < uriLength; k++) { |
| 123 var cc1 = uri.charCodeAt(k); | 151 var cc1 = uri.charCodeAt(k); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 "unescape", URIUnescape, | 390 "unescape", URIUnescape, |
| 363 "decodeURI", URIDecode, | 391 "decodeURI", URIDecode, |
| 364 "decodeURIComponent", URIDecodeComponent, | 392 "decodeURIComponent", URIDecodeComponent, |
| 365 "encodeURI", URIEncode, | 393 "encodeURI", URIEncode, |
| 366 "encodeURIComponent", URIEncodeComponent | 394 "encodeURIComponent", URIEncodeComponent |
| 367 )); | 395 )); |
| 368 } | 396 } |
| 369 | 397 |
| 370 SetupURI(); | 398 SetupURI(); |
| 371 | 399 |
| OLD | NEW |