AddNamedItem() / GetScriptDispatch() broken in jscript9? RRS feed

  • Question

  • Hi All,

    I have a c++ application using jscript. I implemented a module functionality using AddNamedItem() / GetScriptDispatch().

    Now I switched to jscript9.

    GetScriptDispatch() fails with E_OUTOFMEMORY when I try to get the script dispatch for an item (module) I previously set via AddNamedItem() without the SCRIPTITEM_GLOBALMEMBERS flag.

    How to reproduce (error handling omitted):

    // create engine
    // CLSID_JScript9 is {16d51579-a30b-4c8b-a276-0ff4dc41e755}
    CComPtr<IActiveScript> script;
    HRESULT hr = ::CoCreateInstance(
    // pScriptSite is an IActiveScriptSite implementation
    hr = script->SetScriptSite(pScriptSite);
    // usually AddNamedItem would ask pScriptSite for the item,
    // without the SCRIPTITEM_GLOBALMEMBERS flag it doesn't
    hr = script->AddNamedItem(L"test", SCRIPTITEM_CODEONLY);
    CComPtr<IDispatch> scriptDispatch;
    hr = script->GetScriptDispatch(L"test", &scriptDispatch);
    // fails with E_OUTOFMEMORY
    Anybody knows something about this? Is this a (known) bug? I was able to debug this down to a call to ScriptEngine::RegisterNamedItem that in turn calls Js::JavascriptLibrary::AddMember only if the SCRIPTITEM_GLOBALMEMBERS is set.

    Any help is highly appreciated.

    • Edited by Imagiro Tuesday, July 2, 2013 3:11 PM
    Tuesday, July 2, 2013 7:50 AM

All replies

  • Does it make a difference if you also specify SCRIPTITEM_ISVISIBLE?
    Wednesday, July 3, 2013 12:43 AM
  • No, the only flag that helps is SCRIPTITEM_GLOBALMEMBERS.

    I tried all known flags and also all possible other flags (every bit in the DWORD) - no change.

    I tried changing the order of the calls (calling AddNamedItem / GetScriptDispatch later).

    I tried calling it in different states of the script engine (connected, initialized, disconnected etc).

    I tried changing the version via SCRIPTPROP_INVOKEVERSIONING.

    Nothing helps, except the SCRIPTITEM_GLOBALMEMBERS flag.

    Wednesday, July 3, 2013 9:47 AM
  • I added a sample project on github:
    Wednesday, July 3, 2013 1:08 PM
  • Hi Imagiro,

    I have the same problem. Have you solved it?


    Saturday, April 29, 2017 9:09 AM