Commit 972e8522 authored by littledan's avatar littledan Committed by Commit bot

Fix RegExp.prototype.compile error case

If the RegExp doesn't parse, then ES2015 specifies that
RegExp.prototype.compile does not mutate it. This patch changes
our RegExp implementation to follow that logic.

R=yangguo

Review-Url: https://codereview.chromium.org/1972093003
Cr-Commit-Position: refs/heads/master@{#36268}
parent 96aba388
......@@ -15449,6 +15449,9 @@ MaybeHandle<JSRegExp> JSRegExp::Initialize(Handle<JSRegExp> regexp,
ASSIGN_RETURN_ON_EXCEPTION(isolate, escaped_source,
EscapeRegExpSource(isolate, source), JSRegExp);
RETURN_ON_EXCEPTION(isolate, RegExpImpl::Compile(regexp, source, flags),
JSRegExp);
regexp->set_source(*escaped_source);
regexp->set_flags(Smi::FromInt(flags));
......@@ -15469,9 +15472,6 @@ MaybeHandle<JSRegExp> JSRegExp::Initialize(Handle<JSRegExp> regexp,
.Check();
}
RETURN_ON_EXCEPTION(isolate, RegExpImpl::Compile(regexp, source, flags),
JSRegExp);
return regexp;
}
......
......@@ -42,3 +42,7 @@ re.compile("(y)");
assertEquals(["y", "y"], re.exec("axyb"));
assertEquals(2, re.compile.length);
// If RegExp parsing fails, the RegExp is not modified
var r = /./; try { r.compile('? invalid'); } catch(err){}
assertEquals("/./", r.toString());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment