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

#include <qscriptqobject_p.h>

Inheritance diagram for QScript::QMetaObjectWrapperObject:
QScript::QMetaObjectPrototype

Classes

struct  Data
 

Public Functions

virtual const JSC::ClassInfo * classInfo () const
 
virtual bool deleteProperty (JSC::ExecState *, const JSC::Identifier &propertyName)
 
JSC::JSValue execute (JSC::ExecState *exec, const JSC::ArgList &args)
 
virtual JSC::CallType getCallData (JSC::CallData &)
 
virtual JSC::ConstructType getConstructData (JSC::ConstructData &)
 
virtual bool getOwnPropertyDescriptor (JSC::ExecState *, const JSC::Identifier &propertyName, JSC::PropertyDescriptor &)
 
virtual void getOwnPropertyNames (JSC::ExecState *, JSC::PropertyNameArray &, JSC::EnumerationMode mode=JSC::ExcludeDontEnumProperties)
 
virtual bool getOwnPropertySlot (JSC::ExecState *, const JSC::Identifier &propertyName, JSC::PropertySlot &)
 
virtual void markChildren (JSC::MarkStack &markStack)
 
virtual void put (JSC::ExecState *exec, const JSC::Identifier &propertyName, JSC::JSValue, JSC::PutPropertySlot &)
 
 QMetaObjectWrapperObject (JSC::ExecState *, const QMetaObject *metaobject, JSC::JSValue ctor, WTF::PassRefPtr< JSC::Structure > sid)
 
void setValue (const QMetaObject *value)
 
const QMetaObjectvalue () const
 
 ~QMetaObjectWrapperObject ()
 

Static Public Functions

static JSC::JSValue JSC_HOST_CALL call (JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
 
static JSC::JSObject * construct (JSC::ExecState *, JSC::JSObject *, const JSC::ArgList &)
 
static WTF::PassRefPtr< JSC::Structure > createStructure (JSC::JSValue prototype)
 

Static Public Variables

static const JSC::ClassInfo info = { "QMetaObject", 0, 0, 0 }
 

Protected Variables

Datadata
 

Static Protected Variables

static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::OverridesMarkChildren | JSC::OverridesGetPropertyNames | JSC::ImplementsHasInstance | JSObject::StructureFlags
 

Detailed Description

Definition at line 252 of file qscriptqobject_p.h.

Constructors and Destructors

◆ QMetaObjectWrapperObject()

QScript::QMetaObjectWrapperObject::QMetaObjectWrapperObject ( JSC::ExecState *  exec,
const QMetaObject metaobject,
JSC::JSValue  ctor,
WTF::PassRefPtr< JSC::Structure >  sid 
)
explicit

Definition at line 1774 of file qscriptqobject.cpp.

1777  : JSC::JSObject(sid),
1778  data(new Data(metaObject, ctor))
1779 {
1780  if (!ctor)
1781  data->prototype = new (exec)JSC::JSObject(exec->lexicalGlobalObject()->emptyObjectStructure());
1782 }

◆ ~QMetaObjectWrapperObject()

QScript::QMetaObjectWrapperObject::~QMetaObjectWrapperObject ( )

Definition at line 1784 of file qscriptqobject.cpp.

1785 {
1786  delete data;
1787 }

Functions

◆ call()

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

Definition at line 1933 of file qscriptqobject.cpp.

Referenced by getCallData().

1936 {
1938  thisValue = eng_p->toUsableValue(thisValue);
1939  if (!callee->inherits(&QMetaObjectWrapperObject::info))
1940  return throwError(exec, JSC::TypeError, "callee is not a QMetaObject");
1941  QMetaObjectWrapperObject *self = static_cast<QMetaObjectWrapperObject*>(callee);
1942  JSC::ExecState *previousFrame = eng_p->currentFrame;
1943  eng_p->pushContext(exec, thisValue, args, callee);
1944  JSC::JSValue result = self->execute(eng_p->currentFrame, args);
1945  eng_p->popContext();
1946  eng_p->currentFrame = previousFrame;
1947  return result;
1948 }
static const JSC::ClassInfo info
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
QMetaObjectWrapperObject(JSC::ExecState *, const QMetaObject *metaobject, JSC::JSValue ctor, WTF::PassRefPtr< JSC::Structure > sid)
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
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 ...

◆ classInfo()

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

Definition at line 288 of file qscriptqobject_p.h.

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

◆ construct()

JSC::JSObject * QScript::QMetaObjectWrapperObject::construct ( JSC::ExecState *  exec,
JSC::JSObject *  callee,
const JSC::ArgList &  args 
)
static

Definition at line 1950 of file qscriptqobject.cpp.

Referenced by getConstructData().

1951 {
1952  QMetaObjectWrapperObject *self = static_cast<QMetaObjectWrapperObject*>(callee);
1954  JSC::ExecState *previousFrame = eng_p->currentFrame;
1955  eng_p->pushContext(exec, JSC::JSValue(), args, callee, true);
1956  JSC::JSValue result = self->execute(eng_p->currentFrame, args);
1957  eng_p->popContext();
1958  eng_p->currentFrame = previousFrame;
1959  if (!result || !result.isObject())
1960  return 0;
1961  return JSC::asObject(result);
1962 }
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
QMetaObjectWrapperObject(JSC::ExecState *, const QMetaObject *metaobject, JSC::JSValue ctor, WTF::PassRefPtr< JSC::Structure > sid)
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

◆ createStructure()

static WTF::PassRefPtr<JSC::Structure> QScript::QMetaObjectWrapperObject::createStructure ( JSC::JSValue  prototype)
inlinestatic

Definition at line 300 of file qscriptqobject_p.h.

Referenced by QScriptEnginePrivate::QScriptEnginePrivate().

301  {
302  return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags));
303  }
static Expression::Ptr create(Expression *const expr, const YYLTYPE &sourceLocator, const ParserContext *const parseInfo)
static const unsigned StructureFlags
static QByteArray prototype(const QList< QByteArray > &parameterTypes, const QList< QByteArray > &parameterNames, bool *ok)
Definition: qaxserver.cpp:685

