Skip to content

Commit

Permalink
Bug 1847469 - Part 5: Use column number types in ErrorMetadata. r=iain
Browse files Browse the repository at this point in the history
  • Loading branch information
arai-a committed Aug 16, 2023
1 parent 9377598 commit 1c26f53
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 13 deletions.
3 changes: 2 additions & 1 deletion js/src/frontend/Frontend2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "frontend/TokenStream.h" // TokenStreamAnyChars
#include "irregexp/RegExpAPI.h" // irregexp::CheckPatternSyntax
#include "js/CharacterEncoding.h" // JS::UTF8Chars, UTF8CharsToNewTwoByteCharsZ, JS::ConstUTF8CharsZ
#include "js/ColumnNumber.h" // JS::ColumnNumberZeroOrigin
#include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_*
#include "js/GCAPI.h" // JS::AutoCheckCannotGC
#include "js/HeapAPI.h" // JS::GCCellPtr
Expand Down Expand Up @@ -580,7 +581,7 @@ bool Smoosh::tryCompileGlobalScriptToExtensibleStencil(
ErrorMetadata metadata;
metadata.filename = JS::ConstUTF8CharsZ("<unknown>");
metadata.lineNumber = 1;
metadata.columnNumber = 0;
metadata.columnNumber = JS::ColumnNumberZeroOrigin::zero();
metadata.isMuted = false;
ReportSmooshCompileError(cx, fc, std::move(metadata),
JSMSG_SMOOSH_COMPILE_ERROR,
Expand Down
6 changes: 4 additions & 2 deletions js/src/frontend/TokenStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ void TokenStreamAnyChars::computeErrorMetadataNoOffset(
err->isMuted = mutedErrors;
err->filename = filename_;
err->lineNumber = 0;
err->columnNumber = 0;
err->columnNumber = JS::ColumnNumberZeroOrigin::zero();

MOZ_ASSERT(err->lineOfContext == nullptr);
}
Expand All @@ -1477,7 +1477,9 @@ bool TokenStreamAnyChars::fillExceptingContext(ErrorMetadata* err,
maybeCx->realm()->principals());
if (!iter.done() && iter.filename()) {
err->filename = JS::ConstUTF8CharsZ(iter.filename());
err->lineNumber = iter.computeLine(&err->columnNumber);
uint32_t columnNumber;
err->lineNumber = iter.computeLine(&columnNumber);
err->columnNumber = JS::ColumnNumberZeroOrigin(columnNumber);
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion js/src/frontend/TokenStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,7 @@ class GeneralTokenStreamChars : public SpecializedTokenStreamCharsBase<Unit> {
if (anyCharsAccess().fillExceptingContext(err, offset)) {
JS::LimitedColumnNumberZeroOrigin columnNumber;
computeLineAndColumn(offset, &err->lineNumber, &columnNumber);
err->columnNumber = columnNumber.zeroOriginValue();
err->columnNumber = JS::ColumnNumberZeroOrigin(columnNumber);
return true;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions js/src/irregexp/RegExpAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,14 @@ static void ReportSyntaxError(TokenStreamAnyChars& ts,
// inside the literal.
err.lineNumber = *line;
auto offset = JS::ColumnNumberOffset(columnNumber.zeroOriginValue());
err.columnNumber = (*column + offset).zeroOriginValue();
err.columnNumber = *column + offset;
} else {
// Line breaks are not significant in pattern text in the same way as
// in source text, so act as though pattern text is a single line, then
// compute a column based on "code point" count (treating a lone
// surrogate as a "code point" in UTF-16). Gak.
err.lineNumber = 1;
err.columnNumber = columnNumber.zeroOriginValue();
err.columnNumber = columnNumber;
}
}

Expand Down
3 changes: 2 additions & 1 deletion js/src/vm/CompilationAndEvaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "frontend/FrontendContext.h" // js::AutoReportFrontendContext
#include "frontend/Parser.h" // frontend::Parser, frontend::ParseGoal
#include "js/CharacterEncoding.h" // JS::UTF8Chars, JS::ConstUTF8CharsZ, JS::UTF8CharsToNewTwoByteCharsZ
#include "js/ColumnNumber.h" // JS::ColumnNumberZeroOrigin
#include "js/experimental/JSStencil.h" // JS::Stencil
#include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_*
#include "js/RootingAPI.h" // JS::Rooted
Expand Down Expand Up @@ -64,7 +65,7 @@ static void ReportSourceTooLongImpl(JS::FrontendContext* fc, ...) {
js::ErrorMetadata metadata;
metadata.filename = JS::ConstUTF8CharsZ("<unknown>");
metadata.lineNumber = 0;
metadata.columnNumber = 0;
metadata.columnNumber = JS::ColumnNumberZeroOrigin::zero();
metadata.lineLength = 0;
metadata.tokenOffset = 0;
metadata.isMuted = false;
Expand Down
5 changes: 3 additions & 2 deletions js/src/vm/ErrorReporting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "frontend/FrontendContext.h" // AutoReportFrontendContext
#include "js/CharacterEncoding.h" // JS::ConstUTF8CharsZ
#include "js/ColumnNumber.h" // JS::ColumnNumberZeroOrigin
#include "js/ErrorReport.h" // JSErrorBase
#include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_*
#include "js/Printf.h" // JS_vsmprintf
Expand Down Expand Up @@ -68,7 +69,7 @@ bool js::ReportCompileWarning(FrontendContext* fc, ErrorMetadata&& metadata,

err.filename = JS::ConstUTF8CharsZ(metadata.filename);
err.lineno = metadata.lineNumber;
err.column = JSErrorBase::fromZeroOriginToOneOrigin(metadata.columnNumber);
err.column = metadata.columnNumber.oneOriginValue();
err.isMuted = metadata.isMuted;

if (UniqueTwoByteChars lineOfContext = std::move(metadata.lineOfContext)) {
Expand Down Expand Up @@ -97,7 +98,7 @@ static void ReportCompileErrorImpl(FrontendContext* fc,

err.filename = JS::ConstUTF8CharsZ(metadata.filename);
err.lineno = metadata.lineNumber;
err.column = JSErrorBase::fromZeroOriginToOneOrigin(metadata.columnNumber);
err.column = metadata.columnNumber.oneOriginValue();
err.isMuted = metadata.isMuted;

if (UniqueTwoByteChars lineOfContext = std::move(metadata.lineOfContext)) {
Expand Down
5 changes: 3 additions & 2 deletions js/src/vm/ErrorReporting.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "jsfriendapi.h" // for ScriptEnvironmentPreparer

#include "js/CharacterEncoding.h" // JS::ConstUTF8CharsZ
#include "js/ColumnNumber.h" // JS::ColumnNumberZeroOrigin
#include "js/ErrorReport.h" // for JSErrorNotes, JSErrorReport
#include "js/UniquePtr.h" // for UniquePtr
#include "js/Utility.h" // for UniqueTwoByteChars
Expand Down Expand Up @@ -41,8 +42,8 @@ struct ErrorMetadata {
// Line number (1-origin).
uint32_t lineNumber;

// Column number in UTF-16 code units (0-origin).
uint32_t columnNumber;
// Column number in UTF-16 code units.
JS::ColumnNumberZeroOrigin columnNumber;

// If the error occurs at a particular location, context surrounding the
// location of the error: the line that contained the error, or a small
Expand Down
2 changes: 1 addition & 1 deletion js/src/vm/HelperThreads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ static void ReportDecodeFailure(JS::FrontendContext* fc) {
js::ErrorMetadata metadata;
metadata.filename = JS::ConstUTF8CharsZ("<unknown>");
metadata.lineNumber = 0;
metadata.columnNumber = 0;
metadata.columnNumber = JS::ColumnNumberZeroOrigin::zero();
metadata.lineLength = 0;
metadata.tokenOffset = 0;
metadata.isMuted = false;
Expand Down
3 changes: 2 additions & 1 deletion js/src/vm/JSONParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "gc/Tracer.h" // JS::TraceRoot
#include "js/AllocPolicy.h" // ReportOutOfMemory
#include "js/CharacterEncoding.h" // JS::ConstUTF8CharsZ
#include "js/ColumnNumber.h" // JS::ColumnNumberZeroOrigin
#include "js/ErrorReport.h" // JS_ReportErrorNumberASCII
#include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_*
#include "js/GCVector.h" // JS::GCVector
Expand Down Expand Up @@ -1055,7 +1056,7 @@ void JSONSyntaxParseHandler<CharT>::reportError(const char* msg,
metadata.isMuted = false;
metadata.filename = JS::ConstUTF8CharsZ("");
metadata.lineNumber = 0;
metadata.columnNumber = 0;
metadata.columnNumber = JS::ColumnNumberZeroOrigin::zero();

ReportJSONSyntaxError(fc, std::move(metadata), JSMSG_JSON_BAD_PARSE, msg,
lineString, columnString);
Expand Down

0 comments on commit 1c26f53

Please sign in to comment.