Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/node/v8-wasm.h
$ cat -n /usr/include/node/v8-wasm.h 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
9 #include
10 #include
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 17 namespace v8 { 18 19 class ArrayBuffer; 20 class Promise; 21 22 namespace internal { 23 namespace wasm { 24 class NativeModule; 25 class StreamingDecoder; 26 } // namespace wasm 27 } // namespace internal 28 29 /** 30 * An owned byte buffer with associated size. 31 */ 32 struct OwnedBuffer { 33 std::unique_ptr
buffer; 34 size_t size = 0; 35 OwnedBuffer(std::unique_ptr
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. 42 class V8_EXPORT CompiledWasmModule { 43 public: 44 /** 45 * Serialize the compiled module. The serialized data does not include the 46 * wire bytes. 47 */ 48 OwnedBuffer Serialize(); 49 50 /** 51 * Get the (wasm-encoded) wire bytes that were used to compile this module. 52 */ 53 MemorySpan
GetWireBytesRef(); 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
, 62 const char* source_url, size_t url_length); 63 64 const std::shared_ptr
native_module_; 65 const std::string source_url_; 66 }; 67 68 // An instance of WebAssembly.Memory. 69 class V8_EXPORT WasmMemoryObject : public Object { 70 public: 71 WasmMemoryObject() = delete; 72 73 /** 74 * Returns underlying ArrayBuffer. 75 */ 76 Local
Buffer(); 77 78 V8_INLINE static WasmMemoryObject* Cast(Value* value) { 79 #ifdef V8_ENABLE_CHECKS 80 CheckCast(value); 81 #endif 82 return static_cast
(value); 83 } 84 85 private: 86 static void CheckCast(Value* object); 87 }; 88 89 // An instance of WebAssembly.Module. 90 class V8_EXPORT WasmModuleObject : public Object { 91 public: 92 WasmModuleObject() = delete; 93 94 /** 95 * Efficiently re-create a WasmModuleObject, without recompiling, from 96 * a CompiledWasmModule. 97 */ 98 static MaybeLocal
FromCompiledModule( 99 Isolate* isolate, const CompiledWasmModule&); 100 101 /** 102 * Get the compiled module for this module object. The compiled module can be 103 * shared by several module objects. 104 */ 105 CompiledWasmModule GetCompiledModule(); 106 107 /** 108 * Compile a Wasm module from the provided uncompiled bytes. 109 */ 110 static MaybeLocal
Compile( 111 Isolate* isolate, MemorySpan
wire_bytes); 112 113 V8_INLINE static WasmModuleObject* Cast(Value* value) { 114 #ifdef V8_ENABLE_CHECKS 115 CheckCast(value); 116 #endif 117 return static_cast
(value); 118 } 119 120 private: 121 static void CheckCast(Value* obj); 122 }; 123 124 /** 125 * The V8 interface for WebAssembly streaming compilation. When streaming 126 * compilation is initiated, V8 passes a {WasmStreaming} object to the embedder 127 * such that the embedder can pass the input bytes for streaming compilation to 128 * V8. 129 */ 130 class V8_EXPORT WasmStreaming final { 131 public: 132 class WasmStreamingImpl; 133 134 explicit WasmStreaming(std::unique_ptr
impl); 135 136 ~WasmStreaming(); 137 138 /** 139 * Pass a new chunk of bytes to WebAssembly streaming compilation. 140 * The buffer passed into {OnBytesReceived} is owned by the caller. 141 */ 142 void OnBytesReceived(const uint8_t* bytes, size_t size); 143 144 /** 145 * {Finish} should be called after all received bytes where passed to 146 * {OnBytesReceived} to tell V8 that there will be no more bytes. {Finish} 147 * must not be called after {Abort} has been called already. 148 * If {can_use_compiled_module} is true and {SetCompiledModuleBytes} was 149 * previously called, the compiled module bytes can be used. 150 * If {can_use_compiled_module} is false, the compiled module bytes previously 151 * set by {SetCompiledModuleBytes} should not be used. 152 */ 153 void Finish(bool can_use_compiled_module = true); 154 155 /** 156 * Abort streaming compilation. If {exception} has a value, then the promise 157 * associated with streaming compilation is rejected with that value. If 158 * {exception} does not have value, the promise does not get rejected. 159 * {Abort} must not be called repeatedly, or after {Finish}. 160 */ 161 void Abort(MaybeLocal
exception); 162 163 /** 164 * Passes previously compiled module bytes. This must be called before 165 * {OnBytesReceived}, {Finish}, or {Abort}. Returns true if the module bytes 166 * can be used, false otherwise. The buffer passed via {bytes} and {size} 167 * is owned by the caller. If {SetCompiledModuleBytes} returns true, the 168 * buffer must remain valid until either {Finish} or {Abort} completes. 169 * The compiled module bytes should not be used until {Finish(true)} is 170 * called, because they can be invalidated later by {Finish(false)}. 171 */ 172 bool SetCompiledModuleBytes(const uint8_t* bytes, size_t size); 173 174 /** 175 * Sets a callback which is called whenever a significant number of new 176 * functions are ready for serialization. 177 */ 178 void SetMoreFunctionsCanBeSerializedCallback( 179 std::function
); 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 187 /** 188 * Unpacks a {WasmStreaming} object wrapped in a {Managed} for the embedder. 189 * Since the embedder is on the other side of the API, it cannot unpack the 190 * {Managed} itself. 191 */ 192 static std::shared_ptr
Unpack(Isolate* isolate, 193 Local
value); 194 195 private: 196 std::unique_ptr
impl_; 197 }; 198 199 } // namespace v8 200 201 #endif // INCLUDE_V8_WASM_H_
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2025 MyWebUniversity.com ™