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

#include <qscriptqobject_p.h>

Inheritance diagram for QScript::QtFunction:

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 &)
 
int initialIndex () const
 
virtual void markChildren (JSC::MarkStack &)
 
bool maybeOverloaded () const
 
const QMetaObjectmetaObject () const
 
int mostGeneralMethod (QMetaMethod *out=0) const
 
QList< int > overloadedIndexes () const
 
QObjectqobject () const
 
 QtFunction (JSC::JSValue object, int initialIndex, bool maybeOverloaded, JSC::JSGlobalData *, WTF::PassRefPtr< JSC::Structure >, const JSC::Identifier &)
 
QScriptObjectwrapperObject () const
 
virtual ~QtFunction ()
 

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 = { "QtFunction", &InternalFunction::info, 0, 0 }
 

Properties

Datadata
 

Detailed Description

Definition at line 174 of file qscriptqobject_p.h.

Constructors and Destructors

◆ QtFunction()

QScript::QtFunction::QtFunction ( JSC::JSValue  object,
int  initialIndex,
bool  maybeOverloaded,
JSC::JSGlobalData *  data,
WTF::PassRefPtr< JSC::Structure >  sid,
const JSC::Identifier &  ident 
)

Definition at line 273 of file qscriptqobject.cpp.

276  : JSC::InternalFunction(data, sid, ident),
277  data(new Data(object, initialIndex, maybeOverloaded))
278 {
279 }
bool maybeOverloaded() const

◆ ~QtFunction()

QScript::QtFunction::~QtFunction ( )
virtual

Definition at line 281 of file qscriptqobject.cpp.

282 {
283  delete data;
284 }

Functions

◆ call()

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

Definition at line 1029 of file qscriptqobject.cpp.

Referenced by getCallData().

1031 {
1032  if (!callee->inherits(&QtFunction::info))
1033  return throwError(exec, JSC::TypeError, "callee is not a QtFunction object");
1034  QtFunction *qfun = static_cast<QtFunction*>(callee);
1036  JSC::ExecState *previousFrame = eng_p->currentFrame;
1037  eng_p->currentFrame = exec;
1038  eng_p->pushContext(exec, thisValue, args, callee);
1039  JSC::JSValue result = qfun->execute(eng_p->currentFrame, thisValue, args);
1040  eng_p->popContext();
1041  eng_p->currentFrame = previousFrame;
1042  return result;
1043 }
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
QtFunction(JSC::JSValue object, int initialIndex, bool maybeOverloaded, JSC::JSGlobalData *, WTF::PassRefPtr< JSC::Structure >, const JSC::Identifier &)
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.
JSC::ExecState * currentFrame
static const JSC::ClassInfo info

◆ classInfo()

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

Definition at line 195 of file qscriptqobject_p.h.

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

◆ execute()

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

Definition at line 995 of file qscriptqobject.cpp.

Referenced by call().

