commit 59b328741452e211e0a1790c32a621e7e2b05689 Author: Nicholas Nethercote nnethercote@mozilla.com Date: Sun Apr 6 21:31:04 2014 -0700
Bug 992274 - Tweak an edge case in line number handling. r=jorendorff, a=abillings --- js/src/frontend/Parser.cpp | 6 ++++-- js/src/frontend/TokenStream.cpp | 17 +++++++++++------ js/src/frontend/TokenStream.h | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index ce87e25..f9e15a1 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -2058,7 +2058,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, funbox, outerpc->staticLevel + 1, outerpc->blockidGen); @@ -2080,7 +2081,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; }
pn->pn_funbox = funbox; diff --git a/js/src/frontend/TokenStream.cpp b/js/src/frontend/TokenStream.cpp index 02da46f..6ae5102 100644 --- a/js/src/frontend/TokenStream.cpp +++ b/js/src/frontend/TokenStream.cpp @@ -163,20 +163,23 @@ TokenStream::SourceCoords::add(uint32_t lineNum, uint32_t lineStartOffset) } }
-JS_ALWAYS_INLINE void +JS_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; }
JS_ALWAYS_INLINE uint32_t @@ -570,12 +573,14 @@ 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; lastFunctionKeyword = other.lastFunctionKeyword; seek(pos); + return true; }
void diff --git a/js/src/frontend/TokenStream.h b/js/src/frontend/TokenStream.h index 48fdec3..57ac159 100644 --- a/js/src/frontend/TokenStream.h +++ b/js/src/frontend/TokenStream.h @@ -659,7 +659,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); void positionAfterLastFunctionKeyword(Position &pos);
size_t positionToOffset(const Position &pos) const { @@ -750,7 +750,7 @@ class MOZ_STACK_CLASS TokenStream SourceCoords(JSContext *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);