Exemple #1
0
int Start(char* src) {
  if (!InitJerry()) {
    DLOG("InitJerry failed");
    return 1;
  }

  JObject* process = InitModules();

  // FIXME: this should be moved to seperate function
  {
    JObject argv;
    argv.SetProperty("1", JObject(src));
    process->SetProperty("argv", argv);
  }

  if (!StartIoTjs(process)) {
    DLOG("StartIoTJs failed");
    return 1;
  }

  CleanupModules();

  ReleaseJerry();

  return 0;
}
Exemple #2
0
static bool StartIoTjs(Environment* env) {
  // Get jerry global object.
  JObject global = JObject::Global();

  // Bind environment to global object.
  global.SetNative((uintptr_t)(env), NULL);

  // Initialize builtin modules.
  JObject* process = InitModules();

  // Call the entry.
  // load and call iotjs.js
  env->GoStateRunningMain();

  RunIoTjs(process);

  // Run event loop.
  env->GoStateRunningLoop();

  bool more;
  do {
    more = uv_run(env->loop(), UV_RUN_ONCE);
    more |= ProcessNextTick();
    if (more == false) {
      more = uv_loop_alive(env->loop());
    }
  } while (more);

  env->GoStateExiting();

  // Emit 'exit' event.
  ProcessEmitExit(0);

  // Release bulitin modules.
  CleanupModules();

  return true;
}