Subj : Re: updated jsgen (maybe rc1?) - beta 7 To : netscape.public.mozilla.jseng From : Marcello Bastea-Forte Date : Sun Jan 04 2004 01:10 am Ok, I finally updated jsgen (beta 7) to hopefully address all these problems. I've completely rewritten almost all of the documentation, and revised a ton of the code: http://www.cs.unm.edu/~cello/jsgen/ Changelog # Rewrote quite a few bits of jsgen: * Cleaned up code in general * Commented somewhat complex code in jsgenjs.cpp, and added some descriptions in jsgen.cpp * Removed object caching on JSInit (may be slightly slower, but fixes bugs) * Reworked how function/constructor arguments work so that it supports "special" arguments more cleanly * Removed context caching and related getContext() function, in favor of a special argument of type JSContext* * Made uintN argc and jsval* argv special arguments, so they can be used in combination with other arguments * Added ability to get the "this" JSObject* with special argument JSObject* _this * Added JSString* special type # Restructured docs * Cleaned up docs a bit * Added Usage Notes section * Added Makefile Pointers section ----------------- And in reply to the previous post... > Also, you're not worrying about thread safety -- do you plan to handle > multiple threads some day? Threads are the main motivation for > contexts; a single-threaded embedding might use more than one context > (in fact, Mozilla's DOM does), but strictly speaking it need not, > because there are no thread-safety hazards requiring more than one context. I'm not sure how I should be worrying about that. > But to get back to your question: there's no need to call > JS_InitClass(cx, obj, ...) more than once per obj. I know that there's no need, but it's more of a matter that my code *might* call initclass multiple times. In beta 7, I'm now using the following code: JSObject *JSTest::JSInit(JSContext *cx, JSObject *obj) { if (obj==NULL) obj = JS_GetGlobalObject(cx); jsval oldobj; if (JS_TRUE == JS_GetProperty(cx, obj, "JSTest", &oldobj) && !JSVAL_IS_VOID(oldobj)) return JSVAL_TO_OBJECT(oldobj); return JS_InitClass(cx, obj, NULL, &JSTest::_jsClass, JSTest::JSConstructor, 0, JSTest::_JSPropertySpec, JSTest::_JSFunctionSpec, JSTest::_JSPropertySpec_static, JSTest::_JSFunctionSpec_static); } This should theoretically check if the class was already initialized in obj and won't initialize it more than once. I don't know if this is the most efficient way to do it, but it works. > Explicitly parameterize? The JS API has many entry points whose > parameter lists begin (JSContext *cx, JSObject *obj...) and obj is the > parameter independent of cx telling in which object to define a class or > property, e.g. I'm also using JS_GetGlobalObject to get around not having a JSObject * all the time. I should probably add JSObject *obj as an optional parameter on getJSObject(JSContext *cx). Marcello .