Commit 17e0ac9a authored by Manos Koukoutos's avatar Manos Koukoutos Committed by V8 LUCI CQ

[wasm] Do not expose ModuleResult in wasm-engine

Instead, pass a return parameter to store the error message, if any.

Change-Id: Ie71910149271a4268799ee41a8873df51812c505
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3218989
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77375}
parent d9c51dae
......@@ -461,23 +461,23 @@ WasmEngine::~WasmEngine() {
}
bool WasmEngine::SyncValidate(Isolate* isolate, const WasmFeatures& enabled,
const ModuleWireBytes& bytes) {
return SyncValidateResult(isolate, enabled, bytes).ok();
}
ModuleResult WasmEngine::SyncValidateResult(Isolate* isolate,
const WasmFeatures& enabled,
const ModuleWireBytes& bytes) {
const ModuleWireBytes& bytes,
std::string* error_message) {
TRACE_EVENT0("v8.wasm", "wasm.SyncValidate");
// TODO(titzer): remove dependency on the isolate.
if (bytes.start() == nullptr || bytes.length() == 0) {
return ModuleResult(WasmError(0, "empty module wire bytes"));
if (error_message) *error_message = "empty module wire bytes";
return false;
}
return DecodeWasmModule(
auto result = DecodeWasmModule(
enabled, bytes.start(), bytes.end(), true, kWasmOrigin,
isolate->counters(), isolate->metrics_recorder(),
isolate->GetOrRegisterRecorderContextId(isolate->native_context()),
DecodingMethod::kSync, allocator());
if (result.failed() && error_message) {
*error_message = result.error().message();
}
return result.ok();
}
MaybeHandle<AsmWasmData> WasmEngine::SyncCompileTranslatedAsmJs(
......
......@@ -45,11 +45,8 @@ class GdbServer;
class AsyncCompileJob;
class ErrorThrower;
struct ModuleWireBytes;
template <typename T>
class Result;
class StreamingDecoder;
class WasmFeatures;
using ModuleResult = Result<std::shared_ptr<WasmModule>>;
class V8_EXPORT_PRIVATE CompilationResultResolver {
public:
......@@ -151,13 +148,11 @@ class V8_EXPORT_PRIVATE WasmEngine {
~WasmEngine();
// Synchronously validates the given bytes that represent an encoded Wasm
// module.
// module. If validation fails and {error_msg} is present, it is set to the
// validation error.
bool SyncValidate(Isolate* isolate, const WasmFeatures& enabled,
const ModuleWireBytes& bytes);
// Synchronously validates the given bytes that represent an encoded Wasm
// module.
ModuleResult SyncValidateResult(Isolate* isolate, const WasmFeatures& enabled,
const ModuleWireBytes& bytes);
const ModuleWireBytes& bytes,
std::string* error_message = nullptr);
// Synchronously compiles the given bytes that represent a translated
// asm.js module.
......
......@@ -627,14 +627,14 @@ void WasmExecutionFuzzer::FuzzWasmModule(base::Vector<const uint8_t> data,
GenerateTestCase(i_isolate, wire_bytes, compiles);
}
ModuleResult result = GetWasmEngine()->SyncValidateResult(
i_isolate, enabled_features, wire_bytes);
std::string error_message;
bool result = GetWasmEngine()->SyncValidate(i_isolate, enabled_features,
wire_bytes, &error_message);
CHECK_EQ(compiles, result.ok());
CHECK_EQ(compiles, result);
CHECK_WITH_MSG(
!require_valid || result.ok(),
("Generated module should validate, but got: " + result.error().message())
.c_str());
!require_valid || result,
("Generated module should validate, but got: " + error_message).c_str());
if (!compiles) return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment