Index: src/uri.js |
diff --git a/src/uri.js b/src/uri.js |
index 40f8147122012342e1bdaa4d5fc76d71a6d42114..4566a7cc96338e79c5c2c359b8e891964f17486d 100644 |
--- a/src/uri.js |
+++ b/src/uri.js |
@@ -164,11 +164,12 @@ function URIDecodeOctets(octets, result, index) { |
// ECMA-262, section 15.1.3 |
function Encode(uri, unescape) { |
+ uri = TO_STRING_INLINE(uri); |
arv (Not doing code reviews)
2015/06/22 21:45:35
The spec calls this as a first step. This is good
|
var uriLength = uri.length; |
var array = new InternalArray(uriLength); |
var index = 0; |
for (var k = 0; k < uriLength; k++) { |
- var cc1 = uri.charCodeAt(k); |
+ var cc1 = %_StringCharCodeAt(uri, k); |
if (unescape(cc1)) { |
array[index++] = cc1; |
} else { |
@@ -178,7 +179,7 @@ function Encode(uri, unescape) { |
} else { |
k++; |
if (k == uriLength) throw MakeURIError(); |
- var cc2 = uri.charCodeAt(k); |
+ var cc2 = %_StringCharCodeAt(uri, k); |
if (cc2 < 0xDC00 || cc2 > 0xDFFF) throw MakeURIError(); |
index = URIEncodePair(cc1, cc2, array, index); |
} |
@@ -194,6 +195,7 @@ function Encode(uri, unescape) { |
// ECMA-262, section 15.1.3 |
function Decode(uri, reserved) { |
+ uri = TO_STRING_INLINE(uri); |
var uriLength = uri.length; |
var one_byte = %NewString(uriLength, NEW_ONE_BYTE_STRING); |
var index = 0; |
@@ -201,15 +203,18 @@ function Decode(uri, reserved) { |
// Optimistically assume one-byte string. |
for ( ; k < uriLength; k++) { |
- var code = uri.charCodeAt(k); |
+ var code = %_StringCharCodeAt(uri, k); |
if (code == 37) { // '%' |
if (k + 2 >= uriLength) throw MakeURIError(); |
- var cc = URIHexCharsToCharCode(uri.charCodeAt(k+1), uri.charCodeAt(k+2)); |
+ var cc = URIHexCharsToCharCode(%_StringCharCodeAt(uri, k+1), |
+ %_StringCharCodeAt(uri, k+2)); |
if (cc >> 7) break; // Assumption wrong, two-byte string. |
if (reserved(cc)) { |
%_OneByteSeqStringSetChar(index++, 37, one_byte); // '%'. |
- %_OneByteSeqStringSetChar(index++, uri.charCodeAt(k+1), one_byte); |
- %_OneByteSeqStringSetChar(index++, uri.charCodeAt(k+2), one_byte); |
+ %_OneByteSeqStringSetChar(index++, %_StringCharCodeAt(uri, k+1), |
+ one_byte); |
+ %_OneByteSeqStringSetChar(index++, %_StringCharCodeAt(uri, k+2), |
+ one_byte); |
} else { |
%_OneByteSeqStringSetChar(index++, cc, one_byte); |
} |
@@ -228,10 +233,11 @@ function Decode(uri, reserved) { |
index = 0; |
for ( ; k < uriLength; k++) { |
- var code = uri.charCodeAt(k); |
+ var code = %_StringCharCodeAt(uri, k); |
if (code == 37) { // '%' |
if (k + 2 >= uriLength) throw MakeURIError(); |
- var cc = URIHexCharsToCharCode(uri.charCodeAt(++k), uri.charCodeAt(++k)); |
+ var cc = URIHexCharsToCharCode(%_StringCharCodeAt(uri, ++k), |
+ %_StringCharCodeAt(uri, ++k)); |
if (cc >> 7) { |
var n = 0; |
while (((cc << ++n) & 0x80) != 0) { } |
@@ -240,15 +246,17 @@ function Decode(uri, reserved) { |
octets[0] = cc; |
if (k + 3 * (n - 1) >= uriLength) throw MakeURIError(); |
for (var i = 1; i < n; i++) { |
- if (uri.charAt(++k) != '%') throw MakeURIError(); |
- octets[i] = URIHexCharsToCharCode(uri.charCodeAt(++k), |
- uri.charCodeAt(++k)); |
+ if (uri[++k] != '%') throw MakeURIError(); |
+ octets[i] = URIHexCharsToCharCode(%_StringCharCodeAt(uri, ++k), |
+ %_StringCharCodeAt(uri, ++k)); |
} |
index = URIDecodeOctets(octets, two_byte, index); |
} else if (reserved(cc)) { |
%_TwoByteSeqStringSetChar(index++, 37, two_byte); // '%'. |
- %_TwoByteSeqStringSetChar(index++, uri.charCodeAt(k - 1), two_byte); |
- %_TwoByteSeqStringSetChar(index++, uri.charCodeAt(k), two_byte); |
+ %_TwoByteSeqStringSetChar(index++, %_StringCharCodeAt(uri, k - 1), |
+ two_byte); |
+ %_TwoByteSeqStringSetChar(index++, %_StringCharCodeAt(uri, k), |
+ two_byte); |
} else { |
%_TwoByteSeqStringSetChar(index++, cc, two_byte); |
} |