1 // Copyright 2013 the V8 project authors. All rights reserved. 2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions 6 // are met: 7 // 1. Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // 2. Redistributions in binary form must reproduce the above copyright 10 // notice, this list of conditions and the following disclaimer in the 11 // documentation and/or other materials provided with the distribution. 12 // 13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 24 description( 25 'Tests that regular expressions do not have extensions that diverge from the JavaScript specification. ' 26 + 'Because WebKit originally used a copy of PCRE, various non-JavaScript regular expression features were historically present. ' 27 + 'Also tests various related edge cases.' 28 ); 29 30 shouldBe('/\\x{41}/.exec("yA1")', 'null'); 31 shouldBe('/[\\x{41}]/.exec("yA1").toString()', '"1"'); 32 shouldBe('/\\x1g/.exec("x1g").toString()', '"x1g"'); 33 shouldBe('/[\\x1g]/.exec("x").toString()', '"x"'); 34 shouldBe('/[\\x1g]/.exec("1").toString()', '"1"'); 35 shouldBe('/\\2147483648/.exec(String.fromCharCode(140) + "7483648").toString()', 'String.fromCharCode(140) + "7483648"'); 36 shouldBe('/\\4294967296/.exec("\\"94967296").toString()', '"\\"94967296"'); 37 shouldBe('/\\8589934592/.exec("\\\\8589934592").toString()', '"\\\\8589934592"'); 38 shouldBe('"\\nAbc\\n".replace(/(\\n)[^\\n]+$/, "$1")', '"\\nAbc\\n"'); 39 shouldBe('/x$/.exec("x\\n")', 'null'); 40 shouldThrow('/x++/'); 41 shouldBe('/[]]/.exec("]")', 'null'); 42 43 debug(''); 44 debug('Octal escape sequences are in Annex B of the standard.'); 45 debug(''); 46 47 shouldBe('/\\060/.exec("y01").toString()', '"0"'); 48 shouldBe('/[\\060]/.exec("y01").toString()', '"0"'); 49 shouldBe('/\\606/.exec("y06").toString()', '"06"'); 50 shouldBe('/[\\606]/.exec("y06").toString()', '"0"'); 51 shouldBe('/[\\606]/.exec("y6").toString()', '"6"'); 52 shouldBe('/\\101/.exec("yA1").toString()', '"A"'); 53 shouldBe('/[\\101]/.exec("yA1").toString()', '"A"'); 54 shouldBe('/\\1011/.exec("yA1").toString()', '"A1"'); 55 shouldBe('/[\\1011]/.exec("yA1").toString()', '"A"'); 56 shouldBe('/[\\1011]/.exec("y1").toString()', '"1"'); 57 shouldBe('/\\10q/.exec("y" + String.fromCharCode(8) + "q").toString()', 'String.fromCharCode(8) + "q"'); 58 shouldBe('/[\\10q]/.exec("y" + String.fromCharCode(8) + "q").toString()', 'String.fromCharCode(8)'); 59 shouldBe('/\\1q/.exec("y" + String.fromCharCode(1) + "q").toString()', 'String.fromCharCode(1) + "q"'); 60 shouldBe('/[\\1q]/.exec("y" + String.fromCharCode(1) + "q").toString()', 'String.fromCharCode(1)'); 61 shouldBe('/[\\1q]/.exec("yq").toString()', '"q"'); 62 shouldBe('/\\8q/.exec("\\\\8q").toString()', '"\\\\8q"'); 63 shouldBe('/[\\8q]/.exec("y8q").toString()', '"8"'); 64 shouldBe('/[\\8q]/.exec("yq").toString()', '"q"'); 65 shouldBe('/(x)\\1q/.exec("xxq").toString()', '"xxq,x"'); 66 shouldBe('/(x)[\\1q]/.exec("xxq").toString()', '"xq,x"'); 67 shouldBe('/(x)[\\1q]/.exec("xx" + String.fromCharCode(1)).toString()', '"x" + String.fromCharCode(1) + ",x"'); 68 69 debug(''); 70