Reviewers: rossberg,
Description:
Fix small spec violation in String.prototype.split.
Also slightly extended the test coverage.
[email protected]
BUG=v8:3026
Please review this at https://codereview.chromium.org/119093002/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+27, -10 lines):
M src/string.js
A + test/mjsunit/regress/regress-3026.js
M test/mjsunit/string-split.js
Index: src/string.js
diff --git a/src/string.js b/src/string.js
index
14b44ca41f3d7f248a5756b54983f09ab3a55c8e..dd5115d5bf311cb2bc827b33c240b381f480b004
100644
--- a/src/string.js
+++ b/src/string.js
@@ -616,24 +616,22 @@ function StringSplit(separator, limit) {
var subject = TO_STRING_INLINE(this);
limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit);
- // ECMA-262 says that if separator is undefined, the result should
- // be an array of size 1 containing the entire string.
- if (IS_UNDEFINED(separator)) {
- return [subject];
- }
-
var length = subject.length;
if (!IS_REGEXP(separator)) {
- separator = TO_STRING_INLINE(separator);
+ var separator_string = TO_STRING_INLINE(separator);
if (limit === 0) return [];
- var separator_length = separator.length;
+ // ECMA-262 says that if separator is undefined, the result should
+ // be an array of size 1 containing the entire string.
+ if (IS_UNDEFINED(separator)) return [subject];
+
+ var separator_length = separator_string.length;
// If the separator string is empty then return the elements in the
subject.
if (separator_length === 0) return %StringToArray(subject, limit);
- var result = %StringSplit(subject, separator, limit);
+ var result = %StringSplit(subject, separator_string, limit);
return result;
}
Index: test/mjsunit/regress/regress-3026.js
diff --git a/test/mjsunit/regress/regress-2690.js
b/test/mjsunit/regress/regress-3026.js
similarity index 97%
copy from test/mjsunit/regress/regress-2690.js
copy to test/mjsunit/regress/regress-3026.js
index
0ed4c5c679a61e0fdb91cd0758b1246aa8f36565..d25c88d43273ee18a622269f418c4a7792c18ad0
100644
--- a/test/mjsunit/regress/regress-2690.js
+++ b/test/mjsunit/regress/regress-3026.js
@@ -25,4 +25,4 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-assertTrue(/\1[a]/.test("\1a"));
+assertEquals([], "abc".split(undefined, 0));
Index: test/mjsunit/string-split.js
diff --git a/test/mjsunit/string-split.js b/test/mjsunit/string-split.js
index
1308244cabd538eeba01f2d5b27d94c736978991..efd0ef3eae3dc1e8843b33e69f7102e00dca4667
100644
--- a/test/mjsunit/string-split.js
+++ b/test/mjsunit/string-split.js
@@ -145,3 +145,22 @@ for (var i = 0; i < 128; i++) {
assertEquals(1, split_chars[i].length);
assertEquals(i, split_chars[i].charCodeAt(0));
}
+
+// Check that the separator is converted to string before returning due to
+// limit == 0.
+var counter = 0;
+var separator = { toString: function() { counter++; return "b"; }};
+assertEquals([], "abc".split(separator, 0));
+assertEquals(1, counter);
+
+// Check that the subject is converted to string before the separator.
+counter = 0;
+var subject = { toString: function() { assertEquals(0, counter);
+ counter++;
+ return "abc"; }};
+separator = { toString: function() { assertEquals(1, counter);
+ counter++;
+ return "b"; }};
+
+assertEquals(["a", "c"], String.prototype.split.call(subject, separator));
+assertEquals(2, counter);
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.