| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --harmony-regexps | 5 // Flags: --harmony-regexps |
| 6 | 6 |
| 7 delete RegExp.prototype.flags; | |
| 8 RegExp.prototype.flags = 'setter should be undefined'; | 7 RegExp.prototype.flags = 'setter should be undefined'; |
| 9 | 8 |
| 10 assertEquals('', RegExp('').flags); | 9 assertEquals('', RegExp('').flags); |
| 11 assertEquals('', /./.flags); | 10 assertEquals('', /./.flags); |
| 12 assertEquals('gimy', RegExp('', 'ygmi').flags); | 11 assertEquals('gimy', RegExp('', 'ygmi').flags); |
| 13 assertEquals('gimy', /foo/ymig.flags); | 12 assertEquals('gimy', /foo/ymig.flags); |
| 14 | 13 |
| 15 // TODO(dslomov): When support for the `u` flag is added, uncomment the first | 14 // TODO(dslomov): When support for the `u` flag is added, uncomment the first |
| 16 // line below and remove the second line. | 15 // line below and remove the second line. |
| 17 //assertEquals(RegExp('', 'yumig').flags, 'gimuy'); | 16 //assertEquals(RegExp('', 'yumig').flags, 'gimuy'); |
| 18 assertThrows(function() { RegExp('', 'yumig').flags; }, SyntaxError); | 17 assertThrows(function() { RegExp('', 'yumig').flags; }, SyntaxError); |
| 19 | 18 |
| 20 var descriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags'); | 19 var descriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags'); |
| 21 assertFalse(descriptor.configurable); | 20 assertTrue(descriptor.configurable); |
| 22 assertFalse(descriptor.enumerable); | 21 assertFalse(descriptor.enumerable); |
| 23 assertInstanceof(descriptor.get, Function); | 22 assertInstanceof(descriptor.get, Function); |
| 24 assertEquals(undefined, descriptor.set); | 23 assertEquals(undefined, descriptor.set); |
| 25 | 24 |
| 26 function testGenericFlags(object) { | 25 function testGenericFlags(object) { |
| 27 return descriptor.get.call(object); | 26 return descriptor.get.call(object); |
| 28 } | 27 } |
| 29 | 28 |
| 30 assertEquals('', testGenericFlags({})); | 29 assertEquals('', testGenericFlags({})); |
| 31 assertEquals('i', testGenericFlags({ ignoreCase: true })); | 30 assertEquals('i', testGenericFlags({ ignoreCase: true })); |
| 32 assertEquals('uy', testGenericFlags({ global: 0, sticky: 1, unicode: 1 })); | 31 assertEquals('uy', testGenericFlags({ global: 0, sticky: 1, unicode: 1 })); |
| 33 assertEquals('m', testGenericFlags({ __proto__: { multiline: true } })); | 32 assertEquals('m', testGenericFlags({ __proto__: { multiline: true } })); |
| 34 assertThrows(function() { testGenericFlags(); }, TypeError); | 33 assertThrows(function() { testGenericFlags(); }, TypeError); |
| 35 assertThrows(function() { testGenericFlags(undefined); }, TypeError); | 34 assertThrows(function() { testGenericFlags(undefined); }, TypeError); |
| 36 assertThrows(function() { testGenericFlags(null); }, TypeError); | 35 assertThrows(function() { testGenericFlags(null); }, TypeError); |
| 37 assertThrows(function() { testGenericFlags(true); }, TypeError); | 36 assertThrows(function() { testGenericFlags(true); }, TypeError); |
| 38 assertThrows(function() { testGenericFlags(false); }, TypeError); | 37 assertThrows(function() { testGenericFlags(false); }, TypeError); |
| 39 assertThrows(function() { testGenericFlags(''); }, TypeError); | 38 assertThrows(function() { testGenericFlags(''); }, TypeError); |
| 40 assertThrows(function() { testGenericFlags(42); }, TypeError); | 39 assertThrows(function() { testGenericFlags(42); }, TypeError); |
| 40 |
| 41 var counter = 0; |
| 42 var map = {}; |
| 43 var object = { |
| 44 get global() { |
| 45 map.g = counter++; |
| 46 }, |
| 47 get ignoreCase() { |
| 48 map.i = counter++; |
| 49 }, |
| 50 get multiline() { |
| 51 map.m = counter++; |
| 52 }, |
| 53 get unicode() { |
| 54 map.u = counter++; |
| 55 }, |
| 56 get sticky() { |
| 57 map.y = counter++; |
| 58 } |
| 59 }; |
| 60 testGenericFlags(object); |
| 61 assertEquals({ g: 0, i: 1, m: 2, u: 3, y: 4 }, map); |
| OLD | NEW |