Add virtual CreateJSObject to IGUIObject, split from GetJSObject, so that inheriting classes can extend the JS object upon construction, refs #5442, D2136.
Remove the comment from53bcba3368
that allures the reader to believe there is a memory leak which is not and has not been the case, refs D1700. Remove the useless JSAutoRequest from GetJSObject if the object was constructed already (performance improvement), following cx assignment in4b1297b328
, following JSAutoRequest addition ine9e05f4efc
(that also had removed other useles JSAutoRequest calls but not this one). Don't change JS::PersistentRooted to JS::Heap until SpiderMonkey is updated, refs D1700. Provide access to GUI, ScriptHandlers and JSObject for inheriting classes. This was SVN commit r22593.
This commit is contained in:
parent
2510e1b82e
commit
df489f2500
@ -515,18 +515,22 @@ void IGUIObject::ScriptEvent(const CStr& Action, JS::HandleValueArray paramData)
|
||||
JS_ReportError(cx, "Errors executing script action \"%s\"", Action.c_str());
|
||||
}
|
||||
|
||||
JSObject* IGUIObject::GetJSObject()
|
||||
void IGUIObject::CreateJSObject()
|
||||
{
|
||||
JSContext* cx = m_pGUI->GetScriptInterface()->GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
m_JSObject.init(cx, m_pGUI->GetScriptInterface()->CreateCustomObject("GUIObject"));
|
||||
JS_SetPrivate(m_JSObject.get(), this);
|
||||
}
|
||||
|
||||
JSObject* IGUIObject::GetJSObject()
|
||||
{
|
||||
// Cache the object when somebody first asks for it, because otherwise
|
||||
// we end up doing far too much object allocation. TODO: Would be nice to
|
||||
// not have these objects hang around forever using up memory, though.
|
||||
// we end up doing far too much object allocation.
|
||||
if (!m_JSObject.initialized())
|
||||
{
|
||||
m_JSObject.init(cx, m_pGUI->GetScriptInterface()->CreateCustomObject("GUIObject"));
|
||||
JS_SetPrivate(m_JSObject.get(), this);
|
||||
}
|
||||
CreateJSObject();
|
||||
|
||||
return m_JSObject.get();
|
||||
}
|
||||
|
||||
|
@ -243,6 +243,12 @@ public:
|
||||
*/
|
||||
void RegisterScriptHandler(const CStr& Action, const CStr& Code, CGUI* pGUI);
|
||||
|
||||
/**
|
||||
* Creates the JS Object representing this page upon first use.
|
||||
* Can be overridden by derived classes to extend it.
|
||||
*/
|
||||
virtual void CreateJSObject();
|
||||
|
||||
/**
|
||||
* Retrieves the JSObject representing this GUI object.
|
||||
*/
|
||||
@ -509,10 +515,10 @@ protected:
|
||||
*
|
||||
* @see SetupSettings()
|
||||
*/
|
||||
public:
|
||||
public:
|
||||
std::map<CStr, SGUISetting> m_Settings;
|
||||
|
||||
private:
|
||||
protected:
|
||||
// An object can't function stand alone
|
||||
CGUI* const m_pGUI;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user