[wasm][test][cleanup] Use more base::Vector

The {CallWasmFunctionForTesting} function currently receives arguments
as a pair of {int} and {Handle<Object>*}. Encapsulating this as a
{base::Vector} makes the relation more clear and improves readability at
call sites.

R=ahaas@chromium.org

Change-Id: I884f8d0dc1c33389b60cc53750f2e3bfcaf644a5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4218353
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#85638}
This commit is contained in:
Clemens Backes 2023-02-02 14:25:58 +01:00 committed by V8 LUCI CQ
parent 2c9f7ac40d
commit d3a3d73384
7 changed files with 30 additions and 32 deletions

View File

@ -114,8 +114,7 @@ TEST(Run_WasmModule_Buffer_Externalized_GrowMem) {
handle(memory_object->array_buffer(), isolate));
// Grow using an internal Wasm bytecode.
result = testing::CallWasmFunctionForTesting(isolate, instance, "main", 0,
nullptr);
result = testing::CallWasmFunctionForTesting(isolate, instance, "main", {});
CHECK_EQ(26, result);
CHECK(external2.buffer_->was_detached()); // growing always detaches
CHECK_EQ(0, external2.buffer_->byte_length());

View File

@ -138,7 +138,7 @@ TEST(Run_WasmModule_CompilationHintsLazy) {
isolate, &thrower, module.ToHandleChecked(), {}, {});
CHECK(!instance.is_null());
int32_t result = testing::CallWasmFunctionForTesting(
isolate, instance.ToHandleChecked(), "main", 0, nullptr);
isolate, instance.ToHandleChecked(), "main", {});
CHECK_EQ(kReturnValue, result);
// Lazy function was invoked and therefore compiled.
@ -578,7 +578,7 @@ TEST(TestInterruptLoop) {
InterruptThread thread(isolate, memory_array);
CHECK(thread.Start());
testing::CallWasmFunctionForTesting(isolate, instance, "main", 0, nullptr);
testing::CallWasmFunctionForTesting(isolate, instance, "main", {});
Address address = reinterpret_cast<Address>(
&memory_array[InterruptThread::interrupt_location_]);
CHECK_EQ(InterruptThread::interrupt_value_,
@ -658,16 +658,17 @@ TEST(Run_WasmModule_GrowMemOobFixedIndex) {
// Initial memory size is 16 pages, should trap till index > MemSize on
// consecutive GrowMem calls
for (uint32_t i = 1; i < 5; i++) {
Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(i), isolate)};
Handle<Object> params[1] = {handle(Smi::FromInt(i), isolate)};
v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
testing::CallWasmFunctionForTesting(isolate, instance, "main", 1, params);
testing::CallWasmFunctionForTesting(isolate, instance, "main",
base::ArrayVector(params));
CHECK(try_catch.HasCaught());
isolate->clear_pending_exception();
}
Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(1), isolate)};
int32_t result = testing::CallWasmFunctionForTesting(isolate, instance,
"main", 1, params);
Handle<Object> params[1] = {handle(Smi::FromInt(1), isolate)};
int32_t result = testing::CallWasmFunctionForTesting(
isolate, instance, "main", base::ArrayVector(params));
CHECK_EQ(0xACED, result);
}
Cleanup();
@ -708,23 +709,24 @@ TEST(Run_WasmModule_GrowMemOobVariableIndex) {
Handle<Object> params[1] = {
Handle<Object>(Smi::FromInt((16 + i) * kPageSize - 3), isolate)};
v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
testing::CallWasmFunctionForTesting(isolate, instance, "main", 1, params);
testing::CallWasmFunctionForTesting(isolate, instance, "main",
base::ArrayVector(params));
CHECK(try_catch.HasCaught());
isolate->clear_pending_exception();
}
for (int i = 1; i < 5; i++) {
Handle<Object> params[1] = {
Handle<Object>(Smi::FromInt((20 + i) * kPageSize - 4), isolate)};
int32_t result = testing::CallWasmFunctionForTesting(isolate, instance,
"main", 1, params);
handle(Smi::FromInt((20 + i) * kPageSize - 4), isolate)};
int32_t result = testing::CallWasmFunctionForTesting(
isolate, instance, "main", base::ArrayVector(params));
CHECK_EQ(0xACED, result);
}
v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
Handle<Object> params[1] = {
Handle<Object>(Smi::FromInt(25 * kPageSize), isolate)};
testing::CallWasmFunctionForTesting(isolate, instance, "main", 1, params);
Handle<Object> params[1] = {handle(Smi::FromInt(25 * kPageSize), isolate)};
testing::CallWasmFunctionForTesting(isolate, instance, "main",
base::ArrayVector(params));
CHECK(try_catch.HasCaught());
isolate->clear_pending_exception();
}

