LCOV - code coverage report
Current view: top level - test/cctest/compiler - function-tester.h (source / functions) Hit Total Coverage
Test: app.info Lines: 37 37 100.0 %
Date: 2019-04-18 Functions: 54 54 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        1488 : 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         500 :   MaybeHandle<Object> Call() {
      38        1000 :     return Execution::Call(isolate, function, undefined(), 0, nullptr);
      39             :   }
      40             : 
      41             :   template <typename Arg1, typename... Args>
      42      313296 :   MaybeHandle<Object> Call(Arg1 arg1, Args... args) {
      43             :     const int nof_args = sizeof...(Args) + 1;
      44      294940 :     Handle<Object> call_args[] = {arg1, args...};
      45      331940 :     return Execution::Call(isolate, function, undefined(), nof_args, call_args);
      46             :   }
      47             : 
      48             :   template <typename T, typename... Args>
      49         348 :   Handle<T> CallChecked(Args... args) {
      50         696 :     Handle<Object> result = Call(args...).ToHandleChecked();
      51         348 :     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             :   void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b,
      62             :                  Handle<Object> c) {
      63      289588 :     return CheckCall(expected, a, b, c, undefined());
      64             :   }
      65             : 
      66      264180 :   void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b) {
      67      528360 :     return CheckCall(expected, a, b, undefined());
      68             :   }
      69             : 
      70             :   void CheckCall(Handle<Object> expected, Handle<Object> a) {
      71      262332 :     CheckCall(expected, a, undefined());
      72             :   }
      73             : 
      74         128 :   void CheckCall(Handle<Object> expected) { CheckCall(expected, undefined()); }
      75             : 
      76         128 :   void CheckCall(double expected, double a, double b) {
      77         128 :     CheckCall(Val(expected), Val(a), Val(b));
      78         128 :   }
      79             : 
      80          32 :   void CheckTrue(Handle<Object> a) { CheckCall(true_value(), a); }
      81             : 
      82             :   void CheckTrue(Handle<Object> a, Handle<Object> b) {
      83         132 :     CheckCall(true_value(), a, b);
      84             :   }
      85             : 
      86       25408 :   void CheckTrue(Handle<Object> a, Handle<Object> b, Handle<Object> c) {
      87       25408 :     CheckCall(true_value(), a, b, c);
      88       25408 :   }
      89             : 
      90             :   void CheckTrue(Handle<Object> a, Handle<Object> b, Handle<Object> c,
      91             :                  Handle<Object> d) {
      92        4972 :     CheckCall(true_value(), a, b, c, d);
      93             :   }
      94             : 
      95          64 :   void CheckTrue(double a, double b) {
      96          64 :     CheckCall(true_value(), Val(a), Val(b));
      97          64 :   }
      98             : 
      99         144 :   void CheckFalse(Handle<Object> a) { CheckCall(false_value(), a); }
     100             : 
     101             :   void CheckFalse(Handle<Object> a, Handle<Object> b) {
     102         124 :     CheckCall(false_value(), a, b);
     103             :   }
     104             : 
     105          64 :   void CheckFalse(double a, double b) {
     106          64 :     CheckCall(false_value(), Val(a), Val(b));
     107          64 :   }
     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         872 :   std::string BuildFunction(int param_count) {
     129         872 :     std::string function_string = "(function(";
     130         872 :     if (param_count > 0) {
     131             :       function_string += 'a';
     132        1172 :       for (int i = 1; i < param_count; i++) {
     133             :         function_string += ',';
     134         408 :         function_string += static_cast<char>('a' + i);
     135             :       }
     136             :     }
     137             :     function_string += "){})";
     138         872 :     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