2014-07-30 13:54:45 +00:00
|
|
|
// Copyright 2014 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_CCTEST_COMPILER_FUNCTION_TESTER_H_
|
|
|
|
#define V8_CCTEST_COMPILER_FUNCTION_TESTER_H_
|
|
|
|
|
|
|
|
#include "src/handles.h"
|
2015-10-28 13:32:17 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2016-08-26 08:41:20 +00:00
|
|
|
|
|
|
|
class CallInterfaceDescriptor;
|
|
|
|
class Isolate;
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
namespace compiler {
|
|
|
|
|
2016-08-26 08:41:20 +00:00
|
|
|
class Graph;
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
class FunctionTester : public InitializedHandleScope {
|
|
|
|
public:
|
2016-08-26 08:41:20 +00:00
|
|
|
explicit FunctionTester(const char* source, uint32_t flags = 0);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2016-08-26 08:41:20 +00:00
|
|
|
FunctionTester(Graph* graph, int param_count);
|
2014-10-08 09:23:33 +00:00
|
|
|
|
2016-08-26 08:41:20 +00:00
|
|
|
FunctionTester(Handle<Code> code, int param_count);
|
2015-12-02 12:35:12 +00:00
|
|
|
|
2016-11-16 07:53:51 +00:00
|
|
|
FunctionTester(const CallInterfaceDescriptor& descriptor, Handle<Code> code);
|
2016-06-02 15:02:08 +00:00
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
Isolate* isolate;
|
|
|
|
Handle<JSFunction> function;
|
|
|
|
|
2016-08-26 08:41:20 +00:00
|
|
|
MaybeHandle<Object> Call();
|
|
|
|
MaybeHandle<Object> Call(Handle<Object> a);
|
|
|
|
MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b);
|
2016-06-02 15:02:08 +00:00
|
|
|
MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b,
|
2016-08-26 08:41:20 +00:00
|
|
|
Handle<Object> c);
|
2015-05-20 13:19:11 +00:00
|
|
|
MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b, Handle<Object> c,
|
2016-08-26 08:41:20 +00:00
|
|
|
Handle<Object> d);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2016-08-26 08:41:20 +00:00
|
|
|
void CheckThrows(Handle<Object> a, Handle<Object> b);
|
2015-09-21 10:34:44 +00:00
|
|
|
v8::Local<v8::Message> CheckThrowsReturnMessage(Handle<Object> a,
|
2016-08-26 08:41:20 +00:00
|
|
|
Handle<Object> b);
|
2016-06-02 15:02:08 +00:00
|
|
|
void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b,
|
2016-09-01 12:01:33 +00:00
|
|
|
Handle<Object> c, Handle<Object> d);
|
2016-06-01 19:58:46 +00:00
|
|
|
|
2016-06-02 15:02:08 +00:00
|
|
|
void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b,
|
|
|
|
Handle<Object> c) {
|
|
|
|
return CheckCall(expected, a, b, c, undefined());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b) {
|
|
|
|
return CheckCall(expected, a, b, undefined());
|
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
void CheckCall(Handle<Object> expected, Handle<Object> a) {
|
|
|
|
CheckCall(expected, a, undefined());
|
|
|
|
}
|
|
|
|
|
2016-06-02 15:02:08 +00:00
|
|
|
void CheckCall(Handle<Object> expected) { CheckCall(expected, undefined()); }
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
void CheckCall(double expected, double a, double b) {
|
|
|
|
CheckCall(Val(expected), Val(a), Val(b));
|
|
|
|
}
|
|
|
|
|
2016-06-02 15:02:08 +00:00
|
|
|
void CheckTrue(Handle<Object> a) { CheckCall(true_value(), a); }
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
void CheckTrue(Handle<Object> a, Handle<Object> b) {
|
|
|
|
CheckCall(true_value(), a, b);
|
|
|
|
}
|
|
|
|
|
2016-06-02 15:02:08 +00:00
|
|
|
void CheckTrue(Handle<Object> a, Handle<Object> b, Handle<Object> c) {
|
|
|
|
CheckCall(true_value(), a, b, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckTrue(Handle<Object> a, Handle<Object> b, Handle<Object> c,
|
|
|
|
Handle<Object> d) {
|
|
|
|
CheckCall(true_value(), a, b, c, d);
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
void CheckTrue(double a, double b) {
|
|
|
|
CheckCall(true_value(), Val(a), Val(b));
|
|
|
|
}
|
|
|
|
|
2016-06-02 15:02:08 +00:00
|
|
|
void CheckFalse(Handle<Object> a) { CheckCall(false_value(), a); }
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
void CheckFalse(Handle<Object> a, Handle<Object> b) {
|
|
|
|
CheckCall(false_value(), a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckFalse(double a, double b) {
|
|
|
|
CheckCall(false_value(), Val(a), Val(b));
|
|
|
|
}
|
|
|
|
|
2016-09-01 12:01:33 +00:00
|
|
|
Handle<JSFunction> NewFunction(const char* source);
|
|
|
|
Handle<JSObject> NewObject(const char* source);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2016-08-26 08:41:20 +00:00
|
|
|
Handle<String> Val(const char* string);
|
|
|
|
Handle<Object> Val(double value);
|
|
|
|
Handle<Object> infinity();
|
|
|
|
Handle<Object> minus_infinity();
|
|
|
|
Handle<Object> nan();
|
|
|
|
Handle<Object> undefined();
|
|
|
|
Handle<Object> null();
|
|
|
|
Handle<Object> true_value();
|
|
|
|
Handle<Object> false_value();
|
2014-08-21 12:40:10 +00:00
|
|
|
|
2016-09-01 12:01:33 +00:00
|
|
|
static Handle<JSFunction> ForMachineGraph(Graph* graph, int param_count);
|
2016-02-12 17:28:50 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t flags_;
|
|
|
|
|
2016-08-26 08:41:20 +00:00
|
|
|
Handle<JSFunction> Compile(Handle<JSFunction> function);
|
2015-12-02 12:35:12 +00:00
|
|
|
std::string BuildFunction(int param_count) {
|
|
|
|
std::string function_string = "(function(";
|
|
|
|
if (param_count > 0) {
|
2016-02-18 09:28:26 +00:00
|
|
|
function_string += 'a';
|
|
|
|
for (int i = 1; i < param_count; i++) {
|
2015-12-02 12:35:12 +00:00
|
|
|
function_string += ',';
|
2016-02-18 09:28:26 +00:00
|
|
|
function_string += static_cast<char>('a' + i);
|
2015-12-02 12:35:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function_string += "){})";
|
|
|
|
return function_string;
|
|
|
|
}
|
|
|
|
|
2014-10-08 09:23:33 +00:00
|
|
|
// Compile the given machine graph instead of the source of the function
|
|
|
|
// and replace the JSFunction's code with the result.
|
2016-08-26 08:41:20 +00:00
|
|
|
Handle<JSFunction> CompileGraph(Graph* graph);
|
2014-07-30 13:54:45 +00:00
|
|
|
};
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
#endif // V8_CCTEST_COMPILER_FUNCTION_TESTER_H_
|