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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/uri.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // This file contains support for URI manipulations written in 5 // This file contains support for URI manipulations written in
6 // JavaScript. 6 // JavaScript.
7 7
8 (function(global, utils) { 8 (function(global, utils) {
9 9
10 "use strict"; 10 "use strict";
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 %_TwoByteSeqStringSetChar(index++, value, result); 157 %_TwoByteSeqStringSetChar(index++, value, result);
158 } else { 158 } else {
159 %_TwoByteSeqStringSetChar(index++, (value >> 10) + 0xd7c0, result); 159 %_TwoByteSeqStringSetChar(index++, (value >> 10) + 0xd7c0, result);
160 %_TwoByteSeqStringSetChar(index++, (value & 0x3ff) + 0xdc00, result); 160 %_TwoByteSeqStringSetChar(index++, (value & 0x3ff) + 0xdc00, result);
161 } 161 }
162 return index; 162 return index;
163 } 163 }
164 164
165 // ECMA-262, section 15.1.3 165 // ECMA-262, section 15.1.3
166 function Encode(uri, unescape) { 166 function Encode(uri, unescape) {
167 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
167 var uriLength = uri.length; 168 var uriLength = uri.length;
168 var array = new InternalArray(uriLength); 169 var array = new InternalArray(uriLength);
169 var index = 0; 170 var index = 0;
170 for (var k = 0; k < uriLength; k++) { 171 for (var k = 0; k < uriLength; k++) {
171 var cc1 = uri.charCodeAt(k); 172 var cc1 = %_StringCharCodeAt(uri, k);
172 if (unescape(cc1)) { 173 if (unescape(cc1)) {
173 array[index++] = cc1; 174 array[index++] = cc1;
174 } else { 175 } else {
175 if (cc1 >= 0xDC00 && cc1 <= 0xDFFF) throw MakeURIError(); 176 if (cc1 >= 0xDC00 && cc1 <= 0xDFFF) throw MakeURIError();
176 if (cc1 < 0xD800 || cc1 > 0xDBFF) { 177 if (cc1 < 0xD800 || cc1 > 0xDBFF) {
177 index = URIEncodeSingle(cc1, array, index); 178 index = URIEncodeSingle(cc1, array, index);
178 } else { 179 } else {
179 k++; 180 k++;
180 if (k == uriLength) throw MakeURIError(); 181 if (k == uriLength) throw MakeURIError();
181 var cc2 = uri.charCodeAt(k); 182 var cc2 = %_StringCharCodeAt(uri, k);
182 if (cc2 < 0xDC00 || cc2 > 0xDFFF) throw MakeURIError(); 183 if (cc2 < 0xDC00 || cc2 > 0xDFFF) throw MakeURIError();
183 index = URIEncodePair(cc1, cc2, array, index); 184 index = URIEncodePair(cc1, cc2, array, index);
184 } 185 }
185 } 186 }
186 } 187 }
187 188
188 var result = %NewString(array.length, NEW_ONE_BYTE_STRING); 189 var result = %NewString(array.length, NEW_ONE_BYTE_STRING);
189 for (var i = 0; i < array.length; i++) { 190 for (var i = 0; i < array.length; i++) {
190 %_OneByteSeqStringSetChar(i, array[i], result); 191 %_OneByteSeqStringSetChar(i, array[i], result);
191 } 192 }
192 return result; 193 return result;
193 } 194 }
194 195
195 // ECMA-262, section 15.1.3 196 // ECMA-262, section 15.1.3
196 function Decode(uri, reserved) { 197 function Decode(uri, reserved) {
198 uri = TO_STRING_INLINE(uri);
197 var uriLength = uri.length; 199 var uriLength = uri.length;
198 var one_byte = %NewString(uriLength, NEW_ONE_BYTE_STRING); 200 var one_byte = %NewString(uriLength, NEW_ONE_BYTE_STRING);
199 var index = 0; 201 var index = 0;
200 var k = 0; 202 var k = 0;
201 203
202 // Optimistically assume one-byte string. 204 // Optimistically assume one-byte string.
203 for ( ; k < uriLength; k++) { 205 for ( ; k < uriLength; k++) {
204 var code = uri.charCodeAt(k); 206 var code = %_StringCharCodeAt(uri, k);
205 if (code == 37) { // '%' 207 if (code == 37) { // '%'
206 if (k + 2 >= uriLength) throw MakeURIError(); 208 if (k + 2 >= uriLength) throw MakeURIError();
207 var cc = URIHexCharsToCharCode(uri.charCodeAt(k+1), uri.charCodeAt(k+2)); 209 var cc = URIHexCharsToCharCode(%_StringCharCodeAt(uri, k+1),
210 %_StringCharCodeAt(uri, k+2));
208 if (cc >> 7) break; // Assumption wrong, two-byte string. 211 if (cc >> 7) break; // Assumption wrong, two-byte string.
209 if (reserved(cc)) { 212 if (reserved(cc)) {
210 %_OneByteSeqStringSetChar(index++, 37, one_byte); // '%'. 213 %_OneByteSeqStringSetChar(index++, 37, one_byte); // '%'.
211 %_OneByteSeqStringSetChar(index++, uri.charCodeAt(k+1), one_byte); 214 %_OneByteSeqStringSetChar(index++, %_StringCharCodeAt(uri, k+1),
212 %_OneByteSeqStringSetChar(index++, uri.charCodeAt(k+2), one_byte); 215 one_byte);
216 %_OneByteSeqStringSetChar(index++, %_StringCharCodeAt(uri, k+2),
217 one_byte);
213 } else { 218 } else {
214 %_OneByteSeqStringSetChar(index++, cc, one_byte); 219 %_OneByteSeqStringSetChar(index++, cc, one_byte);
215 } 220 }
216 k += 2; 221 k += 2;
217 } else { 222 } else {
218 if (code > 0x7f) break; // Assumption wrong, two-byte string. 223 if (code > 0x7f) break; // Assumption wrong, two-byte string.
219 %_OneByteSeqStringSetChar(index++, code, one_byte); 224 %_OneByteSeqStringSetChar(index++, code, one_byte);
220 } 225 }
221 } 226 }
222 227
223 one_byte = %TruncateString(one_byte, index); 228 one_byte = %TruncateString(one_byte, index);
224 if (k == uriLength) return one_byte; 229 if (k == uriLength) return one_byte;
225 230
226 // Write into two byte string. 231 // Write into two byte string.
227 var two_byte = %NewString(uriLength - k, NEW_TWO_BYTE_STRING); 232 var two_byte = %NewString(uriLength - k, NEW_TWO_BYTE_STRING);
228 index = 0; 233 index = 0;
229 234
230 for ( ; k < uriLength; k++) { 235 for ( ; k < uriLength; k++) {
231 var code = uri.charCodeAt(k); 236 var code = %_StringCharCodeAt(uri, k);
232 if (code == 37) { // '%' 237 if (code == 37) { // '%'
233 if (k + 2 >= uriLength) throw MakeURIError(); 238 if (k + 2 >= uriLength) throw MakeURIError();
234 var cc = URIHexCharsToCharCode(uri.charCodeAt(++k), uri.charCodeAt(++k)); 239 var cc = URIHexCharsToCharCode(%_StringCharCodeAt(uri, ++k),
240 %_StringCharCodeAt(uri, ++k));
235 if (cc >> 7) { 241 if (cc >> 7) {
236 var n = 0; 242 var n = 0;
237 while (((cc << ++n) & 0x80) != 0) { } 243 while (((cc << ++n) & 0x80) != 0) { }
238 if (n == 1 || n > 4) throw MakeURIError(); 244 if (n == 1 || n > 4) throw MakeURIError();
239 var octets = new GlobalArray(n); 245 var octets = new GlobalArray(n);
240 octets[0] = cc; 246 octets[0] = cc;
241 if (k + 3 * (n - 1) >= uriLength) throw MakeURIError(); 247 if (k + 3 * (n - 1) >= uriLength) throw MakeURIError();
242 for (var i = 1; i < n; i++) { 248 for (var i = 1; i < n; i++) {
243 if (uri.charAt(++k) != '%') throw MakeURIError(); 249 if (uri[++k] != '%') throw MakeURIError();
244 octets[i] = URIHexCharsToCharCode(uri.charCodeAt(++k), 250 octets[i] = URIHexCharsToCharCode(%_StringCharCodeAt(uri, ++k),
245 uri.charCodeAt(++k)); 251 %_StringCharCodeAt(uri, ++k));
246 } 252 }
247 index = URIDecodeOctets(octets, two_byte, index); 253 index = URIDecodeOctets(octets, two_byte, index);
248 } else if (reserved(cc)) { 254 } else if (reserved(cc)) {
249 %_TwoByteSeqStringSetChar(index++, 37, two_byte); // '%'. 255 %_TwoByteSeqStringSetChar(index++, 37, two_byte); // '%'.
250 %_TwoByteSeqStringSetChar(index++, uri.charCodeAt(k - 1), two_byte); 256 %_TwoByteSeqStringSetChar(index++, %_StringCharCodeAt(uri, k - 1),
251 %_TwoByteSeqStringSetChar(index++, uri.charCodeAt(k), two_byte); 257 two_byte);
258 %_TwoByteSeqStringSetChar(index++, %_StringCharCodeAt(uri, k),
259 two_byte);
252 } else { 260 } else {
253 %_TwoByteSeqStringSetChar(index++, cc, two_byte); 261 %_TwoByteSeqStringSetChar(index++, cc, two_byte);
254 } 262 }
255 } else { 263 } else {
256 %_TwoByteSeqStringSetChar(index++, code, two_byte); 264 %_TwoByteSeqStringSetChar(index++, code, two_byte);
257 } 265 }
258 } 266 }
259 267
260 two_byte = %TruncateString(two_byte, index); 268 two_byte = %TruncateString(two_byte, index);
261 return one_byte + two_byte; 269 return one_byte + two_byte;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 utils.InstallFunctions(global, DONT_ENUM, [ 371 utils.InstallFunctions(global, DONT_ENUM, [
364 "escape", URIEscapeJS, 372 "escape", URIEscapeJS,
365 "unescape", URIUnescapeJS, 373 "unescape", URIUnescapeJS,
366 "decodeURI", URIDecode, 374 "decodeURI", URIDecode,
367 "decodeURIComponent", URIDecodeComponent, 375 "decodeURIComponent", URIDecodeComponent,
368 "encodeURI", URIEncode, 376 "encodeURI", URIEncode,
369 "encodeURIComponent", URIEncodeComponent 377 "encodeURIComponent", URIEncodeComponent
370 ]); 378 ]);
371 379
372 }) 380 })
OLDNEW
« 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