v8/test/wasm-api-tests/startup-errors.cc
Dan Elphick 7f5383e8ad [base] Move utils/vector.h to base/vector.h
The adding of base:: was mostly prepared using git grep and sed:
git grep -l <pattern> | grep -v base/vector.h | \
  xargs sed -i 's/\b<pattern>\b/base::<pattern>/
with lots of manual clean-ups due to the resulting
v8::internal::base::Vectors.

#includes were fixed using:
git grep -l "src/utils/vector.h" | \
  axargs sed -i 's!src/utils/vector.h!src/base/vector.h!'

Bug: v8:11879
Change-Id: I3e6d622987fee4478089c40539724c19735bd625
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2968412
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75243}
2021-06-18 13:33:13 +00:00

63 lines
2.2 KiB
C++

// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "test/wasm-api-tests/wasm-api-test.h"
namespace v8 {
namespace internal {
namespace wasm {
namespace {
own<Trap> DummyCallback(const Val args[], Val results[]) { return nullptr; }
} // namespace
TEST_F(WasmCapiTest, StartupErrors) {
FunctionSig sig(0, 0, nullptr);
byte code[] = {WASM_UNREACHABLE};
WasmFunctionBuilder* start_func = builder()->AddFunction(&sig);
start_func->EmitCode(code, static_cast<uint32_t>(sizeof(code)));
start_func->Emit(kExprEnd);
builder()->MarkStartFunction(start_func);
builder()->AddImport(base::CStrVector("dummy"), &sig);
Compile();
own<Trap> trap;
// Try to make an Instance with non-matching imports.
own<Func> bad_func = Func::make(store(), cpp_i_i_sig(), DummyCallback);
Extern* bad_imports[] = {bad_func.get()};
own<Instance> instance =
Instance::make(store(), module(), bad_imports, &trap);
EXPECT_EQ(nullptr, instance);
EXPECT_NE(nullptr, trap);
EXPECT_STREQ(
"Uncaught LinkError: instantiation: Import #0 module=\"\" "
"function=\"dummy\" "
"error: imported function does not match the expected type",
trap->message().get());
EXPECT_EQ(nullptr, trap->origin());
// Don't crash if there is no {trap}.
instance = Instance::make(store(), module(), bad_imports, nullptr);
EXPECT_EQ(nullptr, instance);
// Try to make an instance with a {start} function that traps.
own<FuncType> good_sig =
FuncType::make(ownvec<ValType>::make(), ownvec<ValType>::make());
own<Func> good_func = Func::make(store(), good_sig.get(), DummyCallback);
Extern* good_imports[] = {good_func.get()};
instance = Instance::make(store(), module(), good_imports, &trap);
EXPECT_EQ(nullptr, instance);
EXPECT_NE(nullptr, trap);
EXPECT_STREQ("Uncaught RuntimeError: unreachable", trap->message().get());
EXPECT_NE(nullptr, trap->origin());
// Don't crash if there is no {trap}.
instance = Instance::make(store(), module(), good_imports, nullptr);
EXPECT_EQ(nullptr, instance);
}
} // namespace wasm
} // namespace internal
} // namespace v8