/* Exit the application static function exit(status: Number, how: String = "default"): void MOB - status is not implemented */ static EjsObj *app_exit(Ejs *ejs, EjsObj *unused, int argc, EjsObj **argv) { cchar *how; int status, mode; if (ejs->dontExit) { ejsThrowStateError(ejs, "App.exit has been disabled"); return 0; } status = argc >= 1 ? ejsGetInt(ejs, argv[0]) : 0; how = ejsToMulti(ejs, argc >= 2 ? ejsToString(ejs, argv[1]): ESV(empty)); if (scmp(how, "default") == 0) { mode = MPR_EXIT_DEFAULT; } else if (scmp(how, "immediate") == 0) { mode = MPR_EXIT_IMMEDIATE; } else if (scmp(how, "graceful") == 0) { mode = MPR_EXIT_GRACEFUL; } else { mode = MPR_EXIT_NORMAL; } mprTerminate(mode, status); ejsAttention(ejs); return 0; }
EjsAny *ejsThrowException(Ejs *ejs, EjsAny *error) { assert(error); ejs->exception = error; ejsAttention(ejs); return error; }
/* static function exit() */ static EjsObj *workerExit(Ejs *ejs, EjsWorker *unused, int argc, EjsObj **argv) { /* Setting exiting causes the VM to suspend processing this interpreter */ ejs->exiting = 1; ejsAttention(ejs); return 0; }
EjsObj *ejsThrowStopIteration(Ejs *ejs) { #if FUTURE ejs->exception = ejs->iterator; #else ejs->exception = ESV(StopIteration); #endif ejsAttention(ejs); return ejs->exception; }
EjsString *ejsThrowString(Ejs *ejs, cchar *fmt, ...) { va_list fmtArgs; char *msg; assert(fmt); va_start(fmtArgs, fmt); msg = sfmtv(fmt, fmtArgs); va_end(fmtArgs); /* Throwing a string will not create a stack frame */ ejs->exception = ejsCreateStringFromAsc(ejs, msg); ejsAttention(ejs); return ejs->exception; }
/* Exit the application static function exit(status: Number, how: String = "immediate"): void TODO - status is not implemented */ static EjsObj *app_exit(Ejs *ejs, EjsObj *unused, int argc, EjsObj **argv) { MprTicks timeout; cchar *how; int status, mode; if (ejs->dontExit) { ejsThrowStateError(ejs, "App.exit has been disabled"); return 0; } status = argc >= 1 ? ejsGetInt(ejs, argv[0]) : 0; timeout = argc >= 2 ? ejsGetInt(ejs, argv[1]) : 0; how = ejsToMulti(ejs, argc >= 2 ? ejsToString(ejs, argv[1]): ESV(empty)); if (scmp(how, "normal") == 0) { mode = 0; } else if (scmp(how, "abort") == 0) { mode = MPR_EXIT_ABORT; } else if (scmp(how, "safe") == 0) { mode = MPR_EXIT_SAFE; } else if (scmp(how, "restart") == 0) { mode = MPR_EXIT_RESTART; #if DEPRECATED || 1 } else if (scmp(how, "immediate") == 0) { mode = 0; } else if (scmp(how, "graceful") == 0) { mode = 0; if (argc <= 2) { timeout = 30 * 3000; } } else if (scmp(how, "default") == 0) { mode = 0; #endif } else { mode = 0; } mprShutdown(mode, status, timeout); ejsAttention(ejs); return 0; }