3#ifndef QV4FUNCTIONOBJECT_H
4#define QV4FUNCTIONOBJECT_H
20#include <private/qv4mm_p.h>
28struct IndexedBuiltinFunction;
45#define FunctionObjectMembers(class, Member)
48 Index_ProtoConstructor = 0,
50 Index_HasInstance = 1,
53 Q_QML_EXPORT
void init(
QV4::ExecutionEngine *engine,
QV4::String *name =
nullptr);
54 Q_QML_EXPORT
void init(
QV4::ExecutionEngine *engine,
const QString &name);
55 Q_QML_EXPORT
void init();
58#define JavaScriptFunctionObjectMembers(class, Member)
59 Member(class, Pointer, ExecutionContext *, scope)
60 Member(class, NoMark, Function *, function)
63 DECLARE_MARKOBJECTS(JavaScriptFunctionObject)
65 void init(QV4::ExecutionContext *scope, QV4::Function *function, QV4::String *n =
nullptr);
66 Q_QML_EXPORT
void destroy();
68 void setFunction(Function *f);
70 unsigned int formalParameterCount() {
return function ? function->nFormals : 0; }
71 unsigned int varCount() {
return function ? function->compiledFunction->nLocals : 0; }
74#define DynamicFunctionObjectMembers(class, Member)
75 Member(class, NoMark, VTable::Call, jsCall)
81 void init(ExecutionEngine *engine,
QV4::String *name, VTable::Call call);
85 void init(
QV4::ExecutionEngine *engine);
95 inline void init(
QV4::ExecutionEngine *engine, qsizetype index, VTable::Call call);
104 void init(
QV4::ExecutionContext *scope, Function *function,
QV4::String *name =
nullptr);
107#define ScriptFunctionMembers(class, Member)
108 Member(class, Pointer, InternalClass *, cachedClassForConstructor)
111 DECLARE_MARKOBJECTS(ScriptFunction)
112 void init(QV4::ExecutionContext *scope, Function *function);
115#define MemberFunctionMembers(class, Member)
116 Member(class, Pointer, Object *, homeObject)
119 DECLARE_MARKOBJECTS(MemberFunction)
121 void init(QV4::ExecutionContext *scope, Function *function, QV4::String *name =
nullptr) {
122 ArrowFunction::init(scope, function, name);
126#define ConstructorFunctionMembers(class, Member)
127 Member(class, Pointer, Object *, homeObject)
130 DECLARE_MARKOBJECTS(ConstructorFunction)
131 bool isDerivedConstructor;
134#define DefaultClassConstructorFunctionMembers(class, Member)
135 Member(class, Pointer, ExecutionContext *, scope)
138 DECLARE_MARKOBJECTS(DefaultClassConstructorFunction)
140 bool isDerivedConstructor;
142 void init(
QV4::ExecutionContext *scope);
145#define BoundFunctionMembers(class, Member)
146 Member(class, Pointer, FunctionObject *, target)
147 Member(class, HeapValue, HeapValue, boundThis)
148 Member(class, Pointer, MemberData *, boundArgs)
151 DECLARE_MARKOBJECTS(BoundFunction)
153 void init(QV4::FunctionObject *target,
const Value &boundThis, QV4::MemberData *boundArgs);
281 const FunctionObject *f,
const Value *thisObject,
const Value *argv,
int argc);
296 QV4::ExecutionEngine *engine, qsizetype index, VTable::Call call)
298 Heap::FunctionObject::init(engine);
311 static void virtualCallWithMetaTypes(
const FunctionObject *f, QObject *thisObject,
312 void **a,
const QMetaType *types,
int argc);
314 const QV4::Value *argv,
int argc);
371 return v4->hasException ? QV4::Encode::undefined() : result;
bool isString() const
Returns true if the type of this QJSManagedValue is string, or false otherwise.
QJSEngine * engine() const
Returns the QJSEngine this QJSManagedValue belongs to.
bool deleteProperty(quint32 arrayIndex)
Deletes the value stored at arrayIndex from this QJSManagedValue.
QJSValue toJSValue() const
Copies this QJSManagedValue into a new QJSValue.
QJSManagedValue jsMetaType() const
bool isBoolean() const
Returns true if the type of this QJSManagedValue is boolean, or false otherwise.
const QMetaObject * toQMetaObject() const
If this QJSManagedValue holds a QMetaObject pointer, returns it.
QStringList jsMetaMembers() const
bool isArray() const
Returns true if this value represents a JavaScript Array object, or false otherwise.
bool isError() const
Returns true if this value represents a JavaScript Error object, or false otherwise.
bool strictlyEquals(const QJSManagedValue &other) const
Invokes the JavaScript '===' operator on this QJSManagedValue and other, and returns the result.
bool hasProperty(const QString &name) const
Returns true if this QJSManagedValue has a property name, otherwise returns false.
QJSValue call(const QJSValueList &arguments={}) const
If this QJSManagedValue represents a JavaScript FunctionObject, calls it with the given arguments,...
QObject * toQObject() const
If this QJSManagedValue holds a QObject pointer, returns it.
bool isRegularExpression() const
Returns true if this value represents a JavaScript regular expression object, or false otherwise.
QJSValue property(const QString &name) const
Returns the property name of this QJSManagedValue.
QJSManagedValue jsMetaInstantiate(const QJSValueList &values={}) const
bool hasOwnProperty(quint32 arrayIndex) const
Returns true if this QJSManagedValue has an array index arrayIndex, otherwise returns false.
QVariant toVariant() const
Copies this QJSManagedValue into a new QVariant.
bool hasProperty(quint32 arrayIndex) const
Returns true if this QJSManagedValue has an array index arrayIndex, otherwise returns false.
double toNumber() const
Converts the manged value to a number.
QJSManagedValue & operator=(QJSManagedValue &&other)
Move-assigns a QJSManagedValue from other.
QJSValue callAsConstructor(const QJSValueList &arguments={}) const
If this QJSManagedValue represents a JavaScript FunctionObject, calls it as constructor with the give...
bool isVariant() const
Returns true if this value represents a QVariant managed on the JavaScript heap, or false otherwise.
bool isFunction() const
Returns true if the type of this QJSManagedValue is function, false otherwise.
QRegularExpression toRegularExpression() const
If this QJSManagedValue holds a JavaScript regular expression object, returns an equivalent QRegularE...
QJSManagedValue prototype() const
Returns the prototype for this QJSManagedValue.
bool isUndefined() const
Returns true if the type of this QJSManagedValue is undefined, or false otherwise.
bool isDate() const
Returns true if this value represents a JavaScript Date object, or false otherwise.
bool equals(const QJSManagedValue &other) const
Invokes the JavaScript '==' operator on this QJSManagedValue and other, and returns the result.
~QJSManagedValue()
Destroys the QJSManagedValue.
QJSPrimitiveValue toPrimitive() const
Converts the manged value to a QJSPrimitiveValue.
bool deleteProperty(const QString &name)
Deletes the property name from this QJSManagedValue.
bool isQMetaObject() const
Returns true if this value represents a QMetaObject pointer managed on the JavaScript heap,...
QDateTime toDateTime() const
If this QJSManagedValue holds a JavaScript Date object, returns an equivalent QDateTime.
int toInteger() const
Converts the manged value to an integer.
QString toString() const
Converts the manged value to a string.
QUrl toUrl() const
If this QJSManagedValue holds a JavaScript Url object, returns an equivalent QUrl.
bool isQObject() const
Returns true if this value represents a QObject pointer managed on the JavaScript heap,...
bool hasOwnProperty(const QString &name) const
Returns true if this QJSManagedValue has a property name, otherwise returns false.
void setPrototype(const QJSManagedValue &prototype)
Sets the prototype of this QJSManagedValue to prototype.
bool isUrl() const
Returns true if this value represents a JavaScript Url object, or false otherwise.
bool isInteger() const
Returns true if this QJSManagedValue holds an integer value, or false otherwise.
bool isNumber() const
Returns true if the type of this QJSManagedValue is number, or false otherwise.
bool isNull() const
Returns true if this QJSManagedValue holds the JavaScript null value, or false otherwise.
bool isSymbol() const
Returns true if the type of this QJSManagedValue is symbol, or false otherwise.
bool isObject() const
Returns true if the type of this QJSManagedValue is object, or false otherwise.
void setProperty(const QString &name, const QJSValue &value)
Sets the property name to value on this QJSManagedValue.
void setProperty(quint32 arrayIndex, const QJSValue &value)
Stores the value at arrayIndex in this QJSManagedValue.
bool toBoolean() const
Converts the manged value to a boolean.
QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &arguments={}) const
If this QJSManagedValue represents a JavaScript FunctionObject, calls it on instance with the given a...
bool isJsMetaType() const
The QJSPrimitiveValue class operates on primitive types in JavaScript semantics.
static QV4::ExecutionEngine * engine(const QJSValue *jsval)
The QJSValue class acts as a container for Qt/JavaScript data types.
virtual Type type() const =0
Reimplement this function to return the paint engine \l{Type}.
ArrayElementLessThan(ExecutionEngine *engine, const Value &comparefn)
bool operator()(Value v1, Value v2) const
ReturnedValue operator*() const
OptionalReturnedValue(ReturnedValue v)
ReturnedValue operator->() const
Combined button and popup list for selecting options.
DECLARE_EXPORTED_HEAP_OBJECT(Object, Base)
DECLARE_HEAP_OBJECT(MemberData, Base)
DECLARE_HEAP_OBJECT(BoundFunction, JavaScriptFunctionObject)
DECLARE_HEAP_OBJECT(ConstructorFunction, ScriptFunction)
DECLARE_HEAP_OBJECT(FunctionObject, Object)
DECLARE_HEAP_OBJECT(ArrayData, Base)
DECLARE_HEAP_OBJECT(RegExpCtor, FunctionObject)
Q_STATIC_ASSERT(std::is_trivial_v< ArrayData >)
DECLARE_HEAP_OBJECT(JavaScriptFunctionObject, FunctionObject)
DECLARE_HEAP_OBJECT(MemberFunction, ArrowFunction)
DECLARE_HEAP_OBJECT(ScriptFunction, ArrowFunction)
Scoped< FunctionObject > ScopedFunctionObject
void sortHelper(RandomAccessIterator start, RandomAccessIterator end, LessThan lessThan)
QVector< StackFrame > StackTrace
int qYouForgotTheQ_MANAGED_Macro(T, T)
bool hasExceptionOrIsInterrupted(ExecutionEngine *engine)
Scoped< Object > ScopedObject
ReturnedValue value_convert(ExecutionEngine *e, const Value &v)
Scoped< ArrayObject > ScopedArrayObject
ReturnedValue checkedResult(QV4::ExecutionEngine *v4, ReturnedValue result)
Scoped< String > ScopedString
Scoped< StringOrSymbol > ScopedStringOrSymbol
void qYouForgotTheQ_MANAGED_Macro(T1, T2)
@ Attr_ReadOnly_ButConfigurable
Q_STATIC_ASSERT(std::is_trivial_v< Value >)
Scoped< ExecutionContext > ScopedContext
T caughtResult(const QJSValue *v, T(QV4::Value::*convert)() const)
static bool js_equal(const QString &string, const QV4::Value &value)
QDataStream & operator<<(QDataStream &stream, const QJSValue &jsv)
QDataStream & operator>>(QDataStream &stream, QJSValue &jsv)
QList< QJSValue > QJSValueList
Q_DECLARE_TYPEINFO(QObjectPrivate::ConnectionList, Q_RELOCATABLE_TYPE)
#define V4_ARRAYDATA(DataClass)
#define V4_MANAGED(DataClass, superClass)
#define V4_MANAGED_SIZE_TEST
#define V4_MANAGED_ITSELF(DataClass, superClass)
#define Q_MANAGED_TYPE(type)
#define V4_INTERNALCLASS(c)
static bool virtualDefineOwnProperty(Managed *m, PropertyKey id, const Property *p, PropertyAttributes attrs)
static qint64 virtualGetLength(const Managed *m)
QStringList toQStringList() const
void(* setAttribute)(Object *o, uint index, PropertyAttributes attrs)
bool(* putArray)(Object *o, uint index, const Value *values, uint n)
bool(* put)(Object *o, uint index, const Value &value)
void(* push_front)(Object *o, const Value *values, uint n)
ReturnedValue(* get)(const Heap::ArrayData *d, uint index)
bool(* del)(Object *o, uint index)
ReturnedValue(* pop_front)(Object *o)
static ReturnedValue virtualCall(const QV4::FunctionObject *f, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static QQmlRefPointer< ExecutableCompilationUnit > parse(ExecutionEngine *engine, const Value *argv, int argc, Type t=Type_Function)
static ReturnedValue method_bind(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_call(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_hasInstance(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_apply(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static constexpr size_t offset
void set(EngineBase *e, HeapBasePtr b)
void set(EngineBase *e, const Value &newVal)
void init(const QStringList &list)
void init(QV4::ExecutionContext *scope, Function *function, QV4::String *name=nullptr)
void init(QV4::ExecutionEngine *engine)
void init(QV4::ExecutionEngine *engine, qsizetype index, VTable::Call call)
void init(InternalClass *other)
IndexAndAttribute findValueOrSetter(const PropertyKey id)
void init(ExecutionEngine *engine)
static void addMember(QV4::Object *object, PropertyKey id, PropertyAttributes data, InternalClassEntry *entry)
InternalClassEntry find(const PropertyKey id)
bool verifyIndex(const PropertyKey id, uint index)
PropertyHash propertyTable
QVarLengthArray< Transition, 1 > transitions
SharedInternalClassData< PropertyKey > nameMap
bool isUsedAsProto() const
IndexAndAttribute findValueOrGetter(const PropertyKey id)
bool isImplicitlyFrozen() const
quint8 numRedundantTransitions
InternalClassTransition Transition
bool isExtensible() const
uint indexOfValueOrGetter(const PropertyKey id)
@ MaxRedundantTransitions
InternalClassTransition & lookupOrInsertTransition(const InternalClassTransition &t)
static void markObjects(Heap::Base *ic, MarkStack *stack)
static void removeMember(QV4::Object *object, PropertyKey identifier)
static void changeMember(QV4::Object *object, PropertyKey id, PropertyAttributes data, InternalClassEntry *entry=nullptr)
PropertyHash::Entry * findEntry(const PropertyKey id)
SharedInternalClassData< PropertyAttributes > propertyData
PropertyAttributes attributes(uint i) const
uint mappedIndex(uint index) const
void setData(EngineBase *e, uint index, Value newVal)
const Value & data(uint index) const
uint mappedIndex(uint index) const
PropertyAttributes attributes(uint i) const
PropertyAttributes attributes
Heap::InternalClass * lookup
bool operator<(const InternalClassTransition &other) const
bool operator==(const InternalClassTransition &other) const
static Heap::MemberData * allocate(QV4::ExecutionEngine *e, uint n, Heap::MemberData *old=nullptr)
const Value * data() const
void set(EngineBase *e, uint index, Value v)
const Value & operator[](uint idx) const
void set(EngineBase *e, uint index, Heap::Base *b)
PropertyKey next(const Object *o, Property *pd=nullptr, PropertyAttributes *attrs=nullptr) override
PropertyHashData(int numBits)
PropertyHash::Entry * entries
void addEntry(const Entry &entry, int classSize)
PropertyHash(const PropertyHash &other)
PropertyHash & operator=(const PropertyHash &other)
void detach(bool grow, int classSize)
Entry * lookup(PropertyKey identifier) const
const Value * operator->() const
const Value & operator*() const
void set(EngineBase *e, Value newVal)
bool isStringOrSymbol() const
bool isArrayIndex() const
static PropertyKey fromId(quint64 id)
Heap::StringOrSymbol * toStringOrSymbol(ExecutionEngine *e)
bool isCanonicalNumericIndexString() const
Q_QML_EXPORT bool isSymbol() const
bool operator<(const PropertyKey &other) const
Q_QML_EXPORT bool isString() const
StringOrSymbol * asStringOrSymbol() const
uint asArrayIndex() const
bool operator==(const PropertyKey &other) const
static PropertyKey invalid()
static PropertyKey fromStringOrSymbol(Engine *engine, StringOrSymbol *b)
friend size_t qHash(const PropertyKey &key, size_t seed=0)
static PropertyKey fromArrayIndex(uint idx)
Heap::String * asFunctionName(ExecutionEngine *e, FunctionNamePrefix prefix) const
bool operator!=(const PropertyKey &other) const
void setGetter(FunctionObject *g)
Heap::FunctionObject * getter() const
bool isSubset(const PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs) const
void setSetter(FunctionObject *s)
void fullyPopulated(PropertyAttributes *attrs)
bool isCompatible(PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs) const
void copy(const Property *other, PropertyAttributes attrs)
void completed(PropertyAttributes *attrs)
Property(Heap::FunctionObject *getter, Heap::FunctionObject *setter)
Heap::FunctionObject * setter() const
void merge(PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs)
Value * alloc(qint64 nValues) const =delete
Scope(ExecutionEngine *e)
Scope(ExecutionContext *ctx)
PropertyKey * operator->()
ScopedPropertyKey & operator=(const PropertyKey &other)
ScopedPropertyKey(const Scope &scope)
ScopedPropertyKey(const Scope &scope, const PropertyKey &v)
operator PropertyKey() const
bool operator==(const PropertyKey &other) const
bool operator==(const ScopedPropertyKey &other) const
bool operator!=(const ScopedPropertyKey &other) const
bool operator!=(const PropertyKey &other) const
operator const Property *() const
ScopedProperty(Scope &scope)
ScopedValue(const Scope &scope, Managed *m)
ScopedValue & operator=(Managed *m)
ScopedValue & operator=(const Value &v)
ScopedValue(const Scope &scope, const Value &v)
ScopedValue(ScopedValue &&)=default
ScopedValue(const Scope &scope)
ScopedValue(const ScopedValue &)=default
ScopedValue(const Scope &scope, const ReturnedValue &v)
ScopedValue & operator=(const ScopedValue &other)
operator const Value &() const
const Value * operator->() const
ScopedValue(const Scope &scope, Heap::Base *o)
ScopedValue & operator=(const ReturnedValue &v)
ScopedValue & operator=(Heap::Base *o)
Scoped< T > & operator=(typename T::Data *t)
Scoped< T > & operator=(Value *v)
Scoped< T > & operator=(const ReturnedValue &v)
operator const Value &() const
Scoped< T > & operator=(Heap::Base *o)
Scoped< T > & operator=(const Value &v)
QML_NEARLY_ALWAYS_INLINE void setPointer(const Managed *p)
const T * getPointer() const
const T * operator->() const
Scoped< T > & operator=(T *t)
Heap::InternalClass * classForConstructor() const
void markIfNecessary(const PropertyKey &value)
SharedInternalClassDataPrivate(const SharedInternalClassDataPrivate &other, uint pos, PropertyKey value)
void set(uint i, PropertyKey t)
~SharedInternalClassDataPrivate()
SharedInternalClassDataPrivate(ExecutionEngine *e)
PropertyKey at(uint i) const
SharedInternalClassDataPrivate(const SharedInternalClassDataPrivate &other)
void set(uint pos, T value)
SharedInternalClassData(ExecutionEngine *e)
void add(uint pos, T value)
SharedInternalClassData & operator=(const SharedInternalClassData &other)
~SharedInternalClassData()
SharedInternalClassData(const SharedInternalClassData &other)
SparseArrayNode * copy(SparseArray *d) const
SparseArrayNode * lowerBound(uint key)
const SparseArrayNode * previousNode() const
SparseArrayNode * parent() const
SparseArrayNode * nextNode()
SparseArrayNode * upperBound(uint key)
const SparseArrayNode * nextNode() const
SparseArrayNode * previousNode()
void setParent(SparseArrayNode *pp)
SparseArrayNode * upperBound(uint key)
SparseArrayNode * erase(SparseArrayNode *n)
void push_back(uint at, uint len)
SparseArrayNode * lowerBound(uint key)
const SparseArrayNode * begin() const
SparseArrayNode * insert(uint akey)
QList< int > keys() const
SparseArrayNode * findNode(uint akey) const
void freeTree(SparseArrayNode *root, int alignment)
const SparseArrayNode * end() const
const Value * data() const
void set(EngineBase *e, uint index, Value v)
void set(EngineBase *e, uint index, Value::HeapBasePtr b)
void mark(MarkStack *markStack)
Value::HeapBasePtr base()
const Value & operator[](uint index) const
static constexpr size_t offset