From 42bede58bc4c2c64c3e224e054cd5b9b06d521f8 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Sun, 30 Nov 2025 01:26:59 -0600 Subject: [PATCH] js doc --- scripts/js.c | 8 ++++++++ source/qjs_macros.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/js.c b/scripts/js.c index 3b9bbbfc..6b51df38 100644 --- a/scripts/js.c +++ b/scripts/js.c @@ -5,6 +5,7 @@ JSC_CCALL(os_mem_limit, JS_SetMemoryLimit(JS_GetRuntime(js), js2number(js,argv[0 JSC_CCALL(os_gc_threshold, JS_SetGCThreshold(JS_GetRuntime(js), js2number(js,argv[0]))) JSC_CCALL(os_max_stacksize, JS_SetMaxStackSize(JS_GetRuntime(js), js2number(js,argv[0]))) +// Compute the approximate size of a single JS value in memory. JSC_CCALL(os_calc_mem, JSMemoryUsage mu; JS_ComputeMemoryUsage(JS_GetRuntime(js),&mu); @@ -37,19 +38,23 @@ JSC_CCALL(os_calc_mem, JS_SetPropertyStr(js,ret,"binary_object_size",number2js(js,mu.binary_object_size)); ) +// Evaluate a string of JavaScript code in the current QuickJS context. JSC_SSCALL(os_eval, ret = JS_Eval(js,str2,strlen(str2),str, 0); ) +// Compile a string of JavaScript code into a function object. JSC_SSCALL(js_compile, ret = JS_Eval(js, str2, strlen(str2), str, JS_EVAL_FLAG_COMPILE_ONLY); ) +// Evaluate a function object in the current QuickJS context. JSC_CCALL(js_eval_compile, JS_DupValue(js,argv[0]); ret = JS_EvalFunction(js, argv[0]); ) +// Compile a function object into a bytecode blob. JSC_CCALL(js_compile_blob, JSRuntime *rt = JS_GetRuntime(js); // JS_SetStripInfo(rt, JS_STRIP_SOURCE); @@ -63,6 +68,7 @@ JSC_CCALL(js_compile_blob, js_free(js, data); ) +// Compile a bytecode blob into a function object. JSC_CCALL(js_compile_unblob, size_t size; void *data = js_get_blob_data(js, &size, argv[0]); @@ -71,10 +77,12 @@ JSC_CCALL(js_compile_unblob, return JS_ReadObject(js, data, size, JS_READ_OBJ_BYTECODE); ) +// Disassemble a function object into a string. JSC_CCALL(js_disassemble, return js_debugger_fn_bytecode(js, argv[0]); ) +// Return metadata about a given function. JSC_CCALL(js_fn_info, return js_debugger_fn_info(js, argv[0]); ) diff --git a/source/qjs_macros.h b/source/qjs_macros.h index 7e0aed35..3c766f64 100644 --- a/source/qjs_macros.h +++ b/source/qjs_macros.h @@ -194,7 +194,7 @@ JSValue NAME##2js(JSContext *js, int enumval) { \ } #define CELL_USE_INIT(c) \ -JSValue CELL_USE_NAME(JSContext *js) { c } +JSValue CELL_USE_NAME(JSContext *js) { do { c ; } while(0); } #define CELL_USE_FUNCS(FUNCS) \ JSValue CELL_USE_NAME(JSContext *js) { \