Chromium Code Reviews| Index: src/uri.js |
| diff --git a/src/uri.js b/src/uri.js |
| index fb9742fa873d30ebccc7dae2560bdb89cc434ef8..a6b346f48d8dfd8b47c222bec8d60e2d636f4519 100644 |
| --- a/src/uri.js |
| +++ b/src/uri.js |
| @@ -83,16 +83,18 @@ function URIHexCharsToCharCode(highChar, lowChar) { |
| } |
| -function URIDecodeOctets(octets, result, index) { |
| - if (!IS_STRING(result)) throw new $URIError("Internal error"); |
| +// Users of this macro must ensure that OCTETS is an array and RESULT is a |
| +// sufficiently long two-byte sequential string. |
| +// INDEX will be modified as characters are added to RESULT. |
| +macro URI_DECODE_OCTETS(OCTETS, RESULT, INDEX) |
|
rossberg
2014/05/21 14:30:15
Let's at least add a comment that explains why thi
|
| var value; |
| - var o0 = octets[0]; |
| + var o0 = OCTETS[0]; |
| if (o0 < 0x80) { |
| value = o0; |
| } else if (o0 < 0xc2) { |
| throw new $URIError("URI malformed"); |
| } else { |
| - var o1 = octets[1]; |
| + var o1 = OCTETS[1]; |
| if (o0 < 0xe0) { |
| var a = o0 & 0x1f; |
| if ((o1 < 0x80) || (o1 > 0xbf)) { |
| @@ -104,7 +106,7 @@ function URIDecodeOctets(octets, result, index) { |
| throw new $URIError("URI malformed"); |
| } |
| } else { |
| - var o2 = octets[2]; |
| + var o2 = OCTETS[2]; |
| if (o0 < 0xf0) { |
| var a = o0 & 0x0f; |
| if ((o1 < 0x80) || (o1 > 0xbf)) { |
| @@ -120,7 +122,7 @@ function URIDecodeOctets(octets, result, index) { |
| throw new $URIError("URI malformed"); |
| } |
| } else { |
| - var o3 = octets[3]; |
| + var o3 = OCTETS[3]; |
| if (o0 < 0xf8) { |
| var a = (o0 & 0x07); |
| if ((o1 < 0x80) || (o1 > 0xbf)) { |
| @@ -149,20 +151,12 @@ function URIDecodeOctets(octets, result, index) { |
| throw new $URIError("URI malformed"); |
| } |
| if (value < 0x10000) { |
| - if (index < 0 || index >= result.length) { |
| - throw new $URIError("Internal error"); |
| - } |
| - %_TwoByteSeqStringSetChar(result, index++, value); |
| - return index; |
| + %_TwoByteSeqStringSetChar(RESULT, INDEX++, value); |
| } else { |
| - if (index < 0 || index >= result.length - 1) { |
| - throw new $URIError("Internal error"); |
| - } |
| - %_TwoByteSeqStringSetChar(result, index++, (value >> 10) + 0xd7c0); |
| - %_TwoByteSeqStringSetChar(result, index++, (value & 0x3ff) + 0xdc00); |
| - return index; |
| + %_TwoByteSeqStringSetChar(RESULT, INDEX++, (value >> 10) + 0xd7c0); |
| + %_TwoByteSeqStringSetChar(RESULT, INDEX++, (value & 0x3ff) + 0xdc00); |
| } |
| -} |
| +endmacro |
| // ECMA-262, section 15.1.3 |
| @@ -248,7 +242,7 @@ function Decode(uri, reserved) { |
| octets[i] = URIHexCharsToCharCode(uri.charCodeAt(++k), |
| uri.charCodeAt(++k)); |
| } |
| - index = URIDecodeOctets(octets, two_byte, index); |
| + URI_DECODE_OCTETS(octets, two_byte, index); |
| } else if (reserved(cc)) { |
| %_TwoByteSeqStringSetChar(two_byte, index++, 37); // '%'. |
| %_TwoByteSeqStringSetChar(two_byte, index++, uri.charCodeAt(k - 1)); |