Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1841)

Side by Side Diff: src/string.js

Issue 185653004: Experimental parser: merge to r19637 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/spaces-inl.h ('k') | src/stub-cache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
193 if (result !== null) lastMatchInfoOverride = null; 179 if (result !== null) lastMatchInfoOverride = null;
194 regexp.lastIndex = 0; 180 regexp.lastIndex = 0;
195 return result; 181 return result;
196 } 182 }
197 // Non-regexp argument. 183 // Non-regexp argument.
198 regexp = new $RegExp(regexp); 184 regexp = new $RegExp(regexp);
199 return RegExpExecNoTests(regexp, subject, 0); 185 return RegExpExecNoTests(regexp, subject, 0);
200 } 186 }
201 187
202 188
189 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD'];
190
191
192 // ECMA-262 v6, section 21.1.3.12
193 //
194 // For now we do nothing, as proper normalization requires big tables.
195 // If Intl is enabled, then i18n.js will override it and provide the the
196 // proper functionality.
197 function StringNormalize(form) {
198 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
199
200 var form = form ? TO_STRING_INLINE(form) : 'NFC';
201 var normalizationForm = NORMALIZATION_FORMS.indexOf(form);
202 if (normalizationForm === -1) {
203 throw new $RangeError('The normalization form should be one of '
204 + NORMALIZATION_FORMS.join(', ') + '.');
205 }
206
207 return %_ValueOf(this);
208 }
209
210
203 // This has the same size as the lastMatchInfo array, and can be used for 211 // 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 212 // 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 213 // 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 214 // lastMatchArray without erroneously affecting the properties on the global
207 // RegExp object. 215 // RegExp object.
208 var reusableMatchInfo = [2, "", "", -1, -1]; 216 var reusableMatchInfo = [2, "", "", -1, -1];
209 217
210 218
211 // ECMA-262, section 15.5.4.11 219 // ECMA-262, section 15.5.4.11
212 function StringReplace(search, replace) { 220 function StringReplace(search, replace) {
213 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 221 CHECK_OBJECT_COERCIBLE(this, "String.prototype.replace");
214 throw MakeTypeError("called_on_null_or_undefined", 222
215 ["String.prototype.replace"]);
216 }
217 var subject = TO_STRING_INLINE(this); 223 var subject = TO_STRING_INLINE(this);
218 224
219 // Decision tree for dispatch 225 // Decision tree for dispatch
220 // .. regexp search 226 // .. regexp search
221 // .... string replace 227 // .... string replace
222 // ...... non-global search 228 // ...... non-global search
223 // ........ empty string replace 229 // ........ empty string replace
224 // ........ non-empty string replace (with $-expansion) 230 // ........ non-empty string replace (with $-expansion)
225 // ...... global search 231 // ...... global search
226 // ........ no need to circumvent last match info override 232 // ........ no need to circumvent last match info override
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 542
537 result += replacement; // The add method converts to string if necessary. 543 result += replacement; // The add method converts to string if necessary.
538 // Can't use matchInfo any more from here, since the function could 544 // Can't use matchInfo any more from here, since the function could
539 // overwrite it. 545 // overwrite it.
540 return result + %_SubString(subject, endOfMatch, subject.length); 546 return result + %_SubString(subject, endOfMatch, subject.length);
541 } 547 }
542 548
543 549
544 // ECMA-262 section 15.5.4.12 550 // ECMA-262 section 15.5.4.12
545 function StringSearch(re) { 551 function StringSearch(re) {
546 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 552 CHECK_OBJECT_COERCIBLE(this, "String.prototype.search");
547 throw MakeTypeError("called_on_null_or_undefined", 553
548 ["String.prototype.search"]);
549 }
550 var regexp; 554 var regexp;
551 if (IS_STRING(re)) { 555 if (IS_STRING(re)) {
552 regexp = %_GetFromCache(STRING_TO_REGEXP_CACHE_ID, re); 556 regexp = %_GetFromCache(STRING_TO_REGEXP_CACHE_ID, re);
553 } else if (IS_REGEXP(re)) { 557 } else if (IS_REGEXP(re)) {
554 regexp = re; 558 regexp = re;
555 } else { 559 } else {
556 regexp = new $RegExp(re); 560 regexp = new $RegExp(re);
557 } 561 }
558 var match = DoRegExpExec(regexp, TO_STRING_INLINE(this), 0); 562 var match = DoRegExpExec(regexp, TO_STRING_INLINE(this), 0);
559 if (match) { 563 if (match) {
560 return match[CAPTURE0]; 564 return match[CAPTURE0];
561 } 565 }
562 return -1; 566 return -1;
563 } 567 }
564 568
565 569
566 // ECMA-262 section 15.5.4.13 570 // ECMA-262 section 15.5.4.13
567 function StringSlice(start, end) { 571 function StringSlice(start, end) {
568 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 572 CHECK_OBJECT_COERCIBLE(this, "String.prototype.slice");
569 throw MakeTypeError("called_on_null_or_undefined", 573
570 ["String.prototype.slice"]);
571 }
572 var s = TO_STRING_INLINE(this); 574 var s = TO_STRING_INLINE(this);
573 var s_len = s.length; 575 var s_len = s.length;
574 var start_i = TO_INTEGER(start); 576 var start_i = TO_INTEGER(start);
575 var end_i = s_len; 577 var end_i = s_len;
576 if (!IS_UNDEFINED(end)) { 578 if (!IS_UNDEFINED(end)) {
577 end_i = TO_INTEGER(end); 579 end_i = TO_INTEGER(end);
578 } 580 }
579 581
580 if (start_i < 0) { 582 if (start_i < 0) {
581 start_i += s_len; 583 start_i += s_len;
(...skipping 20 matching lines...) Expand all
602 if (end_i <= start_i) { 604 if (end_i <= start_i) {
603 return ''; 605 return '';
604 } 606 }
605 607
606 return %_SubString(s, start_i, end_i); 608 return %_SubString(s, start_i, end_i);
607 } 609 }
608 610
609 611
610 // ECMA-262 section 15.5.4.14 612 // ECMA-262 section 15.5.4.14
611 function StringSplit(separator, limit) { 613 function StringSplit(separator, limit) {
612 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 614 CHECK_OBJECT_COERCIBLE(this, "String.prototype.split");
613 throw MakeTypeError("called_on_null_or_undefined", 615
614 ["String.prototype.split"]);
615 }
616 var subject = TO_STRING_INLINE(this); 616 var subject = TO_STRING_INLINE(this);
617 limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit); 617 limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit);
618 618
619 var length = subject.length; 619 var length = subject.length;
620 if (!IS_REGEXP(separator)) { 620 if (!IS_REGEXP(separator)) {
621 var separator_string = TO_STRING_INLINE(separator); 621 var separator_string = TO_STRING_INLINE(separator);
622 622
623 if (limit === 0) return []; 623 if (limit === 0) return [];
624 624
625 // ECMA-262 says that if separator is undefined, the result should 625 // ECMA-262 says that if separator is undefined, the result should
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 } 702 }
703 703
704 startIndex = currentIndex = endIndex; 704 startIndex = currentIndex = endIndex;
705 } 705 }
706 return result; 706 return result;
707 } 707 }
708 708
709 709
710 // ECMA-262 section 15.5.4.15 710 // ECMA-262 section 15.5.4.15
711 function StringSubstring(start, end) { 711 function StringSubstring(start, end) {
712 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 712 CHECK_OBJECT_COERCIBLE(this, "String.prototype.subString");
713 throw MakeTypeError("called_on_null_or_undefined", 713
714 ["String.prototype.subString"]);
715 }
716 var s = TO_STRING_INLINE(this); 714 var s = TO_STRING_INLINE(this);
717 var s_len = s.length; 715 var s_len = s.length;
718 716
719 var start_i = TO_INTEGER(start); 717 var start_i = TO_INTEGER(start);
720 if (start_i < 0) { 718 if (start_i < 0) {
721 start_i = 0; 719 start_i = 0;
722 } else if (start_i > s_len) { 720 } else if (start_i > s_len) {
723 start_i = s_len; 721 start_i = s_len;
724 } 722 }
725 723
(...skipping 11 matching lines...) Expand all
737 } 735 }
738 } 736 }
739 } 737 }
740 738
741 return %_SubString(s, start_i, end_i); 739 return %_SubString(s, start_i, end_i);
742 } 740 }
743 741
744 742
745 // This is not a part of ECMA-262. 743 // This is not a part of ECMA-262.
746 function StringSubstr(start, n) { 744 function StringSubstr(start, n) {
747 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 745 CHECK_OBJECT_COERCIBLE(this, "String.prototype.substr");
748 throw MakeTypeError("called_on_null_or_undefined", 746
749 ["String.prototype.substr"]);
750 }
751 var s = TO_STRING_INLINE(this); 747 var s = TO_STRING_INLINE(this);
752 var len; 748 var len;
753 749
754 // Correct n: If not given, set to string length; if explicitly 750 // Correct n: If not given, set to string length; if explicitly
755 // set to undefined, zero, or negative, returns empty string. 751 // set to undefined, zero, or negative, returns empty string.
756 if (IS_UNDEFINED(n)) { 752 if (IS_UNDEFINED(n)) {
757 len = s.length; 753 len = s.length;
758 } else { 754 } else {
759 len = TO_INTEGER(n); 755 len = TO_INTEGER(n);
760 if (len <= 0) return ''; 756 if (len <= 0) return '';
(...skipping 18 matching lines...) Expand all
779 775
780 var end = start + len; 776 var end = start + len;
781 if (end > s.length) end = s.length; 777 if (end > s.length) end = s.length;
782 778
783 return %_SubString(s, start, end); 779 return %_SubString(s, start, end);
784 } 780 }
785 781
786 782
787 // ECMA-262, 15.5.4.16 783 // ECMA-262, 15.5.4.16
788 function StringToLowerCase() { 784 function StringToLowerCase() {
789 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 785 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase");
790 throw MakeTypeError("called_on_null_or_undefined", 786
791 ["String.prototype.toLowerCase"]);
792 }
793 return %StringToLowerCase(TO_STRING_INLINE(this)); 787 return %StringToLowerCase(TO_STRING_INLINE(this));
794 } 788 }
795 789
796 790
797 // ECMA-262, 15.5.4.17 791 // ECMA-262, 15.5.4.17
798 function StringToLocaleLowerCase() { 792 function StringToLocaleLowerCase() {
799 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 793 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleLowerCase");
800 throw MakeTypeError("called_on_null_or_undefined", 794
801 ["String.prototype.toLocaleLowerCase"]);
802 }
803 return %StringToLowerCase(TO_STRING_INLINE(this)); 795 return %StringToLowerCase(TO_STRING_INLINE(this));
804 } 796 }
805 797
806 798
807 // ECMA-262, 15.5.4.18 799 // ECMA-262, 15.5.4.18
808 function StringToUpperCase() { 800 function StringToUpperCase() {
809 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 801 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toUpperCase");
810 throw MakeTypeError("called_on_null_or_undefined", 802
811 ["String.prototype.toUpperCase"]);
812 }
813 return %StringToUpperCase(TO_STRING_INLINE(this)); 803 return %StringToUpperCase(TO_STRING_INLINE(this));
814 } 804 }
815 805
816 806
817 // ECMA-262, 15.5.4.19 807 // ECMA-262, 15.5.4.19
818 function StringToLocaleUpperCase() { 808 function StringToLocaleUpperCase() {
819 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 809 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleUpperCase");
820 throw MakeTypeError("called_on_null_or_undefined", 810
821 ["String.prototype.toLocaleUpperCase"]);
822 }
823 return %StringToUpperCase(TO_STRING_INLINE(this)); 811 return %StringToUpperCase(TO_STRING_INLINE(this));
824 } 812 }
825 813
826 // ES5, 15.5.4.20 814 // ES5, 15.5.4.20
827 function StringTrim() { 815 function StringTrim() {
828 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 816 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trim");
829 throw MakeTypeError("called_on_null_or_undefined", 817
830 ["String.prototype.trim"]);
831 }
832 return %StringTrim(TO_STRING_INLINE(this), true, true); 818 return %StringTrim(TO_STRING_INLINE(this), true, true);
833 } 819 }
834 820
835 function StringTrimLeft() { 821 function StringTrimLeft() {
836 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 822 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trimLeft");
837 throw MakeTypeError("called_on_null_or_undefined", 823
838 ["String.prototype.trimLeft"]);
839 }
840 return %StringTrim(TO_STRING_INLINE(this), true, false); 824 return %StringTrim(TO_STRING_INLINE(this), true, false);
841 } 825 }
842 826
843 function StringTrimRight() { 827 function StringTrimRight() {
844 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 828 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trimRight");
845 throw MakeTypeError("called_on_null_or_undefined", 829
846 ["String.prototype.trimRight"]);
847 }
848 return %StringTrim(TO_STRING_INLINE(this), false, true); 830 return %StringTrim(TO_STRING_INLINE(this), false, true);
849 } 831 }
850 832
851 833
852 // ECMA-262, section 15.5.3.2 834 // ECMA-262, section 15.5.3.2
853 function StringFromCharCode(code) { 835 function StringFromCharCode(code) {
854 var n = %_ArgumentsLength(); 836 var n = %_ArgumentsLength();
855 if (n == 1) { 837 if (n == 1) {
856 if (!%_IsSmi(code)) code = ToNumber(code); 838 if (!%_IsSmi(code)) code = ToNumber(code);
857 return %_StringCharFromCode(code & 0xffff); 839 return %_StringCharFromCode(code & 0xffff);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 InstallFunctions($String.prototype, DONT_ENUM, $Array( 957 InstallFunctions($String.prototype, DONT_ENUM, $Array(
976 "valueOf", StringValueOf, 958 "valueOf", StringValueOf,
977 "toString", StringToString, 959 "toString", StringToString,
978 "charAt", StringCharAt, 960 "charAt", StringCharAt,
979 "charCodeAt", StringCharCodeAt, 961 "charCodeAt", StringCharCodeAt,
980 "concat", StringConcat, 962 "concat", StringConcat,
981 "indexOf", StringIndexOf, 963 "indexOf", StringIndexOf,
982 "lastIndexOf", StringLastIndexOf, 964 "lastIndexOf", StringLastIndexOf,
983 "localeCompare", StringLocaleCompare, 965 "localeCompare", StringLocaleCompare,
984 "match", StringMatch, 966 "match", StringMatch,
967 "normalize", StringNormalize,
985 "replace", StringReplace, 968 "replace", StringReplace,
986 "search", StringSearch, 969 "search", StringSearch,
987 "slice", StringSlice, 970 "slice", StringSlice,
988 "split", StringSplit, 971 "split", StringSplit,
989 "substring", StringSubstring, 972 "substring", StringSubstring,
990 "substr", StringSubstr, 973 "substr", StringSubstr,
991 "toLowerCase", StringToLowerCase, 974 "toLowerCase", StringToLowerCase,
992 "toLocaleLowerCase", StringToLocaleLowerCase, 975 "toLocaleLowerCase", StringToLocaleLowerCase,
993 "toUpperCase", StringToUpperCase, 976 "toUpperCase", StringToUpperCase,
994 "toLocaleUpperCase", StringToLocaleUpperCase, 977 "toLocaleUpperCase", StringToLocaleUpperCase,
(...skipping 10 matching lines...) Expand all
1005 "fixed", StringFixed, 988 "fixed", StringFixed,
1006 "italics", StringItalics, 989 "italics", StringItalics,
1007 "small", StringSmall, 990 "small", StringSmall,
1008 "strike", StringStrike, 991 "strike", StringStrike,
1009 "sub", StringSub, 992 "sub", StringSub,
1010 "sup", StringSup 993 "sup", StringSup
1011 )); 994 ));
1012 } 995 }
1013 996
1014 SetUpString(); 997 SetUpString();
OLDNEW
« no previous file with comments | « src/spaces-inl.h ('k') | src/stub-cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698