Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: src/wasm/wasm-module.cc

Issue 2321443002: [wasm] Call the wasm interpreter from the wasm-code-fuzzer. (Closed)
Patch Set: Address comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/cctest/cctest.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-module.cc
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
index 2470257735299c590511fb7e82f6d4f2b4152635..18f6e9ed362d87812f9a5f92c45e063e0a52ce51 100644
--- a/src/wasm/wasm-module.cc
+++ b/src/wasm/wasm-module.cc
@@ -1672,92 +1672,6 @@ MaybeHandle<JSObject> CreateModuleObjectFromBytes(Isolate* isolate,
return CreateCompiledModuleObject(isolate, compiled_module.ToHandleChecked(),
origin);
}
-
-namespace testing {
-
-int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start,
- const byte* module_end, bool asm_js) {
- HandleScope scope(isolate);
- Zone zone(isolate->allocator());
- ErrorThrower thrower(isolate, "CompileAndRunWasmModule");
-
- // Decode the module, but don't verify function bodies, since we'll
- // be compiling them anyway.
- ModuleResult decoding_result =
- DecodeWasmModule(isolate, &zone, module_start, module_end, false,
- asm_js ? kAsmJsOrigin : kWasmOrigin);
-
- 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());
- return -1;
- }
-
- if (module->import_table.size() > 0) {
- thrower.Error("Not supported: module has imports.");
- }
- if (module->export_table.size() == 0) {
- thrower.Error("Not supported: module has no exports.");
- }
-
- if (thrower.error()) return -1;
- MaybeHandle<FixedArray> compiled_module =
- module->CompileFunctions(isolate, &thrower);
-
- if (compiled_module.is_null()) return -1;
- Handle<JSObject> instance =
- WasmModule::Instantiate(isolate, compiled_module.ToHandleChecked(),
- Handle<JSReceiver>::null(),
- Handle<JSArrayBuffer>::null())
- .ToHandleChecked();
-
- return CallFunction(isolate, instance, &thrower, asm_js ? "caller" : "main",
- 0, nullptr, asm_js);
-}
-
-int32_t CallFunction(Isolate* isolate, Handle<JSObject> instance,
- ErrorThrower* thrower, const char* name, int argc,
- Handle<Object> argv[], bool asm_js) {
- Handle<JSObject> exports_object;
- if (asm_js) {
- exports_object = instance;
- } else {
- Handle<Name> exports = isolate->factory()->InternalizeUtf8String("exports");
- exports_object = Handle<JSObject>::cast(
- JSObject::GetProperty(instance, exports).ToHandleChecked());
- }
- Handle<Name> main_name = isolate->factory()->NewStringFromAsciiChecked(name);
- PropertyDescriptor desc;
- Maybe<bool> property_found = JSReceiver::GetOwnPropertyDescriptor(
- isolate, exports_object, main_name, &desc);
- if (!property_found.FromMaybe(false)) return -1;
-
- Handle<JSFunction> main_export = Handle<JSFunction>::cast(desc.value());
-
- // Call the JS function.
- Handle<Object> undefined = isolate->factory()->undefined_value();
- MaybeHandle<Object> retval =
- Execution::Call(isolate, main_export, undefined, argc, argv);
-
- // The result should be a number.
- if (retval.is_null()) {
- thrower->Error("WASM.compileRun() failed: Invocation was null");
- return -1;
- }
- Handle<Object> result = retval.ToHandleChecked();
- if (result->IsSmi()) {
- return Smi::cast(*result)->value();
- }
- if (result->IsHeapNumber()) {
- return static_cast<int32_t>(HeapNumber::cast(*result)->value());
- }
- thrower->Error("WASM.compileRun() failed: Return value should be number");
- return -1;
-}
-
-} // namespace testing
} // namespace wasm
} // namespace internal
} // namespace v8
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/cctest/cctest.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698