예제 #1
0
int main(int argc, char **args) {
  JX_Initialize(args[0], callback);
  JX_InitializeNewEngine();

  JX_DefineMainFile(contents);
  JX_DefineExtension("sampleMethod", sampleMethod);
  JX_StartEngine();

  while (JX_LoopOnce() != 0) usleep(1);

  JXValue *params[2] = {param1, param2};
  JXValue out;

  // call fnc -> JS side function
  // we had made this variable persistent inside sampleMethod
  JX_CallFunction(fnc, *params, 2, &out);

  // we need to clear persistent and then free whenever we
  // are done with persistent values to not to leak
  JX_ClearPersistent(fnc);
  JX_Free(fnc);
  JX_ClearPersistent(param1);
  JX_Free(param1);
  JX_ClearPersistent(param2);
  JX_Free(param2);

  assert(JX_GetDataLength(&out) == 11 &&
         "Expected return value was 'test{\"a\":3}");
  JX_Free(&out);
  assert(out.data_ == NULL && out.size_ == 0 && "JX_FreeResultData leaks?");

  JX_StopEngine();
}
예제 #2
0
JNIEXPORT void JNICALL
Java_org_capriza_jxcore_jxcore_stopEngine(JNIEnv *env, jobject thiz) {
//  JX_ClearPersistent(&eventCB);
//    JX_Free(&eventCB);
__android_log_print(ANDROID_LOG_DEBUG, APPNAME, "ANY DIFFERENCE??", 1);
    JX_StopEngine();
}
예제 #3
0
int main(int argc, char **args) {
  JX_Initialize(args[0], callback);
  JX_InitializeNewEngine();

  JX_DefineMainFile(contents);
  JX_DefineExtension("crashMe", crashMe);
  JX_DefineExtension("sampleMethod", sampleMethod);
  JX_StartEngine();

  while (JX_LoopOnce() != 0) usleep(1);

  JX_StopEngine();
}
예제 #4
0
int main(int argc, char **args) {
  JX_InitializeOnce("/test/bin/cpp/");
  JX_InitializeNewEngine();

  JX_DefineMainFile(contents);
  JX_StartEngine();

  JXValue ret_val;
  JX_Evaluate("process.callMe()", "eval", &ret_val);

  while (JX_LoopOnce() != 0) usleep(1);

  assert(JX_IsError(&ret_val) && "error was expected");

  std::string str;
  ConvertResult(&ret_val, str);
  assert(!strcmp("TypeError: this is type exception", str.c_str()) &&
         "Exception output doesn't match");

  JX_Free(&ret_val);

  JX_StopEngine();
}
예제 #5
0
int main(int argc, char **args) {
  JX_Initialize(args[0], callback);
  JX_InitializeNewEngine();

  JX_DefineMainFile(contents);
  JX_DefineExtension("sampleMethod", sampleMethod);
  JX_StartEngine();

  // loop for possible IO
  // or JX_Loop() without usleep / while
  while (JX_LoopOnce() != 0) usleep(1);

  JXValue result;
  JX_Evaluate(eval_str, "myscript", &result);
  JX_Free(&result);

  // loop for possible IO
  // or JX_Loop() without usleep / while
  while (JX_LoopOnce() != 0) usleep(1);

  JX_StopEngine();

  assert(counter == 3 && "sampleMethod is expected to recive 3 calls (2 sub instance, 1 main)");
}
예제 #6
0
int main(int argc, char **args) {
  JX_Initialize(args[0], callback);
  JX_InitializeNewEngine();

  JX_DefineMainFile(contents);
  
  JX_StartEngine();

  JXValue ret_val;
  
  // this is not a function, it shouldn't return. 
  // exception is expected
  JX_Evaluate("return process.x", "eval", &ret_val);
  
  while (JX_LoopOnce() != 0) usleep(1);
  
  assert(JX_IsError(&ret_val) && "error was expected");
  
  JX_Free(&ret_val);

  JX_StopEngine();
  
  return 0;
}
JNIEXPORT void JNICALL
Java_io_jxcore_node_jxcore_stopEngine(JNIEnv *env, jobject thiz) {
  JX_ClearPersistent(&eventCB);
  JX_Free(&eventCB);
  JX_StopEngine();
}