QScriptValue ModuleProperties::moduleProperties(QScriptContext *context, QScriptEngine *engine, bool oneValue) { if (Q_UNLIKELY(context->argumentCount() < 2)) { return context->throwError(QScriptContext::SyntaxError, Tr::tr("Function moduleProperties() expects 2 arguments")); } const QScriptValue objectWithProperties = context->thisObject(); const QScriptValue typeScriptValue = objectWithProperties.property(typeKey()); if (Q_UNLIKELY(!typeScriptValue.isString())) { return context->throwError(QScriptContext::TypeError, QLatin1String("Internal error: __type not set up")); } const QScriptValue ptrScriptValue = objectWithProperties.property(ptrKey()); if (Q_UNLIKELY(!ptrScriptValue.isNumber())) { return context->throwError(QScriptContext::TypeError, QLatin1String("Internal error: __internalPtr not set up")); } const void *ptr = reinterpret_cast<const void *>(qscriptvalue_cast<quintptr>(ptrScriptValue)); PropertyMapConstPtr properties; const Artifact *artifact = 0; if (typeScriptValue.toString() == productType()) { properties = static_cast<const ResolvedProduct *>(ptr)->moduleProperties; } else if (typeScriptValue.toString() == artifactType()) { artifact = static_cast<const Artifact *>(ptr); properties = artifact->properties; } else { return context->throwError(QScriptContext::TypeError, QLatin1String("Internal error: invalid type")); } ScriptEngine * const qbsEngine = static_cast<ScriptEngine *>(engine); const QString moduleName = context->argument(0).toString(); const QString propertyName = context->argument(1).toString(); QVariant value; if (qbsEngine->isPropertyCacheEnabled()) value = qbsEngine->retrieveFromPropertyCache(moduleName, propertyName, oneValue, properties); if (!value.isValid()) { if (oneValue) value = PropertyFinder().propertyValue(properties->value(), moduleName, propertyName); else value = PropertyFinder().propertyValues(properties->value(), moduleName, propertyName); const Property p(moduleName, propertyName, value); if (artifact) qbsEngine->addPropertyRequestedFromArtifact(artifact, p); else qbsEngine->addPropertyRequestedInScript(p); // Cache the variant value. We must not cache the QScriptValue here, because it's a // reference and the user might change the actual object. if (qbsEngine->isPropertyCacheEnabled()) qbsEngine->addToPropertyCache(moduleName, propertyName, oneValue, properties, value); } return engine->toScriptValue(value); }
QVariant PropertyMapInternal::qbsPropertyValue(const QString &key) const { return PropertyFinder().propertyValue(value(), QLatin1String("qbs"), key); }