added JS_PrintValue() and use it in console.log(), print() and the REPL (#256)

This commit is contained in:
Fabrice Bellard
2025-04-30 13:40:15 +02:00
parent 30fe3de91d
commit be06b3e92b
5 changed files with 752 additions and 440 deletions

View File

@@ -1113,6 +1113,23 @@ int JS_SetModuleExport(JSContext *ctx, JSModuleDef *m, const char *export_name,
int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
const JSCFunctionListEntry *tab, int len);
/* debug value output */
typedef struct {
JS_BOOL show_hidden : 8; /* only show enumerable properties */
JS_BOOL show_closure : 8; /* show closure variables */
JS_BOOL raw_dump : 8; /* avoid doing autoinit and avoid any malloc() call (for internal use) */
uint32_t max_depth; /* recurse up to this depth, 0 = no limit */
uint32_t max_string_length; /* print no more than this length for
strings, 0 = no limit */
uint32_t max_item_count; /* print no more than this count for
arrays or objects, 0 = no limit */
} JSPrintValueOptions;
void JS_PrintValueSetDefaultOptions(JSPrintValueOptions *options);
void JS_PrintValueRT(JSRuntime *rt, FILE *fo, JSValueConst val, const JSPrintValueOptions *options);
void JS_PrintValue(JSContext *ctx, FILE *fo, JSValueConst val, const JSPrintValueOptions *options);
#undef js_unlikely
#undef js_force_inline