Commit f87dfb81 authored by mtrofin's avatar mtrofin Committed by Commit bot

[wasm] C++ style: ErrorThrower& -> ErrorThrower*

All parameters passed by reference must be labeled const.
If the object is mutable, then we pass by pointer.

BUG=

Review-Url: https://codereview.chromium.org/2336233006
Cr-Commit-Position: refs/heads/master@{#39451}
parent 8439401d
......@@ -484,24 +484,25 @@ WasmModule::WasmModule(byte* module_start)
pending_tasks(new base::Semaphore(0)) {}
static MaybeHandle<JSFunction> ReportFFIError(
ErrorThrower& thrower, const char* error, uint32_t index,
ErrorThrower* thrower, const char* error, uint32_t index,
Handle<String> module_name, MaybeHandle<String> function_name) {
Handle<String> function_name_handle;
if (function_name.ToHandle(&function_name_handle)) {
thrower.Error("Import #%d module=\"%.*s\" function=\"%.*s\" error: %s",
index, module_name->length(), module_name->ToCString().get(),
function_name_handle->length(),
function_name_handle->ToCString().get(), error);
thrower->Error("Import #%d module=\"%.*s\" function=\"%.*s\" error: %s",
index, module_name->length(), module_name->ToCString().get(),
function_name_handle->length(),
function_name_handle->ToCString().get(), error);
} else {
thrower.Error("Import #%d module=\"%.*s\" error: %s", index,
module_name->length(), module_name->ToCString().get(), error);
thrower->Error("Import #%d module=\"%.*s\" error: %s", index,
module_name->length(), module_name->ToCString().get(),
error);
}
thrower.Error("Import ");
thrower->Error("Import ");
return MaybeHandle<JSFunction>();
}
static MaybeHandle<JSReceiver> LookupFunction(
ErrorThrower& thrower, Factory* factory, Handle<JSReceiver> ffi,
ErrorThrower* thrower, Factory* factory, Handle<JSReceiver> ffi,
uint32_t index, Handle<String> module_name,
MaybeHandle<String> function_name) {
if (ffi.is_null()) {
......@@ -702,7 +703,7 @@ bool CompileWrappersToImportedFunctions(Isolate* isolate,
CHECK(param_count >= 0);
MaybeHandle<JSReceiver> function = LookupFunction(
*thrower, isolate->factory(), ffi, index, module_name, function_name);
thrower, isolate->factory(), ffi, index, module_name, function_name);
if (function.is_null()) return false;
Handle<Code> code;
Handle<JSReceiver> target = function.ToHandleChecked();
......@@ -760,10 +761,10 @@ bool CompileWrappersToImportedFunctions(Isolate* isolate,
void InitializeParallelCompilation(
Isolate* isolate, const std::vector<WasmFunction>& functions,
std::vector<compiler::WasmCompilationUnit*>& compilation_units,
ModuleEnv& module_env, ErrorThrower& thrower) {
ModuleEnv& module_env, ErrorThrower* thrower) {
for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); ++i) {
compilation_units[i] = new compiler::WasmCompilationUnit(
&thrower, isolate, &module_env, &functions[i], i);
thrower, isolate, &module_env, &functions[i], i);
}
}
......@@ -852,7 +853,7 @@ void CompileInParallel(Isolate* isolate, const WasmModule* module,
// 1) The main thread allocates a compilation unit for each wasm function
// and stores them in the vector {compilation_units}.
InitializeParallelCompilation(isolate, module->functions, compilation_units,
*module_env, *thrower);
*module_env, thrower);
// Objects for the synchronization with the background threads.
base::Mutex result_mutex;
......
......@@ -251,7 +251,7 @@ TEST(Run_WasmModule_Serialization) {
.ToHandleChecked();
Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(41), isolate)};
int32_t result = testing::CallWasmFunctionForTesting(
isolate, instance, thrower, kFunctionName, 1, params,
isolate, instance, &thrower, kFunctionName, 1, params,
ModuleOrigin::kWasmOrigin);
CHECK(result == 42);
new_ctx->Exit();
......
......@@ -24,7 +24,7 @@ uint32_t GetMinModuleMemSize(const WasmModule* module) {
}
const WasmModule* DecodeWasmModuleForTesting(Isolate* isolate, Zone* zone,
ErrorThrower& thrower,
ErrorThrower* thrower,
const byte* module_start,
const byte* module_end,
ModuleOrigin origin) {
......@@ -36,33 +36,33 @@ const WasmModule* DecodeWasmModuleForTesting(Isolate* isolate, Zone* zone,
std::unique_ptr<const WasmModule> module(decoding_result.val);
if (decoding_result.failed()) {
// Module verification failed. throw.
thrower.Error("WASM.compileRun() failed: %s",
decoding_result.error_msg.get());
thrower->Error("WASM.compileRun() failed: %s",
decoding_result.error_msg.get());
return nullptr;
}
if (thrower.error()) return nullptr;
if (thrower->error()) return nullptr;
return module.release();
}
const Handle<JSObject> InstantiateModuleForTesting(Isolate* isolate,
ErrorThrower& thrower,
ErrorThrower* thrower,
const WasmModule* module) {
CHECK(module != nullptr);
if (module->import_table.size() > 0) {
thrower.Error("Not supported: module has imports.");
thrower->Error("Not supported: module has imports.");
}
if (module->export_table.size() == 0) {
thrower.Error("Not supported: module has no exports.");
thrower->Error("Not supported: module has no exports.");
}
if (thrower.error()) return Handle<JSObject>::null();
if (thrower->error()) return Handle<JSObject>::null();
// Although we decoded the module for some pre-validation, run the bytes
// again through the normal pipeline.
MaybeHandle<JSObject> module_object = CreateModuleObjectFromBytes(
isolate, module->module_start, module->module_end, &thrower,
isolate, module->module_start, module->module_end, thrower,
ModuleOrigin::kWasmOrigin);
if (module_object.is_null()) return Handle<JSObject>::null();
return WasmModule::Instantiate(isolate, module_object.ToHandleChecked(),
......@@ -78,22 +78,22 @@ int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start,
ErrorThrower thrower(isolate, "CompileAndRunWasmModule");
std::unique_ptr<const WasmModule> module(DecodeWasmModuleForTesting(
isolate, &zone, thrower, module_start, module_end, origin));
isolate, &zone, &thrower, module_start, module_end, origin));
if (module == nullptr) {
return -1;
}
Handle<JSObject> instance =
InstantiateModuleForTesting(isolate, thrower, module.get());
InstantiateModuleForTesting(isolate, &thrower, module.get());
if (instance.is_null()) {
return -1;
}
const char* f_name = origin == ModuleOrigin::kAsmJsOrigin ? "caller" : "main";
return CallWasmFunctionForTesting(isolate, instance, thrower, f_name, 0,
return CallWasmFunctionForTesting(isolate, instance, &thrower, f_name, 0,
nullptr, origin);
}
int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower& thrower,
int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower* thrower,
const WasmModule* module, int function_index,
WasmVal* args) {
CHECK(module != nullptr);
......@@ -102,13 +102,13 @@ int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower& thrower,
v8::internal::HandleScope scope(isolate);
if (module->import_table.size() > 0) {
thrower.Error("Not supported: module has imports.");
thrower->Error("Not supported: module has imports.");
}
if (module->export_table.size() == 0) {
thrower.Error("Not supported: module has no exports.");
thrower->Error("Not supported: module has no exports.");
}
if (thrower.error()) return -1;
if (thrower->error()) return -1;
ModuleEnv module_env;
module_env.module = module;
......@@ -121,7 +121,7 @@ int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower& thrower,
module->module_start + module->functions[i].code_end_offset};
DecodeResult result = VerifyWasmCode(isolate->allocator(), body);
if (result.failed()) {
thrower.Error("Function did not verify");
thrower->Error("Function did not verify");
return -1;
}
}
......@@ -152,13 +152,14 @@ int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower& thrower,
} else if (thread->state() == WasmInterpreter::TRAPPED) {
return 0xdeadbeef;
} else {
thrower.Error("Interpreter did not finish execution within its step bound");
thrower->Error(
"Interpreter did not finish execution within its step bound");
return -1;
}
}
int32_t CallWasmFunctionForTesting(Isolate* isolate, Handle<JSObject> instance,
ErrorThrower& thrower, const char* name,
ErrorThrower* thrower, const char* name,
int argc, Handle<Object> argv[],
ModuleOrigin origin) {
Handle<JSObject> exports_object;
......@@ -184,7 +185,7 @@ int32_t CallWasmFunctionForTesting(Isolate* isolate, Handle<JSObject> instance,
// The result should be a number.
if (retval.is_null()) {
thrower.Error("WASM.compileRun() failed: Invocation was null");
thrower->Error("WASM.compileRun() failed: Invocation was null");
return -1;
}
Handle<Object> result = retval.ToHandleChecked();
......@@ -194,7 +195,7 @@ int32_t CallWasmFunctionForTesting(Isolate* isolate, Handle<JSObject> instance,
if (result->IsHeapNumber()) {
return static_cast<int32_t>(HeapNumber::cast(*result)->value());
}
thrower.Error("WASM.compileRun() failed: Return value should be number");
thrower->Error("WASM.compileRun() failed: Return value should be number");
return -1;
}
......
......@@ -20,18 +20,18 @@ namespace testing {
// Decodes the given encoded module.
const WasmModule* DecodeWasmModuleForTesting(Isolate* isolate, Zone* zone,
ErrorThrower& thrower,
ErrorThrower* thrower,
const byte* module_start,
const byte* module_end,
ModuleOrigin origin);
// Instantiates a module without any imports and exports.
const Handle<JSObject> InstantiateModuleForTesting(Isolate* isolate,
ErrorThrower& thrower,
ErrorThrower* thrower,
const WasmModule* module);
int32_t CallWasmFunctionForTesting(Isolate* isolate, Handle<JSObject> instance,
ErrorThrower& thrower, const char* name,
ErrorThrower* thrower, const char* name,
int argc, Handle<Object> argv[],
ModuleOrigin origin);
......@@ -43,7 +43,7 @@ int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start,
// Interprets the given module, starting at the function specified by
// {function_index}. The return type of the function has to be int32. The module
// should not have any imports or exports
int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower& thrower,
int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower* thrower,
const WasmModule* module, int function_index,
WasmVal* args);
} // namespace testing
......
......@@ -56,7 +56,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
ErrorThrower interpreter_thrower(i_isolate, "Interpreter");
std::unique_ptr<const WasmModule> module(testing::DecodeWasmModuleForTesting(
i_isolate, &zone, interpreter_thrower, buffer.begin(), buffer.end(),
i_isolate, &zone, &interpreter_thrower, buffer.begin(), buffer.end(),
v8::internal::wasm::ModuleOrigin::kWasmOrigin));
if (module == nullptr) {
......@@ -66,12 +66,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
{
WasmVal args[] = {WasmVal(1), WasmVal(2), WasmVal(3)};
result_interpreted = testing::InterpretWasmModule(
i_isolate, interpreter_thrower, module.get(), 0, args);
i_isolate, &interpreter_thrower, module.get(), 0, args);
}
ErrorThrower compiler_thrower(i_isolate, "Compiler");
v8::internal::Handle<v8::internal::JSObject> instance =
testing::InstantiateModuleForTesting(i_isolate, compiler_thrower,
testing::InstantiateModuleForTesting(i_isolate, &compiler_thrower,
module.get());
if (!interpreter_thrower.error()) {
......@@ -86,7 +86,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
v8::internal::handle(v8::internal::Smi::FromInt(2), i_isolate),
v8::internal::handle(v8::internal::Smi::FromInt(3), i_isolate)};
result_compiled = testing::CallWasmFunctionForTesting(
i_isolate, instance, compiler_thrower, "main", arraysize(arguments),
i_isolate, instance, &compiler_thrower, "main", arraysize(arguments),
arguments, v8::internal::wasm::ModuleOrigin::kWasmOrigin);
}
if (result_interpreted == 0xdeadbeef) {
......
......@@ -47,7 +47,7 @@ int fuzz_wasm_section(WasmSection::Code section, const uint8_t* data,
ErrorThrower thrower(i_isolate, "decoder");
std::unique_ptr<const WasmModule> module(testing::DecodeWasmModuleForTesting(
i_isolate, &zone, thrower, buffer.begin(), buffer.end(), kWasmOrigin));
i_isolate, &zone, &thrower, buffer.begin(), buffer.end(), kWasmOrigin));
return 0;
}
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