Mercurial > spidermonkey-playground
diff memory_profiler.cpp @ 56:b36c15de56f6
added a size property to info
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Wed, 24 Jun 2009 18:36:24 -0700 |
parents | 1aba1b7a0a2c |
children | 1fd63ee398dc |
line wrap: on
line diff
--- a/memory_profiler.cpp Wed Jun 24 18:32:14 2009 -0700 +++ b/memory_profiler.cpp Wed Jun 24 18:36:24 2009 -0700 @@ -1,4 +1,5 @@ #include "jsdhash.h" +#include "jsdbgapi.h" #include "memory_profiler.h" #include "server_socket.h" @@ -125,7 +126,8 @@ JSObject *info = JS_NewObject(cx, NULL, NULL, NULL); JSObject *target = (JSObject *) id; - JSClass *classp = JS_GET_CLASS(tracingState.tracer.context, target); + JSContext *targetCx = tracingState.tracer.context; + JSClass *classp = JS_GET_CLASS(targetCx, target); if (classp != NULL) { // TODO: Should really be using an interned string here or something. JSString *name = JS_NewStringCopyZ(cx, classp->name); @@ -140,6 +142,14 @@ } } + if (!JS_DefineProperty( + cx, info, "size", + INT_TO_JSVAL(JS_GetObjectTotalSize(targetCx, target)), + NULL, NULL, JSPROP_ENUMERATE)) { + JS_ReportOutOfMemory(cx); + return JS_FALSE; + } + *rval = OBJECT_TO_JSVAL(info); } else *rval = JSVAL_NULL;