diff --git a/src/objects.cc b/src/objects.cc index a47028897c..e377238e37 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -16232,7 +16232,7 @@ JSRegExp::Flags RegExpFlagsFromString(Handle flags, bool* success) { JSRegExp::Flags value = JSRegExp::kNone; int length = flags->length(); // A longer flags string cannot be valid. - if (length > 5) return JSRegExp::Flags(0); + if (length > JSRegExp::FlagCount()) return JSRegExp::Flags(0); for (int i = 0; i < length; i++) { JSRegExp::Flag flag = JSRegExp::kNone; switch (flags->Get(i)) { diff --git a/src/objects.h b/src/objects.h index 3b7790d6ed..b14284d465 100644 --- a/src/objects.h +++ b/src/objects.h @@ -7414,9 +7414,12 @@ class JSRegExp: public JSObject { kSticky = 1 << 3, kUnicode = 1 << 4, kDotAll = 1 << 5, + // Update FlagCount when adding new flags. }; typedef base::Flags Flags; + static int FlagCount() { return FLAG_harmony_regexp_dotall ? 6 : 5; } + DECL_ACCESSORS(data, Object) DECL_ACCESSORS(flags, Object) DECL_ACCESSORS(source, Object) diff --git a/test/mjsunit/harmony/regexp-dotall.js b/test/mjsunit/harmony/regexp-dotall.js index 9bf78431a9..eed5d26f05 100644 --- a/test/mjsunit/harmony/regexp-dotall.js +++ b/test/mjsunit/harmony/regexp-dotall.js @@ -56,6 +56,12 @@ function toSlowMode(re) { assertFalse(re.dotAll); } +// Different construction variants with all flags. +{ + assertEquals("gimsuy", new RegExp("", "yusmig").flags); + assertEquals("gimsuy", new RegExp().compile("", "yusmig").flags); +} + // Default '.' behavior. { let re = /^.$/;