[mw-devel] MW3 r1101 - trunk/src

welshbyte at sucs.org welshbyte at sucs.org
Thu Nov 12 22:04:24 GMT 2009


Author: welshbyte
Date: 2009-11-12 22:04:24 +0000 (Thu, 12 Nov 2009)
New Revision: 1101

Modified:
   trunk/src/js.c
Log:
- Change the "persistent" js object to "store".
- Return undefined (JSVAL_VOID) when store.foo isn't in the db.


Modified: trunk/src/js.c
===================================================================
--- trunk/src/js.c	2009-11-12 09:11:12 UTC (rev 1100)
+++ trunk/src/js.c	2009-11-12 22:04:24 UTC (rev 1101)
@@ -1041,18 +1041,22 @@
 	return retval;
 }
 
-static JSBool js_persistent_get(JSContext *cx, JSObject *obj, jsval idval, jsval *vp)
+static JSBool js_store_get(JSContext *cx, JSObject *obj, jsval idval, jsval *vp)
 {
 	if (JSVAL_IS_STRING(idval)) {
 		char *key = JS_GetStringBytes(JS_ValueToString(cx, idval));
 		char *val = userdb_get(USERDB_PUBLIC, user->name, key);
-		JSString *str = JS_NewStringCopyZ(cx, val);
-		*vp = STRING_TO_JSVAL(str);
+		if (val == NULL) {
+			*vp = JSVAL_VOID;
+		} else {
+			JSString *str = JS_NewStringCopyZ(cx, val);
+			*vp = STRING_TO_JSVAL(str);
+		}
 	}
 	return JS_TRUE;
 }
 
-static JSBool js_persistent_set(JSContext *cx, JSObject *obj, jsval idval, jsval *vp)
+static JSBool js_store_set(JSContext *cx, JSObject *obj, jsval idval, jsval *vp)
 {
 	if (JSVAL_IS_STRING(idval) && JSVAL_IS_STRING(*vp)) {
 		char *key = JS_GetStringBytes(JS_ValueToString(cx, idval));
@@ -1062,9 +1066,9 @@
 	return JS_TRUE;
 }
 
-static JSClass js_persistentclass = {
-	"persistent", JSCLASS_HAS_PRIVATE,
-	JS_PropertyStub, JS_PropertyStub, js_persistent_get, js_persistent_set,
+static JSClass js_storeclass = {
+	"store", JSCLASS_HAS_PRIVATE,
+	JS_PropertyStub, JS_PropertyStub, js_store_get, js_store_set,
 	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
 	JSCLASS_NO_OPTIONAL_MEMBERS
 };
@@ -1398,7 +1402,7 @@
 	JS_DefineProperty(jscx, jsroot, "K_BROADCAST", INT_TO_JSVAL(K_BROADCAST), NULL, NULL, JSPROP_READONLY|JSPROP_PERMANENT);
 	
 	/* A stateful object backed with persistent db storage */
-	JS_DefineObject(jscx, jsroot, "persistent", &js_persistentclass, NULL, JSPROP_READONLY|JSPROP_PERMANENT);
+	JS_DefineObject(jscx, jsroot, "store", &js_storeclass, NULL, JSPROP_READONLY|JSPROP_PERMANENT);
 
 	/* not for bbs user */
 	if (is_local) {




More information about the mw-devel mailing list