iotjs_jval_t iotjs_jhelper_call_ok(const iotjs_jval_t* jfunc, const iotjs_jval_t* jthis, const iotjs_jargs_t* jargs) { bool throws; iotjs_jval_t jres = iotjs_jhelper_call(jfunc, jthis, jargs, &throws); IOTJS_ASSERT(!throws); return jres; }
iotjs_jval_t iotjs_make_callback_with_result(const iotjs_jval_t* jfunction, const iotjs_jval_t* jthis, const iotjs_jargs_t* jargs) { // Calls back the function. bool throws; iotjs_jval_t jres = iotjs_jhelper_call(jfunction, jthis, jargs, &throws); if (throws) { iotjs_uncaught_exception(&jres); } // Calls the next tick callbacks. iotjs_process_next_tick(); // Return value. return jres; }
void iotjs_process_emit_exit(int code) { const iotjs_jval_t* process = iotjs_module_get(MODULE_PROCESS); iotjs_jval_t jexit = iotjs_jval_get_property(process, IOTJS_MAGIC_STRING_EMITEXIT); IOTJS_ASSERT(iotjs_jval_is_function(&jexit)); iotjs_jargs_t jargs = iotjs_jargs_create(1); iotjs_jargs_append_number(&jargs, code); bool throws; iotjs_jval_t jres = iotjs_jhelper_call(&jexit, process, &jargs, &throws); iotjs_jargs_destroy(&jargs); iotjs_jval_destroy(&jres); iotjs_jval_destroy(&jexit); if (throws) { exit(2); } }
void iotjs_uncaught_exception(const iotjs_jval_t* jexception) { const iotjs_jval_t* process = iotjs_module_get(MODULE_PROCESS); iotjs_jval_t jonuncaughtexception = iotjs_jval_get_property(process, IOTJS_MAGIC_STRING__ONUNCAUGHTEXCEPTION); IOTJS_ASSERT(iotjs_jval_is_function(&jonuncaughtexception)); iotjs_jargs_t args = iotjs_jargs_create(1); iotjs_jargs_append_jval(&args, jexception); bool throws; iotjs_jval_t jres = iotjs_jhelper_call(&jonuncaughtexception, process, &args, &throws); iotjs_jargs_destroy(&args); iotjs_jval_destroy(&jres); iotjs_jval_destroy(&jonuncaughtexception); if (throws) { exit(2); } }