ladybird/Libraries/LibJS/DecodedBytecodeCache.h
Andreas Kling 6ecfcd3e68 LibWeb+LibJS: Cache decoded JS bytecode sidecars
Add a ref-counted decoded bytecode cache backing so bytecode cache
materialization can create fresh script or module records from a shared
decoded sidecar without passing around one-shot raw blob ownership.

Keep that backing in ExecutableBacking for records materialized from
bytecode cache sidecars, so the immutable decoded data stays alive for
as long as the installed record needs it.

Cover the shared backing path with a bytecode-cache test that
materializes and runs two scripts from one decoded backing.
2026-06-06 09:15:09 +02:00

44 lines
997 B
C++

/*
* Copyright (c) 2026-present, the Ladybird developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/Span.h>
#include <AK/Types.h>
#include <LibCore/ImmutableBytes.h>
#include <LibJS/Export.h>
namespace JS::FFI {
struct DecodedBytecodeCacheBlob;
}
namespace JS::RustIntegration {
enum class ProgramType : u8 {
Script = 0,
Module = 1,
};
class JS_API DecodedBytecodeCache final : public RefCounted<DecodedBytecodeCache> {
public:
static RefPtr<DecodedBytecodeCache> create(Core::ImmutableBytes, ProgramType, ReadonlyBytes source_hash);
static NonnullRefPtr<DecodedBytecodeCache> create(FFI::DecodedBytecodeCacheBlob*);
~DecodedBytecodeCache();
FFI::DecodedBytecodeCacheBlob* create_materialization_handle() const;
private:
explicit DecodedBytecodeCache(FFI::DecodedBytecodeCacheBlob*);
FFI::DecodedBytecodeCacheBlob* m_blob { nullptr };
};
}