Commit e2be5ce5 authored by caitpotter88's avatar caitpotter88 Committed by Commit bot

[parser] fix token end position for regexp literals

Make the end position of a regexp literal the first character following the regexp. This matches the behaviour of number literals and string literals, as well as single-character tokens.

This change corrects the lazy-parsing of arrow functions with concise bodies, whose last token is a regular expression literal.

BUG=v8:4474
LOG=N
R=wingo@igalia.com, adamk@chromium.org, rossberg@chromium.org

Review URL: https://codereview.chromium.org/1389313003

Cr-Commit-Position: refs/heads/master@{#31189}
parent 5bbccc3e
...@@ -1395,7 +1395,7 @@ bool Scanner::ScanRegExpFlags() { ...@@ -1395,7 +1395,7 @@ bool Scanner::ScanRegExpFlags() {
} }
literal.Complete(); literal.Complete();
next_.location.end_pos = source_pos() - 1; next_.location.end_pos = source_pos();
return true; return true;
} }
......
...@@ -68,3 +68,16 @@ assertEquals([5, 10], fives); ...@@ -68,3 +68,16 @@ assertEquals([5, 10], fives);
assertThrows(function() { return arrowFn.caller; }, TypeError); assertThrows(function() { return arrowFn.caller; }, TypeError);
assertThrows(function() { arrowFn.caller = {}; }, TypeError); assertThrows(function() { arrowFn.caller = {}; }, TypeError);
})(); })();
// v8:4474
(function testConciseBodyReturnsRegexp() {
var arrow1 = () => /foo/
var arrow2 = () => /foo/;
var arrow3 = () => /foo/i
var arrow4 = () => /foo/i;
assertEquals(arrow1.toString(), "() => /foo/");
assertEquals(arrow2.toString(), "() => /foo/");
assertEquals(arrow3.toString(), "() => /foo/i");
assertEquals(arrow4.toString(), "() => /foo/i");
});
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