2016-09-12 12:26:37 +00:00
|
|
|
// Copyright 2016 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.
|
|
|
|
|
|
|
|
#ifndef V8_WASM_MODULE_RUNNER_H_
|
|
|
|
#define V8_WASM_MODULE_RUNNER_H_
|
|
|
|
|
|
|
|
#include "src/isolate.h"
|
|
|
|
#include "src/objects.h"
|
|
|
|
#include "src/wasm/wasm-interpreter.h"
|
|
|
|
#include "src/wasm/wasm-module.h"
|
2016-11-16 16:17:22 +00:00
|
|
|
#include "src/wasm/wasm-objects.h"
|
2016-09-12 12:26:37 +00:00
|
|
|
#include "src/wasm/wasm-result.h"
|
2016-09-20 16:07:25 +00:00
|
|
|
#include "src/zone/zone.h"
|
2016-09-12 12:26:37 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2017-01-27 13:53:13 +00:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class Handle;
|
|
|
|
|
2016-09-12 12:26:37 +00:00
|
|
|
namespace wasm {
|
|
|
|
namespace testing {
|
|
|
|
|
|
|
|
// Decodes the given encoded module.
|
2017-05-08 12:45:20 +00:00
|
|
|
std::unique_ptr<WasmModule> DecodeWasmModuleForTesting(
|
2016-11-14 19:45:16 +00:00
|
|
|
Isolate* isolate, ErrorThrower* thrower, const byte* module_start,
|
|
|
|
const byte* module_end, ModuleOrigin origin, bool verify_functions = false);
|
2016-09-12 12:26:37 +00:00
|
|
|
|
[wasm] Use pending exceptions consistently
In our internal code, we should only use pending exceptions. They will
be converted to scheduled exceptions on the API boundary.
Hence, the ErrorThrower just sets a pending exception; it should never
have to think about scheduled exceptions. The new
ScheduledErrorThrower inherits from ErrorThrower and reschedules any
pending exceptions in its destructor (turning them into scheduled
exceptions).
In some situations, there might already be a scheduled exception, e.g.
when calling other API methods (v8::Value::Get). In this case, the
ErrorThrower should also not set another pending exception. For the
reasons mentioned above, this can only be handled in the
ScheduledErrorThrower, which is used the API methods.
This fixes one DCHECK failure and one TODO about scheduled exceptions
if no instance can be created, because the start function throws.
R=mtrofin@chromium.org, mstarzinger@chromium.org
BUG=v8:6232,chromium:736256
Change-Id: I4905be04c565df9495de18fb26adbb5c05d193d2
Reviewed-on: https://chromium-review.googlesource.com/548641
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46314}
2017-06-29 08:16:29 +00:00
|
|
|
// Call an exported wasm function by name. Returns -1 if the export does not
|
|
|
|
// exist or throws an error. Errors are cleared from the isolate before
|
|
|
|
// returning.
|
2016-09-12 12:26:37 +00:00
|
|
|
int32_t CallWasmFunctionForTesting(Isolate* isolate, Handle<JSObject> instance,
|
2016-09-15 16:19:48 +00:00
|
|
|
ErrorThrower* thrower, const char* name,
|
2017-06-21 09:24:03 +00:00
|
|
|
int argc, Handle<Object> argv[]);
|
2016-09-12 12:26:37 +00:00
|
|
|
|
|
|
|
// Decode, verify, and run the function labeled "main" in the
|
|
|
|
// given encoded module. The module should have no imports.
|
|
|
|
int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start,
|
2017-06-09 18:37:54 +00:00
|
|
|
const byte* module_end);
|
|
|
|
|
2016-09-12 12:26:37 +00:00
|
|
|
// 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
|
2017-06-12 11:13:15 +00:00
|
|
|
int32_t InterpretWasmModule(Isolate* isolate,
|
|
|
|
Handle<WasmInstanceObject> instance,
|
|
|
|
ErrorThrower* thrower, int32_t function_index,
|
2017-07-14 13:49:01 +00:00
|
|
|
WasmValue* args, bool* possible_nondeterminism);
|
2016-09-17 01:30:09 +00:00
|
|
|
|
2016-09-28 20:55:42 +00:00
|
|
|
// Runs the module instance with arguments.
|
|
|
|
int32_t RunWasmModuleForTesting(Isolate* isolate, Handle<JSObject> instance,
|
2017-06-21 09:24:03 +00:00
|
|
|
int argc, Handle<Object> argv[]);
|
2017-06-12 12:31:07 +00:00
|
|
|
|
2016-09-17 01:30:09 +00:00
|
|
|
// Install function map, module symbol for testing
|
|
|
|
void SetupIsolateForWasmModule(Isolate* isolate);
|
2017-06-12 11:13:15 +00:00
|
|
|
|
2016-09-12 12:26:37 +00:00
|
|
|
} // namespace testing
|
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif // V8_WASM_MODULE_RUNNER_H_
|