none
AddNamedItem() / GetScriptDispatch() broken in jscript9?

    Frage

  • 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(
      CLSID_JScript9,
      NULL,
      CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
      IID_IActiveScript,
      (void**)&script.p);
    
    // 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.

    • Bearbeitet Imagiro Dienstag, 2. Juli 2013 15:11
    Dienstag, 2. Juli 2013 07:50

Alle Antworten

  • Does it make a difference if you also specify SCRIPTITEM_ISVISIBLE?
    Mittwoch, 3. Juli 2013 00:43
  • 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.

    Mittwoch, 3. Juli 2013 09:47
  • I added a sample project on github: https://github.com/IUnknown68/ascptest
    Mittwoch, 3. Juli 2013 13:08
  • Hi Imagiro,

    I have the same problem. Have you solved it?

    Dimitris

    Samstag, 29. April 2017 09:09