Subj : Re: Iterate all functions in script To : Forest Carlisle From : Brendan Eich Date : Thu May 06 2004 09:23 pm Forest Carlisle wrote: > Thanks for the quick reply. This is what I came up with. JS_Enumerate always > returns a 0 length array. > > JSIdArray* ida = JS_Enumerate(m_pContext, m_pGlobal); // tried both global > and script object > if (ida) > { > for (int i = 0, len = ida->length; i < len; i++) > { > jsid id = ida->vector[i]; > > // convert id to jsval and call JS_ValueToFunction then > JS_GetFunctionId > } > } Have you evaluated the script containing the functions? > > This code works to get a named function. > > void* mark = JS_ARENA_MARK(&m_pContext->tempPool); Please, no. Don't include private header files (jscntxt.h, jsarena.h), don't use private APIs. > > // get the Detect function > jsval fval; > if (JS_GetProperty(m_pContext, m_pGlobal, "Detection", &fval)) > { > if (JSVAL_IS_FUNCTION(m_pContext, fval)) > { > JSObject* pFunObj = JSVAL_TO_OBJECT(fval); ASSERT(pFunObj); > JSFunction* pFun = (JSFunction*) JS_GetPrivate(m_pContext, > pFunObj); ASSERT(pFun); > } > } > > Any ideas would be much appriciated. Is this before or after you've evaluated or compiled *and* executed the script containing the functions? /be .