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