void IDispatchAPI::getMemberNames(std::vector<std::string> &nameVector) const { if (!host->isMainThread()) { typedef void (FB::JSAPI::*getMemberNamesType)(std::vector<std::string> *nameVector) const; host->CallOnMainThread(boost::bind((getMemberNamesType)&FB::JSAPI::getMemberNames, this, &nameVector)); return; } if (is_JSAPI) { FB::JSAPIPtr tmp = inner.lock(); if (tmp) tmp->getMemberNames(nameVector); return; } CComQIPtr<IDispatchEx> dispatchEx(m_obj); if (!dispatchEx) { throw FB::script_error("Cannot enumerate members; IDispatchEx not supported"); } DISPID dispid = DISPID_STARTENUM; while (dispatchEx->GetNextDispID(fdexEnumAll, dispid, &dispid) != S_FALSE) { if (dispid < 0) { continue; } CComBSTR memberName; if (SUCCEEDED(dispatchEx->GetMemberName(dispid, &memberName))) { std::wstring name(memberName); nameVector.push_back(FB::wstring_to_utf8(name)); } } }
void IDispatchAPI::getMemberNames(std::vector<std::string> &nameVector) const { if (!host->isMainThread()) { typedef void (FB::JSAPI::*getMemberNamesType)(std::vector<std::string> *nameVector) const; host->CallOnMainThread(boost::bind((getMemberNamesType)&FB::JSAPI::getMemberNames, this, &nameVector)); return; } if (is_JSAPI) { FB::JSAPIPtr tmp = inner.lock(); if (tmp) tmp->getMemberNames(nameVector); return; } HRESULT hr; DISPID dispid; CComQIPtr<IDispatchEx> dispex(m_obj); if (!dispex) { throw FB::script_error("Cannot enumerate members; IDispatchEx not supported"); } hr = dispex->GetNextDispID(fdexEnumAll, DISPID_STARTENUM, &dispid); while (SUCCEEDED(hr) && dispid > -1) { CComBSTR curName; hr = dispex->GetMemberName(dispid, &curName); std::wstring wStr(curName); nameVector.push_back(FB::wstring_to_utf8(wStr)); hr = dispex->GetNextDispID(fdexEnumAll, dispid, &dispid); } }
void NPObjectAPI::getMemberNames(std::vector<std::string> &nameVector) const { if (m_browser.expired()) return; NpapiBrowserHostPtr browser(getHost()); if (!browser->isMainThread()) { typedef void (FB::JSAPI::*getMemberNamesType)(std::vector<std::string> *nameVector) const; browser->CallOnMainThread(boost::bind((getMemberNamesType)&FB::JSAPI::getMemberNames, this, &nameVector)); return; } if (is_JSAPI) { FB::JSAPIPtr tmp = inner.lock(); if (tmp) tmp->getMemberNames(nameVector); return; } NPIdentifier *idArray(NULL); uint32_t count; browser->Enumerate(obj, &idArray, &count); for (uint32_t i = 0; i < count; i++) { nameVector.push_back(browser->StringFromIdentifier(idArray[i])); } browser->MemFree(idArray); }