[regexp] Fix passing all flags to RegExp construction
Do not bail out when passed a flags string with length > 5, use a meaningful named constant instead. Found by https://github.com/tc39/test262/pull/997#issuecomment-296963675 BUG=v8:6300 Review-Url: https://codereview.chromium.org/2841633004 Cr-Commit-Position: refs/heads/master@{#44834}
This commit is contained in:
parent
904e5df567
commit
a1af3315a2
@ -16232,7 +16232,7 @@ JSRegExp::Flags RegExpFlagsFromString(Handle<String> 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)) {
|
||||
|
@ -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<Flag> Flags;
|
||||
|
||||
static int FlagCount() { return FLAG_harmony_regexp_dotall ? 6 : 5; }
|
||||
|
||||
DECL_ACCESSORS(data, Object)
|
||||
DECL_ACCESSORS(flags, Object)
|
||||
DECL_ACCESSORS(source, Object)
|
||||
|
@ -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 = /^.$/;
|
||||
|
Loading…
Reference in New Issue
Block a user