Debian Codegraph @

js/src/debugger/Script-inl.h

raw
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 debugger_Script_inl_h
8 #define debugger_Script_inl_h
9
10 #include "debugger/Script.h" // for DebuggerScript
11
12 #include "mozilla/Assertions.h" // for AssertionConditionType, MOZ_ASSERT
13 #include "mozilla/Variant.h" // for AsVariant
14
15 #include <utility> // for move
16
17 #include "jstypes.h" // for JS_PUBLIC_API
18 #include "debugger/Debugger.h" // for DebuggerScriptReferent
19 #include "gc/Cell.h" // for Cell
20 #include "vm/JSScript.h" // for BaseScript, JSScript
21 #include "vm/NativeObject.h" // for NativeObject
22 #include "wasm/WasmJS.h" // for WasmInstanceObject
23
24 #include "debugger/Debugger-inl.h" // for Debugger::fromJSObject
25
26 class JS_PUBLIC_API JSObject;
27
28 inline js::Debugger* js::DebuggerScript::owner() const {
29 JSObject* dbgobj = &getReservedSlot(OWNER_SLOT).toObject();
30 return Debugger::fromJSObject(dbgobj);
31 }
32
33 js::gc::Cell* js::DebuggerScript::getReferentCell() const {
34 return maybePtrFromReservedSlot<gc::Cell>(SCRIPT_SLOT);
35 }
36
37 js::DebuggerScriptReferent js::DebuggerScript::getReferent() const {
38 if (gc::Cell* cell = getReferentCell()) {
39 if (cell->is<BaseScript>()) {
40 return mozilla::AsVariant(cell->as<BaseScript>());
41 }
42 MOZ_ASSERT(cell->is<JSObject>());
43 return mozilla::AsVariant(
44 &static_cast<NativeObject*>(cell)->as<WasmInstanceObject>());
45 }
46 return mozilla::AsVariant(static_cast<BaseScript*>(nullptr));
47 }
48
49 js::BaseScript* js::DebuggerScript::getReferentScript() const {
50 gc::Cell* cell = getReferentCell();
51 return cell->as<BaseScript>();
52 }
53
54 #endif /* debugger_Script_inl_h */