v8/test/wasm-api-tests/regressions.cc
Hisham Muhammad 0f748aac3e [wasm][c-api] Add handle scope to fix wasm_module_validate
This adds a handle scope to Module::validate in C API
so that the wasm_module_validate can be usable from C.

Without the added handle scope, attempting to call
wasm_module_validate function from C code fails with:

    #
    # Fatal error in v8::HandleScope::CreateHandle()
    # Cannot create a handle without a HandleScope
    #

Bug: v8:12941
Change-Id: I2b4d5dccdaed9501f31447158ebf8e7906a1f8f0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3692020
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81048}
2022-06-09 16:46:23 +00:00

31 lines
850 B
C++

// Copyright 2022 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 {
TEST_F(WasmCapiTest, Regressions) {
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);
// Ensure we can validate.
bool valid = Validate();
EXPECT_EQ(valid, true);
// Ensure we can compile after validating.
Compile();
}
} // namespace wasm
} // namespace internal
} // namespace v8