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: 2019-01-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        1840 : 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             :   CanonicalHandleScope canonical;
      35             :   Handle<JSFunction> function;
      36             : 
      37         605 :   MaybeHandle<Object> Call() {
      38        1210 :     return Execution::Call(isolate, function, undefined(), 0, nullptr);
      39             :   }
      40             : 
      41             :   template <typename Arg1, typename... Args>
      42      391620 :   MaybeHandle<Object> Call(Arg1 arg1, Args... args) {
      43             :     const int nof_args = sizeof...(Args) + 1;
      44      368675 :     Handle<Object> call_args[] = {arg1, args...};
      45      414925 :     return Execution::Call(isolate, function, undefined(), nof_args, call_args);
      46             :   }
      47             : 
      48             :   template <typename T, typename... Args>
      49         435 :   Handle<T> CallChecked(Args... args) {
      50         870 :     Handle<Object> result = Call(args...).ToHandleChecked();
      51         435 :     return Handle<T>::cast(result);
      52             :   }
      53             : 
      54             :   void CheckThrows(Handle<Object> a);
      55             :   void CheckThrows(Handle<Object> a, Handle<Object> b);
      56             :   v8::Local<v8::Message> CheckThrowsReturnMessage(Handle<Object> a,
      57             :                                                   Handle<Object> b);
      58             :   void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b,
      59             :                  Handle<Object> c, Handle<Object> d);
      60             : 
      61      361985 :   void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b,
      62             :                  Handle<Object> c) {
      63      361985 :     return CheckCall(expected, a, b, c, undefined());
      64             :   }
      65             : 
      66      330225 :   void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b) {
      67      330225 :     return CheckCall(expected, a, b, undefined());
      68             :   }
      69             : 
      70      327915 :   void CheckCall(Handle<Object> expected, Handle<Object> a) {
      71      327915 :     CheckCall(expected, a, undefined());
      72      327915 :   }
      73             : 
      74          80 :   void CheckCall(Handle<Object> expected) { CheckCall(expected, undefined()); }
      75             : 
      76         160 :   void CheckCall(double expected, double a, double b) {
      77         160 :     CheckCall(Val(expected), Val(a), Val(b));
      78         160 :   }
      79             : 
      80          20 :   void CheckTrue(Handle<Object> a) { CheckCall(true_value(), a); }
      81             : 
      82         165 :   void CheckTrue(Handle<Object> a, Handle<Object> b) {
      83         165 :     CheckCall(true_value(), a, b);
      84         165 :   }
      85             : 
      86       31760 :   void CheckTrue(Handle<Object> a, Handle<Object> b, Handle<Object> c) {
      87       31760 :     CheckCall(true_value(), a, b, c);
      88       31760 :   }
      89             : 
      90        6215 :   void CheckTrue(Handle<Object> a, Handle<Object> b, Handle<Object> c,
      91             :                  Handle<Object> d) {
      92        6215 :     CheckCall(true_value(), a, b, c, d);
      93        6215 :   }
      94             : 
      95          80 :   void CheckTrue(double a, double b) {
      96          80 :     CheckCall(true_value(), Val(a), Val(b));
      97          80 :   }
      98             : 
      99          90 :   void CheckFalse(Handle<Object> a) { CheckCall(false_value(), a); }
     100             : 
     101         155 :   void CheckFalse(Handle<Object> a, Handle<Object> b) {
     102         155 :     CheckCall(false_value(), a, b);
     103         155 :   }
     104             : 
     105          80 :   void CheckFalse(double a, double b) {
     106          80 :     CheckCall(false_value(), Val(a), Val(b));
     107          80 :   }
     108             : 
     109             :   Handle<JSFunction> NewFunction(const char* source);
     110             :   Handle<JSObject> NewObject(const char* source);
     111             : 
     112             :   Handle<String> Val(const char* string);
     113             :   Handle<Object> Val(double value);
     114             :   Handle<Object> infinity();
     115             :   Handle<Object> minus_infinity();
     116             :   Handle<Object> nan();
     117             :   Handle<Object> undefined();
     118             :   Handle<Object> null();
     119             :   Handle<Object> true_value();
     120             :   Handle<Object> false_value();
     121             : 
     122             :   static Handle<JSFunction> ForMachineGraph(Graph* graph, int param_count);
     123             : 
     124             :  private:
     125             :   uint32_t flags_;
     126             : 
     127             :   Handle<JSFunction> Compile(Handle<JSFunction> function);
     128        1070 :   std::string BuildFunction(int param_count) {
     129        1070 :     std::string function_string = "(function(";
     130        1070 :     if (param_count > 0) {
     131             :       function_string += 'a';
     132         510 :       for (int i = 1; i < param_count; i++) {
     133             :         function_string += ',';
     134         510 :         function_string += static_cast<char>('a' + i);
     135             :       }
     136             :     }
     137             :     function_string += "){})";
     138        1070 :     return function_string;
     139             :   }
     140             : 
     141             :   // Compile the given machine graph instead of the source of the function
     142             :   // and replace the JSFunction's code with the result.
     143             :   Handle<JSFunction> CompileGraph(Graph* graph);
     144             : };
     145             : }  // namespace compiler
     146             : }  // namespace internal
     147             : }  // namespace v8
     148             : 
     149             : #endif  // V8_CCTEST_COMPILER_FUNCTION_TESTER_H_

Generated by: LCOV version 1.10