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

Side by Side Diff: src/uri.js

Issue 565093002: Reland "Change the order of arguments of the (One|Two)ByteSeqStringSetChar intrinsic." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix typo Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « src/string.js ('k') | src/x64/full-codegen-x64.cc » ('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 "use strict"; 5 "use strict";
6 6
7 // This file relies on the fact that the following declaration has been made 7 // This file relies on the fact that the following declaration has been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $Array = global.Array; 9 // var $Array = global.Array;
10 10
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } else { 165 } else {
166 throw new $URIError("URI malformed"); 166 throw new $URIError("URI malformed");
167 } 167 }
168 } 168 }
169 } 169 }
170 } 170 }
171 if (0xD800 <= value && value <= 0xDFFF) { 171 if (0xD800 <= value && value <= 0xDFFF) {
172 throw new $URIError("URI malformed"); 172 throw new $URIError("URI malformed");
173 } 173 }
174 if (value < 0x10000) { 174 if (value < 0x10000) {
175 %_TwoByteSeqStringSetChar(result, index++, value); 175 %_TwoByteSeqStringSetChar(index++, value, result);
176 } else { 176 } else {
177 %_TwoByteSeqStringSetChar(result, index++, (value >> 10) + 0xd7c0); 177 %_TwoByteSeqStringSetChar(index++, (value >> 10) + 0xd7c0, result);
178 %_TwoByteSeqStringSetChar(result, index++, (value & 0x3ff) + 0xdc00); 178 %_TwoByteSeqStringSetChar(index++, (value & 0x3ff) + 0xdc00, result);
179 } 179 }
180 return index; 180 return index;
181 } 181 }
182 182
183 // ECMA-262, section 15.1.3 183 // ECMA-262, section 15.1.3
184 function Encode(uri, unescape) { 184 function Encode(uri, unescape) {
185 var uriLength = uri.length; 185 var uriLength = uri.length;
186 var array = new InternalArray(uriLength); 186 var array = new InternalArray(uriLength);
187 var index = 0; 187 var index = 0;
188 for (var k = 0; k < uriLength; k++) { 188 for (var k = 0; k < uriLength; k++) {
189 var cc1 = uri.charCodeAt(k); 189 var cc1 = uri.charCodeAt(k);
190 if (unescape(cc1)) { 190 if (unescape(cc1)) {
191 array[index++] = cc1; 191 array[index++] = cc1;
192 } else { 192 } else {
193 if (cc1 >= 0xDC00 && cc1 <= 0xDFFF) throw new $URIError("URI malformed") ; 193 if (cc1 >= 0xDC00 && cc1 <= 0xDFFF) throw new $URIError("URI malformed") ;
194 if (cc1 < 0xD800 || cc1 > 0xDBFF) { 194 if (cc1 < 0xD800 || cc1 > 0xDBFF) {
195 index = URIEncodeSingle(cc1, array, index); 195 index = URIEncodeSingle(cc1, array, index);
196 } else { 196 } else {
197 k++; 197 k++;
198 if (k == uriLength) throw new $URIError("URI malformed"); 198 if (k == uriLength) throw new $URIError("URI malformed");
199 var cc2 = uri.charCodeAt(k); 199 var cc2 = uri.charCodeAt(k);
200 if (cc2 < 0xDC00 || cc2 > 0xDFFF) throw new $URIError("URI malformed") ; 200 if (cc2 < 0xDC00 || cc2 > 0xDFFF) throw new $URIError("URI malformed") ;
201 index = URIEncodePair(cc1, cc2, array, index); 201 index = URIEncodePair(cc1, cc2, array, index);
202 } 202 }
203 } 203 }
204 } 204 }
205 205
206 var result = %NewString(array.length, NEW_ONE_BYTE_STRING); 206 var result = %NewString(array.length, NEW_ONE_BYTE_STRING);
207 for (var i = 0; i < array.length; i++) { 207 for (var i = 0; i < array.length; i++) {
208 %_OneByteSeqStringSetChar(result, i, array[i]); 208 %_OneByteSeqStringSetChar(i, array[i], result);
209 } 209 }
210 return result; 210 return result;
211 } 211 }
212 212
213 // ECMA-262, section 15.1.3 213 // ECMA-262, section 15.1.3
214 function Decode(uri, reserved) { 214 function Decode(uri, reserved) {
215 var uriLength = uri.length; 215 var uriLength = uri.length;
216 var one_byte = %NewString(uriLength, NEW_ONE_BYTE_STRING); 216 var one_byte = %NewString(uriLength, NEW_ONE_BYTE_STRING);
217 var index = 0; 217 var index = 0;
218 var k = 0; 218 var k = 0;
219 219
220 // Optimistically assume one-byte string. 220 // Optimistically assume one-byte string.
221 for ( ; k < uriLength; k++) { 221 for ( ; k < uriLength; k++) {
222 var code = uri.charCodeAt(k); 222 var code = uri.charCodeAt(k);
223 if (code == 37) { // '%' 223 if (code == 37) { // '%'
224 if (k + 2 >= uriLength) throw new $URIError("URI malformed"); 224 if (k + 2 >= uriLength) throw new $URIError("URI malformed");
225 var cc = URIHexCharsToCharCode(uri.charCodeAt(k+1), uri.charCodeAt(k+2)) ; 225 var cc = URIHexCharsToCharCode(uri.charCodeAt(k+1), uri.charCodeAt(k+2)) ;
226 if (cc >> 7) break; // Assumption wrong, two-byte string. 226 if (cc >> 7) break; // Assumption wrong, two-byte string.
227 if (reserved(cc)) { 227 if (reserved(cc)) {
228 %_OneByteSeqStringSetChar(one_byte, index++, 37); // '%'. 228 %_OneByteSeqStringSetChar(index++, 37, one_byte); // '%'.
229 %_OneByteSeqStringSetChar(one_byte, index++, uri.charCodeAt(k+1)); 229 %_OneByteSeqStringSetChar(index++, uri.charCodeAt(k+1), one_byte);
230 %_OneByteSeqStringSetChar(one_byte, index++, uri.charCodeAt(k+2)); 230 %_OneByteSeqStringSetChar(index++, uri.charCodeAt(k+2), one_byte);
231 } else { 231 } else {
232 %_OneByteSeqStringSetChar(one_byte, index++, cc); 232 %_OneByteSeqStringSetChar(index++, cc, one_byte);
233 } 233 }
234 k += 2; 234 k += 2;
235 } else { 235 } else {
236 if (code > 0x7f) break; // Assumption wrong, two-byte string. 236 if (code > 0x7f) break; // Assumption wrong, two-byte string.
237 %_OneByteSeqStringSetChar(one_byte, index++, code); 237 %_OneByteSeqStringSetChar(index++, code, one_byte);
238 } 238 }
239 } 239 }
240 240
241 one_byte = %TruncateString(one_byte, index); 241 one_byte = %TruncateString(one_byte, index);
242 if (k == uriLength) return one_byte; 242 if (k == uriLength) return one_byte;
243 243
244 // Write into two byte string. 244 // Write into two byte string.
245 var two_byte = %NewString(uriLength - k, NEW_TWO_BYTE_STRING); 245 var two_byte = %NewString(uriLength - k, NEW_TWO_BYTE_STRING);
246 index = 0; 246 index = 0;
247 247
248 for ( ; k < uriLength; k++) { 248 for ( ; k < uriLength; k++) {
249 var code = uri.charCodeAt(k); 249 var code = uri.charCodeAt(k);
250 if (code == 37) { // '%' 250 if (code == 37) { // '%'
251 if (k + 2 >= uriLength) throw new $URIError("URI malformed"); 251 if (k + 2 >= uriLength) throw new $URIError("URI malformed");
252 var cc = URIHexCharsToCharCode(uri.charCodeAt(++k), uri.charCodeAt(++k)) ; 252 var cc = URIHexCharsToCharCode(uri.charCodeAt(++k), uri.charCodeAt(++k)) ;
253 if (cc >> 7) { 253 if (cc >> 7) {
254 var n = 0; 254 var n = 0;
255 while (((cc << ++n) & 0x80) != 0) { } 255 while (((cc << ++n) & 0x80) != 0) { }
256 if (n == 1 || n > 4) throw new $URIError("URI malformed"); 256 if (n == 1 || n > 4) throw new $URIError("URI malformed");
257 var octets = new $Array(n); 257 var octets = new $Array(n);
258 octets[0] = cc; 258 octets[0] = cc;
259 if (k + 3 * (n - 1) >= uriLength) throw new $URIError("URI malformed") ; 259 if (k + 3 * (n - 1) >= uriLength) throw new $URIError("URI malformed") ;
260 for (var i = 1; i < n; i++) { 260 for (var i = 1; i < n; i++) {
261 if (uri.charAt(++k) != '%') throw new $URIError("URI malformed"); 261 if (uri.charAt(++k) != '%') throw new $URIError("URI malformed");
262 octets[i] = URIHexCharsToCharCode(uri.charCodeAt(++k), 262 octets[i] = URIHexCharsToCharCode(uri.charCodeAt(++k),
263 uri.charCodeAt(++k)); 263 uri.charCodeAt(++k));
264 } 264 }
265 index = URIDecodeOctets(octets, two_byte, index); 265 index = URIDecodeOctets(octets, two_byte, index);
266 } else if (reserved(cc)) { 266 } else if (reserved(cc)) {
267 %_TwoByteSeqStringSetChar(two_byte, index++, 37); // '%'. 267 %_TwoByteSeqStringSetChar(index++, 37, two_byte); // '%'.
268 %_TwoByteSeqStringSetChar(two_byte, index++, uri.charCodeAt(k - 1)); 268 %_TwoByteSeqStringSetChar(index++, uri.charCodeAt(k - 1), two_byte);
269 %_TwoByteSeqStringSetChar(two_byte, index++, uri.charCodeAt(k)); 269 %_TwoByteSeqStringSetChar(index++, uri.charCodeAt(k), two_byte);
270 } else { 270 } else {
271 %_TwoByteSeqStringSetChar(two_byte, index++, cc); 271 %_TwoByteSeqStringSetChar(index++, cc, two_byte);
272 } 272 }
273 } else { 273 } else {
274 %_TwoByteSeqStringSetChar(two_byte, index++, code); 274 %_TwoByteSeqStringSetChar(index++, code, two_byte);
275 } 275 }
276 } 276 }
277 277
278 two_byte = %TruncateString(two_byte, index); 278 two_byte = %TruncateString(two_byte, index);
279 return one_byte + two_byte; 279 return one_byte + two_byte;
280 } 280 }
281 281
282 // ------------------------------------------------------------------- 282 // -------------------------------------------------------------------
283 // Define exported functions. 283 // Define exported functions.
284 284
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 InstallFunctions(global, DONT_ENUM, $Array( 383 InstallFunctions(global, DONT_ENUM, $Array(
384 "escape", URIEscapeJS, 384 "escape", URIEscapeJS,
385 "unescape", URIUnescapeJS, 385 "unescape", URIUnescapeJS,
386 "decodeURI", URIDecode, 386 "decodeURI", URIDecode,
387 "decodeURIComponent", URIDecodeComponent, 387 "decodeURIComponent", URIDecodeComponent,
388 "encodeURI", URIEncode, 388 "encodeURI", URIEncode,
389 "encodeURIComponent", URIEncodeComponent 389 "encodeURIComponent", URIEncodeComponent
390 )); 390 ));
391 391
392 })(); 392 })();
OLDNEW
« no previous file with comments | « src/string.js ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698