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() { | 8 (function() { |
9 | 9 |
10 "use strict"; | 10 "use strict"; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 255 |
256 two_byte = %TruncateString(two_byte, index); | 256 two_byte = %TruncateString(two_byte, index); |
257 return one_byte + two_byte; | 257 return one_byte + two_byte; |
258 } | 258 } |
259 | 259 |
260 // ------------------------------------------------------------------- | 260 // ------------------------------------------------------------------- |
261 // Define exported functions. | 261 // Define exported functions. |
262 | 262 |
263 // ECMA-262 - B.2.1. | 263 // ECMA-262 - B.2.1. |
264 function URIEscapeJS(str) { | 264 function URIEscapeJS(str) { |
265 var s = $toString(str); | 265 var s = ToString(str); |
266 return %URIEscape(s); | 266 return %URIEscape(s); |
267 } | 267 } |
268 | 268 |
269 // ECMA-262 - B.2.2. | 269 // ECMA-262 - B.2.2. |
270 function URIUnescapeJS(str) { | 270 function URIUnescapeJS(str) { |
271 var s = $toString(str); | 271 var s = ToString(str); |
272 return %URIUnescape(s); | 272 return %URIUnescape(s); |
273 } | 273 } |
274 | 274 |
275 // ECMA-262 - 15.1.3.1. | 275 // ECMA-262 - 15.1.3.1. |
276 function URIDecode(uri) { | 276 function URIDecode(uri) { |
277 var reservedPredicate = function(cc) { | 277 var reservedPredicate = function(cc) { |
278 // #$ | 278 // #$ |
279 if (35 <= cc && cc <= 36) return true; | 279 if (35 <= cc && cc <= 36) return true; |
280 // & | 280 // & |
281 if (cc == 38) return true; | 281 if (cc == 38) return true; |
282 // +, | 282 // +, |
283 if (43 <= cc && cc <= 44) return true; | 283 if (43 <= cc && cc <= 44) return true; |
284 // / | 284 // / |
285 if (cc == 47) return true; | 285 if (cc == 47) return true; |
286 // :; | 286 // :; |
287 if (58 <= cc && cc <= 59) return true; | 287 if (58 <= cc && cc <= 59) return true; |
288 // = | 288 // = |
289 if (cc == 61) return true; | 289 if (cc == 61) return true; |
290 // ?@ | 290 // ?@ |
291 if (63 <= cc && cc <= 64) return true; | 291 if (63 <= cc && cc <= 64) return true; |
292 | 292 |
293 return false; | 293 return false; |
294 }; | 294 }; |
295 var string = $toString(uri); | 295 var string = ToString(uri); |
296 return Decode(string, reservedPredicate); | 296 return Decode(string, reservedPredicate); |
297 } | 297 } |
298 | 298 |
299 // ECMA-262 - 15.1.3.2. | 299 // ECMA-262 - 15.1.3.2. |
300 function URIDecodeComponent(component) { | 300 function URIDecodeComponent(component) { |
301 var reservedPredicate = function(cc) { return false; }; | 301 var reservedPredicate = function(cc) { return false; }; |
302 var string = $toString(component); | 302 var string = ToString(component); |
303 return Decode(string, reservedPredicate); | 303 return Decode(string, reservedPredicate); |
304 } | 304 } |
305 | 305 |
306 // ECMA-262 - 15.1.3.3. | 306 // ECMA-262 - 15.1.3.3. |
307 function URIEncode(uri) { | 307 function URIEncode(uri) { |
308 var unescapePredicate = function(cc) { | 308 var unescapePredicate = function(cc) { |
309 if (isAlphaNumeric(cc)) return true; | 309 if (isAlphaNumeric(cc)) return true; |
310 // ! | 310 // ! |
311 if (cc == 33) return true; | 311 if (cc == 33) return true; |
312 // #$ | 312 // #$ |
313 if (35 <= cc && cc <= 36) return true; | 313 if (35 <= cc && cc <= 36) return true; |
314 // &'()*+,-./ | 314 // &'()*+,-./ |
315 if (38 <= cc && cc <= 47) return true; | 315 if (38 <= cc && cc <= 47) return true; |
316 // :; | 316 // :; |
317 if (58 <= cc && cc <= 59) return true; | 317 if (58 <= cc && cc <= 59) return true; |
318 // = | 318 // = |
319 if (cc == 61) return true; | 319 if (cc == 61) return true; |
320 // ?@ | 320 // ?@ |
321 if (63 <= cc && cc <= 64) return true; | 321 if (63 <= cc && cc <= 64) return true; |
322 // _ | 322 // _ |
323 if (cc == 95) return true; | 323 if (cc == 95) return true; |
324 // ~ | 324 // ~ |
325 if (cc == 126) return true; | 325 if (cc == 126) return true; |
326 | 326 |
327 return false; | 327 return false; |
328 }; | 328 }; |
329 var string = $toString(uri); | 329 var string = ToString(uri); |
330 return Encode(string, unescapePredicate); | 330 return Encode(string, unescapePredicate); |
331 } | 331 } |
332 | 332 |
333 // ECMA-262 - 15.1.3.4 | 333 // ECMA-262 - 15.1.3.4 |
334 function URIEncodeComponent(component) { | 334 function URIEncodeComponent(component) { |
335 var unescapePredicate = function(cc) { | 335 var unescapePredicate = function(cc) { |
336 if (isAlphaNumeric(cc)) return true; | 336 if (isAlphaNumeric(cc)) return true; |
337 // ! | 337 // ! |
338 if (cc == 33) return true; | 338 if (cc == 33) return true; |
339 // '()* | 339 // '()* |
340 if (39 <= cc && cc <= 42) return true; | 340 if (39 <= cc && cc <= 42) return true; |
341 // -. | 341 // -. |
342 if (45 <= cc && cc <= 46) return true; | 342 if (45 <= cc && cc <= 46) return true; |
343 // _ | 343 // _ |
344 if (cc == 95) return true; | 344 if (cc == 95) return true; |
345 // ~ | 345 // ~ |
346 if (cc == 126) return true; | 346 if (cc == 126) return true; |
347 | 347 |
348 return false; | 348 return false; |
349 }; | 349 }; |
350 var string = $toString(component); | 350 var string = ToString(component); |
351 return Encode(string, unescapePredicate); | 351 return Encode(string, unescapePredicate); |
352 } | 352 } |
353 | 353 |
354 // ------------------------------------------------------------------- | 354 // ------------------------------------------------------------------- |
355 // Install exported functions. | 355 // Install exported functions. |
356 | 356 |
357 // Set up non-enumerable URI functions on the global object and set | 357 // Set up non-enumerable URI functions on the global object and set |
358 // their names. | 358 // their names. |
359 $installFunctions(global, DONT_ENUM, [ | 359 $installFunctions(global, DONT_ENUM, [ |
360 "escape", URIEscapeJS, | 360 "escape", URIEscapeJS, |
361 "unescape", URIUnescapeJS, | 361 "unescape", URIUnescapeJS, |
362 "decodeURI", URIDecode, | 362 "decodeURI", URIDecode, |
363 "decodeURIComponent", URIDecodeComponent, | 363 "decodeURIComponent", URIDecodeComponent, |
364 "encodeURI", URIEncode, | 364 "encodeURI", URIEncode, |
365 "encodeURIComponent", URIEncodeComponent | 365 "encodeURIComponent", URIEncodeComponent |
366 ]); | 366 ]); |
367 | 367 |
368 })(); | 368 })(); |
OLD | NEW |