diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2010-03-05 13:31:25 (GMT) |
---|---|---|
committer | Kent Hansen <kent.hansen@nokia.com> | 2010-03-05 13:31:25 (GMT) |
commit | e10c1fe03fbfd3c8bdca7a68d4dc568715db4176 (patch) | |
tree | cd0385082694494847802c3dc6ca3842da3c49ac /src/script/bridge | |
parent | 8a9a160c8f509511b7e44b66a20d60fb37d614cc (diff) | |
download | Qt-e10c1fe03fbfd3c8bdca7a68d4dc568715db4176.zip Qt-e10c1fe03fbfd3c8bdca7a68d4dc568715db4176.tar.gz Qt-e10c1fe03fbfd3c8bdca7a68d4dc568715db4176.tar.bz2 |
Don't needlessly call pushContext() when reading properties
It's only necessary to push a QScriptContext when properties
are read from an object that inherits QScriptable.
Postpone the decision of pushing a context until we know
whether the object is a QScriptable.
Diffstat (limited to 'src/script/bridge')
-rw-r--r-- | src/script/bridge/qscriptqobject.cpp | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/script/bridge/qscriptqobject.cpp b/src/script/bridge/qscriptqobject.cpp index fbb29f5..6c401f8 100644 --- a/src/script/bridge/qscriptqobject.cpp +++ b/src/script/bridge/qscriptqobject.cpp @@ -1057,14 +1057,7 @@ JSC::JSValue JSC_HOST_CALL QtPropertyFunction::call( if (!callee->inherits(&QtPropertyFunction::info)) return throwError(exec, JSC::TypeError, "callee is not a QtPropertyFunction object"); QtPropertyFunction *qfun = static_cast<QtPropertyFunction*>(callee); - QScriptEnginePrivate *eng_p = scriptEngineFromExec(exec); - JSC::ExecState *previousFrame = eng_p->currentFrame; - eng_p->currentFrame = exec; - eng_p->pushContext(exec, thisValue, args, callee); - JSC::JSValue result = qfun->execute(eng_p->currentFrame, thisValue, args); - eng_p->popContext(); - eng_p->currentFrame = previousFrame; - return result; + return qfun->execute(exec, thisValue, args); } JSC::JSValue QtPropertyFunction::execute(JSC::ExecState *exec, @@ -1074,12 +1067,15 @@ JSC::JSValue QtPropertyFunction::execute(JSC::ExecState *exec, JSC::JSValue result = JSC::jsUndefined(); QScriptEnginePrivate *engine = scriptEngineFromExec(exec); - thisValue = engine->toUsableValue(thisValue); - QObject *qobject = QScriptEnginePrivate::toQObject(exec, thisValue); + JSC::ExecState *previousFrame = engine->currentFrame; + engine->currentFrame = exec; + + JSC::JSValue qobjectValue = engine->toUsableValue(thisValue); + QObject *qobject = QScriptEnginePrivate::toQObject(exec, qobjectValue); while ((!qobject || (qobject->metaObject() != data->meta)) - && JSC::asObject(thisValue)->prototype().isObject()) { - thisValue = JSC::asObject(thisValue)->prototype(); - qobject = QScriptEnginePrivate::toQObject(exec, thisValue); + && JSC::asObject(qobjectValue)->prototype().isObject()) { + qobjectValue = JSC::asObject(qobjectValue)->prototype(); + qobject = QScriptEnginePrivate::toQObject(exec, qobjectValue); } Q_ASSERT_X(qobject, Q_FUNC_INFO, "this-object must be a QObject"); @@ -1091,14 +1087,17 @@ JSC::JSValue QtPropertyFunction::execute(JSC::ExecState *exec, QScriptable *scriptable = scriptableFromQObject(qobject); QScriptEngine *oldEngine = 0; if (scriptable) { + engine->pushContext(exec, thisValue, args, this); oldEngine = QScriptablePrivate::get(scriptable)->engine; QScriptablePrivate::get(scriptable)->engine = QScriptEnginePrivate::get(engine); } QVariant v = prop.read(qobject); - if (scriptable) + if (scriptable) { QScriptablePrivate::get(scriptable)->engine = oldEngine; + engine->popContext(); + } result = QScriptEnginePrivate::jscValueFromVariant(exec, v); } @@ -1118,17 +1117,21 @@ JSC::JSValue QtPropertyFunction::execute(JSC::ExecState *exec, QScriptable *scriptable = scriptableFromQObject(qobject); QScriptEngine *oldEngine = 0; if (scriptable) { + engine->pushContext(exec, thisValue, args, this); oldEngine = QScriptablePrivate::get(scriptable)->engine; QScriptablePrivate::get(scriptable)->engine = QScriptEnginePrivate::get(engine); } prop.write(qobject, v); - if (scriptable) + if (scriptable) { QScriptablePrivate::get(scriptable)->engine = oldEngine; + engine->popContext(); + } result = arg; } + engine->currentFrame = previousFrame; return result; } |