Пример #1
0
// native JavaScript method we'll be calling from JS land
void sampleMethod(JXValue *results, int argc) {
  assert(argc == 4 && "number of arguments supposed to be 4");

  assert(JX_IsFunction(&results[0]) && JX_IsFunction(&results[1]) &&
         "both parameters supposed to be a function");

  assert(JX_IsString(&results[2]) && JX_IsString(&results[3]) &&
         "both parameters supposed to be a function");

  bool JX_CallFunction(JXValue * fnc, JXValue * params, const int argc,
                       JXValue * out);

  JXValue out;
  assert(JX_CallFunction(&results[0], &results[2], 1, &out) &&
         "failed while calling console.log");
  assert(JX_IsUndefined(&out) &&
         "return value from console.log should be undefined");

  assert(JX_CallFunction(&results[0], &results[3], 1, &out) &&
         "failed while calling console.error");
  assert(JX_IsUndefined(&out) &&
         "return value from console.error should be undefined");

  counter++;
}
static void callback(JXValue *results, int argc) {
  if (argc != 3) {
    error_console(
        "wrong callback received. expected number of parameters was 3. "
        "received %d",
        argc);
    return;
  }

  if (!JX_IsString(results + 2)) {
    error_console(
        "JXcore-Cordova: Unexpected callback received. Third parameter must "
        "be a String");
    return;
  }

  cb_values = results;

  // results+1 -> err_val
  jxcore::Callback((JX_IsNull(results + 1) || JX_IsUndefined(results + 1)) ? 0
                                                                           : 1);

  cb_values = NULL;
}