BytecodeLocation-inl.h (3820B)
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 #ifndef vm_BytecodeLocation_inl_h 8 #define vm_BytecodeLocation_inl_h 9 10 #include "vm/BytecodeLocation.h" 11 12 #include "vm/JSScript.h" 13 14 #include "vm/BytecodeUtil-inl.h" 15 #include "vm/JSScript-inl.h" 16 17 namespace js { 18 19 inline uint32_t BytecodeLocation::bytecodeToOffset( 20 const JSScript* script) const { 21 MOZ_ASSERT(this->isInBounds()); 22 return script->pcToOffset(this->rawBytecode_); 23 } 24 25 inline JSAtom* BytecodeLocation::getAtom(const JSScript* script) const { 26 MOZ_ASSERT(this->isValid()); 27 return script->getAtom(this->rawBytecode_); 28 } 29 30 inline JSString* BytecodeLocation::getString(const JSScript* script) const { 31 MOZ_ASSERT(this->isValid()); 32 return script->getString(this->rawBytecode_); 33 } 34 35 inline bool BytecodeLocation::atomizeString(JSContext* cx, JSScript* script) { 36 MOZ_ASSERT(this->isValid()); 37 return script->atomizeString(cx, this->rawBytecode_); 38 } 39 40 inline PropertyName* BytecodeLocation::getPropertyName( 41 const JSScript* script) const { 42 MOZ_ASSERT(this->isValid()); 43 return script->getName(this->rawBytecode_); 44 } 45 46 inline JS::BigInt* BytecodeLocation::getBigInt(const JSScript* script) const { 47 MOZ_ASSERT(this->isValid()); 48 MOZ_ASSERT(is(JSOp::BigInt)); 49 return script->getBigInt(this->rawBytecode_); 50 } 51 52 inline JSObject* BytecodeLocation::getObject(const JSScript* script) const { 53 MOZ_ASSERT(this->isValid()); 54 MOZ_ASSERT(is(JSOp::CallSiteObj) || is(JSOp::Object)); 55 return script->getObject(this->rawBytecode_); 56 } 57 58 inline JSFunction* BytecodeLocation::getFunction(const JSScript* script) const { 59 MOZ_ASSERT(this->isValid()); 60 MOZ_ASSERT(is(JSOp::Lambda) || is(JSOp::FunWithProto)); 61 return script->getFunction(this->rawBytecode_); 62 } 63 64 inline js::RegExpObject* BytecodeLocation::getRegExp( 65 const JSScript* script) const { 66 MOZ_ASSERT(this->isValid()); 67 MOZ_ASSERT(is(JSOp::RegExp)); 68 return script->getRegExp(this->rawBytecode_); 69 } 70 71 inline js::Scope* BytecodeLocation::getScope(const JSScript* script) const { 72 MOZ_ASSERT(this->isValid()); 73 return script->getScope(this->rawBytecode_); 74 } 75 76 inline Scope* BytecodeLocation::innermostScope(const JSScript* script) const { 77 MOZ_ASSERT(this->isValid()); 78 return script->innermostScope(this->rawBytecode_); 79 } 80 81 inline uint32_t BytecodeLocation::tableSwitchCaseOffset( 82 const JSScript* script, uint32_t caseIndex) const { 83 return script->tableSwitchCaseOffset(this->rawBytecode_, caseIndex); 84 } 85 86 inline uint32_t BytecodeLocation::getJumpTargetOffset( 87 const JSScript* script) const { 88 MOZ_ASSERT(this->isJump()); 89 return this->bytecodeToOffset(script) + GET_JUMP_OFFSET(this->rawBytecode_); 90 } 91 92 inline uint32_t BytecodeLocation::getTableSwitchDefaultOffset( 93 const JSScript* script) const { 94 MOZ_ASSERT(this->is(JSOp::TableSwitch)); 95 return this->bytecodeToOffset(script) + GET_JUMP_OFFSET(this->rawBytecode_); 96 } 97 98 BytecodeLocation BytecodeLocation::getTableSwitchDefaultTarget() const { 99 MOZ_ASSERT(is(JSOp::TableSwitch)); 100 return BytecodeLocation(*this, rawBytecode_ + GET_JUMP_OFFSET(rawBytecode_)); 101 } 102 103 BytecodeLocation BytecodeLocation::getTableSwitchCaseTarget( 104 const JSScript* script, uint32_t caseIndex) const { 105 MOZ_ASSERT(is(JSOp::TableSwitch)); 106 jsbytecode* casePC = script->tableSwitchCasePC(rawBytecode_, caseIndex); 107 return BytecodeLocation(*this, casePC); 108 } 109 110 inline uint32_t BytecodeLocation::useCount() const { 111 return GetUseCount(this->rawBytecode_); 112 } 113 114 inline uint32_t BytecodeLocation::defCount() const { 115 return GetDefCount(this->rawBytecode_); 116 } 117 118 } // namespace js 119 120 #endif