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

Side by Side Diff: src/string.js

Issue 7976046: Fixed string.split: always convert non-regexp separator to string. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-1711.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 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 561
562 562
563 // ECMA-262 section 15.5.4.14 563 // ECMA-262 section 15.5.4.14
564 function StringSplit(separator, limit) { 564 function StringSplit(separator, limit) {
565 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 565 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
566 throw MakeTypeError("called_on_null_or_undefined", 566 throw MakeTypeError("called_on_null_or_undefined",
567 ["String.prototype.split"]); 567 ["String.prototype.split"]);
568 } 568 }
569 var subject = TO_STRING_INLINE(this); 569 var subject = TO_STRING_INLINE(this);
570 limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit); 570 limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit);
571 if (limit === 0) return [];
572 571
573 // ECMA-262 says that if separator is undefined, the result should 572 // ECMA-262 says that if separator is undefined, the result should
574 // be an array of size 1 containing the entire string. SpiderMonkey 573 // be an array of size 1 containing the entire string. SpiderMonkey
575 // and KJS have this behavior only when no separator is given. If 574 // and KJS have this behavior only when no separator is given. If
576 // undefined is explicitly given, they convert it to a string and 575 // undefined is explicitly given, they convert it to a string and
577 // use that. We do as SpiderMonkey and KJS. 576 // use that. We do as SpiderMonkey and KJS.
578 if (%_ArgumentsLength() === 0) { 577 if (%_ArgumentsLength() === 0) {
579 return [subject]; 578 return [subject];
580 } 579 }
581 580
582 var length = subject.length; 581 var length = subject.length;
583 if (!IS_REGEXP(separator)) { 582 if (!IS_REGEXP(separator)) {
584 separator = TO_STRING_INLINE(separator); 583 separator = TO_STRING_INLINE(separator);
584
585 if (limit === 0) return [];
586
585 var separator_length = separator.length; 587 var separator_length = separator.length;
586 588
587 // If the separator string is empty then return the elements in the subject. 589 // If the separator string is empty then return the elements in the subject.
588 if (separator_length === 0) return %StringToArray(subject, limit); 590 if (separator_length === 0) return %StringToArray(subject, limit);
589 591
590 var result = %StringSplit(subject, separator, limit); 592 var result = %StringSplit(subject, separator, limit);
591 593
592 return result; 594 return result;
593 } 595 }
596
597 if (limit === 0) return [];
594 598
595 %_Log('regexp', 'regexp-split,%0S,%1r', [subject, separator]); 599 %_Log('regexp', 'regexp-split,%0S,%1r', [subject, separator]);
596 600
597 if (length === 0) { 601 if (length === 0) {
598 if (DoRegExpExec(separator, subject, 0, 0) != null) { 602 if (DoRegExpExec(separator, subject, 0, 0) != null) {
599 return []; 603 return [];
600 } 604 }
601 return [subject]; 605 return [subject];
602 } 606 }
603 607
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 "fixed", StringFixed, 990 "fixed", StringFixed,
987 "italics", StringItalics, 991 "italics", StringItalics,
988 "small", StringSmall, 992 "small", StringSmall,
989 "strike", StringStrike, 993 "strike", StringStrike,
990 "sub", StringSub, 994 "sub", StringSub,
991 "sup", StringSup 995 "sup", StringSup
992 )); 996 ));
993 } 997 }
994 998
995 SetUpString(); 999 SetUpString();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-1711.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698