Subj : Re: updated jsgen (maybe rc1?) To : Marcello Bastea-Forte From : Brendan Eich Date : Thu Jan 01 2004 10:01 pm Marcello Bastea-Forte wrote: > I store a single JSObject * with the classes so you can get the JSObject > from a C++ instance, although I'm looking at the Embedder's Guide, and > it's saying that multiple contexts can access the same object (so a > single JSObject* can be used on multiple contexts?) Of course -- context is stack and other execution state, not runtime-wide GC heap (where objects live). Runtime : process, address space :: context : thread. > I don't know if that init object can be used across contexts, but > looking at the code I see a bug. You wouldn't be able to initialize the > class for use in multiple (global) objects. The problem is with > JS_InitClass being called multiple times on the same class. 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. But to get back to your question: there's no need to call JS_InitClass(cx, obj, ...) more than once per obj. > Here I have to refer to the cached init object (I think), because JSInit > requires an object to create it in. Perhaps there's another way to do > this? 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. /be .