diff --git a/js/src/frontend/TokenStream.cpp b/js/src/frontend/TokenStream.cpp index a02b22fc7850..9dc8c46873a5 100644 --- a/js/src/frontend/TokenStream.cpp +++ b/js/src/frontend/TokenStream.cpp @@ -808,17 +808,14 @@ TokenStreamSpecific::computeErrorMetadata(ErrorMetadata* return true; // Add a line of context from this TokenStream to help with debugging. - return computeLineOfContext(err, offset); + return internalComputeLineOfContext(err, offset); } template bool -TokenStreamSpecific::computeLineOfContext(ErrorMetadata* err, - uint32_t offset) +GeneralTokenStreamChars::internalComputeLineOfContext(ErrorMetadata* err, + uint32_t offset) { - // This function presumes |err| is filled in *except* for line-of-context - // fields. It exists to make |TokenStreamSpecific::computeErrorMetadata|, - // above, more readable. TokenStreamAnyChars& anyChars = anyCharsAccess(); // We only have line-start information for the current line. If the error @@ -842,8 +839,8 @@ TokenStreamSpecific::computeLineOfContext(ErrorMetadata* if (windowStart < this->sourceUnits.startOffset()) windowStart = this->sourceUnits.startOffset(); - // The window must end within the current line, no later than - // windowRadius after offset. + // The window must end no further than |windowRadius| after |offset| within + // the current line. size_t windowEnd = this->sourceUnits.findEOLMax(offset, windowRadius); size_t windowLength = windowEnd - windowStart; MOZ_ASSERT(windowLength <= windowRadius * 2); @@ -851,7 +848,7 @@ TokenStreamSpecific::computeLineOfContext(ErrorMetadata* // Create the windowed string, not including the potential line // terminator. StringBuffer windowBuf(anyChars.cx); - if (!windowBuf.append(codeUnitPtrAt(windowStart), windowLength) || + if (!windowBuf.append(this->sourceUnits.codeUnitPtrAt(windowStart), windowLength) || !windowBuf.append('\0')) { return false; diff --git a/js/src/frontend/TokenStream.h b/js/src/frontend/TokenStream.h index 4d0c0123ec36..d576244a74fc 100644 --- a/js/src/frontend/TokenStream.h +++ b/js/src/frontend/TokenStream.h @@ -1555,6 +1555,16 @@ class GeneralTokenStreamChars uint32_t matchUnicodeEscapeIdStart(uint32_t* codePoint); bool matchUnicodeEscapeIdent(uint32_t* codePoint); + /** + * Compute a line of context for an otherwise-filled-in |err| at the given + * offset in this token stream. + * + * This function is very-internal: almost certainly you should use one of + * its callers instead. It basically exists only to make those callers + * more readable. + */ + MOZ_MUST_USE bool internalComputeLineOfContext(ErrorMetadata* err, uint32_t offset); + public: JSAtom* getRawTemplateStringAtom() { TokenStreamAnyChars& anyChars = anyCharsAccess(); @@ -1822,6 +1832,7 @@ class MOZ_STACK_CLASS TokenStreamSpecific using SpecializedChars::getFullAsciiCodePoint; using SpecializedChars::getNonAsciiCodePoint; using SpecializedChars::getNonAsciiCodePointDontNormalize; + using GeneralCharsBase::internalComputeLineOfContext; using TokenStreamCharsShared::isAsciiCodePoint; using CharsBase::matchCodeUnit; using CharsBase::matchLineTerminator; @@ -1902,12 +1913,6 @@ class MOZ_STACK_CLASS TokenStreamSpecific // Warn at the current offset. MOZ_MUST_USE bool warning(unsigned errorNumber, ...); - private: - // Compute a line of context for an otherwise-filled-in |err| at the given - // offset in this token stream. (This function basically exists to make - // |computeErrorMetadata| more readable and shouldn't be called elsewhere.) - MOZ_MUST_USE bool computeLineOfContext(ErrorMetadata* err, uint32_t offset); - public: // Compute error metadata for an error at the given offset. MOZ_MUST_USE bool computeErrorMetadata(ErrorMetadata* err, uint32_t offset);