This commit is contained in:
2025-11-30 01:26:59 -06:00
parent 3800c23eae
commit 42bede58bc
2 changed files with 9 additions and 1 deletions

View File

@@ -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_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]))) 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, JSC_CCALL(os_calc_mem,
JSMemoryUsage mu; JSMemoryUsage mu;
JS_ComputeMemoryUsage(JS_GetRuntime(js),&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)); 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, JSC_SSCALL(os_eval,
ret = JS_Eval(js,str2,strlen(str2),str, 0); ret = JS_Eval(js,str2,strlen(str2),str, 0);
) )
// Compile a string of JavaScript code into a function object.
JSC_SSCALL(js_compile, JSC_SSCALL(js_compile,
ret = JS_Eval(js, str2, strlen(str2), str, JS_EVAL_FLAG_COMPILE_ONLY); 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, JSC_CCALL(js_eval_compile,
JS_DupValue(js,argv[0]); JS_DupValue(js,argv[0]);
ret = JS_EvalFunction(js, argv[0]); ret = JS_EvalFunction(js, argv[0]);
) )
// Compile a function object into a bytecode blob.
JSC_CCALL(js_compile_blob, JSC_CCALL(js_compile_blob,
JSRuntime *rt = JS_GetRuntime(js); JSRuntime *rt = JS_GetRuntime(js);
// JS_SetStripInfo(rt, JS_STRIP_SOURCE); // JS_SetStripInfo(rt, JS_STRIP_SOURCE);
@@ -63,6 +68,7 @@ JSC_CCALL(js_compile_blob,
js_free(js, data); js_free(js, data);
) )
// Compile a bytecode blob into a function object.
JSC_CCALL(js_compile_unblob, JSC_CCALL(js_compile_unblob,
size_t size; size_t size;
void *data = js_get_blob_data(js, &size, argv[0]); 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); return JS_ReadObject(js, data, size, JS_READ_OBJ_BYTECODE);
) )
// Disassemble a function object into a string.
JSC_CCALL(js_disassemble, JSC_CCALL(js_disassemble,
return js_debugger_fn_bytecode(js, argv[0]); return js_debugger_fn_bytecode(js, argv[0]);
) )
// Return metadata about a given function.
JSC_CCALL(js_fn_info, JSC_CCALL(js_fn_info,
return js_debugger_fn_info(js, argv[0]); return js_debugger_fn_info(js, argv[0]);
) )

View File

@@ -194,7 +194,7 @@ JSValue NAME##2js(JSContext *js, int enumval) { \
} }
#define CELL_USE_INIT(c) \ #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) \ #define CELL_USE_FUNCS(FUNCS) \
JSValue CELL_USE_NAME(JSContext *js) { \ JSValue CELL_USE_NAME(JSContext *js) { \