Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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 #####

Expand Down
45 changes: 42 additions & 3 deletions deps/v8/include/v8-wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <functional>
#include <memory>
#include <string>
#include <string_view>
#include <variant>

#include "v8-internal.h" // NOLINT(build/include_directory)
Expand Down Expand Up @@ -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<WasmModuleObject> Compile(
Isolate* isolate, MemorySpan<const uint8_t> wire_bytes);

/**
* Compile a Wasm module from the provided uncompiled bytes, applying the
* given compile options.
*/
static MaybeLocal<WasmModuleObject> Compile(
Isolate* isolate, MemorySpan<const uint8_t> wire_bytes,
const CompileOptions& options);

V8_INLINE static WasmModuleObject* Cast(Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
Expand Down Expand Up @@ -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();

Expand Down
15 changes: 12 additions & 3 deletions deps/v8/src/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8853,7 +8853,15 @@ MaybeLocal<WasmModuleObject> WasmModuleObject::FromCompiledModule(

MaybeLocal<WasmModuleObject> WasmModuleObject::Compile(
Isolate* v8_isolate, MemorySpan<const uint8_t> wire_bytes) {
return Compile(v8_isolate, wire_bytes, CompileOptions{});
}

MaybeLocal<WasmModuleObject> WasmModuleObject::Compile(
Isolate* v8_isolate, MemorySpan<const uint8_t> wire_bytes,
const CompileOptions& options) {
#if V8_ENABLE_WEBASSEMBLY
i::wasm::CompileTimeImports compile_imports =
i::wasm::CompileTimeImportsFromOptions(options);
base::OwnedVector<const uint8_t> bytes = base::OwnedCopyOf(wire_bytes);
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
// We don't check for `IsWasmCodegenAllowed` here, because this function is
Expand All @@ -8864,10 +8872,11 @@ MaybeLocal<WasmModuleObject> 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<const char>(options.source_url.data(),
options.source_url.size()));
}
CHECK_EQ(maybe_compiled.is_null(), i_isolate->has_exception());
if (maybe_compiled.is_null()) return {};
Expand Down
6 changes: 3 additions & 3 deletions deps/v8/src/wasm/wasm-engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,8 @@ DirectHandle<WasmModuleObject> WasmEngine::FinalizeTranslatedAsmJs(
MaybeDirectHandle<WasmModuleObject> WasmEngine::SyncCompile(
Isolate* isolate, WasmEnabledFeatures enabled_features,
CompileTimeImports compile_imports, ErrorThrower* thrower,
base::OwnedVector<const uint8_t> bytes) {
base::OwnedVector<const uint8_t> bytes,
base::Vector<const char> 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 =
Expand Down Expand Up @@ -718,9 +719,8 @@ MaybeDirectHandle<WasmModuleObject> WasmEngine::SyncCompile(
}
#endif

constexpr base::Vector<const char> kNoSourceUrl;
DirectHandle<Script> script =
GetOrCreateScript(isolate, native_module, kNoSourceUrl);
GetOrCreateScript(isolate, native_module, source_url);

native_module->LogWasmCodes(isolate, *script);

Expand Down
3 changes: 2 additions & 1 deletion deps/v8/src/wasm/wasm-engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ class V8_EXPORT_PRIVATE WasmEngine {
MaybeDirectHandle<WasmModuleObject> SyncCompile(
Isolate* isolate, WasmEnabledFeatures enabled,
CompileTimeImports compile_imports, ErrorThrower* thrower,
base::OwnedVector<const uint8_t> bytes);
base::OwnedVector<const uint8_t> bytes,
base::Vector<const char> source_url = {});

// Synchronously instantiate the given Wasm module with the given imports.
// If the module represents an asm.js module, then the supplied {memory}
Expand Down
34 changes: 30 additions & 4 deletions deps/v8/src/wasm/wasm-js.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,16 @@ class WasmModuleCompilation::Impl {
const std::shared_ptr<i::wasm::StreamingDecoder> streaming_decoder_;
};

// TODO(clemensb): Pass enabled features and compile time imports.
WasmModuleCompilation::WasmModuleCompilation()
: impl_(std::make_unique<Impl>(WasmEnabledFeatures::FromFlags(),
CompileTimeImports{})) {
// TODO(clemensb): Pass enabled features.
WasmModuleCompilation::WasmModuleCompilation(const CompileOptions& options)
: impl_(std::make_unique<Impl>(
WasmEnabledFeatures::FromFlags(),
i::wasm::CompileTimeImportsFromOptions(options))) {
TRACE_EVENT0("v8.wasm", "wasm.ModuleCompilation");
if (!options.source_url.empty()) {
impl_->SetUrl(
base::VectorOf(options.source_url.data(), options.source_url.size()));
}
}

WasmModuleCompilation::~WasmModuleCompilation() = default;
Expand Down Expand Up @@ -3959,6 +3964,27 @@ void WasmJs::InstallResizableBufferIntegration(
wasm::WebAssemblyMemoryToResizableBuffer, 0);
}

namespace wasm {
CompileTimeImports CompileTimeImportsFromOptions(
const v8::WasmModuleObject::CompileOptions& options) {
CompileTimeImports result;
using Builtins = v8::WasmModuleObject::CompileOptions::Builtins;
if (options.builtins & Builtins::kJsString) {
result.Add(CompileTimeImport::kJsString);
}
if (options.imported_string_constants_module != nullptr) {
result.constants_module() = options.imported_string_constants_module;
result.Add(CompileTimeImport::kStringConstants);
}
// Mirror the JS `WebAssembly.Module` constructor, which disables denormal
// floats at compile time when the host FPU flushes them.
if (base::FPU::GetFlushDenormals()) {
result.Add(CompileTimeImport::kDisableDenormalFloats);
}
return result;
}
} // namespace wasm

// static
CompileTimeImports WasmJs::CompileTimeImportsFromArgument(
DirectHandle<Object> arg, Isolate* isolate,
Expand Down
7 changes: 6 additions & 1 deletion deps/v8/src/wasm/wasm-js.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

#include <memory>

#include "include/v8-wasm.h"
#include "src/common/globals.h"
#include "src/wasm/wasm-features.h"

namespace v8 {
class Value;
template <typename T>
class FunctionCallbackInfo;
class WasmStreaming;
} // namespace v8

namespace v8::internal {
Expand All @@ -30,6 +30,11 @@ class StreamingDecoder;
V8_EXPORT_PRIVATE std::unique_ptr<WasmStreaming> StartStreamingForTesting(
Isolate*, std::shared_ptr<wasm::CompilationResultResolver>);

// Convert compile options from the public API into compile-time imports,
// including the host-FPU denormal handling applied to all compilations.
V8_EXPORT_PRIVATE CompileTimeImports
CompileTimeImportsFromOptions(const v8::WasmModuleObject::CompileOptions&);

#define WASM_JS_EXTERNAL_REFERENCE_LIST(V) \
V(WebAssemblyCompile) \
V(WebAssemblyException) \
Expand Down
Loading
Loading