Subj : spidermonkey: api question To : netscape.public.mozilla.jseng From : Jens Thiele Date : Fri Jan 07 2005 11:37 am Hi, this is related to: http://groups.google.de/groups?selm=8nhdmc.rk2.ln%40karme.myfqdn.de i am trying again to remove this hack: // we want to use the same [[Class]] but a different constructor // alternatively we could nearly duplicate JS_InitClass (but perhaps // this would also require to use non-public spidermonkey API functions) const char *tmp=BaseWrapper_class.name; BaseWrapper_class.name="Sub"; JSObject* subproto; subproto=JS_InitClass(cx,global,BaseWrapper_proto, &BaseWrapper_class, SubWrapper_cons, 0, NULL, SubWrapper_methods, NULL, NULL); BaseWrapper_class.name=tmp; if (!subproto) return JS_FALSE; return JS_TRUE; (used here: ) it seems it is possible to duplicate enough of JS_InitClass with public API functions - except that one cannot set the clasp member of the JSFunction struct of the constructor: // nearly a duplicate of JS_InitClass JSObject* ejs_WrapClass(JSContext *cx, JSObject *obj, const char* consname, JSObject *parent_proto, JSNative constructor, JSFunctionSpec *methods) { // create prototype object JSObject* proto; if (!(proto=JS_NewObject(cx, NULL, parent_proto, obj))) return NULL; // constructor JSFunction *jscons; if (!(jscons=JS_DefineFunction(cx, obj, consname, constructor, 0, 0))) return NULL; // NOT PART OF PUBLIC API jscons->clasp = &CppClass; // set constructor.prototype if (!JS_DefineProperty(cx, jscons->object, "prototype", OBJECT_TO_JSVAL(proto), JS_PropertyStub, JS_PropertyStub, JSPROP_READONLY | JSPROP_PERMANENT)) return NULL; // set constructor.prototype.constructor if (!JS_DefineProperty(cx, proto, "constructor", OBJECT_TO_JSVAL(jscons->object), JS_PropertyStub, JS_PropertyStub, JSPROP_READONLY | JSPROP_PERMANENT)) return NULL; if (!JS_DefineFunctions(cx, proto, methods)) return NULL; return proto; } did I miss something? could something like JS_SetClass(JSFunction *) be added to the public API? Jens .