OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 80 } |
81 | 81 |
82 | 82 |
83 // ECMA-262, section 15.5.4.6 | 83 // ECMA-262, section 15.5.4.6 |
84 function StringConcat() { | 84 function StringConcat() { |
85 var len = %_ArgumentsLength(); | 85 var len = %_ArgumentsLength(); |
86 var this_as_string = TO_STRING_INLINE(this); | 86 var this_as_string = TO_STRING_INLINE(this); |
87 if (len === 1) { | 87 if (len === 1) { |
88 return this_as_string + %_Arguments(0); | 88 return this_as_string + %_Arguments(0); |
89 } | 89 } |
90 var parts = new $Array(len + 1); | 90 var parts = new InternalArray(len + 1); |
91 parts[0] = this_as_string; | 91 parts[0] = this_as_string; |
92 for (var i = 0; i < len; i++) { | 92 for (var i = 0; i < len; i++) { |
93 var part = %_Arguments(i); | 93 var part = %_Arguments(i); |
94 parts[i + 1] = TO_STRING_INLINE(part); | 94 parts[i + 1] = TO_STRING_INLINE(part); |
95 } | 95 } |
96 return %StringBuilderConcat(parts, len + 1, ""); | 96 return %StringBuilderConcat(parts, len + 1, ""); |
97 } | 97 } |
98 | 98 |
99 // Match ES3 and Safari | 99 // Match ES3 and Safari |
100 %FunctionSetLength(StringConcat, 1); | 100 %FunctionSetLength(StringConcat, 1); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 // Compute start and end. | 350 // Compute start and end. |
351 var start = matchInfo[CAPTURE(scaled)]; | 351 var start = matchInfo[CAPTURE(scaled)]; |
352 if (start < 0) return; | 352 if (start < 0) return; |
353 var end = matchInfo[CAPTURE(scaled + 1)]; | 353 var end = matchInfo[CAPTURE(scaled + 1)]; |
354 builder.addSpecialSlice(start, end); | 354 builder.addSpecialSlice(start, end); |
355 }; | 355 }; |
356 | 356 |
357 // TODO(lrn): This array will survive indefinitely if replace is never | 357 // TODO(lrn): This array will survive indefinitely if replace is never |
358 // called again. However, it will be empty, since the contents are cleared | 358 // called again. However, it will be empty, since the contents are cleared |
359 // in the finally block. | 359 // in the finally block. |
360 var reusableReplaceArray = $Array(16); | 360 var reusableReplaceArray = new InternalArray(16); |
361 | 361 |
362 // Helper function for replacing regular expressions with the result of a | 362 // Helper function for replacing regular expressions with the result of a |
363 // function application in String.prototype.replace. | 363 // function application in String.prototype.replace. |
364 function StringReplaceGlobalRegExpWithFunction(subject, regexp, replace) { | 364 function StringReplaceGlobalRegExpWithFunction(subject, regexp, replace) { |
365 var resultArray = reusableReplaceArray; | 365 var resultArray = reusableReplaceArray; |
366 if (resultArray) { | 366 if (resultArray) { |
367 reusableReplaceArray = null; | 367 reusableReplaceArray = null; |
368 } else { | 368 } else { |
369 // Inside a nested replace (replace called from the replacement function | 369 // Inside a nested replace (replace called from the replacement function |
370 // of another replace) or we have failed to set the reusable array | 370 // of another replace) or we have failed to set the reusable array |
371 // back due to an exception in a replacement function. Create a new | 371 // back due to an exception in a replacement function. Create a new |
372 // array to use in the future, or until the original is written back. | 372 // array to use in the future, or until the original is written back. |
373 resultArray = $Array(16); | 373 resultArray = new InternalArray(16); |
374 } | 374 } |
375 var res = %RegExpExecMultiple(regexp, | 375 var res = %RegExpExecMultiple(regexp, |
376 subject, | 376 subject, |
377 lastMatchInfo, | 377 lastMatchInfo, |
378 resultArray); | 378 resultArray); |
379 regexp.lastIndex = 0; | 379 regexp.lastIndex = 0; |
380 if (IS_NULL(res)) { | 380 if (IS_NULL(res)) { |
381 // No matches at all. | 381 // No matches at all. |
382 reusableReplaceArray = resultArray; | 382 reusableReplaceArray = resultArray; |
383 return subject; | 383 return subject; |
384 } | 384 } |
385 var len = res.length; | 385 var len = res.length; |
386 var i = 0; | 386 var i = 0; |
387 if (NUMBER_OF_CAPTURES(lastMatchInfo) == 2) { | 387 if (NUMBER_OF_CAPTURES(lastMatchInfo) == 2) { |
388 var match_start = 0; | 388 var match_start = 0; |
389 var override = [null, 0, subject]; | 389 var override = new InternalArray(null, 0, subject); |
390 var receiver = %GetGlobalReceiver(); | 390 var receiver = %GetGlobalReceiver(); |
391 while (i < len) { | 391 while (i < len) { |
392 var elem = res[i]; | 392 var elem = res[i]; |
393 if (%_IsSmi(elem)) { | 393 if (%_IsSmi(elem)) { |
394 if (elem > 0) { | 394 if (elem > 0) { |
395 match_start = (elem >> 11) + (elem & 0x7ff); | 395 match_start = (elem >> 11) + (elem & 0x7ff); |
396 } else { | 396 } else { |
397 match_start = res[++i] - elem; | 397 match_start = res[++i] - elem; |
398 } | 398 } |
399 } else { | 399 } else { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 // The number of captures plus one for the match. | 440 // The number of captures plus one for the match. |
441 var m = NUMBER_OF_CAPTURES(matchInfo) >> 1; | 441 var m = NUMBER_OF_CAPTURES(matchInfo) >> 1; |
442 var replacement; | 442 var replacement; |
443 if (m == 1) { | 443 if (m == 1) { |
444 // No captures, only the match, which is always valid. | 444 // No captures, only the match, which is always valid. |
445 var s = SubString(subject, index, endOfMatch); | 445 var s = SubString(subject, index, endOfMatch); |
446 // Don't call directly to avoid exposing the built-in global object. | 446 // Don't call directly to avoid exposing the built-in global object. |
447 replacement = | 447 replacement = |
448 %_CallFunction(%GetGlobalReceiver(), s, index, subject, replace); | 448 %_CallFunction(%GetGlobalReceiver(), s, index, subject, replace); |
449 } else { | 449 } else { |
450 var parameters = $Array(m + 2); | 450 var parameters = new InternalArray(m + 2); |
451 for (var j = 0; j < m; j++) { | 451 for (var j = 0; j < m; j++) { |
452 parameters[j] = CaptureString(subject, matchInfo, j); | 452 parameters[j] = CaptureString(subject, matchInfo, j); |
453 } | 453 } |
454 parameters[j] = index; | 454 parameters[j] = index; |
455 parameters[j + 1] = subject; | 455 parameters[j + 1] = subject; |
456 | 456 |
457 replacement = replace.apply(null, parameters); | 457 replacement = replace.apply(null, parameters); |
458 } | 458 } |
459 | 459 |
460 result.add(replacement); // The add method converts to string if necessary. | 460 result.add(replacement); // The add method converts to string if necessary. |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 } | 713 } |
714 | 714 |
715 function StringTrimLeft() { | 715 function StringTrimLeft() { |
716 return %StringTrim(TO_STRING_INLINE(this), true, false); | 716 return %StringTrim(TO_STRING_INLINE(this), true, false); |
717 } | 717 } |
718 | 718 |
719 function StringTrimRight() { | 719 function StringTrimRight() { |
720 return %StringTrim(TO_STRING_INLINE(this), false, true); | 720 return %StringTrim(TO_STRING_INLINE(this), false, true); |
721 } | 721 } |
722 | 722 |
723 var static_charcode_array = new $Array(4); | 723 var static_charcode_array = new InternalArray(4); |
724 | 724 |
725 // ECMA-262, section 15.5.3.2 | 725 // ECMA-262, section 15.5.3.2 |
726 function StringFromCharCode(code) { | 726 function StringFromCharCode(code) { |
727 var n = %_ArgumentsLength(); | 727 var n = %_ArgumentsLength(); |
728 if (n == 1) { | 728 if (n == 1) { |
729 if (!%_IsSmi(code)) code = ToNumber(code); | 729 if (!%_IsSmi(code)) code = ToNumber(code); |
730 return %_StringCharFromCode(code & 0xffff); | 730 return %_StringCharFromCode(code & 0xffff); |
731 } | 731 } |
732 | 732 |
733 // NOTE: This is not super-efficient, but it is necessary because we | 733 // NOTE: This is not super-efficient, but it is necessary because we |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 function StringSup() { | 818 function StringSup() { |
819 return "<sup>" + this + "</sup>"; | 819 return "<sup>" + this + "</sup>"; |
820 } | 820 } |
821 | 821 |
822 | 822 |
823 // ReplaceResultBuilder support. | 823 // ReplaceResultBuilder support. |
824 function ReplaceResultBuilder(str) { | 824 function ReplaceResultBuilder(str) { |
825 if (%_ArgumentsLength() > 1) { | 825 if (%_ArgumentsLength() > 1) { |
826 this.elements = %_Arguments(1); | 826 this.elements = %_Arguments(1); |
827 } else { | 827 } else { |
828 this.elements = new $Array(); | 828 this.elements = new InternalArray(); |
829 } | 829 } |
830 this.special_string = str; | 830 this.special_string = str; |
831 } | 831 } |
832 | 832 |
833 | 833 |
834 ReplaceResultBuilder.prototype.add = function(str) { | 834 ReplaceResultBuilder.prototype.add = function(str) { |
835 str = TO_STRING_INLINE(str); | 835 str = TO_STRING_INLINE(str); |
836 if (str.length > 0) this.elements.push(str); | 836 if (str.length > 0) this.elements.push(str); |
837 } | 837 } |
838 | 838 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 "italics", StringItalics, | 906 "italics", StringItalics, |
907 "small", StringSmall, | 907 "small", StringSmall, |
908 "strike", StringStrike, | 908 "strike", StringStrike, |
909 "sub", StringSub, | 909 "sub", StringSub, |
910 "sup", StringSup | 910 "sup", StringSup |
911 )); | 911 )); |
912 } | 912 } |
913 | 913 |
914 | 914 |
915 SetupString(); | 915 SetupString(); |
OLD | NEW |