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);
101QQmlExpression::QQmlExpression(
const QQmlScriptString &script, QQmlContext *ctxt, QObject *scope, QObject *parent)
102: QObject(*
new QQmlExpressionPrivate, parent)
105 if (ctxt && !ctxt->isValid())
108 const QQmlScriptStringPrivate *scriptPrivate = script.d.data();
109 if (!scriptPrivate) {
113 d->init(QQmlContextData::get(ctxt), QString(), scope);
117 if (!ctxt && (!scriptPrivate->context || !scriptPrivate->context->isValid()))
120 QQmlRefPointer<QQmlContextData> evalCtxtData
121 = QQmlContextData::get(ctxt ? ctxt : scriptPrivate->context);
122 QObject *scopeObject = scope ? scope : scriptPrivate->scope;
123 QV4::Function *runtimeFunction =
nullptr;
125 if (scriptPrivate->context) {
126 QQmlRefPointer<QQmlContextData> ctxtdata = QQmlContextData::get(scriptPrivate->context);
127 QQmlEnginePrivate *engine = QQmlEnginePrivate::get(scriptPrivate->context->engine());
130 && !ctxtdata->urlString().isEmpty()
131 && ctxtdata->typeCompilationUnit()) {
132 d->url = ctxtdata->urlString();
133 d->line = scriptPrivate->lineNumber;
134 d->column = scriptPrivate->columnNumber;
136 if (scriptPrivate->bindingId != QQmlBinding::Invalid)
137 runtimeFunction = ctxtdata->typeCompilationUnit()->runtimeFunctions.at(scriptPrivate->bindingId);
141 if (runtimeFunction) {
142 d->expression = scriptPrivate->script;
143 d->init(evalCtxtData, runtimeFunction, scopeObject);
145 d->init(evalCtxtData, scriptPrivate->script, scopeObject);
155QQmlExpression::QQmlExpression(QQmlContext *ctxt, QObject *scope,
const QString &expression,
157: QObject(*
new QQmlExpressionPrivate, parent)
160 d->init(QQmlContextData::get(ctxt), expression, scope);
240 if (!hasValidContext()) {
241 qWarning(
"QQmlExpression: Attempted to evaluate an expression in an invalid context");
245 QQmlEngine *engine = q->engine();
249 ep->referenceScarceResources();
252 QV4::Scope scope(engine->handle());
253 QV4::ScopedValue result(scope, v4value(isUndefined));
255 rv = QV4::ExecutionEngine::toVariant(result, QMetaType {});
258 ep->dereferenceScarceResources();