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