39 QV4::Function *runtimeFunction, QObject *me)
42 QV4::ExecutionEngine *engine = ctxt->engine()->handle();
43 QV4::Scope scope(engine);
44 QV4::Scoped<QV4::QmlContext> qmlContext(scope, QV4::QmlContext::create(engine->rootContext(), ctxt, me));
45 setupFunction(qmlContext, runtimeFunction);
47 QQmlJavaScriptExpression::setContext(ctxt);
100QQmlExpression::QQmlExpression(
const QQmlScriptString &script, QQmlContext *ctxt, QObject *scope, QObject *parent)
101: QObject(*
new QQmlExpressionPrivate, parent)
104 if (ctxt && !ctxt->isValid())
107 const QQmlScriptStringPrivate *scriptPrivate = script.d.data();
108 if (!scriptPrivate) {
112 d->init(QQmlContextData::get(ctxt), QString(), scope);
116 if (!ctxt && (!scriptPrivate->context || !scriptPrivate->context->isValid()))
119 QQmlRefPointer<QQmlContextData> evalCtxtData
120 = QQmlContextData::get(ctxt ? ctxt : scriptPrivate->context);
121 QObject *scopeObject = scope ? scope : scriptPrivate->scope;
122 QV4::Function *runtimeFunction =
nullptr;
124 if (scriptPrivate->context) {
125 QQmlRefPointer<QQmlContextData> ctxtdata = QQmlContextData::get(scriptPrivate->context);
126 QQmlEnginePrivate *engine = QQmlEnginePrivate::get(scriptPrivate->context->engine());
129 && !ctxtdata->urlString().isEmpty()
130 && ctxtdata->typeCompilationUnit()) {
131 d->url = ctxtdata->urlString();
132 d->line = scriptPrivate->lineNumber;
133 d->column = scriptPrivate->columnNumber;
135 if (scriptPrivate->bindingId != QQmlBinding::Invalid)
136 runtimeFunction = ctxtdata->typeCompilationUnit()->runtimeFunctions.at(scriptPrivate->bindingId);
140 if (runtimeFunction) {
141 d->expression = scriptPrivate->script;
142 d->init(evalCtxtData, runtimeFunction, scopeObject);
144 d->init(evalCtxtData, scriptPrivate->script, scopeObject);
154QQmlExpression::QQmlExpression(QQmlContext *ctxt, QObject *scope,
const QString &expression,
156: QObject(*
new QQmlExpressionPrivate, parent)
159 d->init(QQmlContextData::get(ctxt), expression, scope);
239 if (!hasValidContext()) {
240 qWarning(
"QQmlExpression: Attempted to evaluate an expression in an invalid context");
244 QQmlEngine *engine = q->engine();
248 ep->referenceScarceResources();
251 QV4::Scope scope(engine->handle());
252 QV4::ScopedValue result(scope, v4value(isUndefined));
254 rv = QV4::ExecutionEngine::toVariant(result, QMetaType {});
257 ep->dereferenceScarceResources();