2014-12-10 20:41:00 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-02-05 14:16:54 +00:00
|
|
|
// Flags: --harmony-regexps --harmony-unicode-regexps
|
2014-12-10 20:41:00 +00:00
|
|
|
|
|
|
|
RegExp.prototype.flags = 'setter should be undefined';
|
|
|
|
|
|
|
|
assertEquals('', RegExp('').flags);
|
|
|
|
assertEquals('', /./.flags);
|
2015-01-12 09:50:15 +00:00
|
|
|
assertEquals('gimuy', RegExp('', 'yugmi').flags);
|
|
|
|
assertEquals('gimuy', /foo/yumig.flags);
|
2014-12-10 20:41:00 +00:00
|
|
|
|
|
|
|
var descriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags');
|
2014-12-13 22:36:21 +00:00
|
|
|
assertTrue(descriptor.configurable);
|
2014-12-10 20:41:00 +00:00
|
|
|
assertFalse(descriptor.enumerable);
|
|
|
|
assertInstanceof(descriptor.get, Function);
|
|
|
|
assertEquals(undefined, descriptor.set);
|
|
|
|
|
|
|
|
function testGenericFlags(object) {
|
|
|
|
return descriptor.get.call(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals('', testGenericFlags({}));
|
|
|
|
assertEquals('i', testGenericFlags({ ignoreCase: true }));
|
|
|
|
assertEquals('uy', testGenericFlags({ global: 0, sticky: 1, unicode: 1 }));
|
|
|
|
assertEquals('m', testGenericFlags({ __proto__: { multiline: true } }));
|
|
|
|
assertThrows(function() { testGenericFlags(); }, TypeError);
|
|
|
|
assertThrows(function() { testGenericFlags(undefined); }, TypeError);
|
|
|
|
assertThrows(function() { testGenericFlags(null); }, TypeError);
|
|
|
|
assertThrows(function() { testGenericFlags(true); }, TypeError);
|
|
|
|
assertThrows(function() { testGenericFlags(false); }, TypeError);
|
|
|
|
assertThrows(function() { testGenericFlags(''); }, TypeError);
|
|
|
|
assertThrows(function() { testGenericFlags(42); }, TypeError);
|
2014-12-13 22:36:21 +00:00
|
|
|
|
|
|
|
var counter = 0;
|
|
|
|
var map = {};
|
|
|
|
var object = {
|
|
|
|
get global() {
|
|
|
|
map.g = counter++;
|
|
|
|
},
|
|
|
|
get ignoreCase() {
|
|
|
|
map.i = counter++;
|
|
|
|
},
|
|
|
|
get multiline() {
|
|
|
|
map.m = counter++;
|
|
|
|
},
|
|
|
|
get unicode() {
|
|
|
|
map.u = counter++;
|
|
|
|
},
|
|
|
|
get sticky() {
|
|
|
|
map.y = counter++;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
testGenericFlags(object);
|
|
|
|
assertEquals({ g: 0, i: 1, m: 2, u: 3, y: 4 }, map);
|