Bug 1477621 - Part 4: Add source note field constants for line. r=jandem
authorTooru Fujisawa <arai_a@mac.com>
Wed, 25 Jul 2018 17:01:49 +0900
changeset 428224 9d328a1be52ce31ef56c4fe7e4155b4a6f2d35fc
parent 428223 d18e67f75339c713ce1aadc54631898b5af5df3d
child 428225 b03792874ae6649f45499652c37021abe1e98c1d
push id105651
push userarai_a@mac.com
push dateWed, 25 Jul 2018 08:02:10 +0000
treeherdermozilla-inbound@e3600583e49a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1477621
milestone63.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 1477621 - Part 4: Add source note field constants for line. r=jandem
js/src/frontend/SourceNotes.h
js/src/shell/js.cpp
js/src/vm/BytecodeUtil-inl.h
js/src/vm/CodeCoverage.cpp
js/src/vm/JSScript.cpp
--- a/js/src/frontend/SourceNotes.h
+++ b/js/src/frontend/SourceNotes.h
@@ -85,16 +85,25 @@ class SrcNote {
       public:
         enum Fields {
             // The column span (the diff between the column corresponds to the
             // current op and last known column).
             Span,
             Count
         };
     };
+    // SRC_SETLINE: Source note for arbitrary ops.
+    class SetLine {
+      public:
+        enum Fields {
+            // The file-absolute source line number of the current op.
+            Line,
+            Count
+        };
+    };
 };
 
 #define FOR_EACH_SRC_NOTE_TYPE(M)                                                                  \
     M(SRC_NULL,         "null",        0)  /* Terminates a note vector. */                         \
     M(SRC_IF,           "if",          0)  /* JSOP_IFEQ bytecode is from an if-then. */            \
     M(SRC_IF_ELSE,      "if-else",     0)  /* JSOP_IFEQ bytecode is from an if-then-else. */       \
     M(SRC_COND,         "cond",        0)  /* JSOP_IFEQ is from conditional ?: operator. */        \
     M(SRC_FOR,          "for",         3)  /* JSOP_NOP or JSOP_POP in for(;;) loop head. */        \
