From 240ca36cf2a3ceb89e46b73486865a4a57339c89 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 20 Jul 2005 06:20:36 +0000 Subject: r8635: make object inheritance with the builtin objects easy by allowing callers to optionally supply an existing object to add the properties to. So you can do: var rpc = samr_init(); lsa_init(rpc); and you end up with 'rpc' having both the samr and lsa functions and constants available. (This used to be commit 6a1ed328e27769bd52899fc2437a43fc17104eff) --- source4/scripting/ejs/mprutil.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source4/scripting/ejs/mprutil.c') diff --git a/source4/scripting/ejs/mprutil.c b/source4/scripting/ejs/mprutil.c index f9813f2597..14d120c45a 100644 --- a/source4/scripting/ejs/mprutil.c +++ b/source4/scripting/ejs/mprutil.c @@ -403,3 +403,17 @@ void mprSetThisPtr(int eid, const char *name, void *ptr) struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0); mprSetPtrChild(this, name, ptr); } + +/* + used by object xxx_init() routines to allow for the caller + to supply a pre-existing object to add properties to, + or create a new object. This makes inheritance easy +*/ +struct MprVar *mprInitObject(int eid, const char *name, int argc, struct MprVar **argv) +{ + if (argc > 0 && mprVarIsObject(argv[0]->type)) { + return argv[0]; + } + mpr_Return(eid, mprObject(name)); + return ejsGetReturnValue(eid); +} -- cgit