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

Side by Side Diff: src/string.js

Issue 1323543002: [runtime] Replace %to_string_fun with %_ToString. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@ToStringStub
Patch Set: REBASE. Fixes Created 5 years, 3 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
« no previous file with comments | « src/runtime/runtime-uri.cc ('k') | src/string-iterator.js » ('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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils) { 5 (function(global, utils) {
6 6
7 %CheckIsBootstrapping(); 7 %CheckIsBootstrapping();
8 8
9 // ------------------------------------------------------------------- 9 // -------------------------------------------------------------------
10 // Imports 10 // Imports
11 11
12 var ArrayIndexOf; 12 var ArrayIndexOf;
13 var ArrayJoin; 13 var ArrayJoin;
14 var GlobalRegExp = global.RegExp; 14 var GlobalRegExp = global.RegExp;
15 var GlobalString = global.String; 15 var GlobalString = global.String;
16 var InternalArray = utils.InternalArray; 16 var InternalArray = utils.InternalArray;
17 var InternalPackedArray = utils.InternalPackedArray; 17 var InternalPackedArray = utils.InternalPackedArray;
18 var RegExpExec; 18 var RegExpExec;
19 var RegExpExecNoTests; 19 var RegExpExecNoTests;
20 var RegExpLastMatchInfo; 20 var RegExpLastMatchInfo;
21 var ToNumber; 21 var ToNumber;
22 var ToString;
23 22
24 utils.Import(function(from) { 23 utils.Import(function(from) {
25 ArrayIndexOf = from.ArrayIndexOf; 24 ArrayIndexOf = from.ArrayIndexOf;
26 ArrayJoin = from.ArrayJoin; 25 ArrayJoin = from.ArrayJoin;
27 RegExpExec = from.RegExpExec; 26 RegExpExec = from.RegExpExec;
28 RegExpExecNoTests = from.RegExpExecNoTests; 27 RegExpExecNoTests = from.RegExpExecNoTests;
29 RegExpLastMatchInfo = from.RegExpLastMatchInfo; 28 RegExpLastMatchInfo = from.RegExpLastMatchInfo;
30 ToNumber = from.ToNumber; 29 ToNumber = from.ToNumber;
31 ToString = from.ToString;
32 }); 30 });
33 31
34 //------------------------------------------------------------------- 32 //-------------------------------------------------------------------
35 33
36 // ECMA-262 section 15.5.4.2 34 // ECMA-262 section 15.5.4.2
37 function StringToString() { 35 function StringToString() {
38 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) { 36 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) {
39 throw MakeTypeError(kNotGeneric, 'String.prototype.toString'); 37 throw MakeTypeError(kNotGeneric, 'String.prototype.toString');
40 } 38 }
41 return %_ValueOf(this); 39 return %_ValueOf(this);
42 } 40 }
43 41
44 42
45 // ECMA-262 section 15.5.4.3 43 // ECMA-262 section 15.5.4.3
46 function StringValueOf() { 44 function StringValueOf() {
47 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) { 45 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) {
48 throw MakeTypeError(kNotGeneric, 'String.prototype.valueOf'); 46 throw MakeTypeError(kNotGeneric, 'String.prototype.valueOf');
49 } 47 }
50 return %_ValueOf(this); 48 return %_ValueOf(this);
51 } 49 }
52 50
53 51
54 // ECMA-262, section 15.5.4.4 52 // ECMA-262, section 15.5.4.4
55 function StringCharAtJS(pos) { 53 function StringCharAtJS(pos) {
56 CHECK_OBJECT_COERCIBLE(this, "String.prototype.charAt"); 54 CHECK_OBJECT_COERCIBLE(this, "String.prototype.charAt");
57 55
58 var result = %_StringCharAt(this, pos); 56 var result = %_StringCharAt(this, pos);
59 if (%_IsSmi(result)) { 57 if (%_IsSmi(result)) {
60 result = %_StringCharAt(TO_STRING_INLINE(this), TO_INTEGER(pos)); 58 result = %_StringCharAt(TO_STRING(this), TO_INTEGER(pos));
61 } 59 }
62 return result; 60 return result;
63 } 61 }
64 62
65 63
66 // ECMA-262 section 15.5.4.5 64 // ECMA-262 section 15.5.4.5
67 function StringCharCodeAtJS(pos) { 65 function StringCharCodeAtJS(pos) {
68 CHECK_OBJECT_COERCIBLE(this, "String.prototype.charCodeAt"); 66 CHECK_OBJECT_COERCIBLE(this, "String.prototype.charCodeAt");
69 67
70 var result = %_StringCharCodeAt(this, pos); 68 var result = %_StringCharCodeAt(this, pos);
71 if (!%_IsSmi(result)) { 69 if (!%_IsSmi(result)) {
72 result = %_StringCharCodeAt(TO_STRING_INLINE(this), TO_INTEGER(pos)); 70 result = %_StringCharCodeAt(TO_STRING(this), TO_INTEGER(pos));
73 } 71 }
74 return result; 72 return result;
75 } 73 }
76 74
77 75
78 // ECMA-262, section 15.5.4.6 76 // ECMA-262, section 15.5.4.6
79 function StringConcat(other /* and more */) { // length == 1 77 function StringConcat(other /* and more */) { // length == 1
80 CHECK_OBJECT_COERCIBLE(this, "String.prototype.concat"); 78 CHECK_OBJECT_COERCIBLE(this, "String.prototype.concat");
81 var len = %_ArgumentsLength(); 79 var len = %_ArgumentsLength();
82 var this_as_string = TO_STRING_INLINE(this); 80 var this_as_string = TO_STRING(this);
83 if (len === 1) { 81 if (len === 1) {
84 return this_as_string + TO_STRING_INLINE(other); 82 return this_as_string + TO_STRING(other);
85 } 83 }
86 var parts = new InternalArray(len + 1); 84 var parts = new InternalArray(len + 1);
87 parts[0] = this_as_string; 85 parts[0] = this_as_string;
88 for (var i = 0; i < len; i++) { 86 for (var i = 0; i < len; i++) {
89 var part = %_Arguments(i); 87 var part = %_Arguments(i);
90 parts[i + 1] = TO_STRING_INLINE(part); 88 parts[i + 1] = TO_STRING(part);
91 } 89 }
92 return %StringBuilderConcat(parts, len + 1, ""); 90 return %StringBuilderConcat(parts, len + 1, "");
93 } 91 }
94 92
95 93
96 // ECMA-262 section 15.5.4.7 94 // ECMA-262 section 15.5.4.7
97 function StringIndexOfJS(pattern /* position */) { // length == 1 95 function StringIndexOfJS(pattern /* position */) { // length == 1
98 CHECK_OBJECT_COERCIBLE(this, "String.prototype.indexOf"); 96 CHECK_OBJECT_COERCIBLE(this, "String.prototype.indexOf");
99 97
100 var subject = TO_STRING_INLINE(this); 98 var subject = TO_STRING(this);
101 pattern = TO_STRING_INLINE(pattern); 99 pattern = TO_STRING(pattern);
102 var index = 0; 100 var index = 0;
103 if (%_ArgumentsLength() > 1) { 101 if (%_ArgumentsLength() > 1) {
104 index = %_Arguments(1); // position 102 index = %_Arguments(1); // position
105 index = TO_INTEGER(index); 103 index = TO_INTEGER(index);
106 if (index < 0) index = 0; 104 if (index < 0) index = 0;
107 if (index > subject.length) index = subject.length; 105 if (index > subject.length) index = subject.length;
108 } 106 }
109 return %StringIndexOf(subject, pattern, index); 107 return %StringIndexOf(subject, pattern, index);
110 } 108 }
111 109
112 110
113 // ECMA-262 section 15.5.4.8 111 // ECMA-262 section 15.5.4.8
114 function StringLastIndexOfJS(pat /* position */) { // length == 1 112 function StringLastIndexOfJS(pat /* position */) { // length == 1
115 CHECK_OBJECT_COERCIBLE(this, "String.prototype.lastIndexOf"); 113 CHECK_OBJECT_COERCIBLE(this, "String.prototype.lastIndexOf");
116 114
117 var sub = TO_STRING_INLINE(this); 115 var sub = TO_STRING(this);
118 var subLength = sub.length; 116 var subLength = sub.length;
119 var pat = TO_STRING_INLINE(pat); 117 var pat = TO_STRING(pat);
120 var patLength = pat.length; 118 var patLength = pat.length;
121 var index = subLength - patLength; 119 var index = subLength - patLength;
122 if (%_ArgumentsLength() > 1) { 120 if (%_ArgumentsLength() > 1) {
123 var position = ToNumber(%_Arguments(1)); 121 var position = ToNumber(%_Arguments(1));
124 if (!NUMBER_IS_NAN(position)) { 122 if (!NUMBER_IS_NAN(position)) {
125 position = TO_INTEGER(position); 123 position = TO_INTEGER(position);
126 if (position < 0) { 124 if (position < 0) {
127 position = 0; 125 position = 0;
128 } 126 }
129 if (position + patLength < subLength) { 127 if (position + patLength < subLength) {
130 index = position; 128 index = position;
131 } 129 }
132 } 130 }
133 } 131 }
134 if (index < 0) { 132 if (index < 0) {
135 return -1; 133 return -1;
136 } 134 }
137 return %StringLastIndexOf(sub, pat, index); 135 return %StringLastIndexOf(sub, pat, index);
138 } 136 }
139 137
140 138
141 // ECMA-262 section 15.5.4.9 139 // ECMA-262 section 15.5.4.9
142 // 140 //
143 // This function is implementation specific. For now, we do not 141 // This function is implementation specific. For now, we do not
144 // do anything locale specific. 142 // do anything locale specific.
145 function StringLocaleCompareJS(other) { 143 function StringLocaleCompareJS(other) {
146 CHECK_OBJECT_COERCIBLE(this, "String.prototype.localeCompare"); 144 CHECK_OBJECT_COERCIBLE(this, "String.prototype.localeCompare");
147 145
148 return %StringLocaleCompare(TO_STRING_INLINE(this), 146 return %StringLocaleCompare(TO_STRING(this), TO_STRING(other));
149 TO_STRING_INLINE(other));
150 } 147 }
151 148
152 149
153 // ECMA-262 section 15.5.4.10 150 // ECMA-262 section 15.5.4.10
154 function StringMatchJS(regexp) { 151 function StringMatchJS(regexp) {
155 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); 152 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match");
156 153
157 var subject = TO_STRING_INLINE(this); 154 var subject = TO_STRING(this);
158 if (IS_REGEXP(regexp)) { 155 if (IS_REGEXP(regexp)) {
159 // Emulate RegExp.prototype.exec's side effect in step 5, even though 156 // Emulate RegExp.prototype.exec's side effect in step 5, even though
160 // value is discarded. 157 // value is discarded.
161 var lastIndex = regexp.lastIndex; 158 var lastIndex = regexp.lastIndex;
162 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex); 159 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex);
163 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0); 160 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0);
164 var result = %StringMatch(subject, regexp, RegExpLastMatchInfo); 161 var result = %StringMatch(subject, regexp, RegExpLastMatchInfo);
165 if (result !== null) $regexpLastMatchInfoOverride = null; 162 if (result !== null) $regexpLastMatchInfoOverride = null;
166 regexp.lastIndex = 0; 163 regexp.lastIndex = 0;
167 return result; 164 return result;
168 } 165 }
169 // Non-regexp argument. 166 // Non-regexp argument.
170 regexp = new GlobalRegExp(regexp); 167 regexp = new GlobalRegExp(regexp);
171 return RegExpExecNoTests(regexp, subject, 0); 168 return RegExpExecNoTests(regexp, subject, 0);
172 } 169 }
173 170
174 171
175 // ECMA-262 v6, section 21.1.3.12 172 // ECMA-262 v6, section 21.1.3.12
176 // 173 //
177 // For now we do nothing, as proper normalization requires big tables. 174 // For now we do nothing, as proper normalization requires big tables.
178 // If Intl is enabled, then i18n.js will override it and provide the the 175 // If Intl is enabled, then i18n.js will override it and provide the the
179 // proper functionality. 176 // proper functionality.
180 function StringNormalizeJS() { 177 function StringNormalizeJS() {
181 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); 178 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
182 var s = TO_STRING_INLINE(this); 179 var s = TO_STRING(this);
183 180
184 var formArg = %_Arguments(0); 181 var formArg = %_Arguments(0);
185 var form = IS_UNDEFINED(formArg) ? 'NFC' : TO_STRING_INLINE(formArg); 182 var form = IS_UNDEFINED(formArg) ? 'NFC' : TO_STRING(formArg);
186 183
187 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD']; 184 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD'];
188 var normalizationForm = 185 var normalizationForm =
189 %_CallFunction(NORMALIZATION_FORMS, form, ArrayIndexOf); 186 %_CallFunction(NORMALIZATION_FORMS, form, ArrayIndexOf);
190 if (normalizationForm === -1) { 187 if (normalizationForm === -1) {
191 throw MakeRangeError(kNormalizationForm, 188 throw MakeRangeError(kNormalizationForm,
192 %_CallFunction(NORMALIZATION_FORMS, ', ', ArrayJoin)); 189 %_CallFunction(NORMALIZATION_FORMS, ', ', ArrayJoin));
193 } 190 }
194 191
195 return s; 192 return s;
196 } 193 }
197 194
198 195
199 // This has the same size as the RegExpLastMatchInfo array, and can be used 196 // This has the same size as the RegExpLastMatchInfo array, and can be used
200 // for functions that expect that structure to be returned. It is used when 197 // for functions that expect that structure to be returned. It is used when
201 // the needle is a string rather than a regexp. In this case we can't update 198 // the needle is a string rather than a regexp. In this case we can't update
202 // lastMatchArray without erroneously affecting the properties on the global 199 // lastMatchArray without erroneously affecting the properties on the global
203 // RegExp object. 200 // RegExp object.
204 var reusableMatchInfo = [2, "", "", -1, -1]; 201 var reusableMatchInfo = [2, "", "", -1, -1];
205 202
206 203
207 // ECMA-262, section 15.5.4.11 204 // ECMA-262, section 15.5.4.11
208 function StringReplace(search, replace) { 205 function StringReplace(search, replace) {
209 CHECK_OBJECT_COERCIBLE(this, "String.prototype.replace"); 206 CHECK_OBJECT_COERCIBLE(this, "String.prototype.replace");
210 207
211 var subject = TO_STRING_INLINE(this); 208 var subject = TO_STRING(this);
212 209
213 // Decision tree for dispatch 210 // Decision tree for dispatch
214 // .. regexp search 211 // .. regexp search
215 // .... string replace 212 // .... string replace
216 // ...... non-global search 213 // ...... non-global search
217 // ........ empty string replace 214 // ........ empty string replace
218 // ........ non-empty string replace (with $-expansion) 215 // ........ non-empty string replace (with $-expansion)
219 // ...... global search 216 // ...... global search
220 // ........ no need to circumvent last match info override 217 // ........ no need to circumvent last match info override
221 // ........ need to circument last match info override 218 // ........ need to circument last match info override
222 // .... function replace 219 // .... function replace
223 // ...... global search 220 // ...... global search
224 // ...... non-global search 221 // ...... non-global search
225 // .. string search 222 // .. string search
226 // .... special case that replaces with one single character 223 // .... special case that replaces with one single character
227 // ...... function replace 224 // ...... function replace
228 // ...... string replace (with $-expansion) 225 // ...... string replace (with $-expansion)
229 226
230 if (IS_REGEXP(search)) { 227 if (IS_REGEXP(search)) {
231 // Emulate RegExp.prototype.exec's side effect in step 5, even if 228 // Emulate RegExp.prototype.exec's side effect in step 5, even if
232 // value is discarded. 229 // value is discarded.
233 var lastIndex = search.lastIndex; 230 var lastIndex = search.lastIndex;
234 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex); 231 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex);
235 232
236 if (!IS_CALLABLE(replace)) { 233 if (!IS_CALLABLE(replace)) {
237 replace = TO_STRING_INLINE(replace); 234 replace = TO_STRING(replace);
238 235
239 if (!search.global) { 236 if (!search.global) {
240 // Non-global regexp search, string replace. 237 // Non-global regexp search, string replace.
241 var match = RegExpExec(search, subject, 0); 238 var match = RegExpExec(search, subject, 0);
242 if (match == null) { 239 if (match == null) {
243 search.lastIndex = 0 240 search.lastIndex = 0
244 return subject; 241 return subject;
245 } 242 }
246 if (replace.length == 0) { 243 if (replace.length == 0) {
247 return %_SubString(subject, 0, match[CAPTURE0]) + 244 return %_SubString(subject, 0, match[CAPTURE0]) +
(...skipping 27 matching lines...) Expand all
275 } 272 }
276 273
277 if (search.global) { 274 if (search.global) {
278 // Global regexp search, function replace. 275 // Global regexp search, function replace.
279 return StringReplaceGlobalRegExpWithFunction(subject, search, replace); 276 return StringReplaceGlobalRegExpWithFunction(subject, search, replace);
280 } 277 }
281 // Non-global regexp search, function replace. 278 // Non-global regexp search, function replace.
282 return StringReplaceNonGlobalRegExpWithFunction(subject, search, replace); 279 return StringReplaceNonGlobalRegExpWithFunction(subject, search, replace);
283 } 280 }
284 281
285 search = TO_STRING_INLINE(search); 282 search = TO_STRING(search);
286 283
287 if (search.length == 1 && 284 if (search.length == 1 &&
288 subject.length > 0xFF && 285 subject.length > 0xFF &&
289 IS_STRING(replace) && 286 IS_STRING(replace) &&
290 %StringIndexOf(replace, '$', 0) < 0) { 287 %StringIndexOf(replace, '$', 0) < 0) {
291 // Searching by traversing a cons string tree and replace with cons of 288 // Searching by traversing a cons string tree and replace with cons of
292 // slices works only when the replaced string is a single character, being 289 // slices works only when the replaced string is a single character, being
293 // replaced by a simple string and only pays off for long strings. 290 // replaced by a simple string and only pays off for long strings.
294 return %StringReplaceOneCharWithString(subject, search, replace); 291 return %StringReplaceOneCharWithString(subject, search, replace);
295 } 292 }
296 var start = %StringIndexOf(subject, search, 0); 293 var start = %StringIndexOf(subject, search, 0);
297 if (start < 0) return subject; 294 if (start < 0) return subject;
298 var end = start + search.length; 295 var end = start + search.length;
299 296
300 var result = %_SubString(subject, 0, start); 297 var result = %_SubString(subject, 0, start);
301 298
302 // Compute the string to replace with. 299 // Compute the string to replace with.
303 if (IS_CALLABLE(replace)) { 300 if (IS_CALLABLE(replace)) {
304 result += replace(search, start, subject); 301 result += replace(search, start, subject);
305 } else { 302 } else {
306 reusableMatchInfo[CAPTURE0] = start; 303 reusableMatchInfo[CAPTURE0] = start;
307 reusableMatchInfo[CAPTURE1] = end; 304 reusableMatchInfo[CAPTURE1] = end;
308 result = ExpandReplacement(TO_STRING_INLINE(replace), 305 result = ExpandReplacement(TO_STRING(replace),
309 subject, 306 subject,
310 reusableMatchInfo, 307 reusableMatchInfo,
311 result); 308 result);
312 } 309 }
313 310
314 return result + %_SubString(subject, end, subject.length); 311 return result + %_SubString(subject, end, subject.length);
315 } 312 }
316 313
317 314
318 // Expand the $-expressions in the string and return a new string with 315 // Expand the $-expressions in the string and return a new string with
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 } else { 457 } else {
461 match_start = res[++i] - elem; 458 match_start = res[++i] - elem;
462 } 459 }
463 } else { 460 } else {
464 override[0] = elem; 461 override[0] = elem;
465 override[1] = match_start; 462 override[1] = match_start;
466 $regexpLastMatchInfoOverride = override; 463 $regexpLastMatchInfoOverride = override;
467 var func_result = replace(elem, match_start, subject); 464 var func_result = replace(elem, match_start, subject);
468 // Overwrite the i'th element in the results with the string we got 465 // Overwrite the i'th element in the results with the string we got
469 // back from the callback function. 466 // back from the callback function.
470 res[i] = TO_STRING_INLINE(func_result); 467 res[i] = TO_STRING(func_result);
471 match_start += elem.length; 468 match_start += elem.length;
472 } 469 }
473 } 470 }
474 } else { 471 } else {
475 for (var i = 0; i < len; i++) { 472 for (var i = 0; i < len; i++) {
476 var elem = res[i]; 473 var elem = res[i];
477 if (!%_IsSmi(elem)) { 474 if (!%_IsSmi(elem)) {
478 // elem must be an Array. 475 // elem must be an Array.
479 // Use the apply argument as backing for global RegExp properties. 476 // Use the apply argument as backing for global RegExp properties.
480 $regexpLastMatchInfoOverride = elem; 477 $regexpLastMatchInfoOverride = elem;
481 var func_result = %Apply(replace, UNDEFINED, elem, 0, elem.length); 478 var func_result = %Apply(replace, UNDEFINED, elem, 0, elem.length);
482 // Overwrite the i'th element in the results with the string we got 479 // Overwrite the i'th element in the results with the string we got
483 // back from the callback function. 480 // back from the callback function.
484 res[i] = TO_STRING_INLINE(func_result); 481 res[i] = TO_STRING(func_result);
485 } 482 }
486 } 483 }
487 } 484 }
488 var result = %StringBuilderConcat(res, res.length, subject); 485 var result = %StringBuilderConcat(res, res.length, subject);
489 resultArray.length = 0; 486 resultArray.length = 0;
490 reusableReplaceArray = resultArray; 487 reusableReplaceArray = resultArray;
491 return result; 488 return result;
492 } 489 }
493 490
494 491
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 // ECMA-262 section 15.5.4.12 529 // ECMA-262 section 15.5.4.12
533 function StringSearch(re) { 530 function StringSearch(re) {
534 CHECK_OBJECT_COERCIBLE(this, "String.prototype.search"); 531 CHECK_OBJECT_COERCIBLE(this, "String.prototype.search");
535 532
536 var regexp; 533 var regexp;
537 if (IS_REGEXP(re)) { 534 if (IS_REGEXP(re)) {
538 regexp = re; 535 regexp = re;
539 } else { 536 } else {
540 regexp = new GlobalRegExp(re); 537 regexp = new GlobalRegExp(re);
541 } 538 }
542 var match = RegExpExec(regexp, TO_STRING_INLINE(this), 0); 539 var match = RegExpExec(regexp, TO_STRING(this), 0);
543 if (match) { 540 if (match) {
544 return match[CAPTURE0]; 541 return match[CAPTURE0];
545 } 542 }
546 return -1; 543 return -1;
547 } 544 }
548 545
549 546
550 // ECMA-262 section 15.5.4.13 547 // ECMA-262 section 15.5.4.13
551 function StringSlice(start, end) { 548 function StringSlice(start, end) {
552 CHECK_OBJECT_COERCIBLE(this, "String.prototype.slice"); 549 CHECK_OBJECT_COERCIBLE(this, "String.prototype.slice");
553 550
554 var s = TO_STRING_INLINE(this); 551 var s = TO_STRING(this);
555 var s_len = s.length; 552 var s_len = s.length;
556 var start_i = TO_INTEGER(start); 553 var start_i = TO_INTEGER(start);
557 var end_i = s_len; 554 var end_i = s_len;
558 if (!IS_UNDEFINED(end)) { 555 if (!IS_UNDEFINED(end)) {
559 end_i = TO_INTEGER(end); 556 end_i = TO_INTEGER(end);
560 } 557 }
561 558
562 if (start_i < 0) { 559 if (start_i < 0) {
563 start_i += s_len; 560 start_i += s_len;
564 if (start_i < 0) { 561 if (start_i < 0) {
(...skipping 21 matching lines...) Expand all
586 } 583 }
587 584
588 return %_SubString(s, start_i, end_i); 585 return %_SubString(s, start_i, end_i);
589 } 586 }
590 587
591 588
592 // ECMA-262 section 15.5.4.14 589 // ECMA-262 section 15.5.4.14
593 function StringSplitJS(separator, limit) { 590 function StringSplitJS(separator, limit) {
594 CHECK_OBJECT_COERCIBLE(this, "String.prototype.split"); 591 CHECK_OBJECT_COERCIBLE(this, "String.prototype.split");
595 592
596 var subject = TO_STRING_INLINE(this); 593 var subject = TO_STRING(this);
597 limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit); 594 limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit);
598 595
599 var length = subject.length; 596 var length = subject.length;
600 if (!IS_REGEXP(separator)) { 597 if (!IS_REGEXP(separator)) {
601 var separator_string = TO_STRING_INLINE(separator); 598 var separator_string = TO_STRING(separator);
602 599
603 if (limit === 0) return []; 600 if (limit === 0) return [];
604 601
605 // ECMA-262 says that if separator is undefined, the result should 602 // ECMA-262 says that if separator is undefined, the result should
606 // be an array of size 1 containing the entire string. 603 // be an array of size 1 containing the entire string.
607 if (IS_UNDEFINED(separator)) return [subject]; 604 if (IS_UNDEFINED(separator)) return [subject];
608 605
609 var separator_length = separator_string.length; 606 var separator_length = separator_string.length;
610 607
611 // If the separator string is empty then return the elements in the subject. 608 // If the separator string is empty then return the elements in the subject.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 var array_result = []; 675 var array_result = [];
679 %MoveArrayContents(result, array_result); 676 %MoveArrayContents(result, array_result);
680 return array_result; 677 return array_result;
681 } 678 }
682 679
683 680
684 // ECMA-262 section 15.5.4.15 681 // ECMA-262 section 15.5.4.15
685 function StringSubstring(start, end) { 682 function StringSubstring(start, end) {
686 CHECK_OBJECT_COERCIBLE(this, "String.prototype.subString"); 683 CHECK_OBJECT_COERCIBLE(this, "String.prototype.subString");
687 684
688 var s = TO_STRING_INLINE(this); 685 var s = TO_STRING(this);
689 var s_len = s.length; 686 var s_len = s.length;
690 687
691 var start_i = TO_INTEGER(start); 688 var start_i = TO_INTEGER(start);
692 if (start_i < 0) { 689 if (start_i < 0) {
693 start_i = 0; 690 start_i = 0;
694 } else if (start_i > s_len) { 691 } else if (start_i > s_len) {
695 start_i = s_len; 692 start_i = s_len;
696 } 693 }
697 694
698 var end_i = s_len; 695 var end_i = s_len;
(...skipping 12 matching lines...) Expand all
711 } 708 }
712 709
713 return %_SubString(s, start_i, end_i); 710 return %_SubString(s, start_i, end_i);
714 } 711 }
715 712
716 713
717 // ES6 draft, revision 26 (2014-07-18), section B.2.3.1 714 // ES6 draft, revision 26 (2014-07-18), section B.2.3.1
718 function StringSubstr(start, n) { 715 function StringSubstr(start, n) {
719 CHECK_OBJECT_COERCIBLE(this, "String.prototype.substr"); 716 CHECK_OBJECT_COERCIBLE(this, "String.prototype.substr");
720 717
721 var s = TO_STRING_INLINE(this); 718 var s = TO_STRING(this);
722 var len; 719 var len;
723 720
724 // Correct n: If not given, set to string length; if explicitly 721 // Correct n: If not given, set to string length; if explicitly
725 // set to undefined, zero, or negative, returns empty string. 722 // set to undefined, zero, or negative, returns empty string.
726 if (IS_UNDEFINED(n)) { 723 if (IS_UNDEFINED(n)) {
727 len = s.length; 724 len = s.length;
728 } else { 725 } else {
729 len = TO_INTEGER(n); 726 len = TO_INTEGER(n);
730 if (len <= 0) return ''; 727 if (len <= 0) return '';
731 } 728 }
(...skipping 19 matching lines...) Expand all
751 if (end > s.length) end = s.length; 748 if (end > s.length) end = s.length;
752 749
753 return %_SubString(s, start, end); 750 return %_SubString(s, start, end);
754 } 751 }
755 752
756 753
757 // ECMA-262, 15.5.4.16 754 // ECMA-262, 15.5.4.16
758 function StringToLowerCaseJS() { 755 function StringToLowerCaseJS() {
759 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase"); 756 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase");
760 757
761 return %StringToLowerCase(TO_STRING_INLINE(this)); 758 return %StringToLowerCase(TO_STRING(this));
762 } 759 }
763 760
764 761
765 // ECMA-262, 15.5.4.17 762 // ECMA-262, 15.5.4.17
766 function StringToLocaleLowerCase() { 763 function StringToLocaleLowerCase() {
767 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleLowerCase"); 764 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleLowerCase");
768 765
769 return %StringToLowerCase(TO_STRING_INLINE(this)); 766 return %StringToLowerCase(TO_STRING(this));
770 } 767 }
771 768
772 769
773 // ECMA-262, 15.5.4.18 770 // ECMA-262, 15.5.4.18
774 function StringToUpperCaseJS() { 771 function StringToUpperCaseJS() {
775 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toUpperCase"); 772 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toUpperCase");
776 773
777 return %StringToUpperCase(TO_STRING_INLINE(this)); 774 return %StringToUpperCase(TO_STRING(this));
778 } 775 }
779 776
780 777
781 // ECMA-262, 15.5.4.19 778 // ECMA-262, 15.5.4.19
782 function StringToLocaleUpperCase() { 779 function StringToLocaleUpperCase() {
783 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleUpperCase"); 780 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleUpperCase");
784 781
785 return %StringToUpperCase(TO_STRING_INLINE(this)); 782 return %StringToUpperCase(TO_STRING(this));
786 } 783 }
787 784
788 // ES5, 15.5.4.20 785 // ES5, 15.5.4.20
789 function StringTrimJS() { 786 function StringTrimJS() {
790 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trim"); 787 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trim");
791 788
792 return %StringTrim(TO_STRING_INLINE(this), true, true); 789 return %StringTrim(TO_STRING(this), true, true);
793 } 790 }
794 791
795 function StringTrimLeft() { 792 function StringTrimLeft() {
796 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trimLeft"); 793 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trimLeft");
797 794
798 return %StringTrim(TO_STRING_INLINE(this), true, false); 795 return %StringTrim(TO_STRING(this), true, false);
799 } 796 }
800 797
801 function StringTrimRight() { 798 function StringTrimRight() {
802 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trimRight"); 799 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trimRight");
803 800
804 return %StringTrim(TO_STRING_INLINE(this), false, true); 801 return %StringTrim(TO_STRING(this), false, true);
805 } 802 }
806 803
807 804
808 // ECMA-262, section 15.5.3.2 805 // ECMA-262, section 15.5.3.2
809 function StringFromCharCode(code) { 806 function StringFromCharCode(code) {
810 var n = %_ArgumentsLength(); 807 var n = %_ArgumentsLength();
811 if (n == 1) { 808 if (n == 1) {
812 if (!%_IsSmi(code)) code = ToNumber(code); 809 if (!%_IsSmi(code)) code = ToNumber(code);
813 return %_StringCharFromCode(code & 0xffff); 810 return %_StringCharFromCode(code & 0xffff);
814 } 811 }
(...skipping 15 matching lines...) Expand all
830 var code = %_Arguments(i); 827 var code = %_Arguments(i);
831 if (!%_IsSmi(code)) code = ToNumber(code) & 0xffff; 828 if (!%_IsSmi(code)) code = ToNumber(code) & 0xffff;
832 %_TwoByteSeqStringSetChar(j, code, two_byte); 829 %_TwoByteSeqStringSetChar(j, code, two_byte);
833 } 830 }
834 return one_byte + two_byte; 831 return one_byte + two_byte;
835 } 832 }
836 833
837 834
838 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2.1 835 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2.1
839 function HtmlEscape(str) { 836 function HtmlEscape(str) {
840 return %_CallFunction(TO_STRING_INLINE(str), /"/g, "&quot;", StringReplace); 837 return %_CallFunction(TO_STRING(str), /"/g, "&quot;", StringReplace);
841 } 838 }
842 839
843 840
844 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2 841 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2
845 function StringAnchor(name) { 842 function StringAnchor(name) {
846 CHECK_OBJECT_COERCIBLE(this, "String.prototype.anchor"); 843 CHECK_OBJECT_COERCIBLE(this, "String.prototype.anchor");
847 return "<a name=\"" + HtmlEscape(name) + "\">" + TO_STRING_INLINE(this) + 844 return "<a name=\"" + HtmlEscape(name) + "\">" + TO_STRING(this) +
848 "</a>"; 845 "</a>";
849 } 846 }
850 847
851 848
852 // ES6 draft, revision 26 (2014-07-18), section B.2.3.3 849 // ES6 draft, revision 26 (2014-07-18), section B.2.3.3
853 function StringBig() { 850 function StringBig() {
854 CHECK_OBJECT_COERCIBLE(this, "String.prototype.big"); 851 CHECK_OBJECT_COERCIBLE(this, "String.prototype.big");
855 return "<big>" + TO_STRING_INLINE(this) + "</big>"; 852 return "<big>" + TO_STRING(this) + "</big>";
856 } 853 }
857 854
858 855
859 // ES6 draft, revision 26 (2014-07-18), section B.2.3.4 856 // ES6 draft, revision 26 (2014-07-18), section B.2.3.4
860 function StringBlink() { 857 function StringBlink() {
861 CHECK_OBJECT_COERCIBLE(this, "String.prototype.blink"); 858 CHECK_OBJECT_COERCIBLE(this, "String.prototype.blink");
862 return "<blink>" + TO_STRING_INLINE(this) + "</blink>"; 859 return "<blink>" + TO_STRING(this) + "</blink>";
863 } 860 }
864 861
865 862
866 // ES6 draft, revision 26 (2014-07-18), section B.2.3.5 863 // ES6 draft, revision 26 (2014-07-18), section B.2.3.5
867 function StringBold() { 864 function StringBold() {
868 CHECK_OBJECT_COERCIBLE(this, "String.prototype.bold"); 865 CHECK_OBJECT_COERCIBLE(this, "String.prototype.bold");
869 return "<b>" + TO_STRING_INLINE(this) + "</b>"; 866 return "<b>" + TO_STRING(this) + "</b>";
870 } 867 }
871 868
872 869
873 // ES6 draft, revision 26 (2014-07-18), section B.2.3.6 870 // ES6 draft, revision 26 (2014-07-18), section B.2.3.6
874 function StringFixed() { 871 function StringFixed() {
875 CHECK_OBJECT_COERCIBLE(this, "String.prototype.fixed"); 872 CHECK_OBJECT_COERCIBLE(this, "String.prototype.fixed");
876 return "<tt>" + TO_STRING_INLINE(this) + "</tt>"; 873 return "<tt>" + TO_STRING(this) + "</tt>";
877 } 874 }
878 875
879 876
880 // ES6 draft, revision 26 (2014-07-18), section B.2.3.7 877 // ES6 draft, revision 26 (2014-07-18), section B.2.3.7
881 function StringFontcolor(color) { 878 function StringFontcolor(color) {
882 CHECK_OBJECT_COERCIBLE(this, "String.prototype.fontcolor"); 879 CHECK_OBJECT_COERCIBLE(this, "String.prototype.fontcolor");
883 return "<font color=\"" + HtmlEscape(color) + "\">" + TO_STRING_INLINE(this) + 880 return "<font color=\"" + HtmlEscape(color) + "\">" + TO_STRING(this) +
884 "</font>"; 881 "</font>";
885 } 882 }
886 883
887 884
888 // ES6 draft, revision 26 (2014-07-18), section B.2.3.8 885 // ES6 draft, revision 26 (2014-07-18), section B.2.3.8
889 function StringFontsize(size) { 886 function StringFontsize(size) {
890 CHECK_OBJECT_COERCIBLE(this, "String.prototype.fontsize"); 887 CHECK_OBJECT_COERCIBLE(this, "String.prototype.fontsize");
891 return "<font size=\"" + HtmlEscape(size) + "\">" + TO_STRING_INLINE(this) + 888 return "<font size=\"" + HtmlEscape(size) + "\">" + TO_STRING(this) +
892 "</font>"; 889 "</font>";
893 } 890 }
894 891
895 892
896 // ES6 draft, revision 26 (2014-07-18), section B.2.3.9 893 // ES6 draft, revision 26 (2014-07-18), section B.2.3.9
897 function StringItalics() { 894 function StringItalics() {
898 CHECK_OBJECT_COERCIBLE(this, "String.prototype.italics"); 895 CHECK_OBJECT_COERCIBLE(this, "String.prototype.italics");
899 return "<i>" + TO_STRING_INLINE(this) + "</i>"; 896 return "<i>" + TO_STRING(this) + "</i>";
900 } 897 }
901 898
902 899
903 // ES6 draft, revision 26 (2014-07-18), section B.2.3.10 900 // ES6 draft, revision 26 (2014-07-18), section B.2.3.10
904 function StringLink(s) { 901 function StringLink(s) {
905 CHECK_OBJECT_COERCIBLE(this, "String.prototype.link"); 902 CHECK_OBJECT_COERCIBLE(this, "String.prototype.link");
906 return "<a href=\"" + HtmlEscape(s) + "\">" + TO_STRING_INLINE(this) + "</a>"; 903 return "<a href=\"" + HtmlEscape(s) + "\">" + TO_STRING(this) + "</a>";
907 } 904 }
908 905
909 906
910 // ES6 draft, revision 26 (2014-07-18), section B.2.3.11 907 // ES6 draft, revision 26 (2014-07-18), section B.2.3.11
911 function StringSmall() { 908 function StringSmall() {
912 CHECK_OBJECT_COERCIBLE(this, "String.prototype.small"); 909 CHECK_OBJECT_COERCIBLE(this, "String.prototype.small");
913 return "<small>" + TO_STRING_INLINE(this) + "</small>"; 910 return "<small>" + TO_STRING(this) + "</small>";
914 } 911 }
915 912
916 913
917 // ES6 draft, revision 26 (2014-07-18), section B.2.3.12 914 // ES6 draft, revision 26 (2014-07-18), section B.2.3.12
918 function StringStrike() { 915 function StringStrike() {
919 CHECK_OBJECT_COERCIBLE(this, "String.prototype.strike"); 916 CHECK_OBJECT_COERCIBLE(this, "String.prototype.strike");
920 return "<strike>" + TO_STRING_INLINE(this) + "</strike>"; 917 return "<strike>" + TO_STRING(this) + "</strike>";
921 } 918 }
922 919
923 920
924 // ES6 draft, revision 26 (2014-07-18), section B.2.3.13 921 // ES6 draft, revision 26 (2014-07-18), section B.2.3.13
925 function StringSub() { 922 function StringSub() {
926 CHECK_OBJECT_COERCIBLE(this, "String.prototype.sub"); 923 CHECK_OBJECT_COERCIBLE(this, "String.prototype.sub");
927 return "<sub>" + TO_STRING_INLINE(this) + "</sub>"; 924 return "<sub>" + TO_STRING(this) + "</sub>";
928 } 925 }
929 926
930 927
931 // ES6 draft, revision 26 (2014-07-18), section B.2.3.14 928 // ES6 draft, revision 26 (2014-07-18), section B.2.3.14
932 function StringSup() { 929 function StringSup() {
933 CHECK_OBJECT_COERCIBLE(this, "String.prototype.sup"); 930 CHECK_OBJECT_COERCIBLE(this, "String.prototype.sup");
934 return "<sup>" + TO_STRING_INLINE(this) + "</sup>"; 931 return "<sup>" + TO_STRING(this) + "</sup>";
935 } 932 }
936 933
937 // ES6 draft 01-20-14, section 21.1.3.13 934 // ES6 draft 01-20-14, section 21.1.3.13
938 function StringRepeat(count) { 935 function StringRepeat(count) {
939 CHECK_OBJECT_COERCIBLE(this, "String.prototype.repeat"); 936 CHECK_OBJECT_COERCIBLE(this, "String.prototype.repeat");
940 937
941 var s = TO_STRING_INLINE(this); 938 var s = TO_STRING(this);
942 var n = $toInteger(count); 939 var n = $toInteger(count);
943 // The maximum string length is stored in a smi, so a longer repeat 940 // The maximum string length is stored in a smi, so a longer repeat
944 // must result in a range error. 941 // must result in a range error.
945 if (n < 0 || n > %_MaxSmi()) throw MakeRangeError(kInvalidCountValue); 942 if (n < 0 || n > %_MaxSmi()) throw MakeRangeError(kInvalidCountValue);
946 943
947 var r = ""; 944 var r = "";
948 while (true) { 945 while (true) {
949 if (n & 1) r += s; 946 if (n & 1) r += s;
950 n >>= 1; 947 n >>= 1;
951 if (n === 0) return r; 948 if (n === 0) return r;
952 s += s; 949 s += s;
953 } 950 }
954 } 951 }
955 952
956 953
957 // ES6 draft 04-05-14, section 21.1.3.18 954 // ES6 draft 04-05-14, section 21.1.3.18
958 function StringStartsWith(searchString /* position */) { // length == 1 955 function StringStartsWith(searchString /* position */) { // length == 1
959 CHECK_OBJECT_COERCIBLE(this, "String.prototype.startsWith"); 956 CHECK_OBJECT_COERCIBLE(this, "String.prototype.startsWith");
960 957
961 var s = TO_STRING_INLINE(this); 958 var s = TO_STRING(this);
962 959
963 if (IS_REGEXP(searchString)) { 960 if (IS_REGEXP(searchString)) {
964 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.startsWith"); 961 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.startsWith");
965 } 962 }
966 963
967 var ss = TO_STRING_INLINE(searchString); 964 var ss = TO_STRING(searchString);
968 var pos = 0; 965 var pos = 0;
969 if (%_ArgumentsLength() > 1) { 966 if (%_ArgumentsLength() > 1) {
970 var arg = %_Arguments(1); // position 967 var arg = %_Arguments(1); // position
971 if (!IS_UNDEFINED(arg)) { 968 if (!IS_UNDEFINED(arg)) {
972 pos = $toInteger(arg); 969 pos = $toInteger(arg);
973 } 970 }
974 } 971 }
975 972
976 var s_len = s.length; 973 var s_len = s.length;
977 if (pos < 0) pos = 0; 974 if (pos < 0) pos = 0;
(...skipping 11 matching lines...) Expand all
989 } 986 }
990 987
991 return true; 988 return true;
992 } 989 }
993 990
994 991
995 // ES6 draft 04-05-14, section 21.1.3.7 992 // ES6 draft 04-05-14, section 21.1.3.7
996 function StringEndsWith(searchString /* position */) { // length == 1 993 function StringEndsWith(searchString /* position */) { // length == 1
997 CHECK_OBJECT_COERCIBLE(this, "String.prototype.endsWith"); 994 CHECK_OBJECT_COERCIBLE(this, "String.prototype.endsWith");
998 995
999 var s = TO_STRING_INLINE(this); 996 var s = TO_STRING(this);
1000 997
1001 if (IS_REGEXP(searchString)) { 998 if (IS_REGEXP(searchString)) {
1002 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.endsWith"); 999 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.endsWith");
1003 } 1000 }
1004 1001
1005 var ss = TO_STRING_INLINE(searchString); 1002 var ss = TO_STRING(searchString);
1006 var s_len = s.length; 1003 var s_len = s.length;
1007 var pos = s_len; 1004 var pos = s_len;
1008 if (%_ArgumentsLength() > 1) { 1005 if (%_ArgumentsLength() > 1) {
1009 var arg = %_Arguments(1); // position 1006 var arg = %_Arguments(1); // position
1010 if (!IS_UNDEFINED(arg)) { 1007 if (!IS_UNDEFINED(arg)) {
1011 pos = $toInteger(arg); 1008 pos = $toInteger(arg);
1012 } 1009 }
1013 } 1010 }
1014 1011
1015 if (pos < 0) pos = 0; 1012 if (pos < 0) pos = 0;
(...skipping 12 matching lines...) Expand all
1028 } 1025 }
1029 1026
1030 return true; 1027 return true;
1031 } 1028 }
1032 1029
1033 1030
1034 // ES6 draft 04-05-14, section 21.1.3.6 1031 // ES6 draft 04-05-14, section 21.1.3.6
1035 function StringIncludes(searchString /* position */) { // length == 1 1032 function StringIncludes(searchString /* position */) { // length == 1
1036 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes"); 1033 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes");
1037 1034
1038 var string = TO_STRING_INLINE(this); 1035 var string = TO_STRING(this);
1039 1036
1040 if (IS_REGEXP(searchString)) { 1037 if (IS_REGEXP(searchString)) {
1041 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.includes"); 1038 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.includes");
1042 } 1039 }
1043 1040
1044 searchString = TO_STRING_INLINE(searchString); 1041 searchString = TO_STRING(searchString);
1045 var pos = 0; 1042 var pos = 0;
1046 if (%_ArgumentsLength() > 1) { 1043 if (%_ArgumentsLength() > 1) {
1047 pos = %_Arguments(1); // position 1044 pos = %_Arguments(1); // position
1048 pos = TO_INTEGER(pos); 1045 pos = TO_INTEGER(pos);
1049 } 1046 }
1050 1047
1051 var stringLength = string.length; 1048 var stringLength = string.length;
1052 if (pos < 0) pos = 0; 1049 if (pos < 0) pos = 0;
1053 if (pos > stringLength) pos = stringLength; 1050 if (pos > stringLength) pos = stringLength;
1054 var searchStringLength = searchString.length; 1051 var searchStringLength = searchString.length;
1055 1052
1056 if (searchStringLength + pos > stringLength) { 1053 if (searchStringLength + pos > stringLength) {
1057 return false; 1054 return false;
1058 } 1055 }
1059 1056
1060 return %StringIndexOf(string, searchString, pos) !== -1; 1057 return %StringIndexOf(string, searchString, pos) !== -1;
1061 } 1058 }
1062 1059
1063 1060
1064 // ES6 Draft 05-22-2014, section 21.1.3.3 1061 // ES6 Draft 05-22-2014, section 21.1.3.3
1065 function StringCodePointAt(pos) { 1062 function StringCodePointAt(pos) {
1066 CHECK_OBJECT_COERCIBLE(this, "String.prototype.codePointAt"); 1063 CHECK_OBJECT_COERCIBLE(this, "String.prototype.codePointAt");
1067 1064
1068 var string = TO_STRING_INLINE(this); 1065 var string = TO_STRING(this);
1069 var size = string.length; 1066 var size = string.length;
1070 pos = TO_INTEGER(pos); 1067 pos = TO_INTEGER(pos);
1071 if (pos < 0 || pos >= size) { 1068 if (pos < 0 || pos >= size) {
1072 return UNDEFINED; 1069 return UNDEFINED;
1073 } 1070 }
1074 var first = %_StringCharCodeAt(string, pos); 1071 var first = %_StringCharCodeAt(string, pos);
1075 if (first < 0xD800 || first > 0xDBFF || pos + 1 == size) { 1072 if (first < 0xD800 || first > 0xDBFF || pos + 1 == size) {
1076 return first; 1073 return first;
1077 } 1074 }
1078 var second = %_StringCharCodeAt(string, pos + 1); 1075 var second = %_StringCharCodeAt(string, pos + 1);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 1111
1115 // ES6 Draft 03-17-2015, section 21.1.2.4 1112 // ES6 Draft 03-17-2015, section 21.1.2.4
1116 function StringRaw(callSite) { 1113 function StringRaw(callSite) {
1117 // TODO(caitp): Use rest parameters when implemented 1114 // TODO(caitp): Use rest parameters when implemented
1118 var numberOfSubstitutions = %_ArgumentsLength(); 1115 var numberOfSubstitutions = %_ArgumentsLength();
1119 var cooked = TO_OBJECT(callSite); 1116 var cooked = TO_OBJECT(callSite);
1120 var raw = TO_OBJECT(cooked.raw); 1117 var raw = TO_OBJECT(cooked.raw);
1121 var literalSegments = $toLength(raw.length); 1118 var literalSegments = $toLength(raw.length);
1122 if (literalSegments <= 0) return ""; 1119 if (literalSegments <= 0) return "";
1123 1120
1124 var result = ToString(raw[0]); 1121 var result = TO_STRING(raw[0]);
1125 1122
1126 for (var i = 1; i < literalSegments; ++i) { 1123 for (var i = 1; i < literalSegments; ++i) {
1127 if (i < numberOfSubstitutions) { 1124 if (i < numberOfSubstitutions) {
1128 result += ToString(%_Arguments(i)); 1125 result += TO_STRING(%_Arguments(i));
1129 } 1126 }
1130 result += ToString(raw[i]); 1127 result += TO_STRING(raw[i]);
1131 } 1128 }
1132 1129
1133 return result; 1130 return result;
1134 } 1131 }
1135 1132
1136 // ------------------------------------------------------------------- 1133 // -------------------------------------------------------------------
1137 1134
1138 // Set the String function and constructor. 1135 // Set the String function and constructor.
1139 %FunctionSetPrototype(GlobalString, new GlobalString()); 1136 %FunctionSetPrototype(GlobalString, new GlobalString());
1140 1137
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 to.StringLastIndexOf = StringLastIndexOfJS; 1201 to.StringLastIndexOf = StringLastIndexOfJS;
1205 to.StringMatch = StringMatchJS; 1202 to.StringMatch = StringMatchJS;
1206 to.StringReplace = StringReplace; 1203 to.StringReplace = StringReplace;
1207 to.StringSlice = StringSlice; 1204 to.StringSlice = StringSlice;
1208 to.StringSplit = StringSplitJS; 1205 to.StringSplit = StringSplitJS;
1209 to.StringSubstr = StringSubstr; 1206 to.StringSubstr = StringSubstr;
1210 to.StringSubstring = StringSubstring; 1207 to.StringSubstring = StringSubstring;
1211 }); 1208 });
1212 1209
1213 }) 1210 })
OLDNEW
« no previous file with comments | « src/runtime/runtime-uri.cc ('k') | src/string-iterator.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698