Commit cf984a49 authored by Frederik Gossen's avatar Frederik Gossen Committed by Commit Bot

[wasm] Fix Streaming API Error Messages

Fix function name in error messages thrown by the streaming API. The API
functions {WebAssembly.compileStreaming} and
{WebAssembly.instantiateStreaming} are now mentioned where needed.

Bug: v8:9184
Change-Id: I70b27efe1c027d119fa7b5b9be27988a92304682
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1588468Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Frederik Gossen <frgossen@google.com>
Cr-Commit-Position: refs/heads/master@{#61202}
parent 914d223d
......@@ -1114,8 +1114,10 @@ std::shared_ptr<NativeModule> CompileToNativeModule(
AsyncCompileJob::AsyncCompileJob(
Isolate* isolate, const WasmFeatures& enabled,
std::unique_ptr<byte[]> bytes_copy, size_t length, Handle<Context> context,
const char* api_method_name,
std::shared_ptr<CompilationResultResolver> resolver)
: isolate_(isolate),
api_method_name_(api_method_name),
enabled_features_(enabled),
wasm_lazy_compilation_(FLAG_wasm_lazy_compilation),
bytes_copy_(std::move(bytes_copy)),
......@@ -1282,7 +1284,7 @@ void AsyncCompileJob::FinishCompile() {
}
void AsyncCompileJob::DecodeFailed(const WasmError& error) {
ErrorThrower thrower(isolate_, "WebAssembly.compile()");
ErrorThrower thrower(isolate_, api_method_name_);
thrower.CompileFailed(error);
// {job} keeps the {this} pointer alive.
std::shared_ptr<AsyncCompileJob> job =
......@@ -1291,7 +1293,7 @@ void AsyncCompileJob::DecodeFailed(const WasmError& error) {
}
void AsyncCompileJob::AsyncCompileFailed() {
ErrorThrower thrower(isolate_, "WebAssembly.compile()");
ErrorThrower thrower(isolate_, api_method_name_);
DCHECK_EQ(native_module_->module()->origin, kWasmOrigin);
const bool lazy_module = wasm_lazy_compilation_;
ValidateSequentially(native_module_->module(), native_module_.get(),
......
......@@ -66,7 +66,7 @@ class AsyncCompileJob {
public:
AsyncCompileJob(Isolate* isolate, const WasmFeatures& enabled_features,
std::unique_ptr<byte[]> bytes_copy, size_t length,
Handle<Context> context,
Handle<Context> context, const char* api_method_name,
std::shared_ptr<CompilationResultResolver> resolver);
~AsyncCompileJob();
......@@ -148,6 +148,7 @@ class AsyncCompileJob {
void NextStep(Args&&... args);
Isolate* const isolate_;
const char* const api_method_name_;
const WasmFeatures enabled_features_;
const bool wasm_lazy_compilation_;
// Copy of the module wire bytes, moved into the {native_module_} on its
......
......@@ -330,9 +330,10 @@ void WasmEngine::AsyncCompile(
Isolate* isolate, const WasmFeatures& enabled,
std::shared_ptr<CompilationResultResolver> resolver,
const ModuleWireBytes& bytes, bool is_shared) {
const char* const kAPIMethodName = "WebAssembly.compile()";
if (!FLAG_wasm_async_compilation) {
// Asynchronous compilation disabled; fall back on synchronous compilation.
ErrorThrower thrower(isolate, "WasmCompile");
ErrorThrower thrower(isolate, kAPIMethodName);
MaybeHandle<WasmModuleObject> module_object;
if (is_shared) {
// Make a copy of the wire bytes to avoid concurrent modification.
......@@ -357,7 +358,7 @@ void WasmEngine::AsyncCompile(
std::shared_ptr<StreamingDecoder> streaming_decoder =
StartStreamingCompilation(isolate, enabled,
handle(isolate->context(), isolate),
std::move(resolver));
kAPIMethodName, std::move(resolver));
streaming_decoder->OnBytesReceived(bytes.module_bytes());
streaming_decoder->Finish();
return;
......@@ -369,16 +370,17 @@ void WasmEngine::AsyncCompile(
AsyncCompileJob* job = CreateAsyncCompileJob(
isolate, enabled, std::move(copy), bytes.length(),
handle(isolate->context(), isolate), std::move(resolver));
handle(isolate->context(), isolate), kAPIMethodName, std::move(resolver));
job->Start();
}
std::shared_ptr<StreamingDecoder> WasmEngine::StartStreamingCompilation(
Isolate* isolate, const WasmFeatures& enabled, Handle<Context> context,
const char* api_method_name,
std::shared_ptr<CompilationResultResolver> resolver) {
AsyncCompileJob* job =
CreateAsyncCompileJob(isolate, enabled, std::unique_ptr<byte[]>(nullptr),
0, context, std::move(resolver));
0, context, api_method_name, std::move(resolver));
return job->CreateStreamingDecoder();
}
......@@ -444,10 +446,11 @@ CodeTracer* WasmEngine::GetCodeTracer() {
AsyncCompileJob* WasmEngine::CreateAsyncCompileJob(
Isolate* isolate, const WasmFeatures& enabled,
std::unique_ptr<byte[]> bytes_copy, size_t length, Handle<Context> context,
const char* api_method_name,
std::shared_ptr<CompilationResultResolver> resolver) {
AsyncCompileJob* job =
new AsyncCompileJob(isolate, enabled, std::move(bytes_copy), length,
context, std::move(resolver));
context, api_method_name, std::move(resolver));
// Pass ownership to the unique_ptr in {async_compile_jobs_}.
base::MutexGuard guard(&mutex_);
async_compile_jobs_[job] = std::unique_ptr<AsyncCompileJob>(job);
......
......@@ -98,6 +98,7 @@ class V8_EXPORT_PRIVATE WasmEngine {
std::shared_ptr<StreamingDecoder> StartStreamingCompilation(
Isolate* isolate, const WasmFeatures& enabled, Handle<Context> context,
const char* api_method_name,
std::shared_ptr<CompilationResultResolver> resolver);
// Compiles the function with the given index at a specific compilation tier.
......@@ -214,7 +215,7 @@ class V8_EXPORT_PRIVATE WasmEngine {
AsyncCompileJob* CreateAsyncCompileJob(
Isolate* isolate, const WasmFeatures& enabled,
std::unique_ptr<byte[]> bytes_copy, size_t length,
Handle<Context> context,
Handle<Context> context, const char* api_method_name,
std::shared_ptr<CompilationResultResolver> resolver);
void TriggerGC();
......
......@@ -36,14 +36,14 @@ namespace v8 {
class WasmStreaming::WasmStreamingImpl {
public:
WasmStreamingImpl(
Isolate* isolate,
Isolate* isolate, const char* api_method_name,
std::shared_ptr<internal::wasm::CompilationResultResolver> resolver)
: isolate_(isolate), resolver_(std::move(resolver)) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate_);
auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
streaming_decoder_ = i_isolate->wasm_engine()->StartStreamingCompilation(
i_isolate, enabled_features, handle(i_isolate->context(), i_isolate),
resolver_);
api_method_name, resolver_);
}
void OnBytesReceived(const uint8_t* bytes, size_t size) {
......@@ -569,7 +569,8 @@ void WebAssemblyCompileStreaming(
v8::Isolate* isolate = args.GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
HandleScope scope(isolate);
ScheduledErrorThrower thrower(i_isolate, "WebAssembly.compile()");
const char* const kAPIMethodName = "WebAssembly.compileStreaming()";
ScheduledErrorThrower thrower(i_isolate, kAPIMethodName);
Local<Context> context = isolate->GetCurrentContext();
// Create and assign the return value of this function.
......@@ -593,8 +594,8 @@ void WebAssemblyCompileStreaming(
i::Handle<i::Managed<WasmStreaming>> data =
i::Managed<WasmStreaming>::Allocate(
i_isolate, 0,
base::make_unique<WasmStreaming::WasmStreamingImpl>(isolate,
resolver));
base::make_unique<WasmStreaming::WasmStreamingImpl>(
isolate, kAPIMethodName, resolver));
DCHECK_NOT_NULL(i_isolate->wasm_streaming_callback());
ASSIGN(
......@@ -828,8 +829,8 @@ void WebAssemblyInstantiateStreaming(
HandleScope scope(isolate);
Local<Context> context = isolate->GetCurrentContext();
ScheduledErrorThrower thrower(i_isolate,
"WebAssembly.instantiateStreaming()");
const char* const kAPIMethodName = "WebAssembly.instantiateStreaming()";
ScheduledErrorThrower thrower(i_isolate, kAPIMethodName);
// Create and assign the return value of this function.
ASSIGN(Promise::Resolver, result_resolver, Promise::Resolver::New(context));
......@@ -873,7 +874,7 @@ void WebAssemblyInstantiateStreaming(
i::Managed<WasmStreaming>::Allocate(
i_isolate, 0,
base::make_unique<WasmStreaming::WasmStreamingImpl>(
isolate, compilation_resolver));
isolate, kAPIMethodName, compilation_resolver));
DCHECK_NOT_NULL(i_isolate->wasm_streaming_callback());
ASSIGN(
......
......@@ -132,6 +132,7 @@ class StreamTester {
stream_ = i_isolate->wasm_engine()->StartStreamingCompilation(
i_isolate, kAllWasmFeatures, v8::Utils::OpenHandle(*context),
"WebAssembly.compileStreaming()",
std::make_shared<TestResolver>(&state_, &error_message_,
&native_module_));
}
......@@ -1211,8 +1212,8 @@ STREAM_TEST(TestCompileErrorFunctionName) {
CHECK(tester.IsPromiseRejected());
CHECK_EQ(
"CompileError: WebAssembly.compile(): Compiling function #0:\"f\" "
"failed: function body must end with \"end\" opcode @+25",
"CompileError: WebAssembly.compileStreaming(): Compiling function "
"#0:\"f\" failed: function body must end with \"end\" opcode @+25",
tester.error_message());
}
}
......
......@@ -13,7 +13,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
let bytes = builder.toBuffer();
assertPromiseResult(WebAssembly.compileStreaming(Promise.resolve(bytes))
.then(assertUnreachable,
error => assertEquals("WebAssembly.compile(): function body must " +
"end with \"end\" opcode @+26",
error => assertEquals("WebAssembly.compileStreaming(): function " +
"body must end with \"end\" opcode @+26",
error.message)));
})();
......@@ -48,8 +48,9 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes),
{mod: {pow: Math.pow}})
.then(assertUnreachable,
error => assertEquals("WebAssembly.compile(): Invalid compilation " +
"hint 0x2d (forbidden downgrade) @+78",
error => assertEquals("WebAssembly.instantiateStreaming(): Invalid " +
"compilation hint 0x2d (forbidden downgrade) " +
"@+78",
error.message)));
})();
......@@ -73,8 +74,10 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes),
{mod: {pow: Math.pow}})
.then(assertUnreachable,
error => assertEquals("WebAssembly.compile(): call[1] expected " +
"type f32, found get_local of type i32 @+94", error.message)));
error => assertEquals("WebAssembly.instantiateStreaming(): call[1] " +
"expected type f32, found get_local of type " +
"i32 @+94",
error.message)));
})();
(function testInstantiateStreamingEmptyModule() {
......
......@@ -24,8 +24,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
builder.addFunction("main", kSig_i_i)
.addBody([kExprGetLocal, 0])
.exportAs("main");
let bytes = builder.toBuffer();
assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes)).then(
let bytes = builder.toBuffer();
assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes)).then(
({module, instance}) => assertEquals(5, instance.exports.main(5))));
})();
......@@ -42,3 +42,26 @@ assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes)).the
assertUnreachable,
error => assertEquals(error, "myError"));
})();
(function TestStreamingErrorMessage() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_i)
.addBody([kExprGetLocal, 0,
kExprGetLocal, 0,
kExprF32Mul])
.exportAs("main");
let bytes = builder.toBuffer();
assertPromiseResult(WebAssembly.compileStreaming(Promise.resolve(bytes)),
assertUnreachable,
error => assertEquals("WebAssembly.compileStreaming(): Compiling " +
"function #0:\"main\" failed: f32.mul[1] expected " +
"type f32, found get_local of type i32 @+37",
error.message));
assertPromiseResult(WebAssembly.instantiateStreaming(Promise.resolve(bytes)),
assertUnreachable,
error => assertEquals("WebAssembly.instantiateStreaming(): Compiling " +
"function #0:\"main\" failed: f32.mul[1] expected " +
"type f32, found get_local of type i32 @+37",
error.message));
})();
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