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 5// Flags: --harmony-regexps --harmony-unicode-regexps 6 7RegExp.prototype.flags = 'setter should be undefined'; 8 9assertEquals('', RegExp('').flags); 10assertEquals('', /./.flags); 11assertEquals('gimuy', RegExp('', 'yugmi').flags); 12assertEquals('gimuy', /foo/yumig.flags); 13 14var descriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags'); 15assertTrue(descriptor.configurable); 16assertFalse(descriptor.enumerable); 17assertInstanceof(descriptor.get, Function); 18assertEquals(undefined, descriptor.set); 19 20function testGenericFlags(object) { 21 return descriptor.get.call(object); 22} 23 24assertEquals('', testGenericFlags({})); 25assertEquals('i', testGenericFlags({ ignoreCase: true })); 26assertEquals('uy', testGenericFlags({ global: 0, sticky: 1, unicode: 1 })); 27assertEquals('m', testGenericFlags({ __proto__: { multiline: true } })); 28assertThrows(function() { testGenericFlags(); }, TypeError); 29assertThrows(function() { testGenericFlags(undefined); }, TypeError); 30assertThrows(function() { testGenericFlags(null); }, TypeError); 31assertThrows(function() { testGenericFlags(true); }, TypeError); 32assertThrows(function() { testGenericFlags(false); }, TypeError); 33assertThrows(function() { testGenericFlags(''); }, TypeError); 34assertThrows(function() { testGenericFlags(42); }, TypeError); 35 36var counter = 0; 37var map = {}; 38var 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}; 55testGenericFlags(object); 56assertEquals({ g: 0, i: 1, m: 2, u: 3, y: 4 }, map); 57