Bug 992274 (part 1) - Tweak an edge case in line number handling. r=jorendorff.

This commit is contained in:
Nicholas Nethercote 2014-04-06 21:31:04 -07:00
parent 85efe0d58e
commit c295279b43
3 changed files with 17 additions and 10 deletions

View File

@ -2125,7 +2125,8 @@ Parser<FullParseHandler>::functionArgsAndBody(ParseNode *pn, HandleFunction fun,
// Move the syntax parser to the current position in the stream.
TokenStream::Position position(keepAtoms);
tokenStream.tell(&position);
parser->tokenStream.seek(position, tokenStream);
if (!parser->tokenStream.seek(position, tokenStream))
return false;
ParseContext<SyntaxParseHandler> funpc(parser, outerpc, SyntaxParseHandler::null(), funbox,
newDirectives, outerpc->staticLevel + 1,
@ -2149,7 +2150,8 @@ Parser<FullParseHandler>::functionArgsAndBody(ParseNode *pn, HandleFunction fun,
// Advance this parser over tokens processed by the syntax parser.
parser->tokenStream.tell(&position);
tokenStream.seek(position, parser->tokenStream);
if (!tokenStream.seek(position, parser->tokenStream))
return false;
// Update the end position of the parse node.
pn->pn_pos.end = tokenStream.currentToken().pos.end;

View File

@ -160,20 +160,23 @@ TokenStream::SourceCoords::add(uint32_t lineNum, uint32_t lineStartOffset)
}
}
MOZ_ALWAYS_INLINE void
MOZ_ALWAYS_INLINE bool
TokenStream::SourceCoords::fill(const TokenStream::SourceCoords &other)
{
JS_ASSERT(lineStartOffsets_.back() == MAX_PTR);
JS_ASSERT(other.lineStartOffsets_.back() == MAX_PTR);
if (lineStartOffsets_.length() >= other.lineStartOffsets_.length())
return;
return true;
uint32_t sentinelIndex = lineStartOffsets_.length() - 1;
lineStartOffsets_[sentinelIndex] = other.lineStartOffsets_[sentinelIndex];
for (size_t i = sentinelIndex + 1; i < other.lineStartOffsets_.length(); i++)
(void)lineStartOffsets_.append(other.lineStartOffsets_[i]);
for (size_t i = sentinelIndex + 1; i < other.lineStartOffsets_.length(); i++) {
if (!lineStartOffsets_.append(other.lineStartOffsets_[i]))
return false;
}
return true;
}
MOZ_ALWAYS_INLINE uint32_t
@ -537,11 +540,13 @@ TokenStream::seek(const Position &pos)
tokens[(cursor + 1 + i) & ntokensMask] = pos.lookaheadTokens[i];
}
void
bool
TokenStream::seek(const Position &pos, const TokenStream &other)
{
srcCoords.fill(other.srcCoords);
if (!srcCoords.fill(other.srcCoords))
return false;
seek(pos);
return true;
}
bool

View File

@ -614,7 +614,7 @@ class MOZ_STACK_CLASS TokenStream
void advance(size_t position);
void tell(Position *);
void seek(const Position &pos);
void seek(const Position &pos, const TokenStream &other);
bool seek(const Position &pos, const TokenStream &other);
size_t positionToOffset(const Position &pos) const {
return pos.buf - userbuf.base();
@ -710,7 +710,7 @@ class MOZ_STACK_CLASS TokenStream
SourceCoords(ExclusiveContext *cx, uint32_t ln);
void add(uint32_t lineNum, uint32_t lineStartOffset);
void fill(const SourceCoords &other);
bool fill(const SourceCoords &other);
bool isOnThisLine(uint32_t offset, uint32_t lineNum) const {
uint32_t lineIndex = lineNumToIndex(lineNum);