Bug 1424394 - Remove ErrorReporter::offset(), replacing its sole use (passing it to ErrorReporter::lineNumAndColumnIndex) with a new ErrorReporter::currentLineAndColumn(). Also rename ErrorReporter::lineNumAndColumnIndex to ErrorReporter::lineAndColumnAt for consistent naming aesthetics. r=Yoric
authorJeff Walden <jwalden@mit.edu>
Tue, 05 Dec 2017 23:58:47 -0800
changeset 396282 b2f626567ad247bf40c9bf4cea23026e1c92fa90
parent 396281 14062282d28b457fa6eb08b4c5e84eb77b2a46ec
child 396283 7496d9ff6fa0ae03545ce206caba5490a26c9226
push id56975
push userdluca@mozilla.com
push dateThu, 14 Dec 2017 09:59:07 +0000
treeherderautoland@16bcfaad13e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1424394
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1424394 - Remove ErrorReporter::offset(), replacing its sole use (passing it to ErrorReporter::lineNumAndColumnIndex) with a new ErrorReporter::currentLineAndColumn(). Also rename ErrorReporter::lineNumAndColumnIndex to ErrorReporter::lineAndColumnAt for consistent naming aesthetics. r=Yoric
js/src/builtin/ModuleObject.cpp
js/src/frontend/BytecodeCompiler.cpp
js/src/frontend/ErrorReporter.h
js/src/frontend/TokenStream.cpp
js/src/frontend/TokenStream.h
--- a/js/src/builtin/ModuleObject.cpp
+++ b/js/src/builtin/ModuleObject.cpp
@@ -1320,17 +1320,17 @@ ModuleBuilder::processImport(frontend::P
         RootedAtom importName(cx_, spec->pn_left->pn_atom);
         RootedAtom localName(cx_, spec->pn_right->pn_atom);
 
         if (!importedBoundNames_.append(localName))
             return false;
 
         uint32_t line;
         uint32_t column;
-        tokenStream_.lineNumAndColumnIndex(spec->pn_left->pn_pos.begin, &line, &column);
+        tokenStream_.lineAndColumnAt(spec->pn_left->pn_pos.begin, &line, &column);
 
         RootedImportEntryObject importEntry(cx_);
         importEntry = ImportEntryObject::create(cx_, module, importName, localName, line, column);
         if (!importEntry || !importEntries_.append(importEntry))
             return false;
     }
 
     return true;
