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

Side by Side Diff: src/string.js

Issue 1316933002: [es6] Initial steps towards a correct implementation of IsCallable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: ia32, arm and arm64 ports. Misc cleanups. 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
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
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // .... special case that replaces with one single character 241 // .... special case that replaces with one single character
242 // ...... function replace 242 // ...... function replace
243 // ...... string replace (with $-expansion) 243 // ...... string replace (with $-expansion)
244 244
245 if (IS_REGEXP(search)) { 245 if (IS_REGEXP(search)) {
246 // Emulate RegExp.prototype.exec's side effect in step 5, even if 246 // Emulate RegExp.prototype.exec's side effect in step 5, even if
247 // value is discarded. 247 // value is discarded.
248 var lastIndex = search.lastIndex; 248 var lastIndex = search.lastIndex;
249 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex); 249 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex);
250 250
251 if (!IS_SPEC_FUNCTION(replace)) { 251 if (!IS_CALLABLE(replace)) {
252 replace = TO_STRING_INLINE(replace); 252 replace = TO_STRING_INLINE(replace);
253 253
254 if (!search.global) { 254 if (!search.global) {
255 // Non-global regexp search, string replace. 255 // Non-global regexp search, string replace.
256 var match = RegExpExec(search, subject, 0); 256 var match = RegExpExec(search, subject, 0);
257 if (match == null) { 257 if (match == null) {
258 search.lastIndex = 0 258 search.lastIndex = 0
259 return subject; 259 return subject;
260 } 260 }
261 if (replace.length == 0) { 261 if (replace.length == 0) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 // replaced by a simple string and only pays off for long strings. 308 // replaced by a simple string and only pays off for long strings.
309 return %StringReplaceOneCharWithString(subject, search, replace); 309 return %StringReplaceOneCharWithString(subject, search, replace);
310 } 310 }
311 var start = %StringIndexOf(subject, search, 0); 311 var start = %StringIndexOf(subject, search, 0);
312 if (start < 0) return subject; 312 if (start < 0) return subject;
313 var end = start + search.length; 313 var end = start + search.length;
314 314
315 var result = %_SubString(subject, 0, start); 315 var result = %_SubString(subject, 0, start);
316 316
317 // Compute the string to replace with. 317 // Compute the string to replace with.
318 if (IS_SPEC_FUNCTION(replace)) { 318 if (IS_CALLABLE(replace)) {
319 var receiver = UNDEFINED; 319 var receiver = UNDEFINED;
320 result += %_CallFunction(receiver, search, start, subject, replace); 320 result += %_CallFunction(receiver, search, start, subject, replace);
321 } else { 321 } else {
322 reusableMatchInfo[CAPTURE0] = start; 322 reusableMatchInfo[CAPTURE0] = start;
323 reusableMatchInfo[CAPTURE1] = end; 323 reusableMatchInfo[CAPTURE1] = end;
324 result = ExpandReplacement(TO_STRING_INLINE(replace), 324 result = ExpandReplacement(TO_STRING_INLINE(replace),
325 subject, 325 subject,
326 reusableMatchInfo, 326 reusableMatchInfo,
327 result); 327 result);
328 } 328 }
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 to.StringLastIndexOf = StringLastIndexOfJS; 1204 to.StringLastIndexOf = StringLastIndexOfJS;
1205 to.StringMatch = StringMatchJS; 1205 to.StringMatch = StringMatchJS;
1206 to.StringReplace = StringReplace; 1206 to.StringReplace = StringReplace;
1207 to.StringSlice = StringSlice; 1207 to.StringSlice = StringSlice;
1208 to.StringSplit = StringSplitJS; 1208 to.StringSplit = StringSplitJS;
1209 to.StringSubstr = StringSubstr; 1209 to.StringSubstr = StringSubstr;
1210 to.StringSubstring = StringSubstring; 1210 to.StringSubstring = StringSubstring;
1211 }); 1211 });
1212 1212
1213 }) 1213 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698