997 {
999  QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(data->object));
1000  QScriptObjectDelegate *delegate = scriptObject->delegate();
1001  Q_ASSERT(delegate && (delegate->type() == QScriptObjectDelegate::QtObject));
1002  QObject *qobj = static_cast<QScript::QObjectDelegate*>(delegate)->value();
1003  if (!qobj)
1004  return JSC::throwError(exec, JSC::GeneralError, QString::fromLatin1("cannot call function of deleted QObject"));
1006 
1007  const QMetaObject *meta = qobj->metaObject();
1008  QObject *thisQObject = 0;
1009  thisValue = engine->toUsableValue(thisValue);
1010  if (thisValue.inherits(&QScriptObject::info)) {
1011  delegate = static_cast<QScriptObject*>(JSC::asObject(thisValue))->delegate();
1012  if (delegate && (delegate->type() == QScriptObjectDelegate::QtObject))
1013  thisQObject = static_cast<QScript::QObjectDelegate*>(delegate)->value();
1014  }
1015  if (!thisQObject)
1016  thisQObject = qobj; // ### TypeError
1017 
1018  if (!meta->cast(thisQObject)) {
1019  // invoking a function in the prototype
1020  thisQObject = qobj;
1021  }
1022 
1023  return callQtMethod(exec, QMetaMethod::Method, thisQObject, scriptArgs,
1025 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
virtual Type type() const =0
static JSC::JSValue callQtMethod(JSC::ExecState *exec, QMetaMethod::MethodType callType, QObject *thisQObject, const JSC::ArgList &scriptArgs, const QMetaObject *meta, int initialIndex, bool maybeOverloaded)
static const JSC::ClassInfo info
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QObject * cast(QObject *obj) const
Returns obj if object obj inherits from this meta-object; otherwise returns 0.
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 ...
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ getCallData()

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

Definition at line 286 of file qscriptqobject.cpp.

287 {
288  callData.native.function = call;
289  return JSC::CallTypeHost;
290 }
static JSC::JSValue JSC_HOST_CALL call(JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)

◆ initialIndex()

int QScript::QtFunction::initialIndex ( ) const

◆ markChildren()

void QScript::QtFunction::markChildren ( JSC::MarkStack &  markStack)
virtual

Definition at line 292 of file qscriptqobject.cpp.

293 {
294  if (data->object)
295  markStack.append(data->object);
296  JSC::InternalFunction::markChildren(markStack);
297 }

◆ maybeOverloaded()

bool QScript::QtFunction::maybeOverloaded ( ) const

Definition at line 326 of file qscriptqobject.cpp.

Referenced by mostGeneralMethod(), and overloadedIndexes().

327 {
328  return data->maybeOverloaded;
329 }

◆ metaObject()

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

Definition at line 313 of file qscriptqobject.cpp.

Referenced by QScript::functionConnect(), QScript::functionDisconnect(), mostGeneralMethod(), and overloadedIndexes().

314 {
315  QObject *qobj = qobject();
316  if (!qobj)
317  return 0;
318  return qobj->metaObject();
319 }
QObject * qobject() const
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ mostGeneralMethod()

int QScript::QtFunction::mostGeneralMethod ( QMetaMethod out = 0) const

Definition at line 331 of file qscriptqobject.cpp.

Referenced by overloadedIndexes(), QScriptEnginePrivate::scriptConnect(), and QScriptEnginePrivate::scriptDisconnect().

332 {
333  const QMetaObject *meta = metaObject();
334  if (!meta)
335  return -1;
336  int index = initialIndex();
337  QMetaMethod method = meta->method(index);
338  if (maybeOverloaded() && (method.attributes() & QMetaMethod::Cloned)) {
339  // find the most general method
340  do {
341  method = meta->method(--index);
342  } while (method.attributes() & QMetaMethod::Cloned);
343  }
344  if (out)
345  *out = method;
346  return index;
347 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
const QMetaObject * metaObject() const
bool maybeOverloaded() const
int attributes() const
quint16 index
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56

◆ overloadedIndexes()

QList< int > QScript::QtFunction::overloadedIndexes ( ) const

Definition at line 349 of file qscriptqobject.cpp.

Referenced by QScript::functionConnect().

350 {
351  if (!maybeOverloaded())
352  return QList<int>();
353  QList<int> result;
354  const QMetaObject *meta = metaObject();
355  QMetaMethod method = meta->method(initialIndex());
356  int nameLength = methodNameLength(method);
357  for (int index = mostGeneralMethod() - 1; index >= 0; --index) {
358  if (methodNameEquals(meta->method(index), method.signature(), nameLength))
359  result.append(index);
360  }
361  return result;
362 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static bool methodNameEquals(const QMetaMethod &method, const char *signature, int nameLength)
Returns true if the name of the given method is the same as that specified by the (signature...
const QMetaObject * metaObject() const
static int methodNameLength(const QMetaMethod &method)
Calculates the length of the name of the given method by looking for the first &#39;(&#39; character...
bool maybeOverloaded() const
quint16 index
int mostGeneralMethod(QMetaMethod *out=0) const
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56

◆ qobject()

QObject * QScript::QtFunction::qobject ( ) const

Definition at line 305 of file qscriptqobject.cpp.

Referenced by metaObject(), QScriptEnginePrivate::scriptConnect(), and QScriptEnginePrivate::scriptDisconnect().

306 {
307  QScriptObject *scriptObject = wrapperObject();
308  QScriptObjectDelegate *delegate = scriptObject->delegate();
309  Q_ASSERT(delegate && (delegate->type() == QScriptObjectDelegate::QtObject));
310  return static_cast<QScript::QObjectDelegate*>(delegate)->value();
311 }
QScriptObject * wrapperObject() const
virtual Type type() const =0
QScriptObjectDelegate * delegate() const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ wrapperObject()

QScriptObject * QScript::QtFunction::wrapperObject ( ) const

Definition at line 299 of file qscriptqobject.cpp.

Referenced by qobject(), and QScriptEnginePrivate::scriptConnect().

300 {
301  Q_ASSERT(JSC::asObject(data->object)->inherits(&QScriptObject::info));
302  return static_cast<QScriptObject*>(JSC::asObject(data->object));
303 }
static const JSC::ClassInfo info
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

Properties

◆ data

Data* QScript::QtFunction::data
private

◆ info

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

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