Qt 4.8
Classes | Public Functions | Static Public Functions | Static Public Variables | Properties | List of all members
QScript::QtPropertyFunction Class Reference

#include <qscriptqobject_p.h>

Inheritance diagram for QScript::QtPropertyFunction:

Classes

struct  Data
 

Public Functions

virtual const JSC::ClassInfo * classInfo () const
 
JSC::JSValue execute (JSC::ExecState *exec, JSC::JSValue thisValue, const JSC::ArgList &args)
 
virtual JSC::CallType getCallData (JSC::CallData &)
 
const QMetaObjectmetaObject () const
 
int propertyIndex () const
 
 QtPropertyFunction (const QMetaObject *meta, int index, JSC::JSGlobalData *, WTF::PassRefPtr< JSC::Structure >, const JSC::Identifier &)
 
virtual ~QtPropertyFunction ()
 

Static Public Functions

static JSC::JSValue JSC_HOST_CALL call (JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
 

Static Public Variables

static const JSC::ClassInfo info = { "QtPropertyFunction", &InternalFunction::info, 0, 0 }
 

Properties

Datadata
 

Detailed Description

Definition at line 216 of file qscriptqobject_p.h.

Constructors and Destructors

◆ QtPropertyFunction()

QScript::QtPropertyFunction::QtPropertyFunction ( const QMetaObject meta,
int  index,
JSC::JSGlobalData *  data,
WTF::PassRefPtr< JSC::Structure >  sid,
const JSC::Identifier &  ident 
)

Definition at line 1047 of file qscriptqobject.cpp.

1051  : JSC::InternalFunction(data, sid, ident),
1052  data(new Data(meta, index))
1053 {
1054 }
quint16 index

◆ ~QtPropertyFunction()

QScript::QtPropertyFunction::~QtPropertyFunction ( )
virtual

Definition at line 1056 of file qscriptqobject.cpp.

1057 {
1058  delete data;
1059 }

Functions

◆ call()

JSC::JSValue JSC_HOST_CALL QScript::QtPropertyFunction::call ( JSC::ExecState *  exec,
JSC::JSObject *  callee,
JSC::JSValue  thisValue,
const JSC::ArgList &  args 
)
static

Definition at line 1067 of file qscriptqobject.cpp.

Referenced by getCallData().

1070 {
1071  if (!callee->inherits(&QtPropertyFunction::info))
1072  return throwError(exec, JSC::TypeError, "callee is not a QtPropertyFunction object");
1073  QtPropertyFunction *qfun = static_cast<QtPropertyFunction*>(callee);
1074  return qfun->execute(exec, thisValue, args);
1075 }
static const JSC::ClassInfo info
QtPropertyFunction(const QMetaObject *meta, int index, JSC::JSGlobalData *, WTF::PassRefPtr< JSC::Structure >, const JSC::Identifier &)

◆ classInfo()

virtual const JSC::ClassInfo* QScript::QtPropertyFunction::classInfo ( ) const
inlinevirtual

Definition at line 236 of file qscriptqobject_p.h.

236 { return &info; }
static const JSC::ClassInfo info

◆ execute()

JSC::JSValue QScript::QtPropertyFunction::execute ( JSC::ExecState *  exec,
JSC::JSValue  thisValue,
const JSC::ArgList &  args 
)

Definition at line 1077 of file qscriptqobject.cpp.

Referenced by call().

1080 {
1081  JSC::JSValue result = JSC::jsUndefined();
1082 
1084  JSC::ExecState *previousFrame = engine->currentFrame;
1085  engine->currentFrame = exec;
1086 
1087  JSC::JSValue qobjectValue = engine->toUsableValue(thisValue);
1088  QObject *qobject = QScriptEnginePrivate::toQObject(exec, qobjectValue);
1089  while ((!qobject || (qobject->metaObject() != data->meta))
1090  && JSC::asObject(qobjectValue)->prototype().isObject()) {
1091  qobjectValue = JSC::asObject(qobjectValue)->prototype();
1092  qobject = QScriptEnginePrivate::toQObject(exec, qobjectValue);
1093  }
1094  Q_ASSERT_X(qobject, Q_FUNC_INFO, "this-object must be a QObject");
1095 
1097  Q_ASSERT(prop.isScriptable());
1098  if (args.size() == 0) {
1099  // get
1100  if (prop.isValid()) {
1101  QScriptable *scriptable = scriptableFromQObject(qobject);
1102  QScriptEngine *oldEngine = 0;
1103  if (scriptable) {
1104  engine->pushContext(exec, thisValue, args, this);
1105  oldEngine = QScriptablePrivate::get(scriptable)->engine;
1107  }
1108 
1109  QVariant v = prop.read(qobject);
1110 
1111  if (scriptable) {
1112  QScriptablePrivate::get(scriptable)->engine = oldEngine;
1113  engine->popContext();
1114  }
1115 
1117  }
1118  } else {
1119  // set
1120  JSC::JSValue arg = args.at(0);
1121  QVariant v;
1122  if (prop.isEnumType() && arg.isString()
1123  && !engine->hasDemarshalFunction(prop.userType())) {
1124  // give QMetaProperty::write() a chance to convert from
1125  // string to enum value
1126  v = (QString)arg.toString(exec);
1127  } else {
1128  v = variantFromValue(exec, prop.userType(), arg);
1129  }
1130 
1131  QScriptable *scriptable = scriptableFromQObject(qobject);
1132  QScriptEngine *oldEngine = 0;
1133  if (scriptable) {
1134  engine->pushContext(exec, thisValue, args, this);
1135  oldEngine = QScriptablePrivate::get(scriptable)->engine;
1137  }
1138 
1139  prop.write(qobject, v);
1140 
1141  if (scriptable) {
1142  QScriptablePrivate::get(scriptable)->engine = oldEngine;
1143  engine->popContext();
1144  }
1145 
1146  result = arg;
1147  }
1148  engine->currentFrame = previousFrame;
1149  return result;
1150 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QVariant variantFromValue(JSC::ExecState *exec, int targetType, JSC::JSValue value)
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
bool isScriptable(const QObject *obj=0) const
Returns true if the property is scriptable for the given object; otherwise returns false...
static JSC::JSValue jscValueFromVariant(JSC::ExecState *, const QVariant &value)
static QScriptEnginePrivate * get(QScriptEngine *q)
JSC::CallFrame * pushContext(JSC::CallFrame *exec, JSC::JSValue thisObject, const JSC::ArgList &args, JSC::JSObject *callee, bool calledAsConstructor=false, bool clearScopeChain=false)
JSC native function doesn&#39;t have different stackframe or context.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
static QObject * toQObject(JSC::ExecState *, JSC::JSValue)
bool isValid() const
Returns true if this property is valid (readable); otherwise returns false.
Definition: qmetaobject.h:213
bool hasDemarshalFunction(int type) const
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
JSC::ExecState * currentFrame
The QScriptable class provides access to the Qt Script environment from Qt C++ member functions...
Definition: qscriptable.h:45
static QScriptablePrivate * get(QScriptable *q)
Definition: qscriptable_p.h:51
The QScriptEngine class provides an environment for evaluating Qt Script code.
bool isEnumType() const
Returns true if the property&#39;s type is an enumeration value; otherwise returns false.
static QScriptable * scriptableFromQObject(QObject *qobj)
int userType() const
Returns this property&#39;s user type.
JSC::JSValue toUsableValue(JSC::JSValue value)
If the given value is the original global object, returns the custom global object or a proxy to the ...
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QVariant read(const QObject *obj) const
Reads the property&#39;s value from the given object.
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
bool write(QObject *obj, const QVariant &value) const
Writes value as the property&#39;s value to the given object.
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.
QScriptEngine * engine
Definition: qscriptable_p.h:54
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ getCallData()

JSC::CallType QScript::QtPropertyFunction::getCallData ( JSC::CallData &  callData)
virtual

Definition at line 1061 of file qscriptqobject.cpp.

1062 {
1063  callData.native.function = call;
1064  return JSC::CallTypeHost;
1065 }
static JSC::JSValue JSC_HOST_CALL call(JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)

◆ metaObject()

const QMetaObject * QScript::QtPropertyFunction::metaObject ( ) const

Definition at line 1152 of file qscriptqobject.cpp.

1153 {
1154  return data->meta;
1155 }

◆ propertyIndex()

int QScript::QtPropertyFunction::propertyIndex ( ) const

Definition at line 1157 of file qscriptqobject.cpp.

Properties

◆ data

Data* QScript::QtPropertyFunction::data
private

Definition at line 249 of file qscriptqobject_p.h.

Referenced by execute(), metaObject(), propertyIndex(), and ~QtPropertyFunction().

◆ info

const JSC::ClassInfo QScript::QtPropertyFunction::info = { "QtPropertyFunction", &InternalFunction::info, 0, 0 }
static

The documentation for this class was generated from the following files: