1// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Flags: --harmony-regexps --harmony-unicode-regexps
6
7var r1 = /abc/gi;
8assertEquals("abc", r1.source);
9assertTrue(r1.global);
10assertTrue(r1.ignoreCase);
11assertFalse(r1.multiline);
12assertFalse(r1.sticky);
13assertFalse(r1.unicode);
14
15// Internal slot of prototype is not read.
16var r2 = { __proto__: r1 };
17assertThrows(function() { r2.source; }, TypeError);
18assertThrows(function() { r2.global; }, TypeError);
19assertThrows(function() { r2.ignoreCase; }, TypeError);
20assertThrows(function() { r2.multiline; }, TypeError);
21assertThrows(function() { r2.sticky; }, TypeError);
22assertThrows(function() { r2.unicode; }, TypeError);
23
24var r3 = /I/;
25var string = "iIiIi";
26var expected = "iXiIi";
27assertFalse(r3.global);
28assertFalse(r3.ignoreCase);
29assertEquals("", r3.flags);
30assertEquals(expected, string.replace(r3, "X"));
31
32var get_count = 0;
33Object.defineProperty(r3, "global", {
34  get: function() { get_count++; return true; }
35});
36Object.defineProperty(r3, "ignoreCase", {
37  get: function() { get_count++; return true; }
38});
39
40assertTrue(r3.global);
41assertEquals(1, get_count);
42assertTrue(r3.ignoreCase);
43assertEquals(2, get_count);
44// Overridden flag getters affects the flags getter.
45assertEquals("gi", r3.flags);
46assertEquals(4, get_count);
47// Overridden flag getters do not affect the internal flags.
48assertEquals(expected, string.replace(r3, "X"));
49assertEquals(4, get_count);
50
51
52function testName(name) {
53  // TODO(littledan): For web compatibility, we don't throw an exception,
54  // but ES2015 expects an exception to be thrown from this getter.
55  assertEquals(undefined, RegExp.prototype[name]);
56  assertEquals(
57      "get " + name,
58      Object.getOwnPropertyDescriptor(RegExp.prototype, name).get.name);
59}
60
61testName("global");
62testName("ignoreCase");
63testName("multiline");
64testName("source");
65testName("sticky");
66testName("unicode");
67