Commit a29516bc authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[cleanup] Add templatized FunctionTester::CallChecked(...) helpers

- use asm_tester instead of data variable name
- directly expose Variable and Label for convenience

Change-Id: I211fe07e236f96067037ca00c1435c1491121e6b
Reviewed-on: https://chromium-review.googlesource.com/574914
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46738}
parent beb4037a
......@@ -42,38 +42,13 @@ FunctionTester::FunctionTester(Handle<Code> code, int param_count)
function((FLAG_allow_natives_syntax = true,
NewFunction(BuildFunction(param_count).c_str()))),
flags_(0) {
CHECK(!code.is_null());
Compile(function);
function->ReplaceCode(*code);
}
FunctionTester::FunctionTester(Handle<Code> code) : FunctionTester(code, 0) {}
MaybeHandle<Object> FunctionTester::Call() {
return Execution::Call(isolate, function, undefined(), 0, nullptr);
}
MaybeHandle<Object> FunctionTester::Call(Handle<Object> a) {
Handle<Object> args[] = {a};
return Execution::Call(isolate, function, undefined(), 1, args);
}
MaybeHandle<Object> FunctionTester::Call(Handle<Object> a, Handle<Object> b) {
Handle<Object> args[] = {a, b};
return Execution::Call(isolate, function, undefined(), 2, args);
}
MaybeHandle<Object> FunctionTester::Call(Handle<Object> a, Handle<Object> b,
Handle<Object> c) {
Handle<Object> args[] = {a, b, c};
return Execution::Call(isolate, function, undefined(), 3, args);
}
MaybeHandle<Object> FunctionTester::Call(Handle<Object> a, Handle<Object> b,
Handle<Object> c, Handle<Object> d) {
Handle<Object> args[] = {a, b, c, d};
return Execution::Call(isolate, function, undefined(), 4, args);
}
void FunctionTester::CheckThrows(Handle<Object> a) {
TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
MaybeHandle<Object> no_result = Call(a);
......
......@@ -5,6 +5,7 @@
#ifndef V8_CCTEST_COMPILER_FUNCTION_TESTER_H_
#define V8_CCTEST_COMPILER_FUNCTION_TESTER_H_
#include "src/execution.h"
#include "src/handles.h"
#include "test/cctest/cctest.h"
......@@ -32,13 +33,22 @@ class FunctionTester : public InitializedHandleScope {
Isolate* isolate;
Handle<JSFunction> function;
MaybeHandle<Object> Call();
MaybeHandle<Object> Call(Handle<Object> a);
MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b);
MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b,
Handle<Object> c);
MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b, Handle<Object> c,
Handle<Object> d);
MaybeHandle<Object> Call() {
return Execution::Call(isolate, function, undefined(), 0, nullptr);
}
template <typename Arg1, typename... Args>
MaybeHandle<Object> Call(Arg1 arg1, Args... args) {
const int nof_args = sizeof...(Args) + 1;
Handle<Object> call_args[] = {arg1, args...};
return Execution::Call(isolate, function, undefined(), nof_args, call_args);
}
template <typename T, typename... Args>
Handle<T> CallChecked(Args... args) {
Handle<Object> result = Call(args...).ToHandleChecked();
return Handle<T>::cast(result);
}
void CheckThrows(Handle<Object> a);
void CheckThrows(Handle<Object> a, Handle<Object> b);
......
This diff is collapsed.
This diff is collapsed.
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