#pragma once
#if ENABLE(WEBASSEMBLY)
#include "WasmCodeBlock.h"
#include "WasmMemory.h"
#include <wtf/Expected.h>
#include <wtf/Lock.h>
#include <wtf/SharedTask.h>
#include <wtf/ThreadSafeRefCounted.h>
namespace JSC { namespace Wasm {
struct ModuleInformation;
class Plan;
using SignatureIndex = uint32_t;
class Module : public ThreadSafeRefCounted<Module> {
public:
using ValidationResult = WTF::Expected<RefPtr<Module>, String>;
typedef void CallbackType(VM&, ValidationResult&&);
using AsyncValidationCallback = RefPtr<SharedTask<CallbackType>>;
static ValidationResult validateSync(VM&, Vector<uint8_t>&& source);
static void validateAsync(VM&, Vector<uint8_t>&& source, Module::AsyncValidationCallback&&);
static Ref<Module> create(Ref<ModuleInformation>&& moduleInformation)
{
return adoptRef(*new Module(WTFMove(moduleInformation)));
}
Wasm::SignatureIndex signatureIndexFromFunctionIndexSpace(unsigned functionIndexSpace) const;
const Wasm::ModuleInformation& moduleInformation() const { return m_moduleInformation.get(); }
Ref<CodeBlock> compileSync(MemoryMode);
void compileAsync(VM&, MemoryMode, CodeBlock::AsyncCompilationCallback&&);
JS_EXPORT_PRIVATE ~Module();
CodeBlock* codeBlockFor(MemoryMode mode) { return m_codeBlocks[static_cast<uint8_t>(mode)].get(); }
private:
Ref<CodeBlock> getOrCreateCodeBlock(MemoryMode);
Module(Ref<ModuleInformation>&&);
Ref<ModuleInformation> m_moduleInformation;
RefPtr<CodeBlock> m_codeBlocks[Wasm::NumberOfMemoryModes];
Lock m_lock;
};
} }
#endif // ENABLE(WEBASSEMBLY)