tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

JumpList.cpp (1454B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "frontend/JumpList.h"
      8 
      9 #include "mozilla/Assertions.h"  // MOZ_ASSERT
     10 
     11 #include "vm/BytecodeUtil.h"  // GET_JUMP_OFFSET, SET_JUMP_OFFSET, IsJumpOpcode
     12 
     13 using namespace js;
     14 using namespace js::frontend;
     15 
     16 void JumpList::push(jsbytecode* code, BytecodeOffset jumpOffset) {
     17  if (!offset.valid()) {
     18    SET_JUMP_OFFSET(&code[jumpOffset.value()], END_OF_LIST_DELTA);
     19  } else {
     20    SET_JUMP_OFFSET(&code[jumpOffset.value()], (offset - jumpOffset).value());
     21  }
     22  offset = jumpOffset;
     23 }
     24 
     25 void JumpList::patchAll(jsbytecode* code, JumpTarget target) {
     26  if (!offset.valid()) {
     27    // This list is not used. Nothing to do.
     28    return;
     29  }
     30 
     31  BytecodeOffsetDiff delta;
     32  BytecodeOffset jumpOffset = offset;
     33  while (true) {
     34    jsbytecode* pc = &code[jumpOffset.value()];
     35    MOZ_ASSERT(IsJumpOpcode(JSOp(*pc)));
     36    delta = BytecodeOffsetDiff(GET_JUMP_OFFSET(pc));
     37    MOZ_ASSERT(delta.value() == END_OF_LIST_DELTA || delta.value() < 0);
     38    BytecodeOffsetDiff span = target.offset - jumpOffset;
     39    SET_JUMP_OFFSET(pc, span.value());
     40 
     41    if (delta.value() == END_OF_LIST_DELTA) {
     42      break;
     43    }
     44    jumpOffset += delta;
     45  }
     46 }