diff --git a/common.gypi b/common.gypi index 71712d308472..7eaad1e5ea1e 100644 --- a/common.gypi +++ b/common.gypi @@ -43,7 +43,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.34', + 'v8_embedder_string': '-node.35', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/include/v8-wasm.h b/deps/v8/include/v8-wasm.h index 550cdfb32783..034912de0f8b 100644 --- a/deps/v8/include/v8-wasm.h +++ b/deps/v8/include/v8-wasm.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "v8-internal.h" // NOLINT(build/include_directory) @@ -106,12 +107,48 @@ class V8_EXPORT WasmModuleObject : public Object { */ CompiledWasmModule GetCompiledModule(); + /** + * Options that influence how a Wasm module is compiled. The compile-time + * import options mirror those accepted by the JS `WebAssembly.Module` + * constructor (`{ builtins, importedStringConstants }`). + */ + struct CompileOptions { + // Builtin compile-time imports, mirroring the strings accepted in the + // `builtins` array of the JS `WebAssembly.Module` constructor options. + // Combine values with bitwise-or to enable multiple builtins. + struct Builtins { + enum { + kNone = 0, + kJsString = 1 << 0, // "js-string" + }; + }; + // Bitwise-or of `Builtins` values to enable as compile-time imports. + int builtins = Builtins::kNone; + // If non-null, enable imported string constants from the named module + // (e.g. "wasm:js/string-constants"). The string must be null-terminated and + // remain valid for the duration of the compile call. + const char* imported_string_constants_module = nullptr; + // If non-empty, associated with the module's script as its source URL, for + // use in stack traces and developer tooling. If a script already exists in + // the isolate for the same module, its existing URL is retained. The + // string must remain valid for the duration of the compile call. + std::string_view source_url = {}; + }; + /** * Compile a Wasm module from the provided uncompiled bytes. */ static MaybeLocal Compile( Isolate* isolate, MemorySpan wire_bytes); + /** + * Compile a Wasm module from the provided uncompiled bytes, applying the + * given compile options. + */ + static MaybeLocal Compile( + Isolate* isolate, MemorySpan wire_bytes, + const CompileOptions& options); + V8_INLINE static WasmModuleObject* Cast(Value* value) { #ifdef V8_ENABLE_CHECKS CheckCast(value); @@ -224,13 +261,15 @@ class V8_EXPORT WasmStreaming final { class V8_EXPORT WasmModuleCompilation final { public: using ModuleCachingCallback = WasmStreaming::ModuleCachingCallback; + using CompileOptions = WasmModuleObject::CompileOptions; /** - * Start an asynchronous module compilation. This can be called on any thread. + * Start an asynchronous module compilation, applying the given compile + * options. This can be called on any thread. Providing + * {CompileOptions::source_url} is equivalent to calling {SetUrl}. * TODO(clemensb): Add some way to pass enabled features. - * TODO(clemensb): Add some way to pass compile time imports. */ - WasmModuleCompilation(); + explicit WasmModuleCompilation(const CompileOptions& options = {}); ~WasmModuleCompilation(); diff --git a/deps/v8/src/api/api.cc b/deps/v8/src/api/api.cc index eb3cd7dee28f..181d1a126faf 100644 --- a/deps/v8/src/api/api.cc +++ b/deps/v8/src/api/api.cc @@ -8853,7 +8853,15 @@ MaybeLocal WasmModuleObject::FromCompiledModule( MaybeLocal WasmModuleObject::Compile( Isolate* v8_isolate, MemorySpan wire_bytes) { + return Compile(v8_isolate, wire_bytes, CompileOptions{}); +} + +MaybeLocal WasmModuleObject::Compile( + Isolate* v8_isolate, MemorySpan wire_bytes, + const CompileOptions& options) { #if V8_ENABLE_WEBASSEMBLY + i::wasm::CompileTimeImports compile_imports = + i::wasm::CompileTimeImportsFromOptions(options); base::OwnedVector bytes = base::OwnedCopyOf(wire_bytes); i::Isolate* i_isolate = reinterpret_cast(v8_isolate); // We don't check for `IsWasmCodegenAllowed` here, because this function is @@ -8864,10 +8872,11 @@ MaybeLocal WasmModuleObject::Compile( i::wasm::ErrorThrower thrower(i_isolate, "WasmModuleObject::Compile()"); auto enabled_features = i::wasm::WasmEnabledFeatures::FromIsolate(i_isolate); - // TODO(14179): Provide an API method that supports compile options. maybe_compiled = i::wasm::GetWasmEngine()->SyncCompile( - i_isolate, enabled_features, i::wasm::CompileTimeImports{}, &thrower, - std::move(bytes)); + i_isolate, enabled_features, std::move(compile_imports), &thrower, + std::move(bytes), + base::Vector(options.source_url.data(), + options.source_url.size())); } CHECK_EQ(maybe_compiled.is_null(), i_isolate->has_exception()); if (maybe_compiled.is_null()) return {}; diff --git a/deps/v8/src/wasm/wasm-engine.cc b/deps/v8/src/wasm/wasm-engine.cc index 1380f8166b0f..c9184ef647c3 100644 --- a/deps/v8/src/wasm/wasm-engine.cc +++ b/deps/v8/src/wasm/wasm-engine.cc @@ -666,7 +666,8 @@ DirectHandle WasmEngine::FinalizeTranslatedAsmJs( MaybeDirectHandle WasmEngine::SyncCompile( Isolate* isolate, WasmEnabledFeatures enabled_features, CompileTimeImports compile_imports, ErrorThrower* thrower, - base::OwnedVector bytes) { + base::OwnedVector bytes, + base::Vector source_url) { int compilation_id = next_compilation_id_.fetch_add(1); TRACE_EVENT1("v8.wasm", "wasm.SyncCompile", "id", compilation_id); v8::metrics::Recorder::ContextId context_id = @@ -718,9 +719,8 @@ MaybeDirectHandle WasmEngine::SyncCompile( } #endif - constexpr base::Vector kNoSourceUrl; DirectHandle