◆ deleteProperty()

bool QScript::QMetaObjectWrapperObject::deleteProperty ( JSC::ExecState *  exec,
const JSC::Identifier &  propertyName 
)
virtual

Definition at line 1878 of file qscriptqobject.cpp.

1880 {
1881  if (propertyName == exec->propertyNames().prototype)
1882  return false;
1883  const QMetaObject *meta = data->value;
1884  if (meta) {
1885  QByteArray name = convertToLatin1(propertyName.ustring());
1886  for (int i = 0; i < meta->enumeratorCount(); ++i) {
1887  QMetaEnum e = meta->enumerator(i);
1888  for (int j = 0; j < e.keyCount(); ++j) {
1889  if (!qstrcmp(e.key(j), name.constData()))
1890  return false;
1891  }
1892  }
1893  }
1894  return JSC::JSObject::deleteProperty(exec, propertyName);
1895 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
The QMetaEnum class provides meta-data about an enumerator.
Definition: qmetaobject.h:147
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const char * key(int index) const
Returns the key with the given index, or 0 if no such key exists.
const char * name
int enumeratorCount() const
Returns the number of enumerators in this class.
int keyCount() const
Returns the number of keys.
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QMetaEnum enumerator(int index) const
Returns the meta-data for the enumerator with the given index.
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
QByteArray convertToLatin1(const JSC::UString &str)

◆ execute()

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

Definition at line 1964 of file qscriptqobject.cpp.

Referenced by QScript::QObjectConnectionManager::qt_metacall().

1966 {
1967  if (data->ctor) {
1969  QScriptContext *ctx = eng_p->contextForFrame(exec);
1970  JSC::CallData callData;
1971  JSC::CallType callType = data->ctor.getCallData(callData);
1972  Q_UNUSED(callType);
1973  Q_ASSERT_X(callType == JSC::CallTypeHost, Q_FUNC_INFO, "script constructors not supported");
1974  if (data->ctor.inherits(&FunctionWithArgWrapper::info)) {
1975  FunctionWithArgWrapper *wrapper = static_cast<FunctionWithArgWrapper*>(JSC::asObject(data->ctor));
1976  QScriptValue result = wrapper->function()(ctx, QScriptEnginePrivate::get(eng_p), wrapper->arg());
1977  return eng_p->scriptValueToJSCValue(result);
1978  } else {
1979  Q_ASSERT(data->ctor.inherits(&FunctionWrapper::info));
1980  FunctionWrapper *wrapper = static_cast<FunctionWrapper*>(JSC::asObject(data->ctor));
1981  QScriptValue result = wrapper->function()(ctx, QScriptEnginePrivate::get(eng_p));
1982  return eng_p->scriptValueToJSCValue(result);
1983  }
1984  } else {
1985  const QMetaObject *meta = data->value;
1986  if (meta->constructorCount() > 0) {
1987  JSC::JSValue result = callQtMethod(exec, QMetaMethod::Constructor, /*thisQObject=*/0,
1988  args, meta, meta->constructorCount()-1, /*maybeOverloaded=*/true);
1989  if (!exec->hadException()) {
1990  Q_ASSERT(result && result.inherits(&QScriptObject::info));
1991  QScriptObject *object = static_cast<QScriptObject*>(JSC::asObject(result));
1992  QScript::QObjectDelegate *delegate = static_cast<QScript::QObjectDelegate*>(object->delegate());
1994  if (data->prototype)
1995  object->setPrototype(data->prototype);
1996  }
1997  return result;
1998  } else {
1999  QString message = QString::fromLatin1("no constructor for %0")
2000  .arg(QLatin1String(meta->className()));
2001  return JSC::throwError(exec, JSC::TypeError, message);
2002  }
2003  }
2004 }
The QScriptContext class represents a Qt Script function invocation.
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
static QScriptEnginePrivate * get(QScriptEngine *q)
static JSC::JSValue callQtMethod(JSC::ExecState *exec, QMetaMethod::MethodType callType, QObject *thisQObject, const JSC::ArgList &scriptArgs, const QMetaObject *meta, int initialIndex, bool maybeOverloaded)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static const JSC::ClassInfo info
int constructorCount() const
Returns the number of constructors in this class.
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static const JSC::ClassInfo info
void setOwnership(QScriptEngine::ValueOwnership ownership)
JSC::JSValue scriptValueToJSCValue(const QScriptValue &value)
static QScriptContext * contextForFrame(JSC::ExecState *frame)
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
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
#define ctx
Definition: qgl.cpp:6094
static const JSC::ClassInfo info
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ getCallData()

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

Definition at line 1921 of file qscriptqobject.cpp.

1922 {
1923  callData.native.function = call;
1924  return JSC::CallTypeHost;
1925 }
static JSC::JSValue JSC_HOST_CALL call(JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)

◆ getConstructData()

JSC::ConstructType QScript::QMetaObjectWrapperObject::getConstructData ( JSC::ConstructData &  constructData)
virtual

Definition at line 1927 of file qscriptqobject.cpp.

1928 {
1929  constructData.native.function = construct;
1930  return JSC::ConstructTypeHost;
1931 }
static JSC::JSObject * construct(JSC::ExecState *, JSC::JSObject *, const JSC::ArgList &)

◆ getOwnPropertyDescriptor()

bool QScript::QMetaObjectWrapperObject::getOwnPropertyDescriptor ( JSC::ExecState *  exec,
const JSC::Identifier &  propertyName,
JSC::PropertyDescriptor &  descriptor 
)
virtual

Definition at line 1821 of file qscriptqobject.cpp.

1824 {
1825  const QMetaObject *meta = data->value;
1826  if (!meta)
1827  return false;
1828 
1829  if (propertyName == exec->propertyNames().prototype) {
1830  descriptor.setDescriptor(data->ctor
1831  ? data->ctor.get(exec, propertyName)
1832  : data->prototype,
1833  JSC::DontDelete | JSC::DontEnum);
1834  return true;
1835  }
1836 
1837  QByteArray name = QString(propertyName.ustring()).toLatin1();
1838 
1839  for (int i = 0; i < meta->enumeratorCount(); ++i) {
1840  QMetaEnum e = meta->enumerator(i);
1841  for (int j = 0; j < e.keyCount(); ++j) {
1842  const char *key = e.key(j);
1843  if (!qstrcmp(key, name.constData())) {
1844  descriptor.setDescriptor(JSC::JSValue(exec, e.value(j)),
1845  JSC::ReadOnly | JSC::DontDelete);
1846  return true;
1847  }
1848  }
1849  }
1850 
1851  return JSC::JSObject::getOwnPropertyDescriptor(exec, propertyName, descriptor);
1852 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
The QMetaEnum class provides meta-data about an enumerator.
Definition: qmetaobject.h:147
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const char * key(int index) const
Returns the key with the given index, or 0 if no such key exists.
The QString class provides a Unicode character string.
Definition: qstring.h:83
const char * name
int enumeratorCount() const
Returns the number of enumerators in this class.
int keyCount() const
Returns the number of keys.
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int key
QMetaEnum enumerator(int index) const
Returns the meta-data for the enumerator with the given index.
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
int value(int index) const
Returns the value with the given index; or returns -1 if there is no such value.

◆ getOwnPropertyNames()

void QScript::QMetaObjectWrapperObject::getOwnPropertyNames ( JSC::ExecState *  exec,
JSC::PropertyNameArray &  propertyNames,
JSC::EnumerationMode  mode = JSC::ExcludeDontEnumProperties 
)
virtual

Definition at line 1897 of file qscriptqobject.cpp.

1900 {
1901  const QMetaObject *meta = data->value;
1902  if (!meta)
1903  return;
1904  for (int i = 0; i < meta->enumeratorCount(); ++i) {
1905  QMetaEnum e = meta->enumerator(i);
1906  for (int j = 0; j < e.keyCount(); ++j)
1907  propertyNames.add(JSC::Identifier(exec, e.key(j)));
1908  }
1909  JSC::JSObject::getOwnPropertyNames(exec, propertyNames, mode);
1910 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
The QMetaEnum class provides meta-data about an enumerator.
Definition: qmetaobject.h:147
const char * key(int index) const
Returns the key with the given index, or 0 if no such key exists.
int enumeratorCount() const
Returns the number of enumerators in this class.
int keyCount() const
Returns the number of keys.
QMetaEnum enumerator(int index) const
Returns the meta-data for the enumerator with the given index.

◆ getOwnPropertySlot()

bool QScript::QMetaObjectWrapperObject::getOwnPropertySlot ( JSC::ExecState *  exec,
const JSC::Identifier &  propertyName,
JSC::PropertySlot &  slot 
)
virtual

Definition at line 1789 of file qscriptqobject.cpp.

1792 {
1793  const QMetaObject *meta = data->value;
1794  if (!meta)
1795  return false;
1796 
1797  if (propertyName == exec->propertyNames().prototype) {
1798  if (data->ctor)
1799  slot.setValue(data->ctor.get(exec, propertyName));
1800  else
1801  slot.setValue(data->prototype);
1802  return true;
1803  }
1804 
1805  QByteArray name = convertToLatin1(propertyName.ustring());
1806 
1807  for (int i = 0; i < meta->enumeratorCount(); ++i) {
1808  QMetaEnum e = meta->enumerator(i);
1809  for (int j = 0; j < e.keyCount(); ++j) {
1810  const char *key = e.key(j);
1811  if (!qstrcmp(key, name.constData())) {
1812  slot.setValue(JSC::JSValue(exec, e.value(j)));
1813  return true;
1814  }
1815  }
1816  }
1817 
1818  return JSC::JSObject::getOwnPropertySlot(exec, propertyName, slot);
1819 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
The QMetaEnum class provides meta-data about an enumerator.
Definition: qmetaobject.h:147
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const char * key(int index) const
Returns the key with the given index, or 0 if no such key exists.
const char * name
int enumeratorCount() const
Returns the number of enumerators in this class.
int keyCount() const
Returns the number of keys.
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int key
QMetaEnum enumerator(int index) const
Returns the meta-data for the enumerator with the given index.
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
QByteArray convertToLatin1(const JSC::UString &str)
int value(int index) const
Returns the value with the given index; or returns -1 if there is no such value.

◆ markChildren()

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

Definition at line 1912 of file qscriptqobject.cpp.

1913 {
1914  if (data->ctor)
1915  markStack.append(data->ctor);
1916  if (data->prototype)
1917  markStack.append(data->prototype);
1918  JSC::JSObject::markChildren(markStack);
1919 }

◆ put()

void QScript::QMetaObjectWrapperObject::put ( JSC::ExecState *  exec,
const JSC::Identifier &  propertyName,
JSC::JSValue  value,
JSC::PutPropertySlot &  slot 
)
virtual

Definition at line 1854 of file qscriptqobject.cpp.

1856 {
1857  if (propertyName == exec->propertyNames().prototype) {
1858  if (data->ctor)
1859  data->ctor.put(exec, propertyName, value, slot);
1860  else
1861  data->prototype = value;
1862  return;
1863  }
1864  const QMetaObject *meta = data->value;
1865  if (meta) {
1866  QByteArray name = convertToLatin1(propertyName.ustring());
1867  for (int i = 0; i < meta->enumeratorCount(); ++i) {
1868  QMetaEnum e = meta->enumerator(i);
1869  for (int j = 0; j < e.keyCount(); ++j) {
1870  if (!qstrcmp(e.key(j), name.constData()))
1871  return;
1872  }
1873  }
1874  }
1875  JSC::JSObject::put(exec, propertyName, value, slot);
1876 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
The QMetaEnum class provides meta-data about an enumerator.
Definition: qmetaobject.h:147
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const char * key(int index) const
Returns the key with the given index, or 0 if no such key exists.
const QMetaObject * value() const
const char * name
int enumeratorCount() const
Returns the number of enumerators in this class.
int keyCount() const
Returns the number of keys.
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QMetaEnum enumerator(int index) const
Returns the meta-data for the enumerator with the given index.
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
QByteArray convertToLatin1(const JSC::UString &str)

◆ setValue()

void QScript::QMetaObjectWrapperObject::setValue ( const QMetaObject value)
inline

Definition at line 298 of file qscriptqobject_p.h.

◆ value()

const QMetaObject* QScript::QMetaObjectWrapperObject::value ( ) const
inline

Properties

◆ data

Data* QScript::QMetaObjectWrapperObject::data
protected

◆ info

const JSC::ClassInfo QScript::QMetaObjectWrapperObject::info = { "QMetaObject", 0, 0, 0 }
static

◆ StructureFlags

const unsigned QScript::QMetaObjectWrapperObject::StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::OverridesMarkChildren | JSC::OverridesGetPropertyNames | JSC::ImplementsHasInstance | JSObject::StructureFlags
staticprotected

Definition at line 306 of file qscriptqobject_p.h.


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