Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Unified Diff: src/uri.js

Issue 1204483003: Remove usage of S.p.charCodeAt from uri.js (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/uri.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « no previous file | test/mjsunit/uri.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698