17#include <private/qqmlengine_p.h>
18#include <private/qqmllistwrapper_p.h>
19#include <private/qqmlvaluetype_p.h>
20#include <private/qqmlvaluetypewrapper_p.h>
21#include <private/qv4alloca_p.h>
22#include <private/qv4context_p.h>
23#include <private/qv4dateobject_p.h>
24#include <private/qv4function_p.h>
25#include <private/qv4functionobject_p.h>
26#include <private/qv4object_p.h>
27#include <private/qv4qobjectwrapper_p.h>
28#include <private/qv4regexpobject_p.h>
29#include <private/qv4scopedvalue_p.h>
30#include <private/qv4stackframe_p.h>
31#include <private/qv4urlobject_p.h>
32#include <private/qv4variantobject_p.h>
34#if QT_CONFIG(regularexpression)
35#include <QtCore/qregularexpression.h>
42template<
typename Args>
56 ptr->function =
f->asReturnedValue();
114template<
typename Callable>
117 const Value *thisObject,
const Value *argv,
int argc, Callable call)
119 const qsizetype numFunctionArguments = aotFunction->types.length() - 1;
124 const QMetaType argumentType = aotFunction->types[
i + 1];
125 types[
i + 1] = argumentType;
147 types[0] = aotFunction->types[0];
152 types[0].construct(returnValue);
160 call(cppThisObject->object(),
values,
types, argc);
182template<
typename Callable>
189 for (
int ii = 0; ii < argc; ++ii)
190 jsCallData.args[ii] =
engine->metaTypeToJS(
types[ii + 1],
a[ii + 1]);
202 ScopedValue jsResult(scope, call(jsThisObject, jsCallData.args, argc));
205 return !jsResult->isUndefined();
211 resultType.construct(
result);
212 }
else if (resultType == QMetaType::fromType<QVariant>()) {
219 resultType.destruct(
result);
220 resultType.construct(
result);
222 return !jsResult->isUndefined();
254 const auto metaSequence = [&]() {
264 if (sequence->d()->listType() ==
type)
265 return value.asReturnedValue();
269 if (
list->d()->propertyType() ==
type)
270 return value.asReturnedValue();
274 if (!listValueType.
isValid()) {
276 return value.asReturnedValue();
290 QQmlListProperty<QObject> *listProperty = newList->d()->property();
299 return newList->asReturnedValue();
306 sequence->containerPutIndexed(
i,
array->get(
i));
307 return sequence->asReturnedValue();
321 if (!
value.isUndefined())
323 return value.asReturnedValue();
326 switch (metaType.
id()) {
327 case QMetaType::Void:
330 return value.asReturnedValue();
333 case QMetaType::Double:
334 return value.convertedToNumber();
335 case QMetaType::QString:
337 case QMetaType::Bool:
339 case QMetaType::QDateTime:
341 return value.asReturnedValue();
345 case QMetaType::QDateTime:
347 case QMetaType::QTime:
349 case QMetaType::QDate:
356 case QMetaType::QUrl:
358 return value.asReturnedValue();
361 return var.
metaType() == QMetaType::fromType<QUrl>()
363 :
engine->newUrlObject()->asReturnedValue();
368 return engine->newUrlObject()->asReturnedValue();
369#if QT_CONFIG(regularexpression)
370 case QMetaType::QRegularExpression:
372 return value.asReturnedValue();
375 if (
var.
metaType() == QMetaType::fromType<QRegularExpression>())
378 return engine->newRegExpObject(
QString(), 0)->asReturnedValue();
386 ?
value.asReturnedValue()
391 if (
wrapper->type() == metaType)
392 return value.asReturnedValue();
398 nullptr, -1, Heap::ReferenceObject::NoFlag);
401 return wrapper->asReturnedValue();
407template<
typename Callable>
411 const Value *argv,
int argc, Callable call)
435 = (fromObj && fromObj->metaObject()->inherits(toType.metaObject()))
441 if (toType == QMetaType::fromType<QVariant>()) {
446 if (toType == QMetaType::fromType<QJSPrimitiveValue>()) {
451 if (fromType == QMetaType::fromType<QVariant>()) {
453 if (fromVariant->
metaType() == toType)
454 toType.construct(to, fromVariant->
data());
460 if (fromType == QMetaType::fromType<QJSPrimitiveValue>()) {
462 if (fromPrimitive->metaType() == toType)
463 toType.construct(to, fromPrimitive->data());
465 coerce(
engine, fromPrimitive->metaType(), fromPrimitive->data(), toType, to);
473 toType.construct(to);
480template<
typename TypedFunction,
typename Callable>
485 const qsizetype numFunctionArguments = typedFunction->parameterCount();
490 const QMetaType returnType = typedFunction->returnMetaType();
492 bool returnsQVariantWrapper =
false;
493 if (argv[0] && returnType != frameReturn) {
494 Q_ALLOCA_ASSIGN(
void *, transformedArguments, (numFunctionArguments + 1) *
sizeof(
void *));
495 memcpy(transformedArguments, argv, (argc + 1) *
sizeof(
void *));
497 if (frameReturn == QMetaType::fromType<QVariant>()) {
499 *returnValue =
QVariant(returnType);
500 transformedResult = transformedArguments[0] = returnValue->
data();
501 returnsQVariantWrapper =
true;
502 }
else if (returnType.
sizeOf() > 0) {
504 transformedArguments[0] = transformedResult;
508 transformedResult = transformedArguments[0] = &argc;
513 const bool isValid = argc >
i;
516 const QMetaType argumentType = typedFunction->parameterMetaType(
i);
517 if (isValid && argumentType == frameType)
520 if (transformedArguments ==
nullptr) {
521 Q_ALLOCA_ASSIGN(
void *, transformedArguments, (numFunctionArguments + 1) *
sizeof(
void *));
522 memcpy(transformedArguments, argv, (argc + 1) *
sizeof(
void *));
525 if (argumentType.
sizeOf() == 0) {
526 transformedArguments[
i + 1] =
nullptr;
530 void *frameVal = isValid ? argv[
i + 1] :
nullptr;
531 if (isValid && frameType == QMetaType::fromType<QVariant>()) {
535 if (variantType == argumentType) {
542 transformedArguments[
i + 1] =
arg;
554 transformedArguments[
i + 1] =
arg;
557 if (!transformedArguments) {
558 call(argv, numFunctionArguments);
562 call(transformedArguments, numFunctionArguments);
564 if (transformedResult && !returnsQVariantWrapper) {
565 if (frameReturn.sizeOf() > 0) {
567 frameReturn.destruct(argv[0]);
568 coerce(
engine, returnType, transformedResult, frameReturn, argv[0]);
571 returnType.
destruct(transformedResult);
575 void *
arg = transformedArguments[
i + 1];
578 if (
i >= argc ||
arg != argv[
i + 1]) {
579 const QMetaType argumentType = typedFunction->parameterMetaType(
i);
\inmodule QtCore\reentrant
\inmodule QtCore \reentrant
QJSValue globalObject() const
Returns this engine's Global Object.
The QJSPrimitiveValue class operates on primitive types in JavaScript semantics.
const QMetaObject * metaObjectForValueType() const
bool isSequentialContainer() const
QMetaSequence listMetaSequence() const
QMetaType qListTypeId() const
static Q_QML_EXPORT void * heapCreateValueType(const QQmlType &targetType, const QV4::Value &source)
\inmodule QtCore \reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
\inmodule QtCore \reentrant
void * data()
Returns a pointer to the contained object as a generic void* that can be written to.
QMetaType metaType() const
const void * constData() const
Combined button and popup list for selecting options.
ReturnedValue coerceListType(ExecutionEngine *engine, const Value &value, const QQmlType &qmlType)
ReturnedValue convertAndCall(ExecutionEngine *engine, const Function::AOTCompiledFunction *aotFunction, const Value *thisObject, const Value *argv, int argc, Callable call)
CallData * callDatafromJS(const Scope &scope, const Args *args, const FunctionObject *f=nullptr)
ReturnedValue coerce(ExecutionEngine *engine, const Value &value, const QQmlType &qmlType, bool isList)
void populateJSCallArguments(ExecutionEngine *v4, JSCallArguments &jsCall, int argc, void **args, const QMetaType *types)
QObject * coerceQObject(const Value &value, const QQmlType &qmlType)
ReturnedValue coerceAndCall(ExecutionEngine *engine, const Function::JSTypedFunction *typedFunction, const CompiledData::Function *compiledFunction, const Value *argv, int argc, Callable call)
Q_QML_EXPORT void warnAboutCoercionToVoid(ExecutionEngine *engine, const Value &value, CoercionProblem problem)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static ControlElement< T > * ptr(QWidget *widget)
GLenum GLsizei GLsizei GLint * values
[15]
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei GLenum GLenum * types
GLenum GLuint GLenum GLsizei length
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei const GLchar *const * string
[0]
bool qmlobject_can_qml_cast(QObject *object, const QQmlType &type)
#define Q_ALLOCA_VAR(type, name, size)
#define Q_ALLOCA_ASSIGN(type, name, size)
#define Q_ALLOCA_DECLARE(type, name)
const Parameter * formalsTable() const
static constexpr ReturnedValue undefined()
static constexpr ReturnedValue null()
static bool metaTypeFromJS(const Value &value, QMetaType type, void *data)
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, bool createJSValueForObjectsAndSymbols=true)
ReturnedValue callAsConstructor(const Value *argv, int argc, const Value *newTarget=nullptr) const
ReturnedValue call(const Value *thisObject, const Value *argv, int argc) const
JSCallArguments(const Scope &scope, int argc=0)
CallData * callData(const Scope &scope, const FunctionObject *f=nullptr) const
CallData * callData(const Scope &scope, const FunctionObject *f=nullptr) const
JSCallData(const Value *thisObject, const Value *argv, int argc)
Q_IMPLICIT JSCallData(const JSCallArguments &args)
static ReturnedValue wrap(ExecutionEngine *engine, QObject *object)
static V4_NEEDS_DESTROY ReturnedValue create(ExecutionEngine *engine, QObject *object, int propId, QMetaType propType)
Value * alloc(qint64 nValues) const =delete
bool hasException() const
static ReturnedValue fromData(QV4::ExecutionEngine *engine, QMetaType type, QMetaSequence metaSequence, const void *data)
QML_NEARLY_ALWAYS_INLINE String * stringValue() const
uchar data[MaxInternalSize]