summaryrefslogtreecommitdiffstats
path: root/js/src/vm/BytecodeLocation-inl.h
blob: f254515a505940d353b5024a1e21b4c8438285c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * vim: set ts=8 sts=2 et sw=2 tw=80:
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef vm_BytecodeLocation_inl_h
#define vm_BytecodeLocation_inl_h

#include "vm/BytecodeLocation.h"

#include "vm/JSScript.h"

#include "vm/BytecodeUtil-inl.h"
#include "vm/JSScript-inl.h"

namespace js {

inline uint32_t BytecodeLocation::bytecodeToOffset(
    const JSScript* script) const {
  MOZ_ASSERT(this->isInBounds());
  return script->pcToOffset(this->rawBytecode_);
}

inline JSAtom* BytecodeLocation::getAtom(const JSScript* script) const {
  MOZ_ASSERT(this->isValid());
  return script->getAtom(this->rawBytecode_);
}

inline PropertyName* BytecodeLocation::getPropertyName(
    const JSScript* script) const {
  MOZ_ASSERT(this->isValid());
  return script->getName(this->rawBytecode_);
}

inline JS::BigInt* BytecodeLocation::getBigInt(const JSScript* script) const {
  MOZ_ASSERT(this->isValid());
  MOZ_ASSERT(is(JSOp::BigInt));
  return script->getBigInt(this->rawBytecode_);
}

inline JSObject* BytecodeLocation::getObject(const JSScript* script) const {
  MOZ_ASSERT(this->isValid());
  MOZ_ASSERT(is(JSOp::CallSiteObj) || is(JSOp::Object));
  return script->getObject(this->rawBytecode_);
}

inline JSFunction* BytecodeLocation::getFunction(const JSScript* script) const {
  MOZ_ASSERT(this->isValid());
  MOZ_ASSERT(is(JSOp::Lambda) || is(JSOp::LambdaArrow) ||
             is(JSOp::FunWithProto));
  return script->getFunction(this->rawBytecode_);
}

inline js::RegExpObject* BytecodeLocation::getRegExp(
    const JSScript* script) const {
  MOZ_ASSERT(this->isValid());
  MOZ_ASSERT(is(JSOp::RegExp));
  return script->getRegExp(this->rawBytecode_);
}

inline js::Scope* BytecodeLocation::getScope(const JSScript* script) const {
  MOZ_ASSERT(this->isValid());
  return script->getScope(this->rawBytecode_);
}

inline Scope* BytecodeLocation::innermostScope(const JSScript* script) const {
  MOZ_ASSERT(this->isValid());
  return script->innermostScope(this->rawBytecode_);
}

inline uint32_t BytecodeLocation::tableSwitchCaseOffset(
    const JSScript* script, uint32_t caseIndex) const {
  return script->tableSwitchCaseOffset(this->rawBytecode_, caseIndex);
}

inline uint32_t BytecodeLocation::getJumpTargetOffset(
    const JSScript* script) const {
  MOZ_ASSERT(this->isJump());
  return this->bytecodeToOffset(script) + GET_JUMP_OFFSET(this->rawBytecode_);
}

inline uint32_t BytecodeLocation::getTableSwitchDefaultOffset(
    const JSScript* script) const {
  MOZ_ASSERT(this->is(JSOp::TableSwitch));
  return this->bytecodeToOffset(script) + GET_JUMP_OFFSET(this->rawBytecode_);
}

BytecodeLocation BytecodeLocation::getTableSwitchDefaultTarget() const {
  MOZ_ASSERT(is(JSOp::TableSwitch));
  return BytecodeLocation(*this, rawBytecode_ + GET_JUMP_OFFSET(rawBytecode_));
}

BytecodeLocation BytecodeLocation::getTableSwitchCaseTarget(
    const JSScript* script, uint32_t caseIndex) const {
  MOZ_ASSERT(is(JSOp::TableSwitch));
  jsbytecode* casePC = script->tableSwitchCasePC(rawBytecode_, caseIndex);
  return BytecodeLocation(*this, casePC);
}

inline uint32_t BytecodeLocation::useCount() const {
  return GetUseCount(this->rawBytecode_);
}

inline uint32_t BytecodeLocation::defCount() const {
  return GetDefCount(this->rawBytecode_);
}

}  // namespace js

#endif