mirror of
https://github.com/bellard/quickjs.git
synced 2025-09-30 23:07:42 +03:00
added JS_PrintValue() and use it in console.log(), print() and the REPL (#256)
This commit is contained in:
@@ -376,22 +376,29 @@ static JSValue js_print(JSContext *ctx, JSValueConst this_val,
|
||||
int argc, JSValueConst *argv)
|
||||
{
|
||||
int i;
|
||||
const char *str;
|
||||
|
||||
JSValueConst v;
|
||||
|
||||
if (outfile) {
|
||||
for (i = 0; i < argc; i++) {
|
||||
if (i != 0)
|
||||
fputc(' ', outfile);
|
||||
str = JS_ToCString(ctx, argv[i]);
|
||||
if (!str)
|
||||
return JS_EXCEPTION;
|
||||
if (!strcmp(str, "Test262:AsyncTestComplete")) {
|
||||
async_done++;
|
||||
} else if (strstart(str, "Test262:AsyncTestFailure", NULL)) {
|
||||
async_done = 2; /* force an error */
|
||||
v = argv[i];
|
||||
if (JS_IsString(v)) {
|
||||
const char *str;
|
||||
size_t len;
|
||||
str = JS_ToCStringLen(ctx, &len, v);
|
||||
if (!str)
|
||||
return JS_EXCEPTION;
|
||||
if (!strcmp(str, "Test262:AsyncTestComplete")) {
|
||||
async_done++;
|
||||
} else if (strstart(str, "Test262:AsyncTestFailure", NULL)) {
|
||||
async_done = 2; /* force an error */
|
||||
}
|
||||
fwrite(str, 1, len, outfile);
|
||||
JS_FreeCString(ctx, str);
|
||||
} else {
|
||||
JS_PrintValue(ctx, outfile, v, NULL);
|
||||
}
|
||||
fputs(str, outfile);
|
||||
JS_FreeCString(ctx, str);
|
||||
}
|
||||
fputc('\n', outfile);
|
||||
}
|
||||
|
Reference in New Issue
Block a user