v8 12.4.254 (node 22.4.1)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
v8-wasm.h
Go to the documentation of this file.
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef INCLUDE_V8_WASM_H_
6#define INCLUDE_V8_WASM_H_
7
8#include <functional>
9#include <memory>
10#include <string>
11
12#include "v8-local-handle.h" // NOLINT(build/include_directory)
13#include "v8-memory-span.h" // NOLINT(build/include_directory)
14#include "v8-object.h" // NOLINT(build/include_directory)
15#include "v8config.h" // NOLINT(build/include_directory)
16
17namespace v8 {
18
19class ArrayBuffer;
20class Promise;
21
22namespace internal {
23namespace wasm {
24class NativeModule;
25class StreamingDecoder;
26} // namespace wasm
27} // namespace internal
28
33 std::unique_ptr<const uint8_t[]> buffer;
34 size_t size = 0;
35 OwnedBuffer(std::unique_ptr<const uint8_t[]> buffer, size_t size)
36 : buffer(std::move(buffer)), size(size) {}
37 OwnedBuffer() = default;
38};
39
40// Wrapper around a compiled WebAssembly module, which is potentially shared by
41// different WasmModuleObjects.
43 public:
49
54
55 const std::string& source_url() const { return source_url_; }
56
57 private:
58 friend class WasmModuleObject;
59 friend class WasmStreaming;
60
61 explicit CompiledWasmModule(std::shared_ptr<internal::wasm::NativeModule>,
62 const char* source_url, size_t url_length);
63
64 const std::shared_ptr<internal::wasm::NativeModule> native_module_;
65 const std::string source_url_;
66};
67
68// An instance of WebAssembly.Memory.
70 public:
71 WasmMemoryObject() = delete;
72
77
79#ifdef V8_ENABLE_CHECKS
80 CheckCast(value);
81#endif
82 return static_cast<WasmMemoryObject*>(value);
83 }
84
85 private:
86 static void CheckCast(Value* object);
87};
88
89// An instance of WebAssembly.Module.
91 public:
92 WasmModuleObject() = delete;
93
99 Isolate* isolate, const CompiledWasmModule&);
100
106
111 Isolate* isolate, MemorySpan<const uint8_t> wire_bytes);
112
114#ifdef V8_ENABLE_CHECKS
115 CheckCast(value);
116#endif
117 return static_cast<WasmModuleObject*>(value);
118 }
119
120 private:
121 static void CheckCast(Value* obj);
122};
123
131 public:
132 class WasmStreamingImpl;
133
134 explicit WasmStreaming(std::unique_ptr<WasmStreamingImpl> impl);
135
137
142 void OnBytesReceived(const uint8_t* bytes, size_t size);
143
153 void Finish(bool can_use_compiled_module = true);
154
161 void Abort(MaybeLocal<Value> exception);
162
172 bool SetCompiledModuleBytes(const uint8_t* bytes, size_t size);
173
179 std::function<void(CompiledWasmModule)>);
180
181 /*
182 * Sets the UTF-8 encoded source URL for the {Script} object. This must be
183 * called before {Finish}.
184 */
185 void SetUrl(const char* url, size_t length);
186
192 static std::shared_ptr<WasmStreaming> Unpack(Isolate* isolate,
193 Local<Value> value);
194
195 private:
196 std::unique_ptr<WasmStreamingImpl> impl_;
197};
198
199} // namespace v8
200
201#endif // INCLUDE_V8_WASM_H_
const std::string & source_url() const
Definition v8-wasm.h:55
MemorySpan< const uint8_t > GetWireBytesRef()
OwnedBuffer Serialize()
Local< ArrayBuffer > Buffer()
static V8_INLINE WasmMemoryObject * Cast(Value *value)
Definition v8-wasm.h:78
static V8_INLINE WasmModuleObject * Cast(Value *value)
Definition v8-wasm.h:113
static MaybeLocal< WasmModuleObject > FromCompiledModule(Isolate *isolate, const CompiledWasmModule &)
static MaybeLocal< WasmModuleObject > Compile(Isolate *isolate, MemorySpan< const uint8_t > wire_bytes)
CompiledWasmModule GetCompiledModule()
void Finish(bool can_use_compiled_module=true)
void Abort(MaybeLocal< Value > exception)
void OnBytesReceived(const uint8_t *bytes, size_t size)
void SetUrl(const char *url, size_t length)
bool SetCompiledModuleBytes(const uint8_t *bytes, size_t size)
static std::shared_ptr< WasmStreaming > Unpack(Isolate *isolate, Local< Value > value)
WasmStreaming(std::unique_ptr< WasmStreamingImpl > impl)
void SetMoreFunctionsCanBeSerializedCallback(std::function< void(CompiledWasmModule)>)
size_t size
Definition v8-wasm.h:34
std::unique_ptr< const uint8_t[]> buffer
Definition v8-wasm.h:33
OwnedBuffer()=default
OwnedBuffer(std::unique_ptr< const uint8_t[]> buffer, size_t size)
Definition v8-wasm.h:35
#define V8_EXPORT
Definition v8config.h:753
#define V8_INLINE
Definition v8config.h:477