Exemplo n.º 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 defineEventCB(JXValue *results, int argc) {
  if (!JX_IsFunction(results + 1)) {
    error_console("defineEventCB expects a function");
    return;
  }

  JX_MakePersistent(results+1);
  eventCB = *(results + 1);
}