From 4e7d587a1b120080cbe00f1b506e0f17a4eb5151 Mon Sep 17 00:00:00 2001 From: deuce <> Date: Tue, 23 Oct 2012 06:31:43 +0000 Subject: [PATCH] Add a get_size() global command which returns the stored size of an object. --- src/sbbs3/js_global.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/sbbs3/js_global.c b/src/sbbs3/js_global.c index fffad2fa62..b2384d379b 100644 --- a/src/sbbs3/js_global.c +++ b/src/sbbs3/js_global.c @@ -46,6 +46,7 @@ /* SpiderMonkey: */ #include <jsapi.h> +#include <jsdbgapi.h> #define MAX_ANSI_SEQ 16 #define MAX_ANSI_PARAMS 8 @@ -3487,6 +3488,18 @@ js_list_named_queues(JSContext *cx, uintN argc, jsval *arglist) return(JS_TRUE); } +static JSBool js_getsize(JSContext *cx, uintN argc, jsval *arglist) +{ + jsval *argv=JS_ARGV(cx, arglist); + + JSObject* tmp_obj=JSVAL_TO_OBJECT(argv[0]); + if(!tmp_obj) + return(JS_FALSE); + JS_SET_RVAL(cx, arglist, DOUBLE_TO_JSVAL(JS_GetObjectTotalSize(cx, tmp_obj))); + return(JS_TRUE); +} + + static JSBool js_flags_str(JSContext *cx, uintN argc, jsval *arglist) { @@ -3833,6 +3846,10 @@ static jsSyncMethodSpec js_global_functions[] = { "(returns number OR string) - (added in v3.13)") ,313 }, + {"get_size", js_getsize, 1, JSTYPE_NUMBER, JSDOCSTR("[number]") + ,JSDOCSTR("Gets the size in bytes the object uses in memory (forces GC) ") + ,314 + }, {0} }; -- GitLab