1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

[quickjs] console.exit

This commit is contained in:
Witold Filipczyk 2024-04-11 19:10:41 +02:00
parent 6adca27072
commit 58515c8df4

View File

@ -13,6 +13,7 @@
#include "ecmascript/ecmascript.h" #include "ecmascript/ecmascript.h"
#include "ecmascript/quickjs.h" #include "ecmascript/quickjs.h"
#include "ecmascript/quickjs/console.h" #include "ecmascript/quickjs/console.h"
#include "main/main.h"
#define DEBUG 0 #define DEBUG 0
@ -113,6 +114,20 @@ js_console_error(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *
return js_console_log_common(ctx, this_val, argc, argv, console_error_filename); return js_console_log_common(ctx, this_val, argc, argv, console_error_filename);
} }
static JSValue
js_console_exit(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
if (!get_cmd_opt_bool("test")) {
return JS_UNDEFINED;
}
program.retval = JS_ToBool(ctx, argv[0]) ? RET_ERROR : RET_OK;
program.terminate = 1;
return JS_UNDEFINED;
}
static JSValue static JSValue
js_console_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) js_console_toString(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{ {
@ -128,6 +143,7 @@ static const JSCFunctionListEntry js_console_funcs[] = {
JS_CFUNC_DEF("assert", 2, js_console_assert), JS_CFUNC_DEF("assert", 2, js_console_assert),
JS_CFUNC_DEF("log", 1, js_console_log), JS_CFUNC_DEF("log", 1, js_console_log),
JS_CFUNC_DEF("error", 1, js_console_error), JS_CFUNC_DEF("error", 1, js_console_error),
JS_CFUNC_DEF("exit", 1, js_console_exit),
JS_CFUNC_DEF("toString", 0, js_console_toString) JS_CFUNC_DEF("toString", 0, js_console_toString)
}; };