OLD | NEW |
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"; |
11 | 11 |
12 %CheckIsBootstrapping(); | 12 %CheckIsBootstrapping(); |
13 | 13 |
14 //- ------------------------------------------------------------------ | 14 //- ------------------------------------------------------------------ |
15 // Imports | 15 // Imports |
16 | 16 |
17 var GlobalObject = global.Object; | 17 var GlobalObject = global.Object; |
18 var GlobalArray = global.Array; | 18 var GlobalArray = global.Array; |
19 var InternalArray = utils.InternalArray; | 19 var InternalArray = utils.InternalArray; |
| 20 var ToString; |
| 21 |
| 22 utils.Import(function(from) { |
| 23 ToString = from.ToString; |
| 24 }); |
20 | 25 |
21 // ------------------------------------------------------------------- | 26 // ------------------------------------------------------------------- |
22 // Define internal helper functions. | 27 // Define internal helper functions. |
23 | 28 |
24 function HexValueOf(code) { | 29 function HexValueOf(code) { |
25 // 0-9 | 30 // 0-9 |
26 if (code >= 48 && code <= 57) return code - 48; | 31 if (code >= 48 && code <= 57) return code - 48; |
27 // A-F | 32 // A-F |
28 if (code >= 65 && code <= 70) return code - 55; | 33 if (code >= 65 && code <= 70) return code - 55; |
29 // a-f | 34 // a-f |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 272 |
268 two_byte = %TruncateString(two_byte, index); | 273 two_byte = %TruncateString(two_byte, index); |
269 return one_byte + two_byte; | 274 return one_byte + two_byte; |
270 } | 275 } |
271 | 276 |
272 // ------------------------------------------------------------------- | 277 // ------------------------------------------------------------------- |
273 // Define exported functions. | 278 // Define exported functions. |
274 | 279 |
275 // ECMA-262 - B.2.1. | 280 // ECMA-262 - B.2.1. |
276 function URIEscapeJS(str) { | 281 function URIEscapeJS(str) { |
277 var s = $toString(str); | 282 var s = ToString(str); |
278 return %URIEscape(s); | 283 return %URIEscape(s); |
279 } | 284 } |
280 | 285 |
281 // ECMA-262 - B.2.2. | 286 // ECMA-262 - B.2.2. |
282 function URIUnescapeJS(str) { | 287 function URIUnescapeJS(str) { |
283 var s = $toString(str); | 288 var s = ToString(str); |
284 return %URIUnescape(s); | 289 return %URIUnescape(s); |
285 } | 290 } |
286 | 291 |
287 // ECMA-262 - 15.1.3.1. | 292 // ECMA-262 - 15.1.3.1. |
288 function URIDecode(uri) { | 293 function URIDecode(uri) { |
289 var reservedPredicate = function(cc) { | 294 var reservedPredicate = function(cc) { |
290 // #$ | 295 // #$ |
291 if (35 <= cc && cc <= 36) return true; | 296 if (35 <= cc && cc <= 36) return true; |
292 // & | 297 // & |
293 if (cc == 38) return true; | 298 if (cc == 38) return true; |
294 // +, | 299 // +, |
295 if (43 <= cc && cc <= 44) return true; | 300 if (43 <= cc && cc <= 44) return true; |
296 // / | 301 // / |
297 if (cc == 47) return true; | 302 if (cc == 47) return true; |
298 // :; | 303 // :; |
299 if (58 <= cc && cc <= 59) return true; | 304 if (58 <= cc && cc <= 59) return true; |
300 // = | 305 // = |
301 if (cc == 61) return true; | 306 if (cc == 61) return true; |
302 // ?@ | 307 // ?@ |
303 if (63 <= cc && cc <= 64) return true; | 308 if (63 <= cc && cc <= 64) return true; |
304 | 309 |
305 return false; | 310 return false; |
306 }; | 311 }; |
307 var string = $toString(uri); | 312 var string = ToString(uri); |
308 return Decode(string, reservedPredicate); | 313 return Decode(string, reservedPredicate); |
309 } | 314 } |
310 | 315 |
311 // ECMA-262 - 15.1.3.2. | 316 // ECMA-262 - 15.1.3.2. |
312 function URIDecodeComponent(component) { | 317 function URIDecodeComponent(component) { |
313 var reservedPredicate = function(cc) { return false; }; | 318 var reservedPredicate = function(cc) { return false; }; |
314 var string = $toString(component); | 319 var string = ToString(component); |
315 return Decode(string, reservedPredicate); | 320 return Decode(string, reservedPredicate); |
316 } | 321 } |
317 | 322 |
318 // ECMA-262 - 15.1.3.3. | 323 // ECMA-262 - 15.1.3.3. |
319 function URIEncode(uri) { | 324 function URIEncode(uri) { |
320 var unescapePredicate = function(cc) { | 325 var unescapePredicate = function(cc) { |
321 if (isAlphaNumeric(cc)) return true; | 326 if (isAlphaNumeric(cc)) return true; |
322 // ! | 327 // ! |
323 if (cc == 33) return true; | 328 if (cc == 33) return true; |
324 // #$ | 329 // #$ |
325 if (35 <= cc && cc <= 36) return true; | 330 if (35 <= cc && cc <= 36) return true; |
326 // &'()*+,-./ | 331 // &'()*+,-./ |
327 if (38 <= cc && cc <= 47) return true; | 332 if (38 <= cc && cc <= 47) return true; |
328 // :; | 333 // :; |
329 if (58 <= cc && cc <= 59) return true; | 334 if (58 <= cc && cc <= 59) return true; |
330 // = | 335 // = |
331 if (cc == 61) return true; | 336 if (cc == 61) return true; |
332 // ?@ | 337 // ?@ |
333 if (63 <= cc && cc <= 64) return true; | 338 if (63 <= cc && cc <= 64) return true; |
334 // _ | 339 // _ |
335 if (cc == 95) return true; | 340 if (cc == 95) return true; |
336 // ~ | 341 // ~ |
337 if (cc == 126) return true; | 342 if (cc == 126) return true; |
338 | 343 |
339 return false; | 344 return false; |
340 }; | 345 }; |
341 var string = $toString(uri); | 346 var string = ToString(uri); |
342 return Encode(string, unescapePredicate); | 347 return Encode(string, unescapePredicate); |
343 } | 348 } |
344 | 349 |
345 // ECMA-262 - 15.1.3.4 | 350 // ECMA-262 - 15.1.3.4 |
346 function URIEncodeComponent(component) { | 351 function URIEncodeComponent(component) { |
347 var unescapePredicate = function(cc) { | 352 var unescapePredicate = function(cc) { |
348 if (isAlphaNumeric(cc)) return true; | 353 if (isAlphaNumeric(cc)) return true; |
349 // ! | 354 // ! |
350 if (cc == 33) return true; | 355 if (cc == 33) return true; |
351 // '()* | 356 // '()* |
352 if (39 <= cc && cc <= 42) return true; | 357 if (39 <= cc && cc <= 42) return true; |
353 // -. | 358 // -. |
354 if (45 <= cc && cc <= 46) return true; | 359 if (45 <= cc && cc <= 46) return true; |
355 // _ | 360 // _ |
356 if (cc == 95) return true; | 361 if (cc == 95) return true; |
357 // ~ | 362 // ~ |
358 if (cc == 126) return true; | 363 if (cc == 126) return true; |
359 | 364 |
360 return false; | 365 return false; |
361 }; | 366 }; |
362 var string = $toString(component); | 367 var string = ToString(component); |
363 return Encode(string, unescapePredicate); | 368 return Encode(string, unescapePredicate); |
364 } | 369 } |
365 | 370 |
366 // ------------------------------------------------------------------- | 371 // ------------------------------------------------------------------- |
367 // Install exported functions. | 372 // Install exported functions. |
368 | 373 |
369 // Set up non-enumerable URI functions on the global object and set | 374 // Set up non-enumerable URI functions on the global object and set |
370 // their names. | 375 // their names. |
371 utils.InstallFunctions(global, DONT_ENUM, [ | 376 utils.InstallFunctions(global, DONT_ENUM, [ |
372 "escape", URIEscapeJS, | 377 "escape", URIEscapeJS, |
373 "unescape", URIUnescapeJS, | 378 "unescape", URIUnescapeJS, |
374 "decodeURI", URIDecode, | 379 "decodeURI", URIDecode, |
375 "decodeURIComponent", URIDecodeComponent, | 380 "decodeURIComponent", URIDecodeComponent, |
376 "encodeURI", URIEncode, | 381 "encodeURI", URIEncode, |
377 "encodeURIComponent", URIEncodeComponent | 382 "encodeURIComponent", URIEncodeComponent |
378 ]); | 383 ]); |
379 | 384 |
380 }) | 385 }) |
OLD | NEW |