LCOV - code coverage report
Current view: top level - test/cctest/compiler - function-tester.h (source / functions) Hit Total Coverage
Test: app.info Lines: 46 46 100.0 %
Date: 2017-10-20 Functions: 59 59 100.0 %

          Line data    Source code
       1             : // Copyright 2014 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_CCTEST_COMPILER_FUNCTION_TESTER_H_
       6             : #define V8_CCTEST_COMPILER_FUNCTION_TESTER_H_
       7             : 
       8             : #include "src/execution.h"
       9             : #include "src/handles.h"
      10             : #include "test/cctest/cctest.h"
      11             : 
      12             : namespace v8 {
      13             : namespace internal {
      14             : 
      15             : class CallInterfaceDescriptor;
      16             : class Isolate;
      17             : 
      18             : namespace compiler {
      19             : 
      20             : class Graph;
      21             : 
      22        1536 : class FunctionTester : public InitializedHandleScope {
      23             :  public:
      24             :   explicit FunctionTester(const char* source, uint32_t flags = 0);
      25             : 
      26             :   FunctionTester(Graph* graph, int param_count);
      27             : 
      28             :   FunctionTester(Handle<Code> code, int param_count);
      29             : 
      30             :   // Assumes VoidDescriptor call interface.
      31             :   explicit FunctionTester(Handle<Code> code);
      32             : 
      33             :   Isolate* isolate;
      34             :   Handle<JSFunction> function;
      35             : 
      36         108 :   MaybeHandle<Object> Call() {
      37         216 :     return Execution::Call(isolate, function, undefined(), 0, nullptr);
      38             :   }
      39             : 
      40             :   template <typename Arg1, typename... Args>
      41      480150 :   MaybeHandle<Object> Call(Arg1 arg1, Args... args) {
      42             :     const int nof_args = sizeof...(Args) + 1;
      43      452772 :     Handle<Object> call_args[] = {arg1, args...};
      44      507966 :     return Execution::Call(isolate, function, undefined(), nof_args, call_args);
      45             :   }
      46             : 
      47             :   template <typename T, typename... Args>
      48         498 :   Handle<T> CallChecked(Args... args) {
      49         996 :     Handle<Object> result = Call(args...).ToHandleChecked();
      50         498 :     return Handle<T>::cast(result);
      51             :   }
      52             : 
      53             :   void CheckThrows(Handle<Object> a);
      54             :   void CheckThrows(Handle<Object> a, Handle<Object> b);
      55             :   v8::Local<v8::Message> CheckThrowsReturnMessage(Handle<Object> a,
      56             :                                                   Handle<Object> b);
      57             :   void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b,
      58             :                  Handle<Object> c, Handle<Object> d);
      59             : 
      60      440088 :   void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b,
      61             :                  Handle<Object> c) {
      62      440088 :     return CheckCall(expected, a, b, c, undefined());
      63             :   }
      64             : 
      65      396426 :   void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b) {
      66      396426 :     return CheckCall(expected, a, b, undefined());
      67             :   }
      68             : 
      69      393618 :   void CheckCall(Handle<Object> expected, Handle<Object> a) {
      70      393618 :     CheckCall(expected, a, undefined());
      71      393618 :   }
      72             : 
      73          60 :   void CheckCall(Handle<Object> expected) { CheckCall(expected, undefined()); }
      74             : 
      75         192 :   void CheckCall(double expected, double a, double b) {
      76         192 :     CheckCall(Val(expected), Val(a), Val(b));
      77         192 :   }
      78             : 
      79          36 :   void CheckTrue(Handle<Object> a) { CheckCall(true_value(), a); }
      80             : 
      81         198 :   void CheckTrue(Handle<Object> a, Handle<Object> b) {
      82         198 :     CheckCall(true_value(), a, b);
      83         198 :   }
      84             : 
      85       43662 :   void CheckTrue(Handle<Object> a, Handle<Object> b, Handle<Object> c) {
      86       43662 :     CheckCall(true_value(), a, b, c);
      87       43662 :   }
      88             : 
      89       12108 :   void CheckTrue(Handle<Object> a, Handle<Object> b, Handle<Object> c,
      90             :                  Handle<Object> d) {
      91       12108 :     CheckCall(true_value(), a, b, c, d);
      92       12108 :   }
      93             : 
      94          96 :   void CheckTrue(double a, double b) {
      95          96 :     CheckCall(true_value(), Val(a), Val(b));
      96          96 :   }
      97             : 
      98         204 :   void CheckFalse(Handle<Object> a) { CheckCall(false_value(), a); }
      99             : 
     100         186 :   void CheckFalse(Handle<Object> a, Handle<Object> b) {
     101         186 :     CheckCall(false_value(), a, b);
     102         186 :   }
     103             : 
     104          96 :   void CheckFalse(double a, double b) {
     105          96 :     CheckCall(false_value(), Val(a), Val(b));
     106          96 :   }
     107             : 
     108             :   Handle<JSFunction> NewFunction(const char* source);
     109             :   Handle<JSObject> NewObject(const char* source);
     110             : 
     111             :   Handle<String> Val(const char* string);
     112             :   Handle<Object> Val(double value);
     113             :   Handle<Object> infinity();
     114             :   Handle<Object> minus_infinity();
     115             :   Handle<Object> nan();
     116             :   Handle<Object> undefined();
     117             :   Handle<Object> null();
     118             :   Handle<Object> true_value();
     119             :   Handle<Object> false_value();
     120             : 
     121             :   static Handle<JSFunction> ForMachineGraph(Graph* graph, int param_count);
     122             : 
     123             :  private:
     124             :   uint32_t flags_;
     125             : 
     126             :   Handle<JSFunction> Compile(Handle<JSFunction> function);
     127         582 :   std::string BuildFunction(int param_count) {
     128         582 :     std::string function_string = "(function(";
     129         582 :     if (param_count > 0) {
     130             :       function_string += 'a';
     131         576 :       for (int i = 1; i < param_count; i++) {
     132             :         function_string += ',';
     133         576 :         function_string += static_cast<char>('a' + i);
     134             :       }
     135             :     }
     136             :     function_string += "){})";
     137         582 :     return function_string;
     138             :   }
     139             : 
     140             :   // Compile the given machine graph instead of the source of the function
     141             :   // and replace the JSFunction's code with the result.
     142             :   Handle<JSFunction> CompileGraph(Graph* graph);
     143             : };
     144             : }  // namespace compiler
     145             : }  // namespace internal
     146             : }  // namespace v8
     147             : 
     148             : #endif  // V8_CCTEST_COMPILER_FUNCTION_TESTER_H_

Generated by: LCOV version 1.10