#include "test.hh"


int n_calls = 0;
void recursor(v8i::function_callback_info&& cbi)
{
  cout << (++n_calls) << " " << endl; //if(++n_calls > 20) return;
  if(n_calls > v8i::engine::max_eval_recursion_depth()+1) {
    test_fail("Recursion not detected");
    throw v8i::callback_error("Recursion not detected");
  }
  js.eval("recursor();");
}

/**
 * Test: eval recursion
 */
void test()
{
  v8i::engine::max_eval_recursion_depth(10);
  js.define("recursor", recursor);
  test_expect_except( include_test_js() );
  test_comment( string("Number of recursor() calls: ") + std::to_string(n_calls) );
  test_expect( n_calls == v8i::engine::max_eval_recursion_depth() );
}
