Пример #1
0
static bool InitJerry() {

  uint32_t jerry_flag = JERRY_FLAG_ABORT_ON_FAIL;

#ifdef ENABLE_JERRY_MEM_STATS
  jerry_flag |= JERRY_FLAG_MEM_STATS;
  jerry_flag |= JERRY_FLAG_SHOW_OPCODES;
#endif

  jerry_init(jerry_flag);

  InitJerryMagicStringEx();

  if (!jerry_parse((jerry_api_char_t*)"", 0)) {
    DLOG("jerry_parse() failed");
    return false;
  }

  if (jerry_run() != JERRY_COMPLETION_CODE_OK) {
    DLOG("jerry_run() failed");
    return false;
  }

  return true;
}
Пример #2
0
/**
 * Initialize JerryScript.
 */
static bool InitJerry(Environment* env) {
  // Set jerry run flags.
  uint32_t jerry_flag = JERRY_FLAG_EMPTY;

  if (env->config()->memstat) {
    jerry_flag |= JERRY_FLAG_MEM_STATS;
  }

  if (env->config()->show_opcode) {
    jerry_flag |= JERRY_FLAG_SHOW_OPCODES;
  }

  // Initialize jerry.
  jerry_init((jerry_flag_t) jerry_flag);

  // Set magic strings.
  InitJerryMagicStringEx();

  // Do parse and run to generate initial javascript environment.
  jerry_api_object_t *err_obj_p = NULL;
  if (!jerry_parse((jerry_api_char_t*)"", 0, &err_obj_p)) {
    DLOG("jerry_parse() failed");
    jerry_api_release_object (err_obj_p);
    return false;
  }

  jerry_api_value_t err_val;
  if (jerry_run(&err_val) != JERRY_COMPLETION_CODE_OK) {
    DLOG("jerry_run() failed");
    jerry_api_release_value (&err_val);
    return false;
  }

  return true;
}