diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index d53265706bd..538ebb30493 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -2125,7 +2125,8 @@ Parser::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 funpc(parser, outerpc, SyntaxParseHandler::null(), funbox, newDirectives, outerpc->staticLevel + 1, @@ -2149,7 +2150,8 @@ Parser::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; diff --git a/js/src/frontend/TokenStream.cpp b/js/src/frontend/TokenStream.cpp index c59912d2f7b..106fb86782d 100644 --- a/js/src/frontend/TokenStream.cpp +++ b/js/src/frontend/TokenStream.cpp @@ -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 diff --git a/js/src/frontend/TokenStream.h b/js/src/frontend/TokenStream.h index 85b00192282..d24f821563a 100644 --- a/js/src/frontend/TokenStream.h +++ b/js/src/frontend/TokenStream.h @@ -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);