diff options
author | Fabrice Bellard <fabrice@bellard.org> | 2025-05-05 15:59:04 +0200 |
---|---|---|
committer | Fabrice Bellard <fabrice@bellard.org> | 2025-05-05 15:59:04 +0200 |
commit | 0a6160d7b3290710daf2dbeaba73d4d50e93b684 (patch) | |
tree | b4966d7b811806532b268fce6d48a1a58aac3ba4 /quickjs-libc.c | |
parent | 11d076fac6691da27df021872cdb12ec44d022e6 (diff) | |
download | quickjs-0a6160d7b3290710daf2dbeaba73d4d50e93b684.tar.gz quickjs-0a6160d7b3290710daf2dbeaba73d4d50e93b684.zip |
avoid relying on 'FILE *' in JS_PrintValue() API
Diffstat (limited to 'quickjs-libc.c')
-rw-r--r-- | quickjs-libc.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/quickjs-libc.c b/quickjs-libc.c index b59c6ac..2b26e85 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -160,6 +160,7 @@ static BOOL my_isdigit(int c) return (c >= '0' && c <= '9'); } +/* XXX: use 'o' and 'O' for object using JS_PrintValue() ? */ static JSValue js_printf_internal(JSContext *ctx, int argc, JSValueConst *argv, FILE *fp) { @@ -1083,10 +1084,16 @@ static JSValue js_std_file_printf(JSContext *ctx, JSValueConst this_val, return js_printf_internal(ctx, argc, argv, f); } +static void js_print_value_write(void *opaque, const char *buf, size_t len) +{ + FILE *fo = opaque; + fwrite(buf, 1, len, fo); +} + static JSValue js_std_file_printObject(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { - JS_PrintValue(ctx, stdout, argv[0], NULL); + JS_PrintValue(ctx, js_print_value_write, stdout, argv[0], NULL); return JS_UNDEFINED; } @@ -3914,7 +3921,7 @@ static JSValue js_print(JSContext *ctx, JSValueConst this_val, fwrite(str, 1, len, stdout); JS_FreeCString(ctx, str); } else { - JS_PrintValue(ctx, stdout, v, NULL); + JS_PrintValue(ctx, js_print_value_write, stdout, v, NULL); } } putchar('\n'); @@ -4028,7 +4035,7 @@ void js_std_free_handlers(JSRuntime *rt) static void js_std_dump_error1(JSContext *ctx, JSValueConst exception_val) { - JS_PrintValue(ctx, stderr, exception_val, NULL); + JS_PrintValue(ctx, js_print_value_write, stderr, exception_val, NULL); fputc('\n', stderr); } |