summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/es6/regexp-flags.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/mjsunit/es6/regexp-flags.js')
-rw-r--r--deps/v8/test/mjsunit/es6/regexp-flags.js67
1 files changed, 61 insertions, 6 deletions
diff --git a/deps/v8/test/mjsunit/es6/regexp-flags.js b/deps/v8/test/mjsunit/es6/regexp-flags.js
index 79b0197e91..480222d95a 100644
--- a/deps/v8/test/mjsunit/es6/regexp-flags.js
+++ b/deps/v8/test/mjsunit/es6/regexp-flags.js
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Flags: --harmony-regexps --harmony-unicode-regexps
+// Flags: --harmony-unicode-regexps
var r1 = /abc/gi;
assertEquals("abc", r1.source);
@@ -44,15 +44,18 @@ assertEquals(2, get_count);
// Overridden flag getters affects the flags getter.
assertEquals("gi", r3.flags);
assertEquals(4, get_count);
-// Overridden flag getters do not affect the internal flags.
+// Overridden flag getters affect string.replace
+// TODO(adamk): Add more tests here once we've switched
+// to use [[OriginalFlags]] in more cases.
assertEquals(expected, string.replace(r3, "X"));
-assertEquals(4, get_count);
+assertEquals(5, get_count);
function testName(name) {
- // TODO(littledan): For web compatibility, we don't throw an exception,
- // but ES2015 expects an exception to be thrown from this getter.
- assertEquals(undefined, RegExp.prototype[name]);
+ // Test for ES2017 RegExp web compatibility semantics
+ // https://github.com/tc39/ecma262/pull/511
+ assertEquals(name === "source" ? "(?:)" : undefined,
+ RegExp.prototype[name]);
assertEquals(
"get " + name,
Object.getOwnPropertyDescriptor(RegExp.prototype, name).get.name);
@@ -64,3 +67,55 @@ testName("multiline");
testName("source");
testName("sticky");
testName("unicode");
+
+
+RegExp.prototype.flags = 'setter should be undefined';
+
+assertEquals('', RegExp('').flags);
+assertEquals('', /./.flags);
+assertEquals('gimuy', RegExp('', 'yugmi').flags);
+assertEquals('gimuy', /foo/yumig.flags);
+
+var descriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags');
+assertTrue(descriptor.configurable);
+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);
+
+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);