@@ -113,17 +122,17 @@ class SrcNote {
     M(SRC_NEXTCASE,     "nextcase",    SrcNote::NextCase::Count) \
     M(SRC_ASSIGNOP,     "assignop",    0)  /* += or another assign-op follows. */                  \
     M(SRC_CLASS_SPAN,   "class",       2)  /* The starting and ending offsets for the class, used  \
                                               for toString correctness for default ctors. */       \
     M(SRC_TRY,          "try",         SrcNote::Try::Count) \
     /* All notes above here are "gettable".  See SN_IS_GETTABLE below. */                          \
     M(SRC_COLSPAN,      "colspan",     SrcNote::ColSpan::Count) \
     M(SRC_NEWLINE,      "newline",     0)  /* Bytecode follows a source newline. */                \
-    M(SRC_SETLINE,      "setline",     1)  /* A file-absolute source line number note. */          \
+    M(SRC_SETLINE,      "setline",     SrcNote::SetLine::Count) \
     M(SRC_UNUSED21,     "unused21",    0)  /* Unused. */                                           \
     M(SRC_UNUSED22,     "unused22",    0)  /* Unused. */                                           \
     M(SRC_UNUSED23,     "unused23",    0)  /* Unused. */                                           \
     M(SRC_XDELTA,       "xdelta",      0)  /* 24-31 are for extended delta notes. */
 
 enum SrcNoteType {
 #define DEFINE_SRC_NOTE_TYPE(sym, name, arity) sym,
     FOR_EACH_SRC_NOTE_TYPE(DEFINE_SRC_NOTE_TYPE)
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -2726,17 +2726,17 @@ SrcNotes(JSContext* cx, HandleScript scr
 
           case SRC_COLSPAN:
             colspan = SN_OFFSET_TO_COLSPAN(GetSrcNoteOffset(sn, SrcNote::ColSpan::Span));
             if (!sp->jsprintf("%d", colspan))
                 return false;
             break;
 
           case SRC_SETLINE:
-            lineno = GetSrcNoteOffset(sn, 0);
+            lineno = GetSrcNoteOffset(sn, SrcNote::SetLine::Line);
             if (!sp->jsprintf(" lineno %u", lineno))
                 return false;
             break;
 
           case SRC_NEWLINE:
             ++lineno;
             break;
 
--- a/js/src/vm/BytecodeUtil-inl.h
+++ b/js/src/vm/BytecodeUtil-inl.h
@@ -179,17 +179,17 @@ class BytecodeRangeWithPosition : privat
             SrcNoteType type = SN_TYPE(sn);
             if (type == SRC_COLSPAN) {
                 ptrdiff_t colspan =
                     SN_OFFSET_TO_COLSPAN(GetSrcNoteOffset(sn, SrcNote::ColSpan::Span));
                 MOZ_ASSERT(ptrdiff_t(column) + colspan >= 0);
                 column += colspan;
                 lastLinePC = snpc;
             } else if (type == SRC_SETLINE) {
-                lineno = size_t(GetSrcNoteOffset(sn, 0));
+                lineno = size_t(GetSrcNoteOffset(sn, SrcNote::SetLine::Line));
                 column = 0;
                 lastLinePC = snpc;
             } else if (type == SRC_NEWLINE) {
                 lineno++;
                 column = 0;
                 lastLinePC = snpc;
             }
 
--- a/js/src/vm/CodeCoverage.cpp
+++ b/js/src/vm/CodeCoverage.cpp
@@ -191,17 +191,17 @@ LCovSource::writeScript(JSScript* script
 
         // If we have additional source notes, walk all the source notes of the
         // current pc.
         if (snpc <= pc || !firstLineHasBeenWritten) {
             size_t oldLine = lineno;
             while (!SN_IS_TERMINATOR(sn) && snpc <= pc) {
                 SrcNoteType type = SN_TYPE(sn);
                 if (type == SRC_SETLINE)
-                    lineno = size_t(GetSrcNoteOffset(sn, 0));
+                    lineno = size_t(GetSrcNoteOffset(sn, SrcNote::SetLine::Line));
                 else if (type == SRC_NEWLINE)
                     lineno++;
                 else if (type == SRC_TABLESWITCH)
                     tableswitchExitOffset = GetSrcNoteOffset(sn, SrcNote::TableSwitch::EndOffset);
 
                 sn = SN_NEXT(sn);
                 snpc += SN_DELTA(sn);
             }
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -3266,17 +3266,17 @@ js::PCToLineNumber(unsigned startLine, j
     ptrdiff_t target = pc - code;
     for (jssrcnote* sn = notes; !SN_IS_TERMINATOR(sn); sn = SN_NEXT(sn)) {
         offset += SN_DELTA(sn);
         if (offset > target)
             break;
 
         SrcNoteType type = SN_TYPE(sn);
         if (type == SRC_SETLINE) {
-            lineno = unsigned(GetSrcNoteOffset(sn, 0));
+            lineno = unsigned(GetSrcNoteOffset(sn, SrcNote::SetLine::Line));
             column = 0;
         } else if (type == SRC_NEWLINE) {
             lineno++;
             column = 0;
         } else if (type == SRC_COLSPAN) {
             ptrdiff_t colspan = SN_OFFSET_TO_COLSPAN(GetSrcNoteOffset(sn, SrcNote::ColSpan::Span));
             MOZ_ASSERT(ptrdiff_t(column) + colspan >= 0);
             column += colspan;
@@ -3318,17 +3318,17 @@ js::LineNumberToPC(JSScript* script, uns
             if (diff < bestdiff) {
                 bestdiff = diff;
                 best = offset;
             }
         }
         offset += SN_DELTA(sn);
         SrcNoteType type = SN_TYPE(sn);
         if (type == SRC_SETLINE) {
-            lineno = unsigned(GetSrcNoteOffset(sn, 0));
+            lineno = unsigned(GetSrcNoteOffset(sn, SrcNote::SetLine::Line));
         } else if (type == SRC_NEWLINE) {
             lineno++;
         }
     }
     if (best >= 0)
         offset = best;
 out:
     return script->offsetToPC(offset);
@@ -3337,17 +3337,17 @@ out:
 JS_FRIEND_API(unsigned)
 js::GetScriptLineExtent(JSScript* script)
 {
     unsigned lineno = script->lineno();
     unsigned maxLineNo = lineno;
     for (jssrcnote* sn = script->notes(); !SN_IS_TERMINATOR(sn); sn = SN_NEXT(sn)) {
         SrcNoteType type = SN_TYPE(sn);
         if (type == SRC_SETLINE)
-            lineno = unsigned(GetSrcNoteOffset(sn, 0));
+            lineno = unsigned(GetSrcNoteOffset(sn, SrcNote::SetLine::Line));
         else if (type == SRC_NEWLINE)
             lineno++;
 
         if (maxLineNo < lineno)
             maxLineNo = lineno;
     }
 
     return 1 + maxLineNo - script->lineno();