| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 function StringValueOf() { | 54 function StringValueOf() { |
| 55 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) { | 55 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) { |
| 56 throw new $TypeError('String.prototype.valueOf is not generic'); | 56 throw new $TypeError('String.prototype.valueOf is not generic'); |
| 57 } | 57 } |
| 58 return %_ValueOf(this); | 58 return %_ValueOf(this); |
| 59 } | 59 } |
| 60 | 60 |
| 61 | 61 |
| 62 // ECMA-262, section 15.5.4.4 | 62 // ECMA-262, section 15.5.4.4 |
| 63 function StringCharAt(pos) { | 63 function StringCharAt(pos) { |
| 64 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 64 CHECK_OBJECT_COERCIBLE(this, "String.prototype.charAt"); |
| 65 throw MakeTypeError("called_on_null_or_undefined", | 65 |
| 66 ["String.prototype.charAt"]); | |
| 67 } | |
| 68 var result = %_StringCharAt(this, pos); | 66 var result = %_StringCharAt(this, pos); |
| 69 if (%_IsSmi(result)) { | 67 if (%_IsSmi(result)) { |
| 70 result = %_StringCharAt(TO_STRING_INLINE(this), TO_INTEGER(pos)); | 68 result = %_StringCharAt(TO_STRING_INLINE(this), TO_INTEGER(pos)); |
| 71 } | 69 } |
| 72 return result; | 70 return result; |
| 73 } | 71 } |
| 74 | 72 |
| 75 | 73 |
| 76 // ECMA-262 section 15.5.4.5 | 74 // ECMA-262 section 15.5.4.5 |
| 77 function StringCharCodeAt(pos) { | 75 function StringCharCodeAt(pos) { |
| 78 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 76 CHECK_OBJECT_COERCIBLE(this, "String.prototype.charCodeAt"); |
| 79 throw MakeTypeError("called_on_null_or_undefined", | 77 |
| 80 ["String.prototype.charCodeAt"]); | |
| 81 } | |
| 82 var result = %_StringCharCodeAt(this, pos); | 78 var result = %_StringCharCodeAt(this, pos); |
| 83 if (!%_IsSmi(result)) { | 79 if (!%_IsSmi(result)) { |
| 84 result = %_StringCharCodeAt(TO_STRING_INLINE(this), TO_INTEGER(pos)); | 80 result = %_StringCharCodeAt(TO_STRING_INLINE(this), TO_INTEGER(pos)); |
| 85 } | 81 } |
| 86 return result; | 82 return result; |
| 87 } | 83 } |
| 88 | 84 |
| 89 | 85 |
| 90 // ECMA-262, section 15.5.4.6 | 86 // ECMA-262, section 15.5.4.6 |
| 91 function StringConcat() { | 87 function StringConcat() { |
| 92 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 88 CHECK_OBJECT_COERCIBLE(this, "String.prototype.concat"); |
| 93 throw MakeTypeError("called_on_null_or_undefined", | 89 |
| 94 ["String.prototype.concat"]); | |
| 95 } | |
| 96 var len = %_ArgumentsLength(); | 90 var len = %_ArgumentsLength(); |
| 97 var this_as_string = TO_STRING_INLINE(this); | 91 var this_as_string = TO_STRING_INLINE(this); |
| 98 if (len === 1) { | 92 if (len === 1) { |
| 99 return this_as_string + %_Arguments(0); | 93 return this_as_string + %_Arguments(0); |
| 100 } | 94 } |
| 101 var parts = new InternalArray(len + 1); | 95 var parts = new InternalArray(len + 1); |
| 102 parts[0] = this_as_string; | 96 parts[0] = this_as_string; |
| 103 for (var i = 0; i < len; i++) { | 97 for (var i = 0; i < len; i++) { |
| 104 var part = %_Arguments(i); | 98 var part = %_Arguments(i); |
| 105 parts[i + 1] = TO_STRING_INLINE(part); | 99 parts[i + 1] = TO_STRING_INLINE(part); |
| 106 } | 100 } |
| 107 return %StringBuilderConcat(parts, len + 1, ""); | 101 return %StringBuilderConcat(parts, len + 1, ""); |
| 108 } | 102 } |
| 109 | 103 |
| 110 // Match ES3 and Safari | 104 // Match ES3 and Safari |
| 111 %FunctionSetLength(StringConcat, 1); | 105 %FunctionSetLength(StringConcat, 1); |
| 112 | 106 |
| 113 | 107 |
| 114 // ECMA-262 section 15.5.4.7 | 108 // ECMA-262 section 15.5.4.7 |
| 115 function StringIndexOf(pattern /* position */) { // length == 1 | 109 function StringIndexOf(pattern /* position */) { // length == 1 |
| 116 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 110 CHECK_OBJECT_COERCIBLE(this, "String.prototype.indexOf"); |
| 117 throw MakeTypeError("called_on_null_or_undefined", | 111 |
| 118 ["String.prototype.indexOf"]); | |
| 119 } | |
| 120 var subject = TO_STRING_INLINE(this); | 112 var subject = TO_STRING_INLINE(this); |
| 121 pattern = TO_STRING_INLINE(pattern); | 113 pattern = TO_STRING_INLINE(pattern); |
| 122 var index = 0; | 114 var index = 0; |
| 123 if (%_ArgumentsLength() > 1) { | 115 if (%_ArgumentsLength() > 1) { |
| 124 index = %_Arguments(1); // position | 116 index = %_Arguments(1); // position |
| 125 index = TO_INTEGER(index); | 117 index = TO_INTEGER(index); |
| 126 if (index < 0) index = 0; | 118 if (index < 0) index = 0; |
| 127 if (index > subject.length) index = subject.length; | 119 if (index > subject.length) index = subject.length; |
| 128 } | 120 } |
| 129 return %StringIndexOf(subject, pattern, index); | 121 return %StringIndexOf(subject, pattern, index); |
| 130 } | 122 } |
| 131 | 123 |
| 132 | 124 |
| 133 // ECMA-262 section 15.5.4.8 | 125 // ECMA-262 section 15.5.4.8 |
| 134 function StringLastIndexOf(pat /* position */) { // length == 1 | 126 function StringLastIndexOf(pat /* position */) { // length == 1 |
| 135 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 127 CHECK_OBJECT_COERCIBLE(this, "String.prototype.lastIndexOf"); |
| 136 throw MakeTypeError("called_on_null_or_undefined", | 128 |
| 137 ["String.prototype.lastIndexOf"]); | |
| 138 } | |
| 139 var sub = TO_STRING_INLINE(this); | 129 var sub = TO_STRING_INLINE(this); |
| 140 var subLength = sub.length; | 130 var subLength = sub.length; |
| 141 var pat = TO_STRING_INLINE(pat); | 131 var pat = TO_STRING_INLINE(pat); |
| 142 var patLength = pat.length; | 132 var patLength = pat.length; |
| 143 var index = subLength - patLength; | 133 var index = subLength - patLength; |
| 144 if (%_ArgumentsLength() > 1) { | 134 if (%_ArgumentsLength() > 1) { |
| 145 var position = ToNumber(%_Arguments(1)); | 135 var position = ToNumber(%_Arguments(1)); |
| 146 if (!NUMBER_IS_NAN(position)) { | 136 if (!NUMBER_IS_NAN(position)) { |
| 147 position = TO_INTEGER(position); | 137 position = TO_INTEGER(position); |
| 148 if (position < 0) { | 138 if (position < 0) { |
| 149 position = 0; | 139 position = 0; |
| 150 } | 140 } |
| 151 if (position + patLength < subLength) { | 141 if (position + patLength < subLength) { |
| 152 index = position; | 142 index = position; |
| 153 } | 143 } |
| 154 } | 144 } |
| 155 } | 145 } |
| 156 if (index < 0) { | 146 if (index < 0) { |
| 157 return -1; | 147 return -1; |
| 158 } | 148 } |
| 159 return %StringLastIndexOf(sub, pat, index); | 149 return %StringLastIndexOf(sub, pat, index); |
| 160 } | 150 } |
| 161 | 151 |
| 162 | 152 |
| 163 // ECMA-262 section 15.5.4.9 | 153 // ECMA-262 section 15.5.4.9 |
| 164 // | 154 // |
| 165 // This function is implementation specific. For now, we do not | 155 // This function is implementation specific. For now, we do not |
| 166 // do anything locale specific. | 156 // do anything locale specific. |
| 167 function StringLocaleCompare(other) { | 157 function StringLocaleCompare(other) { |
| 168 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 158 CHECK_OBJECT_COERCIBLE(this, "String.prototype.localeCompare"); |
| 169 throw MakeTypeError("called_on_null_or_undefined", | 159 |
| 170 ["String.prototype.localeCompare"]); | |
| 171 } | |
| 172 return %StringLocaleCompare(TO_STRING_INLINE(this), | 160 return %StringLocaleCompare(TO_STRING_INLINE(this), |
| 173 TO_STRING_INLINE(other)); | 161 TO_STRING_INLINE(other)); |
| 174 } | 162 } |
| 175 | 163 |
| 176 | 164 |
| 177 // ECMA-262 section 15.5.4.10 | 165 // ECMA-262 section 15.5.4.10 |
| 178 function StringMatch(regexp) { | 166 function StringMatch(regexp) { |
| 179 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 167 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); |
| 180 throw MakeTypeError("called_on_null_or_undefined", | 168 |
| 181 ["String.prototype.match"]); | |
| 182 } | |
| 183 var subject = TO_STRING_INLINE(this); | 169 var subject = TO_STRING_INLINE(this); |
| 184 if (IS_REGEXP(regexp)) { | 170 if (IS_REGEXP(regexp)) { |
| 185 // Emulate RegExp.prototype.exec's side effect in step 5, even though | 171 // Emulate RegExp.prototype.exec's side effect in step 5, even though |
| 186 // value is discarded. | 172 // value is discarded. |
| 187 var lastIndex = regexp.lastIndex; | 173 var lastIndex = regexp.lastIndex; |
| 188 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex); | 174 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex); |
| 189 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0); | 175 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0); |
| 190 %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]); | 176 %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]); |
| 191 // lastMatchInfo is defined in regexp.js. | 177 // lastMatchInfo is defined in regexp.js. |
| 192 var result = %StringMatch(subject, regexp, lastMatchInfo); | 178 var result = %StringMatch(subject, regexp, lastMatchInfo); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 203 // This has the same size as the lastMatchInfo array, and can be used for | 189 // This has the same size as the lastMatchInfo array, and can be used for |
| 204 // functions that expect that structure to be returned. It is used when the | 190 // functions that expect that structure to be returned. It is used when the |
| 205 // needle is a string rather than a regexp. In this case we can't update | 191 // needle is a string rather than a regexp. In this case we can't update |
| 206 // lastMatchArray without erroneously affecting the properties on the global | 192 // lastMatchArray without erroneously affecting the properties on the global |
| 207 // RegExp object. | 193 // RegExp object. |
| 208 var reusableMatchInfo = [2, "", "", -1, -1]; | 194 var reusableMatchInfo = [2, "", "", -1, -1]; |
| 209 | 195 |
| 210 | 196 |
| 211 // ECMA-262, section 15.5.4.11 | 197 // ECMA-262, section 15.5.4.11 |
| 212 function StringReplace(search, replace) { | 198 function StringReplace(search, replace) { |
| 213 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 199 CHECK_OBJECT_COERCIBLE(this, "String.prototype.replace"); |
| 214 throw MakeTypeError("called_on_null_or_undefined", | 200 |
| 215 ["String.prototype.replace"]); | |
| 216 } | |
| 217 var subject = TO_STRING_INLINE(this); | 201 var subject = TO_STRING_INLINE(this); |
| 218 | 202 |
| 219 // Decision tree for dispatch | 203 // Decision tree for dispatch |
| 220 // .. regexp search | 204 // .. regexp search |
| 221 // .... string replace | 205 // .... string replace |
| 222 // ...... non-global search | 206 // ...... non-global search |
| 223 // ........ empty string replace | 207 // ........ empty string replace |
| 224 // ........ non-empty string replace (with $-expansion) | 208 // ........ non-empty string replace (with $-expansion) |
| 225 // ...... global search | 209 // ...... global search |
| 226 // ........ no need to circumvent last match info override | 210 // ........ no need to circumvent last match info override |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 | 520 |
| 537 result += replacement; // The add method converts to string if necessary. | 521 result += replacement; // The add method converts to string if necessary. |
| 538 // Can't use matchInfo any more from here, since the function could | 522 // Can't use matchInfo any more from here, since the function could |
| 539 // overwrite it. | 523 // overwrite it. |
| 540 return result + %_SubString(subject, endOfMatch, subject.length); | 524 return result + %_SubString(subject, endOfMatch, subject.length); |
| 541 } | 525 } |
| 542 | 526 |
| 543 | 527 |
| 544 // ECMA-262 section 15.5.4.12 | 528 // ECMA-262 section 15.5.4.12 |
| 545 function StringSearch(re) { | 529 function StringSearch(re) { |
| 546 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 530 CHECK_OBJECT_COERCIBLE(this, "String.prototype.search"); |
| 547 throw MakeTypeError("called_on_null_or_undefined", | 531 |
| 548 ["String.prototype.search"]); | |
| 549 } | |
| 550 var regexp; | 532 var regexp; |
| 551 if (IS_STRING(re)) { | 533 if (IS_STRING(re)) { |
| 552 regexp = %_GetFromCache(STRING_TO_REGEXP_CACHE_ID, re); | 534 regexp = %_GetFromCache(STRING_TO_REGEXP_CACHE_ID, re); |
| 553 } else if (IS_REGEXP(re)) { | 535 } else if (IS_REGEXP(re)) { |
| 554 regexp = re; | 536 regexp = re; |
| 555 } else { | 537 } else { |
| 556 regexp = new $RegExp(re); | 538 regexp = new $RegExp(re); |
| 557 } | 539 } |
| 558 var match = DoRegExpExec(regexp, TO_STRING_INLINE(this), 0); | 540 var match = DoRegExpExec(regexp, TO_STRING_INLINE(this), 0); |
| 559 if (match) { | 541 if (match) { |
| 560 return match[CAPTURE0]; | 542 return match[CAPTURE0]; |
| 561 } | 543 } |
| 562 return -1; | 544 return -1; |
| 563 } | 545 } |
| 564 | 546 |
| 565 | 547 |
| 566 // ECMA-262 section 15.5.4.13 | 548 // ECMA-262 section 15.5.4.13 |
| 567 function StringSlice(start, end) { | 549 function StringSlice(start, end) { |
| 568 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 550 CHECK_OBJECT_COERCIBLE(this, "String.prototype.slice"); |
| 569 throw MakeTypeError("called_on_null_or_undefined", | 551 |
| 570 ["String.prototype.slice"]); | |
| 571 } | |
| 572 var s = TO_STRING_INLINE(this); | 552 var s = TO_STRING_INLINE(this); |
| 573 var s_len = s.length; | 553 var s_len = s.length; |
| 574 var start_i = TO_INTEGER(start); | 554 var start_i = TO_INTEGER(start); |
| 575 var end_i = s_len; | 555 var end_i = s_len; |
| 576 if (!IS_UNDEFINED(end)) { | 556 if (!IS_UNDEFINED(end)) { |
| 577 end_i = TO_INTEGER(end); | 557 end_i = TO_INTEGER(end); |
| 578 } | 558 } |
| 579 | 559 |
| 580 if (start_i < 0) { | 560 if (start_i < 0) { |
| 581 start_i += s_len; | 561 start_i += s_len; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 602 if (end_i <= start_i) { | 582 if (end_i <= start_i) { |
| 603 return ''; | 583 return ''; |
| 604 } | 584 } |
| 605 | 585 |
| 606 return %_SubString(s, start_i, end_i); | 586 return %_SubString(s, start_i, end_i); |
| 607 } | 587 } |
| 608 | 588 |
| 609 | 589 |
| 610 // ECMA-262 section 15.5.4.14 | 590 // ECMA-262 section 15.5.4.14 |
| 611 function StringSplit(separator, limit) { | 591 function StringSplit(separator, limit) { |
| 612 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 592 CHECK_OBJECT_COERCIBLE(this, "String.prototype.split"); |
| 613 throw MakeTypeError("called_on_null_or_undefined", | 593 |
| 614 ["String.prototype.split"]); | |
| 615 } | |
| 616 var subject = TO_STRING_INLINE(this); | 594 var subject = TO_STRING_INLINE(this); |
| 617 limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit); | 595 limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit); |
| 618 | 596 |
| 619 var length = subject.length; | 597 var length = subject.length; |
| 620 if (!IS_REGEXP(separator)) { | 598 if (!IS_REGEXP(separator)) { |
| 621 var separator_string = TO_STRING_INLINE(separator); | 599 var separator_string = TO_STRING_INLINE(separator); |
| 622 | 600 |
| 623 if (limit === 0) return []; | 601 if (limit === 0) return []; |
| 624 | 602 |
| 625 // ECMA-262 says that if separator is undefined, the result should | 603 // ECMA-262 says that if separator is undefined, the result should |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 } | 680 } |
| 703 | 681 |
| 704 startIndex = currentIndex = endIndex; | 682 startIndex = currentIndex = endIndex; |
| 705 } | 683 } |
| 706 return result; | 684 return result; |
| 707 } | 685 } |
| 708 | 686 |
| 709 | 687 |
| 710 // ECMA-262 section 15.5.4.15 | 688 // ECMA-262 section 15.5.4.15 |
| 711 function StringSubstring(start, end) { | 689 function StringSubstring(start, end) { |
| 712 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 690 CHECK_OBJECT_COERCIBLE(this, "String.prototype.subString"); |
| 713 throw MakeTypeError("called_on_null_or_undefined", | 691 |
| 714 ["String.prototype.subString"]); | |
| 715 } | |
| 716 var s = TO_STRING_INLINE(this); | 692 var s = TO_STRING_INLINE(this); |
| 717 var s_len = s.length; | 693 var s_len = s.length; |
| 718 | 694 |
| 719 var start_i = TO_INTEGER(start); | 695 var start_i = TO_INTEGER(start); |
| 720 if (start_i < 0) { | 696 if (start_i < 0) { |
| 721 start_i = 0; | 697 start_i = 0; |
| 722 } else if (start_i > s_len) { | 698 } else if (start_i > s_len) { |
| 723 start_i = s_len; | 699 start_i = s_len; |
| 724 } | 700 } |
| 725 | 701 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 737 } | 713 } |
| 738 } | 714 } |
| 739 } | 715 } |
| 740 | 716 |
| 741 return %_SubString(s, start_i, end_i); | 717 return %_SubString(s, start_i, end_i); |
| 742 } | 718 } |
| 743 | 719 |
| 744 | 720 |
| 745 // This is not a part of ECMA-262. | 721 // This is not a part of ECMA-262. |
| 746 function StringSubstr(start, n) { | 722 function StringSubstr(start, n) { |
| 747 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 723 CHECK_OBJECT_COERCIBLE(this, "String.prototype.substr"); |
| 748 throw MakeTypeError("called_on_null_or_undefined", | 724 |
| 749 ["String.prototype.substr"]); | |
| 750 } | |
| 751 var s = TO_STRING_INLINE(this); | 725 var s = TO_STRING_INLINE(this); |
| 752 var len; | 726 var len; |
| 753 | 727 |
| 754 // Correct n: If not given, set to string length; if explicitly | 728 // Correct n: If not given, set to string length; if explicitly |
| 755 // set to undefined, zero, or negative, returns empty string. | 729 // set to undefined, zero, or negative, returns empty string. |
| 756 if (IS_UNDEFINED(n)) { | 730 if (IS_UNDEFINED(n)) { |
| 757 len = s.length; | 731 len = s.length; |
| 758 } else { | 732 } else { |
| 759 len = TO_INTEGER(n); | 733 len = TO_INTEGER(n); |
| 760 if (len <= 0) return ''; | 734 if (len <= 0) return ''; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 779 | 753 |
| 780 var end = start + len; | 754 var end = start + len; |
| 781 if (end > s.length) end = s.length; | 755 if (end > s.length) end = s.length; |
| 782 | 756 |
| 783 return %_SubString(s, start, end); | 757 return %_SubString(s, start, end); |
| 784 } | 758 } |
| 785 | 759 |
| 786 | 760 |
| 787 // ECMA-262, 15.5.4.16 | 761 // ECMA-262, 15.5.4.16 |
| 788 function StringToLowerCase() { | 762 function StringToLowerCase() { |
| 789 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 763 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase"); |
| 790 throw MakeTypeError("called_on_null_or_undefined", | 764 |
| 791 ["String.prototype.toLowerCase"]); | |
| 792 } | |
| 793 return %StringToLowerCase(TO_STRING_INLINE(this)); | 765 return %StringToLowerCase(TO_STRING_INLINE(this)); |
| 794 } | 766 } |
| 795 | 767 |
| 796 | 768 |
| 797 // ECMA-262, 15.5.4.17 | 769 // ECMA-262, 15.5.4.17 |
| 798 function StringToLocaleLowerCase() { | 770 function StringToLocaleLowerCase() { |
| 799 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 771 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleLowerCase"); |
| 800 throw MakeTypeError("called_on_null_or_undefined", | 772 |
| 801 ["String.prototype.toLocaleLowerCase"]); | |
| 802 } | |
| 803 return %StringToLowerCase(TO_STRING_INLINE(this)); | 773 return %StringToLowerCase(TO_STRING_INLINE(this)); |
| 804 } | 774 } |
| 805 | 775 |
| 806 | 776 |
| 807 // ECMA-262, 15.5.4.18 | 777 // ECMA-262, 15.5.4.18 |
| 808 function StringToUpperCase() { | 778 function StringToUpperCase() { |
| 809 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 779 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toUpperCase"); |
| 810 throw MakeTypeError("called_on_null_or_undefined", | 780 |
| 811 ["String.prototype.toUpperCase"]); | |
| 812 } | |
| 813 return %StringToUpperCase(TO_STRING_INLINE(this)); | 781 return %StringToUpperCase(TO_STRING_INLINE(this)); |
| 814 } | 782 } |
| 815 | 783 |
| 816 | 784 |
| 817 // ECMA-262, 15.5.4.19 | 785 // ECMA-262, 15.5.4.19 |
| 818 function StringToLocaleUpperCase() { | 786 function StringToLocaleUpperCase() { |
| 819 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 787 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleUpperCase"); |
| 820 throw MakeTypeError("called_on_null_or_undefined", | 788 |
| 821 ["String.prototype.toLocaleUpperCase"]); | |
| 822 } | |
| 823 return %StringToUpperCase(TO_STRING_INLINE(this)); | 789 return %StringToUpperCase(TO_STRING_INLINE(this)); |
| 824 } | 790 } |
| 825 | 791 |
| 826 // ES5, 15.5.4.20 | 792 // ES5, 15.5.4.20 |
| 827 function StringTrim() { | 793 function StringTrim() { |
| 828 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 794 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trim"); |
| 829 throw MakeTypeError("called_on_null_or_undefined", | 795 |
| 830 ["String.prototype.trim"]); | |
| 831 } | |
| 832 return %StringTrim(TO_STRING_INLINE(this), true, true); | 796 return %StringTrim(TO_STRING_INLINE(this), true, true); |
| 833 } | 797 } |
| 834 | 798 |
| 835 function StringTrimLeft() { | 799 function StringTrimLeft() { |
| 836 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 800 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trimLeft"); |
| 837 throw MakeTypeError("called_on_null_or_undefined", | 801 |
| 838 ["String.prototype.trimLeft"]); | |
| 839 } | |
| 840 return %StringTrim(TO_STRING_INLINE(this), true, false); | 802 return %StringTrim(TO_STRING_INLINE(this), true, false); |
| 841 } | 803 } |
| 842 | 804 |
| 843 function StringTrimRight() { | 805 function StringTrimRight() { |
| 844 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 806 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trimRight"); |
| 845 throw MakeTypeError("called_on_null_or_undefined", | 807 |
| 846 ["String.prototype.trimRight"]); | |
| 847 } | |
| 848 return %StringTrim(TO_STRING_INLINE(this), false, true); | 808 return %StringTrim(TO_STRING_INLINE(this), false, true); |
| 849 } | 809 } |
| 850 | 810 |
| 851 | 811 |
| 852 // ECMA-262, section 15.5.3.2 | 812 // ECMA-262, section 15.5.3.2 |
| 853 function StringFromCharCode(code) { | 813 function StringFromCharCode(code) { |
| 854 var n = %_ArgumentsLength(); | 814 var n = %_ArgumentsLength(); |
| 855 if (n == 1) { | 815 if (n == 1) { |
| 856 if (!%_IsSmi(code)) code = ToNumber(code); | 816 if (!%_IsSmi(code)) code = ToNumber(code); |
| 857 return %_StringCharFromCode(code & 0xffff); | 817 return %_StringCharFromCode(code & 0xffff); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 "fixed", StringFixed, | 965 "fixed", StringFixed, |
| 1006 "italics", StringItalics, | 966 "italics", StringItalics, |
| 1007 "small", StringSmall, | 967 "small", StringSmall, |
| 1008 "strike", StringStrike, | 968 "strike", StringStrike, |
| 1009 "sub", StringSub, | 969 "sub", StringSub, |
| 1010 "sup", StringSup | 970 "sup", StringSup |
| 1011 )); | 971 )); |
| 1012 } | 972 } |
| 1013 | 973 |
| 1014 SetUpString(); | 974 SetUpString(); |
| OLD | NEW |