We've been using active scripting in our browser extension (BHO) for a while with the old JScript engine (CLSID_JScript), and we recently decided to support the new IE9 script engine (Chakra) as well. One thing we do is add symbols to the engine using AddNamedItem
with the SCRIPTITEM_CODEONLY
option to create our own modules (namespaces). Unfortunately, we haven't been able to get this to work with Chakra. Even the most trivial example where we add a symbol and immediately retrieve its script dispatch yields an E_OUTOFMEMORY
error.
if (SUCCEEDED(hr)) {
hr = scriptEngine->AddNamedItem(L"test", SCRIPTITEM_CODEONLY);
}
if (SUCCEEDED(hr)) {
hr = scriptEngine->GetScriptDispatch(L"test", &scriptDispatch);
}
The GetScriptDispatch
call returns the error. You can see the whole example on Github.
I set breakpoints on all the IActiveScriptSite
methods and the only ones that are called are GetLCID
and OnStateChange
, so don't think the site implementation is the problem.
I've looked at every example I can find and tried everything I can think of, including setting the engine state to SCRIPTSTATE_CONNECTED
manually, implementing any additional interfaces that it QIs for, etc. I even tried returning a valid LCID
. Nothing seems to make a difference.
Any idea what gives? I assume this basic example should work in Chakra.