40 QV4::Function *runtimeFunction, QObject *me)
43 QV4::ExecutionEngine *engine = ctxt->engine()->handle();
44 QV4::Scope scope(engine);
45 QV4::Scoped<QV4::QmlContext> qmlContext(scope, QV4::QmlContext::create(engine->rootContext(), ctxt, me));
46 setupFunction(qmlContext, runtimeFunction);
48 QQmlJavaScriptExpression::setContext(ctxt);
106QQmlExpression::QQmlExpression(
const QQmlScriptString &script, QQmlContext *ctxt, QObject *scope, QObject *parent)
107: QObject(*
new QQmlExpressionPrivate, parent)
110 if (ctxt && !ctxt->isValid())
113 const QQmlScriptStringPrivate *scriptPrivate = script.d.data();
114 if (!scriptPrivate) {
118 d->init(QQmlContextData::get(ctxt), QString(), scope);
122 if (!ctxt && (!scriptPrivate->context || !scriptPrivate->context->isValid()))
125 QQmlRefPointer<QQmlContextData> evalCtxtData
126 = QQmlContextData::get(ctxt ? ctxt : scriptPrivate->context);
127 QObject *scopeObject = scope ? scope : scriptPrivate->scope;
128 QV4::Function *runtimeFunction =
nullptr;
130 if (scriptPrivate->context) {
131 QQmlRefPointer<QQmlContextData> ctxtdata = QQmlContextData::get(scriptPrivate->context);
132 QQmlEnginePrivate *engine = QQmlEnginePrivate::get(scriptPrivate->context->engine());
135 && !ctxtdata->urlString().isEmpty()
136 && ctxtdata->typeCompilationUnit()) {
137 d->url = ctxtdata->urlString();
138 d->line = scriptPrivate->lineNumber;
139 d->column = scriptPrivate->columnNumber;
141 if (scriptPrivate->bindingId != QQmlBinding::Invalid)
142 runtimeFunction = ctxtdata->typeCompilationUnit()->runtimeFunctions.at(scriptPrivate->bindingId);
146 if (runtimeFunction) {
147 d->expression = scriptPrivate->script;
148 d->init(evalCtxtData, runtimeFunction, scopeObject);
150 d->init(evalCtxtData, scriptPrivate->script, scopeObject);
160QQmlExpression::QQmlExpression(QQmlContext *ctxt, QObject *scope,
const QString &expression,
162: QObject(*
new QQmlExpressionPrivate, parent)
165 d->init(QQmlContextData::get(ctxt), expression, scope);
258 if (!hasValidContext()) {
259 qWarning(
"QQmlExpression: Attempted to evaluate an expression in an invalid context");
263 QQmlEngine *engine = q->engine();
267 ep->referenceScarceResources();
270 QV4::Scope scope(engine->handle());
271 QV4::ScopedValue result(scope, v4value(isUndefined));
273 rv = QV4::ExecutionEngine::toVariant(result, QMetaType {});
276 ep->dereferenceScarceResources();