View File

@ -96,10 +96,10 @@ class WasmSerializationTest {
Handle<JSReceiver>::null(),
MaybeHandle<JSArrayBuffer>())
.ToHandleChecked();
Handle<Object> params[1] = {
Handle<Object>(Smi::FromInt(41), CcTest::i_isolate())};
Handle<Object> params[1] = {handle(Smi::FromInt(41), CcTest::i_isolate())};
int32_t result = testing::CallWasmFunctionForTesting(
CcTest::i_isolate(), instance, kFunctionName, 1, params);
CcTest::i_isolate(), instance, kFunctionName,
base::ArrayVector(params));
CHECK_EQ(42, result);
}
@ -171,7 +171,7 @@ class WasmSerializationTest {
CHECK_EQ(0, data_.size);
while (data_.size == 0) {
testing::CallWasmFunctionForTesting(serialization_isolate, instance,
kFunctionName, 0, nullptr);
kFunctionName, {});
data_ = compiled_module.Serialize();
}
CHECK_LT(0, data_.size);

View File

@ -73,8 +73,7 @@ class SharedEngineIsolate {
}
int32_t Run(Handle<WasmInstanceObject> instance) {
return testing::CallWasmFunctionForTesting(isolate(), instance, "main", 0,
nullptr);
return testing::CallWasmFunctionForTesting(isolate(), instance, "main", {});
}
private:

View File

@ -130,7 +130,7 @@ int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start,
return -1;
}
return CallWasmFunctionForTesting(isolate, instance.ToHandleChecked(), "main",
0, nullptr);
{});
}
WasmInterpretationResult InterpretWasmModule(
@ -218,8 +218,8 @@ MaybeHandle<WasmExportedFunction> GetExportedFunction(
int32_t CallWasmFunctionForTesting(Isolate* isolate,
Handle<WasmInstanceObject> instance,
const char* name, int argc,
Handle<Object> argv[],
const char* name,
base::Vector<Handle<Object>> args,
std::unique_ptr<const char[]>* exception) {
DCHECK_IMPLIES(exception != nullptr, *exception == nullptr);
MaybeHandle<WasmExportedFunction> maybe_export =
@ -231,8 +231,8 @@ int32_t CallWasmFunctionForTesting(Isolate* isolate,
// Call the JS function.
Handle<Object> undefined = isolate->factory()->undefined_value();
MaybeHandle<Object> retval =
Execution::Call(isolate, main_export, undefined, argc, argv);
MaybeHandle<Object> retval = Execution::Call(isolate, main_export, undefined,
args.length(), args.begin());
// The result should be a number.
if (retval.is_null()) {

View File

@ -34,7 +34,7 @@ MaybeHandle<WasmExportedFunction> GetExportedFunction(
// set and an exception occurs).
int32_t CallWasmFunctionForTesting(
Isolate* isolate, Handle<WasmInstanceObject> instance, const char* name,
int argc, Handle<Object> argv[],
base::Vector<Handle<Object>> args,
std::unique_ptr<const char[]>* exception = nullptr);
// Decode, verify, and run the function labeled "main" in the

View File

@ -124,8 +124,7 @@ void ExecuteAgainstReference(Isolate* isolate,
testing::MakeDefaultArguments(isolate, main_function->sig());
std::unique_ptr<const char[]> exception_ref;
int32_t result_ref = testing::CallWasmFunctionForTesting(
isolate, instance_ref, "main", static_cast<int>(compiled_args.size()),
compiled_args.begin(), &exception_ref);
isolate, instance_ref, "main", compiled_args.as_vector(), &exception_ref);
// Reached max steps, do not try to execute the test module as it might
// never terminate.
if (max_steps < 0) return;
@ -157,8 +156,7 @@ void ExecuteAgainstReference(Isolate* isolate,
std::unique_ptr<const char[]> exception;
int32_t result = testing::CallWasmFunctionForTesting(
isolate, instance, "main", static_cast<int>(compiled_args.size()),
compiled_args.begin(), &exception);
isolate, instance, "main", compiled_args.as_vector(), &exception);
if ((exception_ref != nullptr) != (exception != nullptr)) {
FATAL("Exception mispatch! Expected: <%s>; got: <%s>",