@@ -1458,47 +1458,47 @@ ModuleBuilder::hasExportedName(JSAtom* n
 }
 
 bool
 ModuleBuilder::appendExportEntry(HandleAtom exportName, HandleAtom localName, ParseNode* node)
 {
     uint32_t line = 0;
     uint32_t column = 0;
     if (node)
-        tokenStream_.lineNumAndColumnIndex(node->pn_pos.begin, &line, &column);
+        tokenStream_.lineAndColumnAt(node->pn_pos.begin, &line, &column);
 
     Rooted<ExportEntryObject*> exportEntry(cx_);
     exportEntry = ExportEntryObject::create(cx_, exportName, nullptr, nullptr, localName,
                                             line, column);
     return exportEntry && exportEntries_.append(exportEntry);
 }
 
 bool
 ModuleBuilder::appendExportFromEntry(HandleAtom exportName, HandleAtom moduleRequest,
                                      HandleAtom importName, ParseNode* node)
 {
     uint32_t line;
     uint32_t column;
-    tokenStream_.lineNumAndColumnIndex(node->pn_pos.begin, &line, &column);
+    tokenStream_.lineAndColumnAt(node->pn_pos.begin, &line, &column);
 
     Rooted<ExportEntryObject*> exportEntry(cx_);
     exportEntry = ExportEntryObject::create(cx_, exportName, moduleRequest, importName, nullptr,
                                             line, column);
     return exportEntry && exportEntries_.append(exportEntry);
 }
 
 bool
 ModuleBuilder::maybeAppendRequestedModule(HandleAtom specifier, ParseNode* node)
 {
     if (requestedModuleSpecifiers_.has(specifier))
         return true;
 
     uint32_t line;
     uint32_t column;
-    tokenStream_.lineNumAndColumnIndex(node->pn_pos.begin, &line, &column);
+    tokenStream_.lineAndColumnAt(node->pn_pos.begin, &line, &column);
 
     JSContext* cx = cx_;
     RootedRequestedModuleObject req(cx, RequestedModuleObject::create(cx, specifier, line, column));
     if (!req)
         return false;
 
     return FreezeObject(cx, req) &&
            requestedModules_.append(req) &&
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -100,18 +100,17 @@ AutoFrontendTraceLog::AutoFrontendTraceL
 {
     // If the tokenizer hasn't yet gotten any tokens, use the line and column
     // numbers from CompileOptions.
     uint32_t line, column;
     if (errorReporter.hasTokenizationStarted()) {
         line = errorReporter.options().lineno;
         column = errorReporter.options().column;
     } else {
-        uint32_t offset = errorReporter.offset();
-        errorReporter.lineNumAndColumnIndex(offset, &line, &column);
+        errorReporter.currentLineAndColumn(&line, &column);
     }
     frontendEvent_.emplace(TraceLogger_Frontend, errorReporter.getFilename(), line, column);
     frontendLog_.emplace(logger_, *frontendEvent_);
     typeLog_.emplace(logger_, id);
 }
 #else
 { }
 #endif
@@ -132,17 +131,17 @@ AutoFrontendTraceLog::AutoFrontendTraceL
 #endif
 
 AutoFrontendTraceLog::AutoFrontendTraceLog(JSContext* cx, const TraceLoggerTextId id,
                                            const ErrorReporter& errorReporter, ParseNode* pn)
 #ifdef JS_TRACE_LOGGING
   : logger_(TraceLoggerForCurrentThread(cx))
 {
     uint32_t line, column;
-    errorReporter.lineNumAndColumnIndex(pn->pn_pos.begin, &line, &column);
+    errorReporter.lineAndColumnAt(pn->pn_pos.begin, &line, &column);
     frontendEvent_.emplace(TraceLogger_Frontend, errorReporter.getFilename(), line, column);
     frontendLog_.emplace(logger_, *frontendEvent_);
     typeLog_.emplace(logger_, id);
 }
 #else
 { }
 #endif
 
--- a/js/src/frontend/ErrorReporter.h
+++ b/js/src/frontend/ErrorReporter.h
@@ -15,18 +15,20 @@
 
 namespace js {
 namespace frontend {
 
 class ErrorReporter
 {
   public:
     virtual const JS::ReadOnlyCompileOptions& options() const = 0;
-    virtual void lineNumAndColumnIndex(size_t offset, uint32_t* line, uint32_t* column) const = 0;
-    virtual size_t offset() const = 0;
+
+    virtual void lineAndColumnAt(size_t offset, uint32_t* line, uint32_t* column) const = 0;
+    virtual void currentLineAndColumn(uint32_t* line, uint32_t* column) const = 0;
+
     virtual bool hasTokenizationStarted() const = 0;
     virtual void reportErrorNoOffsetVA(unsigned errorNumber, va_list args) = 0;
     virtual const char* getFilename() const = 0;
 
     void reportErrorNoOffset(unsigned errorNumber, ...) {
         va_list args;
         va_start(args, errorNumber);
 
--- a/js/src/frontend/TokenStream.cpp
+++ b/js/src/frontend/TokenStream.cpp
@@ -738,26 +738,26 @@ TokenStreamAnyChars::fillExcludingContex
 
 bool
 TokenStreamAnyChars::hasTokenizationStarted() const
 {
     return isCurrentTokenType(TOK_EOF) && !isEOF();
 }
 
 void
-TokenStreamAnyChars::lineNumAndColumnIndex(size_t offset, uint32_t* line, uint32_t* column) const
+TokenStreamAnyChars::lineAndColumnAt(size_t offset, uint32_t* line, uint32_t* column) const
 {
     srcCoords.lineNumAndColumnIndex(offset, line, column);
 }
 
-size_t
-TokenStreamAnyChars::offset() const
+void
+TokenStreamAnyChars::currentLineAndColumn(uint32_t* line, uint32_t* column) const
 {
-    // Default implementation. Overridden by `TokenStream`.
-    return 0;
+    uint32_t offset = currentToken().pos.begin;
+    srcCoords.lineNumAndColumnIndex(offset, line, column);
 }
 
 bool
 TokenStream::computeErrorMetadata(ErrorMetadata* err, uint32_t offset)
 {
     if (offset == NoOffset) {
         computeErrorMetadataNoOffset(err);
         return true;
@@ -822,22 +822,16 @@ TokenStream::computeLineOfContext(ErrorM
         return false;
 
     err->lineLength = windowLength;
     err->tokenOffset = offset - windowStart;
     return true;
 }
 
 
-size_t
-TokenStream::offset() const
-{
-    return userbuf.offset();
-}
-
 bool
 TokenStream::reportStrictModeError(unsigned errorNumber, ...)
 {
     va_list args;
     va_start(args, errorNumber);
     bool result = reportStrictModeErrorNumberVA(nullptr, currentToken().pos.begin, strictMode(),
                                                 errorNumber, &args);
     va_end(args);
--- a/js/src/frontend/TokenStream.h
+++ b/js/src/frontend/TokenStream.h
@@ -578,20 +578,22 @@ class TokenStreamAnyChars: public ErrorR
   public:
     MOZ_MUST_USE bool compileWarning(ErrorMetadata&& metadata, UniquePtr<JSErrorNotes> notes,
                                      unsigned flags, unsigned errorNumber, va_list args);
 
     // Compute error metadata for an error at no offset.
     void computeErrorMetadataNoOffset(ErrorMetadata* err);
 
     virtual const char* getFilename() const override { return filename; }
+
+    virtual void lineAndColumnAt(size_t offset, uint32_t* line, uint32_t* column) const override;
+    virtual void currentLineAndColumn(uint32_t* line, uint32_t* column) const override;
+
     virtual bool hasTokenizationStarted() const override;
-    virtual void lineNumAndColumnIndex(size_t offset, uint32_t* line, uint32_t* column) const override;
     virtual void reportErrorNoOffsetVA(unsigned errorNumber, va_list args) override;
-    virtual size_t offset() const override;
 
   protected:
     // Options used for parsing/tokenizing.
     const ReadOnlyCompileOptions& options_;
 
     Token               tokens[ntokens];    // circular token buffer
     unsigned            cursor;             // index of last parsed token
     unsigned            lookahead;          // count of lookahead tokens
@@ -1118,19 +1120,16 @@ class MOZ_STACK_CLASS TokenStream final 
             getCharIgnoreEOL();
         }
     }
 
     MOZ_MUST_USE MOZ_ALWAYS_INLINE bool updateLineInfoForEOL();
 
     TokenBuf            userbuf;            // user input buffer
     CharBuffer          tokenbuf;           // current token string buffer
-
-public:
-    virtual size_t offset() const override;
 };
 
 extern const char*
 TokenKindToDesc(TokenKind tt);
 
 } // namespace frontend
 } // namespace js