
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-14, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/RefCounted.h>
|
|
#include <LibJS/Bytecode/Operand.h>
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
class ScopedOperandImpl : public RefCounted<ScopedOperandImpl> {
|
|
public:
|
|
ScopedOperandImpl(Generator& generator, Operand operand)
|
|
: m_generator(generator)
|
|
, m_operand(operand)
|
|
{
|
|
}
|
|
|
|
~ScopedOperandImpl();
|
|
|
|
[[nodiscard]] Operand const& operand() const { return m_operand; }
|
|
[[nodiscard]] Operand& operand() { return m_operand; }
|
|
|
|
private:
|
|
Generator& m_generator;
|
|
Operand m_operand;
|
|
};
|
|
|
|
class ScopedOperand {
|
|
public:
|
|
explicit ScopedOperand(Generator& generator, Operand operand)
|
|
: m_impl(adopt_ref(*new ScopedOperandImpl(generator, operand)))
|
|
{
|
|
}
|
|
|
|
[[nodiscard]] Operand const& operand() const { return m_impl->operand(); }
|
|
[[nodiscard]] Operand& operand() { return m_impl->operand(); }
|
|
operator Operand() const { return operand(); }
|
|
|
|
[[nodiscard]] bool operator==(ScopedOperand const& other) const { return operand() == other.operand(); }
|
|
|
|
[[nodiscard]] size_t ref_count() const { return m_impl->ref_count(); }
|
|
|
|
private:
|
|
NonnullRefPtr<ScopedOperandImpl> m_impl;
|
|
};
|
|
|
|
}
|