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

Side by Side Diff: src/string.js

Issue 1528005: Fix bug in string replace regexp with function when returning non-string. (Closed)
Patch Set: Created 10 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
« no previous file with comments | « no previous file | test/mjsunit/string-replace.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 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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 while (i < len) { 443 while (i < len) {
444 var elem = res[i]; 444 var elem = res[i];
445 if (%_IsSmi(elem)) { 445 if (%_IsSmi(elem)) {
446 if (elem > 0) { 446 if (elem > 0) {
447 match_start = (elem >> 11) + (elem & 0x7ff); 447 match_start = (elem >> 11) + (elem & 0x7ff);
448 } else { 448 } else {
449 match_start = res[++i] - elem; 449 match_start = res[++i] - elem;
450 } 450 }
451 } else { 451 } else {
452 var func_result = replace.call(null, elem, match_start, subject); 452 var func_result = replace.call(null, elem, match_start, subject);
453 if (!IS_STRING(func_result)) func_result = TO_STRING(func_result); 453 if (!IS_STRING(func_result)) func_result = NonStringToString(func_re sult);
fschneider 2010/03/29 16:21:47 Long line.
Vitaly Repeshko 2010/03/29 16:52:53 You can use func_result = TO_STRING_INLINE(func_re
Lasse Reichstein 2010/03/29 18:58:31 Line wrapped. Re. TO_STRING_INLINE, I considered i
454 res[i] = func_result; 454 res[i] = func_result;
455 match_start += elem.length; 455 match_start += elem.length;
456 } 456 }
457 i++; 457 i++;
458 } 458 }
459 } else { 459 } else {
460 while (i < len) { 460 while (i < len) {
461 var elem = res[i]; 461 var elem = res[i];
462 if (!%_IsSmi(elem)) { 462 if (!%_IsSmi(elem)) {
463 // elem must be an Array. 463 // elem must be an Array.
464 // Use the apply argument as backing for global RegExp properties. 464 // Use the apply argument as backing for global RegExp properties.
465 lastMatchInfoOverride = elem; 465 lastMatchInfoOverride = elem;
466 var func_result = replace.apply(null, elem); 466 var func_result = replace.apply(null, elem);
467 if (!IS_STRING(func_result)) func_result = TO_STRING(func_result); 467 if (!IS_STRING(func_result)) func_result = NonStringToString(func_re sult);
fschneider 2010/03/29 16:21:47 Long line.
Vitaly Repeshko 2010/03/29 16:52:53 Same here.
Lasse Reichstein 2010/03/29 18:58:31 Dittos.
468 res[i] = func_result; 468 res[i] = func_result;
469 } 469 }
470 i++; 470 i++;
471 } 471 }
472 } 472 }
473 var result = new ReplaceResultBuilder(subject, res); 473 var result = new ReplaceResultBuilder(subject, res);
474 return result.generate(); 474 return result.generate();
475 } finally { 475 } finally {
476 lastMatchInfoOverride = null; 476 lastMatchInfoOverride = null;
477 resultArray.length = 0; 477 resultArray.length = 0;
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 "small", StringSmall, 981 "small", StringSmall,
982 "strike", StringStrike, 982 "strike", StringStrike,
983 "sub", StringSub, 983 "sub", StringSub,
984 "sup", StringSup, 984 "sup", StringSup,
985 "toJSON", StringToJSON 985 "toJSON", StringToJSON
986 )); 986 ));
987 } 987 }
988 988
989 989
990 SetupString(); 990 SetupString();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/string-replace.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698