author | sundar |
Wed, 06 May 2015 20:04:42 +0530 | |
changeset 30394 | 72a59e4dffea |
parent 24778 | 2ff5d7041566 |
permissions | -rw-r--r-- |
17245
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
1 |
/* |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
17245
diff
changeset
|
4 |
* |
17245
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
17245
diff
changeset
|
8 |
* |
17245
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
13 |
* accompanied this code). |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
17245
diff
changeset
|
14 |
* |
17245
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
17245
diff
changeset
|
18 |
* |
17245
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
21 |
* questions. |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
22 |
*/ |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
23 |
|
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
24 |
/** |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
25 |
* JDK-8013131: Various compatibility issues in String.prototype.split() |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
26 |
* |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
27 |
* @test |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
28 |
* @run |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
29 |
*/ |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
30 |
|
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
31 |
|
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
32 |
// Make sure limit is honored with undefined/empty separator |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
33 |
print(JSON.stringify("aa".split(undefined, 0))); |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
34 |
print(JSON.stringify("abc".split("", 1))); |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
35 |
|
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
36 |
// Make sure limit is honored with capture groups |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
37 |
print(JSON.stringify("aa".split(/(a)/, 1))); |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
38 |
print(JSON.stringify("aa".split(/(a)/, 2))); |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
39 |
print(JSON.stringify("aa".split(/((a))/, 1))); |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
40 |
print(JSON.stringify("aa".split(/((a))/, 2))); |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
41 |
|
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
42 |
// Empty capture group at end of string should be ignored |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
43 |
print(JSON.stringify("aaa".split(/((?:))/))); |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
44 |
|
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
45 |
// Tests below are to make sure that split does not read or write lastIndex property |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
46 |
var r = /a/; |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
47 |
r.lastIndex = { |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
48 |
valueOf: function(){throw 2} |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
49 |
}; |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
50 |
print(JSON.stringify("aa".split(r))); |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
51 |
|
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
52 |
r = /a/g; |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
53 |
r.lastIndex = 100; |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
54 |
print(JSON.stringify("aa".split(r))); |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
55 |
print(r.lastIndex); |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
56 |
|
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
57 |
r = /((?:))/g; |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
58 |
r.lastIndex = 100; |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
59 |
print(JSON.stringify("aaa".split(r))); |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
60 |
print(r.lastIndex); |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
61 |
|
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
62 |
// Make sure lastIndex is not updated on non-global regexp |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
63 |
r = /a/; |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
64 |
r.lastIndex = 100; |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
65 |
print(JSON.stringify(r.exec("aaa"))); |
c49b17cd464b
8013131: Various compatibility issues in String.prototype.split()
hannesw
parents:
diff
changeset
|
66 |
print(r.lastIndex); |