v8/test/wasm-api-tests/serialize.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

50 lines
1.4 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 {
bool g_callback_called;
own<Trap> Callback(const Val args[], Val results[]) {
g_callback_called = true;
return nullptr;
}
} // namespace
TEST_F(WasmCapiTest, Serialize) {
FunctionSig sig(0, 0, nullptr);
uint32_t callback_index =
builder()->AddImport(base::CStrVector("callback"), &sig);
byte code[] = {WASM_CALL_FUNCTION0(callback_index)};
AddExportedFunction(base::CStrVector("run"), code, sizeof(code), &sig);
Compile();
vec<byte_t> serialized = module()->serialize();
EXPECT_TRUE(serialized); // Serialization succeeded.
own<Module> deserialized = Module::deserialize(store(), serialized);
own<FuncType> callback_type =
FuncType::make(ownvec<ValType>::make(), ownvec<ValType>::make());
own<Func> callback = Func::make(store(), callback_type.get(), Callback);
Extern* imports[] = {callback.get()};
own<Instance> instance = Instance::make(store(), deserialized.get(), imports);
ownvec<Extern> exports = instance->exports();
Func* run = exports[0]->func();
g_callback_called = false;
run->call();
EXPECT_TRUE(g_callback_called);
}
} // namespace wasm
} // namespace internal
} // namespace v8