1a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// Copyright 2014 the V8 project authors. All rights reserved.
2a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// Redistribution and use in source and binary forms, with or without
3a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// modification, are permitted provided that the following conditions are
4a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// met:
5a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org//
6a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org//     * Redistributions of source code must retain the above copyright
7a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org//       notice, this list of conditions and the following disclaimer.
8a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org//     * Redistributions in binary form must reproduce the above
9a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org//       copyright notice, this list of conditions and the following
10a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org//       disclaimer in the documentation and/or other materials provided
11a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org//       with the distribution.
12a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org//     * Neither the name of Google Inc. nor the names of its
13a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org//       contributors may be used to endorse or promote products derived
14a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org//       from this software without specific prior written permission.
15a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org//
16a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org
28a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// Test that sticky regexp support is not affecting V8 when the
29a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org// --harmony-regexps flag is not on.
30a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org
31a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertThrows(function() { eval("/foo.bar/y"); }, SyntaxError);
32a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertThrows(function() { eval("/foobar/y"); }, SyntaxError);
33a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertThrows(function() { eval("/foo.bar/gy"); }, SyntaxError);
34a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertThrows(function() { eval("/foobar/gy"); }, SyntaxError);
35a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertThrows(function() { new RegExp("foo.bar", "y"); }, SyntaxError);
36a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertThrows(function() { new RegExp("foobar", "y"); }, SyntaxError);
37a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertThrows(function() { new RegExp("foo.bar", "gy"); }, SyntaxError);
38a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertThrows(function() { new RegExp("foobar", "gy"); }, SyntaxError);
39a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org
40a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgvar re = /foo.bar/;
41a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertEquals("/foo.bar/", "" + re);
42a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgvar plain = /foobar/;
43a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertEquals("/foobar/", "" + plain);
44a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org
45a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgre.compile("foo.bar");
46a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertEquals(void 0, re.sticky);
47a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org
48a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgvar global = /foo.bar/g;
49a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertEquals("/foo.bar/g", "" + global);
50a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgvar plainglobal = /foobar/g;
51a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertEquals("/foobar/g", "" + plainglobal);
52a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org
53a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertEquals(void 0, re.sticky);
54a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgre.sticky = true; // Has no effect on the regexp, just sets a property.
55a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertTrue(re.sticky);
56a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org
57a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertTrue(re.test("..foo.bar"));
58a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org
59a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgre.lastIndex = -1; // Ignored for non-global, non-sticky.
60a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertTrue(re.test("..foo.bar"));
61a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertEquals(-1, re.lastIndex);
62a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org
63a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgre.lastIndex = -1; // Ignored for non-global, non-sticky.
64a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertTrue(!!re.exec("..foo.bar"));
65a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.orgassertEquals(-1, re.lastIndex);
66