OLD | NEW |
(Empty) | |
| 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 |
| 7 var r1 = /abc/gi; |
| 8 assertEquals("abc", r1.source); |
| 9 assertTrue(r1.global); |
| 10 assertTrue(r1.ignoreCase); |
| 11 assertFalse(r1.multiline); |
| 12 assertFalse(r1.sticky); |
| 13 assertFalse(r1.unicode); |
| 14 |
| 15 // Internal slot of prototype is not read. |
| 16 var r2 = { __proto__: r1 }; |
| 17 assertThrows(function() { r2.source; }, TypeError); |
| 18 assertThrows(function() { r2.global; }, TypeError); |
| 19 assertThrows(function() { r2.ignoreCase; }, TypeError); |
| 20 assertThrows(function() { r2.multiline; }, TypeError); |
| 21 assertThrows(function() { r2.sticky; }, TypeError); |
| 22 assertThrows(function() { r2.unicode; }, TypeError); |
| 23 |
| 24 var r3 = /I/; |
| 25 var string = "iIiIi"; |
| 26 var expected = "iXiIi"; |
| 27 assertFalse(r3.global); |
| 28 assertFalse(r3.ignoreCase); |
| 29 assertEquals("", r3.flags); |
| 30 assertEquals(expected, string.replace(r3, "X")); |
| 31 |
| 32 var get_count = 0; |
| 33 Object.defineProperty(r3, "global", { |
| 34 get: function() { get_count++; return true; } |
| 35 }); |
| 36 Object.defineProperty(r3, "ignoreCase", { |
| 37 get: function() { get_count++; return true; } |
| 38 }); |
| 39 |
| 40 assertTrue(r3.global); |
| 41 assertEquals(1, get_count); |
| 42 assertTrue(r3.ignoreCase); |
| 43 assertEquals(2, get_count); |
| 44 // Overridden flag getters affects the flags getter. |
| 45 assertEquals("gi", r3.flags); |
| 46 assertEquals(4, get_count); |
| 47 // Overridden flag getters do not affect the internal flags. |
| 48 assertEquals(expected, string.replace(r3, "X")); |
| 49 assertEquals(4, get_count); |
| 50 |
| 51 |
| 52 function testName(name) { |
| 53 assertThrows(() => RegExp.prototype[name], TypeError); |
| 54 assertEquals( |
| 55 "RegExp.prototype." + name, |
| 56 Object.getOwnPropertyDescriptor(RegExp.prototype, name).get.name); |
| 57 } |
| 58 |
| 59 testName("global"); |
| 60 testName("ignoreCase"); |
| 61 testName("multiline"); |
| 62 testName("source"); |
| 63 testName("sticky"); |
| 64 testName("unicode"); |
OLD | NEW |