Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1 | // Copyright 2014 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 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5 | // Flags: --harmony-regexps --harmony-unicode-regexps |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6 | |
| 7 | RegExp.prototype.flags = 'setter should be undefined'; |
| 8 | |
| 9 | assertEquals('', RegExp('').flags); |
| 10 | assertEquals('', /./.flags); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 11 | assertEquals('gimuy', RegExp('', 'yugmi').flags); |
| 12 | assertEquals('gimuy', /foo/yumig.flags); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 13 | |
| 14 | var descriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags'); |
| 15 | assertTrue(descriptor.configurable); |
| 16 | assertFalse(descriptor.enumerable); |
| 17 | assertInstanceof(descriptor.get, Function); |
| 18 | assertEquals(undefined, descriptor.set); |
| 19 | |
| 20 | function testGenericFlags(object) { |
| 21 | return descriptor.get.call(object); |
| 22 | } |
| 23 | |
| 24 | assertEquals('', testGenericFlags({})); |
| 25 | assertEquals('i', testGenericFlags({ ignoreCase: true })); |
| 26 | assertEquals('uy', testGenericFlags({ global: 0, sticky: 1, unicode: 1 })); |
| 27 | assertEquals('m', testGenericFlags({ __proto__: { multiline: true } })); |
| 28 | assertThrows(function() { testGenericFlags(); }, TypeError); |
| 29 | assertThrows(function() { testGenericFlags(undefined); }, TypeError); |
| 30 | assertThrows(function() { testGenericFlags(null); }, TypeError); |
| 31 | assertThrows(function() { testGenericFlags(true); }, TypeError); |
| 32 | assertThrows(function() { testGenericFlags(false); }, TypeError); |
| 33 | assertThrows(function() { testGenericFlags(''); }, TypeError); |
| 34 | assertThrows(function() { testGenericFlags(42); }, TypeError); |
| 35 | |
| 36 | var counter = 0; |
| 37 | var map = {}; |
| 38 | var object = { |
| 39 | get global() { |
| 40 | map.g = counter++; |
| 41 | }, |
| 42 | get ignoreCase() { |
| 43 | map.i = counter++; |
| 44 | }, |
| 45 | get multiline() { |
| 46 | map.m = counter++; |
| 47 | }, |
| 48 | get unicode() { |
| 49 | map.u = counter++; |
| 50 | }, |
| 51 | get sticky() { |
| 52 | map.y = counter++; |
| 53 | } |
| 54 | }; |
| 55 | testGenericFlags(object); |
| 56 | assertEquals({ g: 0, i: 1, m: 2, u: 3, y: 4 }, map); |