r8489: neaten up the object handling
authorAndrew Tridgell <tridge@samba.org>
Fri, 15 Jul 2005 11:23:17 +0000 (11:23 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:23:09 +0000 (13:23 -0500)
(This used to be commit ccf20b2b13b11ac07b59988809b6c5160388a616)

source4/scripting/ejs/mprutil.c
source4/scripting/ejs/smbcalls_ldb.c

index f25064f245d06db0e808ab774617d3029a65bbe2..f9813f259762b97c22dd10e37989a24ed451a080 100644 (file)
@@ -385,3 +385,21 @@ void mpr_ReturnString(int eid, const char *s)
 {
        mprSetVar(obj, name, mprCreateStringCFunctionVar(fn, obj, MPR_VAR_SCRIPT_HANDLE));
 }
+
+/*
+  get a poiner in the current object
+*/
+void *mprGetThisPtr(int eid, const char *name)
+{
+       struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0);
+       return mprGetPtr(this, name);
+}
+
+/*
+  set a pointer as a child of the local object
+*/
+void mprSetThisPtr(int eid, const char *name, void *ptr)
+{
+       struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0);
+       mprSetPtrChild(this, name, ptr);
+}
index 924a9665b3bec42135f004ee4be688cfb83079e7..cdf3b3dd6ce6ba9956a6c05ba2a48e42d38ab6a5 100644 (file)
@@ -30,8 +30,7 @@
  */
 static struct ldb_context *ejs_ldb_db(int eid)
 {
-       struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0);
-       struct ldb_context *ldb = mprGetPtr(this, "db");
+       struct ldb_context *ldb = mprGetThisPtr(eid, "db");
        if (ldb == NULL) {
                ejsSetErrorMsg(eid, "invalid ldb connection");
        }
@@ -227,7 +226,6 @@ static int ejs_ldbConnect(MprVarHandle eid, int argc, char **argv)
 {
        struct ldb_context *ldb;
        const char *dbfile;
-       struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0);
 
        if (argc != 1) {
                ejsSetErrorMsg(eid, "ldb.connect invalid arguments");
@@ -241,7 +239,7 @@ static int ejs_ldbConnect(MprVarHandle eid, int argc, char **argv)
                ejsSetErrorMsg(eid, "ldb.connect failed to open %s", dbfile);
        }
 
-       mprSetPtrChild(this, "db", ldb);
+       mprSetThisPtr(eid, "db", ldb);
        mpr_Return(eid, mprCreateBoolVar(ldb != NULL));
        return 0;
 }