diff --git a/src/sbbs3/js_file_area.c b/src/sbbs3/js_file_area.c index e8e1ef0643a4a48531ba59618712303207071918..7fd3a81c6c7ededc38c6ac4cb9714203a143c4ad 100644 --- a/src/sbbs3/js_file_area.c +++ b/src/sbbs3/js_file_area.c @@ -77,6 +77,10 @@ JSObject* DLLCALL js_CreateFileAreaObject(JSContext* cx, JSObject* parent, scfg_ uint l,d; JSBool found; + /* Return existing object if it's already been created */ + if(JS_GetProperty(cx,parent,"file_area",&val)) + return(JSVAL_TO_OBJECT(val)); + areaobj = JS_DefineObject(cx, parent, "file_area", &js_file_area_class, NULL, 0); if(areaobj==NULL) diff --git a/src/sbbs3/js_msg_area.c b/src/sbbs3/js_msg_area.c index 2cfcf25d55ddfabfa108586e2e5ab4de7df8724c..18ba32c2c0c568e60aea18f31cba60966801c66c 100644 --- a/src/sbbs3/js_msg_area.c +++ b/src/sbbs3/js_msg_area.c @@ -129,6 +129,10 @@ JSObject* DLLCALL js_CreateMsgAreaObject(JSContext* cx, JSObject* parent, scfg_t uint c,l,d; JSBool found; + /* Return existing object if it's already been created */ + if(JS_GetProperty(cx,parent,"msg_area",&val)) + return(JSVAL_TO_OBJECT(val)); + areaobj = JS_DefineObject(cx, parent, "msg_area", &js_msg_area_class, NULL, 0); if(areaobj==NULL) diff --git a/src/sbbs3/js_user.c b/src/sbbs3/js_user.c index a5125f442baa06f16f27ba50865b9c01e099f95c..1da4e854a749f103aecb89f74d07eb104ab22565 100644 --- a/src/sbbs3/js_user.c +++ b/src/sbbs3/js_user.c @@ -747,18 +747,23 @@ JSObject* DLLCALL js_CreateUserObject(JSContext* cx, JSObject* parent, scfg_t* c JSObject* statsobj; JSObject* securityobj; private_t* p; + jsval val; - if((p=(private_t*)malloc(sizeof(private_t)))==NULL) - return(NULL); - - p->cfg = cfg; - p->usernumber = usernumber; + /* Return existing user object if it's already been created */ + if(JS_GetProperty(cx,parent,name,&val)) + return(JSVAL_TO_OBJECT(val)); userobj = JS_DefineObject(cx, parent, name, &js_user_class, NULL, 0); if(userobj==NULL) return(NULL); + if((p=(private_t*)malloc(sizeof(private_t)))==NULL) + return(NULL); + + p->cfg = cfg; + p->usernumber = usernumber; + JS_SetPrivate(cx, userobj, p); JS_DefineProperties(cx, userobj, js_user_properties); @@ -769,8 +774,10 @@ JSObject* DLLCALL js_CreateUserObject(JSContext* cx, JSObject* parent, scfg_t* c statsobj = JS_DefineObject(cx, userobj, "stats" ,&js_user_stats_class, NULL, 0); - if(statsobj==NULL) + if(statsobj==NULL) { + free(p); return(NULL); + } JS_SetPrivate(cx, statsobj, p); @@ -780,8 +787,10 @@ JSObject* DLLCALL js_CreateUserObject(JSContext* cx, JSObject* parent, scfg_t* c securityobj = JS_DefineObject(cx, userobj, "security" ,&js_user_security_class, NULL, 0); - if(securityobj==NULL) + if(securityobj==NULL) { + free(p); return(NULL); + } JS_SetPrivate(cx, securityobj, p);