SkinContext::SkinContext(const SkinContext& parent) : m_xmlPath(parent.m_xmlPath), m_skinBasePath(parent.m_skinBasePath), m_pConfig(parent.m_pConfig), m_variables(parent.variables()), m_pScriptEngine(parent.m_pScriptEngine), m_pScriptDebugger(parent.m_pScriptDebugger), m_parentGlobal(m_pScriptEngine->globalObject()), m_pSingletons(parent.m_pSingletons) { // we generate a new global object to preserve the scope between // a context and its children QScriptValue context = m_pScriptEngine->pushContext()->activationObject(); QScriptValue newGlobal = m_pScriptEngine->newObject(); QScriptValueIterator it(m_parentGlobal); while (it.hasNext()) { it.next(); newGlobal.setProperty(it.name(), it.value()); } m_pScriptEngine->setGlobalObject(newGlobal); for (QHash<QString, QString>::const_iterator it = m_variables.begin(); it != m_variables.end(); ++it) { m_pScriptEngine->globalObject().setProperty(it.key(), it.value()); } }
SkinContext::SkinContext(const SkinContext& parent) : m_skinBasePath(parent.m_skinBasePath), m_pConfig(parent.m_pConfig), m_variables(parent.variables()), m_pScriptEngine(parent.m_pScriptEngine), m_pScriptDebugger(parent.m_pScriptDebugger), m_parentGlobal(m_pScriptEngine->globalObject()), m_hookRx(parent.m_hookRx), m_pSvgCache(parent.m_pSvgCache), m_pSingletons(parent.m_pSingletons), m_scaleFactor(parent.m_scaleFactor) { // we generate a new global object to preserve the scope between // a context and its children setXmlPath(parent.m_xmlPath); QScriptValue context = m_pScriptEngine->pushContext()->activationObject(); QScriptValue newGlobal = m_pScriptEngine->newObject(); QScriptValueIterator it(m_parentGlobal); while (it.hasNext()) { it.next(); newGlobal.setProperty(it.name(), it.value()); } for (auto it = m_variables.constBegin(); it != m_variables.constEnd(); ++it) { newGlobal.setProperty(it.key(), it.value()); } m_pScriptEngine->setGlobalObject(newGlobal); }
SkinContext::SkinContext(const SkinContext& parent) : m_variables(parent.variables()), m_skinBasePath(parent.m_skinBasePath) { QScriptValue context = m_scriptEngine.currentContext()->activationObject(); for (QHash<QString, QString>::const_iterator it = m_variables.begin(); it != m_variables.end(); ++it) { context.setProperty(it.key(), it.value()); } }