summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-07-27 12:10:30 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-07-27 12:10:30 (GMT)
commitc068efe3b63508e9a805674ac787e23a953ca5cb (patch)
tree26fca9084a7c31a198d36054cb349a391d824b9a
parentba2432acf72a0649f0f841759a61ec246c5a9b1f (diff)
downloadQt-c068efe3b63508e9a805674ac787e23a953ca5cb.zip
Qt-c068efe3b63508e9a805674ac787e23a953ca5cb.tar.gz
Qt-c068efe3b63508e9a805674ac787e23a953ca5cb.tar.bz2
introduce scriptEngineFromExec() helper function
No need to expose the fact that we go via the Global Object to get an engine pointer.
-rw-r--r--src/script/api/qscriptengine.cpp27
-rw-r--r--src/script/api/qscriptengine_p.h27
-rw-r--r--src/script/bridge/qscriptclassobject.cpp17
-rw-r--r--src/script/bridge/qscriptqobject.cpp21
4 files changed, 47 insertions, 45 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index 524a250..7ffb178 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -307,6 +307,29 @@ public:
namespace QScript
{
+
+class GlobalObject : public JSC::JSGlobalObject
+{
+public:
+ GlobalObject(QScriptEnginePrivate*);
+ virtual ~GlobalObject();
+ virtual JSC::UString className() const { return "global"; }
+ virtual void mark();
+ virtual bool getOwnPropertySlot(JSC::ExecState*,
+ const JSC::Identifier& propertyName,
+ JSC::PropertySlot&);
+ virtual void put(JSC::ExecState* exec, const JSC::Identifier& propertyName,
+ JSC::JSValue, JSC::PutPropertySlot&);
+ virtual bool deleteProperty(JSC::ExecState*,
+ const JSC::Identifier& propertyName);
+ virtual bool getPropertyAttributes(JSC::ExecState*, const JSC::Identifier&,
+ unsigned&) const;
+ virtual void getPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&);
+
+public:
+ QScriptEnginePrivate *engine;
+};
+
static int toDigit(char c)
{
if ((c >= '0') && (c <= '9'))
@@ -387,6 +410,10 @@ QString qtStringFromJSCUString(const JSC::UString &str)
return QString(reinterpret_cast<const QChar*>(str.data()), str.size());
}
+QScriptEnginePrivate *scriptEngineFromExec(JSC::ExecState *exec)
+{
+ return static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+}
bool isFunction(JSC::JSValue value)
{
diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h
index e6db40e..b7109b0 100644
--- a/src/script/api/qscriptengine_p.h
+++ b/src/script/api/qscriptengine_p.h
@@ -196,33 +196,6 @@ public:
#endif
};
-namespace QScript
-{
-
-class GlobalObject : public JSC::JSGlobalObject
-{
-public:
- GlobalObject(QScriptEnginePrivate*);
- virtual ~GlobalObject();
- virtual JSC::UString className() const { return "global"; }
- virtual void mark();
- virtual bool getOwnPropertySlot(JSC::ExecState*,
- const JSC::Identifier& propertyName,
- JSC::PropertySlot&);
- virtual void put(JSC::ExecState* exec, const JSC::Identifier& propertyName,
- JSC::JSValue, JSC::PutPropertySlot&);
- virtual bool deleteProperty(JSC::ExecState*,
- const JSC::Identifier& propertyName);
- virtual bool getPropertyAttributes(JSC::ExecState*, const JSC::Identifier&,
- unsigned&) const;
- virtual void getPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&);
-
-public:
- QScriptEnginePrivate *engine;
-};
-
-} // namespace QScript
-
QT_END_NAMESPACE
#endif // QT_NO_SCRIPT
diff --git a/src/script/bridge/qscriptclassobject.cpp b/src/script/bridge/qscriptclassobject.cpp
index 277754e..0d00456 100644
--- a/src/script/bridge/qscriptclassobject.cpp
+++ b/src/script/bridge/qscriptclassobject.cpp
@@ -32,6 +32,7 @@ namespace QScript
QString qtStringFromJSCUString(const JSC::UString &str);
JSC::UString qtStringToJSCUString(const QString &str);
+QScriptEnginePrivate *scriptEngineFromExec(JSC::ExecState *exec);
ClassObjectDelegate::ClassObjectDelegate(QScriptClass *scriptClass)
: m_scriptClass(scriptClass)
@@ -62,7 +63,7 @@ bool ClassObjectDelegate::getOwnPropertySlot(QScriptObject* object,
const JSC::Identifier &propertyName,
JSC::PropertySlot &slot)
{
- QScriptEnginePrivate *engine = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
QScriptValue scriptObject = engine->scriptValueFromJSCValue(object);
QString name = qtStringFromJSCUString(propertyName.ustring());
QScriptString scriptName = QScriptEnginePrivate::get(engine)->toStringHandle(name);
@@ -81,7 +82,7 @@ void ClassObjectDelegate::put(QScriptObject* object, JSC::ExecState *exec,
const JSC::Identifier &propertyName,
JSC::JSValue value, JSC::PutPropertySlot &slot)
{
- QScriptEnginePrivate *engine = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
QScriptValue scriptObject = engine->scriptValueFromJSCValue(object);
QString name = qtStringFromJSCUString(propertyName.ustring());
QScriptString scriptName = QScriptEnginePrivate::get(engine)->toStringHandle(name);
@@ -99,7 +100,7 @@ bool ClassObjectDelegate::deleteProperty(QScriptObject* object, JSC::ExecState *
const JSC::Identifier &propertyName)
{
// ### avoid duplication of put()
- QScriptEnginePrivate *engine = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
QScriptValue scriptObject = engine->scriptValueFromJSCValue(object);
QString name = qtStringFromJSCUString(propertyName.ustring());
QScriptString scriptName = QScriptEnginePrivate::get(engine)->toStringHandle(name);
@@ -119,7 +120,7 @@ bool ClassObjectDelegate::getPropertyAttributes(const QScriptObject* object, JSC
const JSC::Identifier &propertyName,
unsigned &attribs) const
{
- QScriptEnginePrivate *engine = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
QScriptValue scriptObject = engine->scriptValueFromJSCValue(object);
QString name = qtStringFromJSCUString(propertyName.ustring());
QScriptString scriptName = QScriptEnginePrivate::get(engine)->toStringHandle(name);
@@ -148,7 +149,7 @@ bool ClassObjectDelegate::getPropertyAttributes(const QScriptObject* object, JSC
void ClassObjectDelegate::getPropertyNames(QScriptObject* object, JSC::ExecState *exec,
JSC::PropertyNameArray &propertyNames)
{
- QScriptEnginePrivate *engine = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
QScriptValue scriptObject = engine->scriptValueFromJSCValue(object);
QScriptClassPropertyIterator *it = m_scriptClass->newIterator(scriptObject);
if (it != 0) {
@@ -180,7 +181,7 @@ JSC::JSValue JSC_HOST_CALL ClassObjectDelegate::call(JSC::ExecState *exec, JSC::
if (!delegate || (delegate->type() != QScriptObjectDelegate::ClassObject))
return JSC::throwError(exec, JSC::TypeError, "callee is not a ClassObject object");
QScriptClass *scriptClass = static_cast<ClassObjectDelegate*>(delegate)->scriptClass();
- QScriptEnginePrivate *eng_p = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *eng_p = scriptEngineFromExec(exec);
JSC::ExecState *previousFrame = eng_p->currentFrame;
QScriptContext *ctx = eng_p->contextForFrame(exec);
eng_p->currentFrame = exec;
@@ -206,7 +207,7 @@ JSC::JSObject* ClassObjectDelegate::construct(JSC::ExecState *exec, JSC::JSObjec
QScriptObject *obj = static_cast<QScriptObject*>(callee);
QScriptObjectDelegate *delegate = obj->delegate();
QScriptClass *scriptClass = static_cast<ClassObjectDelegate*>(delegate)->scriptClass();
- QScriptEnginePrivate *eng_p = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *eng_p = scriptEngineFromExec(exec);
JSC::ExecState *previousFrame = eng_p->currentFrame;
QScriptContext *ctx = eng_p->contextForFrame(exec);
eng_p->currentFrame = exec;
@@ -225,7 +226,7 @@ bool ClassObjectDelegate::hasInstance(QScriptObject* object, JSC::ExecState *exe
if (!scriptClass()->supportsExtension(QScriptClass::HasInstance))
return QScriptObjectDelegate::hasInstance(object, exec, value, proto);
QScriptValueList args;
- QScriptEnginePrivate *eng_p = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *eng_p = scriptEngineFromExec(exec);
args << eng_p->scriptValueFromJSCValue(object) << eng_p->scriptValueFromJSCValue(value);
QVariant result = scriptClass()->extension(QScriptClass::HasInstance, qVariantFromValue(args));
return result.toBool();
diff --git a/src/script/bridge/qscriptqobject.cpp b/src/script/bridge/qscriptqobject.cpp
index 36c601f..d903efd 100644
--- a/src/script/bridge/qscriptqobject.cpp
+++ b/src/script/bridge/qscriptqobject.cpp
@@ -215,6 +215,7 @@ static inline QScriptable *scriptableFromQObject(QObject *qobj)
JSC::UString qtStringToJSCUString(const QString &str);
QString qtStringFromJSCUString(const JSC::UString &str);
+QScriptEnginePrivate *scriptEngineFromExec(JSC::ExecState *exec);
QtFunction::QtFunction(JSC::JSValue object, int initialIndex, bool maybeOverloaded,
JSC::JSGlobalData *data, WTF::PassRefPtr<JSC::Structure> sid,
@@ -482,7 +483,7 @@ JSC::JSValue QtFunction::execute(JSC::ExecState *exec, JSC::JSValue thisValue,
Q_ASSERT(delegate && (delegate->type() == QScriptObjectDelegate::QtObject));
QObject *qobj = static_cast<QScript::QObjectDelegate*>(delegate)->value();
Q_ASSERT_X(qobj != 0, "QtFunction::call", "handle the case when QObject has been deleted");
- QScriptEnginePrivate *engine = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
const QMetaObject *meta = qobj->metaObject();
QObject *thisQObject = 0;
@@ -975,7 +976,7 @@ JSC::JSValue JSC_HOST_CALL QtFunction::call(JSC::ExecState *exec, JSC::JSObject
if (!callee->isObject(&QtFunction::info))
return throwError(exec, JSC::TypeError, "callee is not a QtFunction object");
QtFunction *qfun = static_cast<QtFunction*>(callee);
- QScriptEnginePrivate *eng_p = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *eng_p = scriptEngineFromExec(exec);
JSC::ExecState *previousFrame = eng_p->currentFrame;
eng_p->currentFrame = exec;
JSC::JSValue result = qfun->execute(exec, thisValue, args);
@@ -1012,7 +1013,7 @@ JSC::JSValue JSC_HOST_CALL QtPropertyFunction::call(
if (!callee->isObject(&QtPropertyFunction::info))
return throwError(exec, JSC::TypeError, "callee is not a QtPropertyFunction object");
QtPropertyFunction *qfun = static_cast<QtPropertyFunction*>(callee);
- QScriptEnginePrivate *eng_p = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *eng_p = scriptEngineFromExec(exec);
JSC::ExecState *previousFrame = eng_p->currentFrame;
eng_p->currentFrame = exec;
JSC::JSValue result = qfun->execute(exec, thisValue, args);
@@ -1027,7 +1028,7 @@ JSC::JSValue QtPropertyFunction::execute(JSC::ExecState *exec,
JSC::JSValue result = JSC::jsUndefined();
// ### don't go via QScriptValue
- QScriptEnginePrivate *engine = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
QScriptValue object = engine->scriptValueFromJSCValue(thisValue);
QObject *qobject = object.toQObject();
while ((!qobject || (qobject->metaObject() != data->meta))
@@ -1156,7 +1157,7 @@ bool QObjectDelegate::getOwnPropertySlot(QScriptObject *object, JSC::ExecState *
}
const QScriptEngine::QObjectWrapOptions &opt = data->options;
- QScriptEnginePrivate *eng = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *eng = scriptEngineFromExec(exec);
int index = -1;
if (name.contains('(')) {
QByteArray normalized = QMetaObject::normalizedSignature(name);
@@ -1257,7 +1258,7 @@ void QObjectDelegate::put(QScriptObject *object, JSC::ExecState* exec,
const QScriptEngine::QObjectWrapOptions &opt = data->options;
const QMetaObject *meta = qobject->metaObject();
- QScriptEnginePrivate *eng = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *eng = scriptEngineFromExec(exec);
int index = -1;
if (name.contains('(')) {
QByteArray normalized = QMetaObject::normalizedSignature(name);
@@ -1531,7 +1532,7 @@ static JSC::JSValue JSC_HOST_CALL qobjectProtoFuncFindChild(JSC::ExecState *exec
name = QScript::qtStringFromJSCUString(args.at(0).toString(exec));
QObject *child = qFindChild<QObject*>(obj, name);
QScriptEngine::QObjectWrapOptions opt = QScriptEngine::PreferExistingWrapperObject;
- QScriptEnginePrivate *engine = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
return engine->newQObject(child, QScriptEngine::QtOwnership, opt);
}
@@ -1579,7 +1580,7 @@ static JSC::JSValue JSC_HOST_CALL qobjectProtoFuncFindChildren(JSC::ExecState *e
JSC::JSArray *const result = JSC::constructEmptyArray(exec, length);
QScriptEngine::QObjectWrapOptions opt = QScriptEngine::PreferExistingWrapperObject;
- QScriptEnginePrivate *engine = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
for (int i = 0; i < length; ++i) {
QObject *const child = children.at(i);
result->put(exec, i, engine->newQObject(child, QScriptEngine::QtOwnership, opt));
@@ -1773,7 +1774,7 @@ JSC::JSValue JSC_HOST_CALL QMetaObjectWrapperObject::call(
if (!callee->isObject(&QMetaObjectWrapperObject::info))
return throwError(exec, JSC::TypeError, "callee is not a QMetaObject");
QMetaObjectWrapperObject *self = static_cast<QMetaObjectWrapperObject*>(callee);
- QScriptEnginePrivate *eng_p = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *eng_p = scriptEngineFromExec(exec);
JSC::ExecState *previousFrame = eng_p->currentFrame;
eng_p->currentFrame = exec;
JSC::JSValue result = self->execute(exec, args);
@@ -1784,7 +1785,7 @@ JSC::JSValue JSC_HOST_CALL QMetaObjectWrapperObject::call(
JSC::JSObject* QMetaObjectWrapperObject::construct(JSC::ExecState *exec, JSC::JSObject *callee, const JSC::ArgList &args)
{
QMetaObjectWrapperObject *self = static_cast<QMetaObjectWrapperObject*>(callee);
- QScriptEnginePrivate *eng_p = static_cast<QScript::GlobalObject*>(exec->lexicalGlobalObject())->engine;
+ QScriptEnginePrivate *eng_p = scriptEngineFromExec(exec);
JSC::ExecState *previousFrame = eng_p->currentFrame;
eng_p->currentFrame = exec;
JSC::JSValue result = self->execute(exec, args);