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

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: Rebase again. 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-proxy.cc ('k') | src/v8natives.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
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 // .... special case that replaces with one single character 243 // .... special case that replaces with one single character
244 // ...... function replace 244 // ...... function replace
245 // ...... string replace (with $-expansion) 245 // ...... string replace (with $-expansion)
246 246
247 if (IS_REGEXP(search)) { 247 if (IS_REGEXP(search)) {
248 // Emulate RegExp.prototype.exec's side effect in step 5, even if 248 // Emulate RegExp.prototype.exec's side effect in step 5, even if
249 // value is discarded. 249 // value is discarded.
250 var lastIndex = search.lastIndex; 250 var lastIndex = search.lastIndex;
251 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex); 251 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex);
252 252
253 if (!IS_SPEC_FUNCTION(replace)) { 253 if (!IS_CALLABLE(replace)) {
254 replace = TO_STRING_INLINE(replace); 254 replace = TO_STRING_INLINE(replace);
255 255
256 if (!search.global) { 256 if (!search.global) {
257 // Non-global regexp search, string replace. 257 // Non-global regexp search, string replace.
258 var match = RegExpExec(search, subject, 0); 258 var match = RegExpExec(search, subject, 0);
259 if (match == null) { 259 if (match == null) {
260 search.lastIndex = 0 260 search.lastIndex = 0
261 return subject; 261 return subject;
262 } 262 }
263 if (replace.length == 0) { 263 if (replace.length == 0) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 // replaced by a simple string and only pays off for long strings. 310 // replaced by a simple string and only pays off for long strings.
311 return %StringReplaceOneCharWithString(subject, search, replace); 311 return %StringReplaceOneCharWithString(subject, search, replace);
312 } 312 }
313 var start = %StringIndexOf(subject, search, 0); 313 var start = %StringIndexOf(subject, search, 0);
314 if (start < 0) return subject; 314 if (start < 0) return subject;
315 var end = start + search.length; 315 var end = start + search.length;
316 316
317 var result = %_SubString(subject, 0, start); 317 var result = %_SubString(subject, 0, start);
318 318
319 // Compute the string to replace with. 319 // Compute the string to replace with.
320 if (IS_SPEC_FUNCTION(replace)) { 320 if (IS_CALLABLE(replace)) {
321 var receiver = UNDEFINED; 321 var receiver = UNDEFINED;
322 result += %_CallFunction(receiver, search, start, subject, replace); 322 result += %_CallFunction(receiver, search, start, subject, replace);
323 } else { 323 } else {
324 reusableMatchInfo[CAPTURE0] = start; 324 reusableMatchInfo[CAPTURE0] = start;
325 reusableMatchInfo[CAPTURE1] = end; 325 reusableMatchInfo[CAPTURE1] = end;
326 result = ExpandReplacement(TO_STRING_INLINE(replace), 326 result = ExpandReplacement(TO_STRING_INLINE(replace),
327 subject, 327 subject,
328 reusableMatchInfo, 328 reusableMatchInfo,
329 result); 329 result);
330 } 330 }
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 to.StringLastIndexOf = StringLastIndexOfJS; 1206 to.StringLastIndexOf = StringLastIndexOfJS;
1207 to.StringMatch = StringMatchJS; 1207 to.StringMatch = StringMatchJS;
1208 to.StringReplace = StringReplace; 1208 to.StringReplace = StringReplace;
1209 to.StringSlice = StringSlice; 1209 to.StringSlice = StringSlice;
1210 to.StringSplit = StringSplitJS; 1210 to.StringSplit = StringSplitJS;
1211 to.StringSubstr = StringSubstr; 1211 to.StringSubstr = StringSubstr;
1212 to.StringSubstring = StringSubstring; 1212 to.StringSubstring = StringSubstring;
1213 }); 1213 });
1214 1214
1215 }) 1215 })
OLDNEW
« no previous file with comments | « src/runtime/runtime-proxy.cc ('k') | src/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698