Subj : Re: Help with embedding spidermonkey please!!! To : netscape.public.mozilla.jseng From : Brendan Eich Date : Sat Nov 08 2003 10:23 am Georg Maaß wrote: > Blacksage wrote: > >> ScriptEngine::ScriptEngine() >> { >> cout << "Contstructor Start" << endl; >> >> m_JSRunTime = NULL; >> m_JSContext = NULL; >> m_GlobalObject = NULL; >> >> m_JSRunTime = JS_NewRuntime(4 * 1024 * 1024); >> m_JSContext = JS_NewContext(m_JSRunTime, 8 * 1024); >> >> JSClass globalClass = > > > naming a local variable globalClass does not make it global. After the > ScriptEngine constructor finished its work, the global object no > longer exists, because it was a local object. Define it as global > variable of the application [awful] or as member of the ScriptEngine > class [more flexible]. Do not define it as local variable of the > ScriptEngine constructor. This must crash or at least cause > unpredictionable results. Thanks, Georg. I wanted to add an explanation of why this is so: the JS engine uses the *address* of each JSClass as the unique-per-class (among all runtimes!) [[Class]] internal property value (see ECMA-262). This internal property of all native objects tells us what class each belongs to, via pointer comparison or, more frequently, via calls through clasp->getProperty, etc. (or clasp->getObjectOps()->...). Make each JSClass static and you'll be happy. /be .