Commit 4a76ab95 authored by Tooru Fujisawa's avatar Tooru Fujisawa
Browse files

Bug 1477621 - Part 2: Add source note field constants for try. r=jandem

parent 53c7a51a
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -70,6 +70,16 @@ class SrcNote {
            Count
        };
    };
    // SRC_TRY: Source note for JSOP_TRY.
    class Try {
      public:
        enum Fields {
            // The offset of the JSOP_GOTO at the end of the try block from
            // JSOP_TRY.
            EndOfTryJumpOffset,
            Count
        };
    };
};

#define FOR_EACH_SRC_NOTE_TYPE(M)                                                                  \
@@ -94,8 +104,7 @@ class SrcNote {
    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",         1)  /* JSOP_TRY, offset points to goto at the end of the    \
                                              try block. */                                        \
    M(SRC_TRY,          "try",         SrcNote::Try::Count) \
    /* All notes above here are "gettable".  See SN_IS_GETTABLE below. */                          \
    M(SRC_COLSPAN,      "colspan",     1)  /* Number of columns this opcode spans. */              \
    M(SRC_NEWLINE,      "newline",     0)  /* Bytecode follows a source newline. */                \
+4 −1
Original line number Diff line number Diff line
@@ -81,8 +81,11 @@ TryEmitter::emitTryEnd()
    }

    // Source note points to the jump at the end of the try block.
    if (!bce_->setSrcNoteOffset(noteIndex_, 0, bce_->offset() - tryStart_ + JSOP_TRY_LENGTH))
    if (!bce_->setSrcNoteOffset(noteIndex_, SrcNote::Try::EndOfTryJumpOffset,
                                bce_->offset() - tryStart_ + JSOP_TRY_LENGTH))
    {
        return false;
    }

    // Emit jump over catch and/or finally.
    if (!bce_->emitJump(JSOP_GOTO, &catchAndFinallyJump_))
+1 −1
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ BytecodeAnalysis::init(TempAllocator& alloc, GSNCache& gsn)
            jssrcnote* sn = GetSrcNote(gsn, script_, pc);
            MOZ_ASSERT(SN_TYPE(sn) == SRC_TRY);

            jsbytecode* endOfTry = pc + GetSrcNoteOffset(sn, 0);
            jsbytecode* endOfTry = pc + GetSrcNoteOffset(sn, SrcNote::Try::EndOfTryJumpOffset);
            MOZ_ASSERT(JSOp(*endOfTry) == JSOP_GOTO);

            jsbytecode* afterTry = endOfTry + GET_JUMP_OFFSET(endOfTry);
+1 −1
Original line number Diff line number Diff line
@@ -546,7 +546,7 @@ ControlFlowGenerator::processTry()

    // Get the pc of the last instruction in the try block. It's a JSOP_GOTO to
    // jump over the catch block.
    jsbytecode* endpc = pc + GetSrcNoteOffset(sn, 0);
    jsbytecode* endpc = pc + GetSrcNoteOffset(sn, SrcNote::Try::EndOfTryJumpOffset);
    MOZ_ASSERT(JSOp(*endpc) == JSOP_GOTO);
    MOZ_ASSERT(GetJumpOffset(endpc) > 0);

+4 −1
Original line number Diff line number Diff line
@@ -2802,8 +2802,11 @@ SrcNotes(JSContext* cx, HandleScript script, Sprinter* sp)

          case SRC_TRY:
            MOZ_ASSERT(JSOp(script->code()[offset]) == JSOP_TRY);
            if (!sp->jsprintf(" offset to jump %u", unsigned(GetSrcNoteOffset(sn, 0))))
            if (!sp->jsprintf(" offset to jump %u",
                              unsigned(GetSrcNoteOffset(sn, SrcNote::Try::EndOfTryJumpOffset))))
            {
                return false;
            }
            break;

          case SRC_CLASS_SPAN: {