| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 // ECMA-262 section 15.5.4.3 | 55 // ECMA-262 section 15.5.4.3 |
| 56 function StringValueOf() { | 56 function StringValueOf() { |
| 57 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) | 57 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) |
| 58 throw new $TypeError('String.prototype.valueOf is not generic'); | 58 throw new $TypeError('String.prototype.valueOf is not generic'); |
| 59 return %_ValueOf(this); | 59 return %_ValueOf(this); |
| 60 } | 60 } |
| 61 | 61 |
| 62 | 62 |
| 63 // ECMA-262, section 15.5.4.4 | 63 // ECMA-262, section 15.5.4.4 |
| 64 function StringCharAt(pos) { | 64 function StringCharAt(pos) { |
| 65 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 66 throw MakeTypeError("called_on_null_or_undefined", | |
| 67 ["String.prototype.charAt"]); | |
| 68 } | |
| 69 var result = %_StringCharAt(this, pos); | 65 var result = %_StringCharAt(this, pos); |
| 70 if (%_IsSmi(result)) { | 66 if (%_IsSmi(result)) { |
| 71 result = %_StringCharAt(TO_STRING_INLINE(this), TO_INTEGER(pos)); | 67 result = %_StringCharAt(TO_STRING_INLINE(this), TO_INTEGER(pos)); |
| 72 } | 68 } |
| 73 return result; | 69 return result; |
| 74 } | 70 } |
| 75 | 71 |
| 76 | 72 |
| 77 // ECMA-262 section 15.5.4.5 | 73 // ECMA-262 section 15.5.4.5 |
| 78 function StringCharCodeAt(pos) { | 74 function StringCharCodeAt(pos) { |
| 79 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 80 throw MakeTypeError("called_on_null_or_undefined", | |
| 81 ["String.prototype.charCodeAt"]); | |
| 82 } | |
| 83 var result = %_StringCharCodeAt(this, pos); | 75 var result = %_StringCharCodeAt(this, pos); |
| 84 if (!%_IsSmi(result)) { | 76 if (!%_IsSmi(result)) { |
| 85 result = %_StringCharCodeAt(TO_STRING_INLINE(this), TO_INTEGER(pos)); | 77 result = %_StringCharCodeAt(TO_STRING_INLINE(this), TO_INTEGER(pos)); |
| 86 } | 78 } |
| 87 return result; | 79 return result; |
| 88 } | 80 } |
| 89 | 81 |
| 90 | 82 |
| 91 // ECMA-262, section 15.5.4.6 | 83 // ECMA-262, section 15.5.4.6 |
| 92 function StringConcat() { | 84 function StringConcat() { |
| 93 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 94 throw MakeTypeError("called_on_null_or_undefined", ["String.prototype.concat
"]); | |
| 95 } | |
| 96 var len = %_ArgumentsLength(); | 85 var len = %_ArgumentsLength(); |
| 97 var this_as_string = TO_STRING_INLINE(this); | 86 var this_as_string = TO_STRING_INLINE(this); |
| 98 if (len === 1) { | 87 if (len === 1) { |
| 99 return this_as_string + %_Arguments(0); | 88 return this_as_string + %_Arguments(0); |
| 100 } | 89 } |
| 101 var parts = new InternalArray(len + 1); | 90 var parts = new InternalArray(len + 1); |
| 102 parts[0] = this_as_string; | 91 parts[0] = this_as_string; |
| 103 for (var i = 0; i < len; i++) { | 92 for (var i = 0; i < len; i++) { |
| 104 var part = %_Arguments(i); | 93 var part = %_Arguments(i); |
| 105 parts[i + 1] = TO_STRING_INLINE(part); | 94 parts[i + 1] = TO_STRING_INLINE(part); |
| 106 } | 95 } |
| 107 return %StringBuilderConcat(parts, len + 1, ""); | 96 return %StringBuilderConcat(parts, len + 1, ""); |
| 108 } | 97 } |
| 109 | 98 |
| 110 // Match ES3 and Safari | 99 // Match ES3 and Safari |
| 111 %FunctionSetLength(StringConcat, 1); | 100 %FunctionSetLength(StringConcat, 1); |
| 112 | 101 |
| 113 | 102 |
| 114 // ECMA-262 section 15.5.4.7 | 103 // ECMA-262 section 15.5.4.7 |
| 115 function StringIndexOf(pattern /* position */) { // length == 1 | 104 function StringIndexOf(pattern /* position */) { // length == 1 |
| 116 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 117 throw MakeTypeError("called_on_null_or_undefined", | |
| 118 ["String.prototype.indexOf"]); | |
| 119 } | |
| 120 var subject = TO_STRING_INLINE(this); | 105 var subject = TO_STRING_INLINE(this); |
| 121 pattern = TO_STRING_INLINE(pattern); | 106 pattern = TO_STRING_INLINE(pattern); |
| 122 var index = 0; | 107 var index = 0; |
| 123 if (%_ArgumentsLength() > 1) { | 108 if (%_ArgumentsLength() > 1) { |
| 124 index = %_Arguments(1); // position | 109 index = %_Arguments(1); // position |
| 125 index = TO_INTEGER(index); | 110 index = TO_INTEGER(index); |
| 126 if (index < 0) index = 0; | 111 if (index < 0) index = 0; |
| 127 if (index > subject.length) index = subject.length; | 112 if (index > subject.length) index = subject.length; |
| 128 } | 113 } |
| 129 return %StringIndexOf(subject, pattern, index); | 114 return %StringIndexOf(subject, pattern, index); |
| 130 } | 115 } |
| 131 | 116 |
| 132 | 117 |
| 133 // ECMA-262 section 15.5.4.8 | 118 // ECMA-262 section 15.5.4.8 |
| 134 function StringLastIndexOf(pat /* position */) { // length == 1 | 119 function StringLastIndexOf(pat /* position */) { // length == 1 |
| 135 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 136 throw MakeTypeError("called_on_null_or_undefined", | |
| 137 ["String.prototype.lastIndexOf"]); | |
| 138 } | |
| 139 var sub = TO_STRING_INLINE(this); | 120 var sub = TO_STRING_INLINE(this); |
| 140 var subLength = sub.length; | 121 var subLength = sub.length; |
| 141 var pat = TO_STRING_INLINE(pat); | 122 var pat = TO_STRING_INLINE(pat); |
| 142 var patLength = pat.length; | 123 var patLength = pat.length; |
| 143 var index = subLength - patLength; | 124 var index = subLength - patLength; |
| 144 if (%_ArgumentsLength() > 1) { | 125 if (%_ArgumentsLength() > 1) { |
| 145 var position = ToNumber(%_Arguments(1)); | 126 var position = ToNumber(%_Arguments(1)); |
| 146 if (!NUMBER_IS_NAN(position)) { | 127 if (!NUMBER_IS_NAN(position)) { |
| 147 position = TO_INTEGER(position); | 128 position = TO_INTEGER(position); |
| 148 if (position < 0) { | 129 if (position < 0) { |
| 149 position = 0; | 130 position = 0; |
| 150 } | 131 } |
| 151 if (position + patLength < subLength) { | 132 if (position + patLength < subLength) { |
| 152 index = position | 133 index = position |
| 153 } | 134 } |
| 154 } | 135 } |
| 155 } | 136 } |
| 156 if (index < 0) { | 137 if (index < 0) { |
| 157 return -1; | 138 return -1; |
| 158 } | 139 } |
| 159 return %StringLastIndexOf(sub, pat, index); | 140 return %StringLastIndexOf(sub, pat, index); |
| 160 } | 141 } |
| 161 | 142 |
| 162 | 143 |
| 163 // ECMA-262 section 15.5.4.9 | 144 // ECMA-262 section 15.5.4.9 |
| 164 // | 145 // |
| 165 // This function is implementation specific. For now, we do not | 146 // This function is implementation specific. For now, we do not |
| 166 // do anything locale specific. | 147 // do anything locale specific. |
| 167 function StringLocaleCompare(other) { | 148 function StringLocaleCompare(other) { |
| 168 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 169 throw MakeTypeError("called_on_null_or_undefined", | |
| 170 ["String.prototype.localeCompare"]); | |
| 171 } | |
| 172 if (%_ArgumentsLength() === 0) return 0; | 149 if (%_ArgumentsLength() === 0) return 0; |
| 173 return %StringLocaleCompare(TO_STRING_INLINE(this), | 150 return %StringLocaleCompare(TO_STRING_INLINE(this), |
| 174 TO_STRING_INLINE(other)); | 151 TO_STRING_INLINE(other)); |
| 175 } | 152 } |
| 176 | 153 |
| 177 | 154 |
| 178 // ECMA-262 section 15.5.4.10 | 155 // ECMA-262 section 15.5.4.10 |
| 179 function StringMatch(regexp) { | 156 function StringMatch(regexp) { |
| 180 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 181 throw MakeTypeError("called_on_null_or_undefined", | |
| 182 ["String.prototype.match"]); | |
| 183 } | |
| 184 var subject = TO_STRING_INLINE(this); | 157 var subject = TO_STRING_INLINE(this); |
| 185 if (IS_REGEXP(regexp)) { | 158 if (IS_REGEXP(regexp)) { |
| 186 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0); | 159 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0); |
| 187 %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]); | 160 %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]); |
| 188 // lastMatchInfo is defined in regexp.js. | 161 // lastMatchInfo is defined in regexp.js. |
| 189 return %StringMatch(subject, regexp, lastMatchInfo); | 162 return %StringMatch(subject, regexp, lastMatchInfo); |
| 190 } | 163 } |
| 191 // Non-regexp argument. | 164 // Non-regexp argument. |
| 192 regexp = new $RegExp(regexp); | 165 regexp = new $RegExp(regexp); |
| 193 return RegExpExecNoTests(regexp, subject, 0); | 166 return RegExpExecNoTests(regexp, subject, 0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 207 // This has the same size as the lastMatchInfo array, and can be used for | 180 // This has the same size as the lastMatchInfo array, and can be used for |
| 208 // functions that expect that structure to be returned. It is used when the | 181 // functions that expect that structure to be returned. It is used when the |
| 209 // needle is a string rather than a regexp. In this case we can't update | 182 // needle is a string rather than a regexp. In this case we can't update |
| 210 // lastMatchArray without erroneously affecting the properties on the global | 183 // lastMatchArray without erroneously affecting the properties on the global |
| 211 // RegExp object. | 184 // RegExp object. |
| 212 var reusableMatchInfo = [2, "", "", -1, -1]; | 185 var reusableMatchInfo = [2, "", "", -1, -1]; |
| 213 | 186 |
| 214 | 187 |
| 215 // ECMA-262, section 15.5.4.11 | 188 // ECMA-262, section 15.5.4.11 |
| 216 function StringReplace(search, replace) { | 189 function StringReplace(search, replace) { |
| 217 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 218 throw MakeTypeError("called_on_null_or_undefined", | |
| 219 ["String.prototype.replace"]); | |
| 220 } | |
| 221 var subject = TO_STRING_INLINE(this); | 190 var subject = TO_STRING_INLINE(this); |
| 222 | 191 |
| 223 // Delegate to one of the regular expression variants if necessary. | 192 // Delegate to one of the regular expression variants if necessary. |
| 224 if (IS_REGEXP(search)) { | 193 if (IS_REGEXP(search)) { |
| 225 %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]); | 194 %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]); |
| 226 if (IS_FUNCTION(replace)) { | 195 if (IS_FUNCTION(replace)) { |
| 227 if (search.global) { | 196 if (search.global) { |
| 228 return StringReplaceGlobalRegExpWithFunction(subject, search, replace); | 197 return StringReplaceGlobalRegExpWithFunction(subject, search, replace); |
| 229 } else { | 198 } else { |
| 230 return StringReplaceNonGlobalRegExpWithFunction(subject, | 199 return StringReplaceNonGlobalRegExpWithFunction(subject, |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 result.add(replacement); // The add method converts to string if necessary. | 460 result.add(replacement); // The add method converts to string if necessary. |
| 492 // Can't use matchInfo any more from here, since the function could | 461 // Can't use matchInfo any more from here, since the function could |
| 493 // overwrite it. | 462 // overwrite it. |
| 494 result.addSpecialSlice(endOfMatch, subject.length); | 463 result.addSpecialSlice(endOfMatch, subject.length); |
| 495 return result.generate(); | 464 return result.generate(); |
| 496 } | 465 } |
| 497 | 466 |
| 498 | 467 |
| 499 // ECMA-262 section 15.5.4.12 | 468 // ECMA-262 section 15.5.4.12 |
| 500 function StringSearch(re) { | 469 function StringSearch(re) { |
| 501 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 502 throw MakeTypeError("called_on_null_or_undefined", | |
| 503 ["String.prototype.search"]); | |
| 504 } | |
| 505 var regexp; | 470 var regexp; |
| 506 if (IS_STRING(re)) { | 471 if (IS_STRING(re)) { |
| 507 regexp = %_GetFromCache(STRING_TO_REGEXP_CACHE_ID, re); | 472 regexp = %_GetFromCache(STRING_TO_REGEXP_CACHE_ID, re); |
| 508 } else if (IS_REGEXP(re)) { | 473 } else if (IS_REGEXP(re)) { |
| 509 regexp = re; | 474 regexp = re; |
| 510 } else { | 475 } else { |
| 511 regexp = new $RegExp(re); | 476 regexp = new $RegExp(re); |
| 512 } | 477 } |
| 513 var match = DoRegExpExec(regexp, TO_STRING_INLINE(this), 0); | 478 var match = DoRegExpExec(regexp, TO_STRING_INLINE(this), 0); |
| 514 if (match) { | 479 if (match) { |
| 515 return match[CAPTURE0]; | 480 return match[CAPTURE0]; |
| 516 } | 481 } |
| 517 return -1; | 482 return -1; |
| 518 } | 483 } |
| 519 | 484 |
| 520 | 485 |
| 521 // ECMA-262 section 15.5.4.13 | 486 // ECMA-262 section 15.5.4.13 |
| 522 function StringSlice(start, end) { | 487 function StringSlice(start, end) { |
| 523 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 524 throw MakeTypeError("called_on_null_or_undefined", | |
| 525 ["String.prototype.slice"]); | |
| 526 } | |
| 527 var s = TO_STRING_INLINE(this); | 488 var s = TO_STRING_INLINE(this); |
| 528 var s_len = s.length; | 489 var s_len = s.length; |
| 529 var start_i = TO_INTEGER(start); | 490 var start_i = TO_INTEGER(start); |
| 530 var end_i = s_len; | 491 var end_i = s_len; |
| 531 if (end !== void 0) | 492 if (end !== void 0) |
| 532 end_i = TO_INTEGER(end); | 493 end_i = TO_INTEGER(end); |
| 533 | 494 |
| 534 if (start_i < 0) { | 495 if (start_i < 0) { |
| 535 start_i += s_len; | 496 start_i += s_len; |
| 536 if (start_i < 0) | 497 if (start_i < 0) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 552 var num_c = end_i - start_i; | 513 var num_c = end_i - start_i; |
| 553 if (num_c < 0) | 514 if (num_c < 0) |
| 554 num_c = 0; | 515 num_c = 0; |
| 555 | 516 |
| 556 return SubString(s, start_i, start_i + num_c); | 517 return SubString(s, start_i, start_i + num_c); |
| 557 } | 518 } |
| 558 | 519 |
| 559 | 520 |
| 560 // ECMA-262 section 15.5.4.14 | 521 // ECMA-262 section 15.5.4.14 |
| 561 function StringSplit(separator, limit) { | 522 function StringSplit(separator, limit) { |
| 562 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 563 throw MakeTypeError("called_on_null_or_undefined", | |
| 564 ["String.prototype.split"]); | |
| 565 } | |
| 566 var subject = TO_STRING_INLINE(this); | 523 var subject = TO_STRING_INLINE(this); |
| 567 limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit); | 524 limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit); |
| 568 if (limit === 0) return []; | 525 if (limit === 0) return []; |
| 569 | 526 |
| 570 // ECMA-262 says that if separator is undefined, the result should | 527 // ECMA-262 says that if separator is undefined, the result should |
| 571 // be an array of size 1 containing the entire string. SpiderMonkey | 528 // be an array of size 1 containing the entire string. SpiderMonkey |
| 572 // and KJS have this behavior only when no separator is given. If | 529 // and KJS have this behavior only when no separator is given. If |
| 573 // undefined is explicitly given, they convert it to a string and | 530 // undefined is explicitly given, they convert it to a string and |
| 574 // use that. We do as SpiderMonkey and KJS. | 531 // use that. We do as SpiderMonkey and KJS. |
| 575 if (%_ArgumentsLength() === 0) { | 532 if (%_ArgumentsLength() === 0) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 } | 606 } |
| 650 | 607 |
| 651 startIndex = currentIndex = endIndex; | 608 startIndex = currentIndex = endIndex; |
| 652 } | 609 } |
| 653 return result; | 610 return result; |
| 654 } | 611 } |
| 655 | 612 |
| 656 | 613 |
| 657 // ECMA-262 section 15.5.4.15 | 614 // ECMA-262 section 15.5.4.15 |
| 658 function StringSubstring(start, end) { | 615 function StringSubstring(start, end) { |
| 659 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 660 throw MakeTypeError("called_on_null_or_undefined", | |
| 661 ["String.prototype.subString"]); | |
| 662 } | |
| 663 var s = TO_STRING_INLINE(this); | 616 var s = TO_STRING_INLINE(this); |
| 664 var s_len = s.length; | 617 var s_len = s.length; |
| 665 | 618 |
| 666 var start_i = TO_INTEGER(start); | 619 var start_i = TO_INTEGER(start); |
| 667 if (start_i < 0) { | 620 if (start_i < 0) { |
| 668 start_i = 0; | 621 start_i = 0; |
| 669 } else if (start_i > s_len) { | 622 } else if (start_i > s_len) { |
| 670 start_i = s_len; | 623 start_i = s_len; |
| 671 } | 624 } |
| 672 | 625 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 686 } | 639 } |
| 687 | 640 |
| 688 return (start_i + 1 == end_i | 641 return (start_i + 1 == end_i |
| 689 ? %_StringCharAt(s, start_i) | 642 ? %_StringCharAt(s, start_i) |
| 690 : %_SubString(s, start_i, end_i)); | 643 : %_SubString(s, start_i, end_i)); |
| 691 } | 644 } |
| 692 | 645 |
| 693 | 646 |
| 694 // This is not a part of ECMA-262. | 647 // This is not a part of ECMA-262. |
| 695 function StringSubstr(start, n) { | 648 function StringSubstr(start, n) { |
| 696 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 697 throw MakeTypeError("called_on_null_or_undefined", | |
| 698 ["String.prototype.substr"]); | |
| 699 } | |
| 700 var s = TO_STRING_INLINE(this); | 649 var s = TO_STRING_INLINE(this); |
| 701 var len; | 650 var len; |
| 702 | 651 |
| 703 // Correct n: If not given, set to string length; if explicitly | 652 // Correct n: If not given, set to string length; if explicitly |
| 704 // set to undefined, zero, or negative, returns empty string. | 653 // set to undefined, zero, or negative, returns empty string. |
| 705 if (n === void 0) { | 654 if (n === void 0) { |
| 706 len = s.length; | 655 len = s.length; |
| 707 } else { | 656 } else { |
| 708 len = TO_INTEGER(n); | 657 len = TO_INTEGER(n); |
| 709 if (len <= 0) return ''; | 658 if (len <= 0) return ''; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 730 if (end > s.length) end = s.length; | 679 if (end > s.length) end = s.length; |
| 731 | 680 |
| 732 return (start + 1 == end | 681 return (start + 1 == end |
| 733 ? %_StringCharAt(s, start) | 682 ? %_StringCharAt(s, start) |
| 734 : %_SubString(s, start, end)); | 683 : %_SubString(s, start, end)); |
| 735 } | 684 } |
| 736 | 685 |
| 737 | 686 |
| 738 // ECMA-262, 15.5.4.16 | 687 // ECMA-262, 15.5.4.16 |
| 739 function StringToLowerCase() { | 688 function StringToLowerCase() { |
| 740 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 741 throw MakeTypeError("called_on_null_or_undefined", | |
| 742 ["String.prototype.toLowerCase"]); | |
| 743 } | |
| 744 return %StringToLowerCase(TO_STRING_INLINE(this)); | 689 return %StringToLowerCase(TO_STRING_INLINE(this)); |
| 745 } | 690 } |
| 746 | 691 |
| 747 | 692 |
| 748 // ECMA-262, 15.5.4.17 | 693 // ECMA-262, 15.5.4.17 |
| 749 function StringToLocaleLowerCase() { | 694 function StringToLocaleLowerCase() { |
| 750 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 751 throw MakeTypeError("called_on_null_or_undefined", | |
| 752 ["String.prototype.toLocaleLowerCase"]); | |
| 753 } | |
| 754 return %StringToLowerCase(TO_STRING_INLINE(this)); | 695 return %StringToLowerCase(TO_STRING_INLINE(this)); |
| 755 } | 696 } |
| 756 | 697 |
| 757 | 698 |
| 758 // ECMA-262, 15.5.4.18 | 699 // ECMA-262, 15.5.4.18 |
| 759 function StringToUpperCase() { | 700 function StringToUpperCase() { |
| 760 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 761 throw MakeTypeError("called_on_null_or_undefined", | |
| 762 ["String.prototype.toUpperCase"]); | |
| 763 } | |
| 764 return %StringToUpperCase(TO_STRING_INLINE(this)); | 701 return %StringToUpperCase(TO_STRING_INLINE(this)); |
| 765 } | 702 } |
| 766 | 703 |
| 767 | 704 |
| 768 // ECMA-262, 15.5.4.19 | 705 // ECMA-262, 15.5.4.19 |
| 769 function StringToLocaleUpperCase() { | 706 function StringToLocaleUpperCase() { |
| 770 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 771 throw MakeTypeError("called_on_null_or_undefined", | |
| 772 ["String.prototype.toLocaleUpperCase"]); | |
| 773 } | |
| 774 return %StringToUpperCase(TO_STRING_INLINE(this)); | 707 return %StringToUpperCase(TO_STRING_INLINE(this)); |
| 775 } | 708 } |
| 776 | 709 |
| 777 // ES5, 15.5.4.20 | 710 // ES5, 15.5.4.20 |
| 778 function StringTrim() { | 711 function StringTrim() { |
| 779 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 780 throw MakeTypeError("called_on_null_or_undefined", | |
| 781 ["String.prototype.trim"]); | |
| 782 } | |
| 783 return %StringTrim(TO_STRING_INLINE(this), true, true); | 712 return %StringTrim(TO_STRING_INLINE(this), true, true); |
| 784 } | 713 } |
| 785 | 714 |
| 786 function StringTrimLeft() { | 715 function StringTrimLeft() { |
| 787 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 788 throw MakeTypeError("called_on_null_or_undefined", | |
| 789 ["String.prototype.trimLeft"]); | |
| 790 } | |
| 791 return %StringTrim(TO_STRING_INLINE(this), true, false); | 716 return %StringTrim(TO_STRING_INLINE(this), true, false); |
| 792 } | 717 } |
| 793 | 718 |
| 794 function StringTrimRight() { | 719 function StringTrimRight() { |
| 795 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | |
| 796 throw MakeTypeError("called_on_null_or_undefined", | |
| 797 ["String.prototype.trimRight"]); | |
| 798 } | |
| 799 return %StringTrim(TO_STRING_INLINE(this), false, true); | 720 return %StringTrim(TO_STRING_INLINE(this), false, true); |
| 800 } | 721 } |
| 801 | 722 |
| 802 var static_charcode_array = new InternalArray(4); | 723 var static_charcode_array = new InternalArray(4); |
| 803 | 724 |
| 804 // ECMA-262, section 15.5.3.2 | 725 // ECMA-262, section 15.5.3.2 |
| 805 function StringFromCharCode(code) { | 726 function StringFromCharCode(code) { |
| 806 var n = %_ArgumentsLength(); | 727 var n = %_ArgumentsLength(); |
| 807 if (n == 1) { | 728 if (n == 1) { |
| 808 if (!%_IsSmi(code)) code = ToNumber(code); | 729 if (!%_IsSmi(code)) code = ToNumber(code); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 "italics", StringItalics, | 906 "italics", StringItalics, |
| 986 "small", StringSmall, | 907 "small", StringSmall, |
| 987 "strike", StringStrike, | 908 "strike", StringStrike, |
| 988 "sub", StringSub, | 909 "sub", StringSub, |
| 989 "sup", StringSup | 910 "sup", StringSup |
| 990 )); | 911 )); |
| 991 } | 912 } |
| 992 | 913 |
| 993 | 914 |
| 994 SetupString(); | 915 SetupString(); |
| OLD | NEW |