diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-07-27 14:32:16 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-07-27 17:58:12 (GMT) |
commit | b9026b5f2182db6f0e607035cb4ac3798bf09054 (patch) | |
tree | 4b3c06b391e10d063f3301705e7b8f314c9d3826 | |
parent | 4832462e2f0a3f68485ae85efff368e3346d5c1f (diff) | |
download | Qt-b9026b5f2182db6f0e607035cb4ac3798bf09054.zip Qt-b9026b5f2182db6f0e607035cb4ac3798bf09054.tar.gz Qt-b9026b5f2182db6f0e607035cb4ac3798bf09054.tar.bz2 |
don't rely on custom global object to get GC callback
Install custom ClientData on JSGlobalData instance instead.
Also some cleanups to avoid globalObject et al being accessed
directly.
Killed the proxying scheme employed in setGlobalObject() since it
didn't work; if you stored the original Global Object and replaced
it with another object, then added properties to the new object,
they would show up in the old object, too (because the old object
would always proxy to whatever the current Global Object was).
-rw-r--r-- | src/script/api/qscriptcontext.cpp | 12 | ||||
-rw-r--r-- | src/script/api/qscriptengine.cpp | 61 | ||||
-rw-r--r-- | src/script/api/qscriptengine_p.h | 4 | ||||
-rw-r--r-- | src/script/api/qscriptvalue.cpp | 4 | ||||
-rw-r--r-- | src/script/api/qscriptvalueiterator.cpp | 2 | ||||
-rw-r--r-- | src/script/bridge/qscriptfunction.cpp | 4 |
6 files changed, 42 insertions, 45 deletions
diff --git a/src/script/api/qscriptcontext.cpp b/src/script/api/qscriptcontext.cpp index e05e786..8d4fe18 100644 --- a/src/script/api/qscriptcontext.cpp +++ b/src/script/api/qscriptcontext.cpp @@ -205,8 +205,8 @@ QScriptContext::QScriptContext() QScriptValue QScriptContext::throwValue(const QScriptValue &value) { Q_D(QScriptContext); - JSC::ExecState *exec = d->engine->globalObject->globalExec(); JSC::JSValue jscValue = d->engine->scriptValueToJSCValue(value); + JSC::ExecState *exec = d->frame; exec->setException(jscValue); return value; } @@ -248,7 +248,7 @@ QScriptValue QScriptContext::throwError(Error error, const QString &text) jscError = JSC::URIError; break; } - JSC::ExecState *exec = d->engine->globalObject->globalExec(); + JSC::ExecState *exec = d->frame; JSC::JSObject *result = JSC::throwError(exec, jscError, QScript::qtStringToJSCUString(text)); return d->engine->scriptValueFromJSCValue(result); } @@ -264,7 +264,7 @@ QScriptValue QScriptContext::throwError(Error error, const QString &text) QScriptValue QScriptContext::throwError(const QString &text) { Q_D(QScriptContext); - JSC::ExecState *exec = d->engine->globalObject->globalExec(); + JSC::ExecState *exec = d->frame; JSC::JSObject *result = JSC::throwError(exec, JSC::GeneralError, QScript::qtStringToJSCUString(text)); return d->engine->scriptValueFromJSCValue(result); } @@ -334,7 +334,7 @@ QScriptValue QScriptContext::callee() const QScriptValue QScriptContext::argumentsObject() const { Q_D(const QScriptContext); - if (d->frame == d->engine->globalObject->globalExec()) { + if (d->frame == d->engine->globalExec()) { //global context doesn't have any argument, return an empty object return static_cast<QScriptEngine *>(d->engine->q_ptr)->newObject(); } @@ -481,7 +481,7 @@ void QScriptContext::setThisObject(const QScriptValue &thisObject) "a different engine"); return; } - if (d->frame == d->engine->globalObject->globalExec()) { + if (d->frame == d->engine->globalExec()) { qWarning("QScriptContext::setThisObject(): setting this-object of global context is not supported"); return; } @@ -501,7 +501,7 @@ void QScriptContext::setThisObject(const QScriptValue &thisObject) QScriptContext::ExecutionState QScriptContext::state() const { Q_D(const QScriptContext); - if (d->engine->globalObject->globalExec()->hadException()) + if (d->frame->hadException()) return QScriptContext::ExceptionState; return QScriptContext::NormalState; } diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 5cbb8d7..2f7e976 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -313,6 +313,7 @@ struct GlobalClientData : public JSC::JSGlobalData::ClientData GlobalClientData(QScriptEnginePrivate *e) : engine(e) {} virtual ~GlobalClientData() {} + virtual void mark() { engine->mark(); } QScriptEnginePrivate *engine; }; @@ -596,50 +597,35 @@ GlobalObject::~GlobalObject() void GlobalObject::mark() { JSC::JSGlobalObject::mark(); - engine->mark(); } bool GlobalObject::getOwnPropertySlot(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::PropertySlot& slot) { - if (engine->customGlobalObject) - return engine->customGlobalObject->getOwnPropertySlot(exec, propertyName, slot); return JSC::JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot); } void GlobalObject::put(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::JSValue value, JSC::PutPropertySlot& slot) { - if (engine->customGlobalObject) { - engine->customGlobalObject->put(exec, propertyName, value, slot); - return; - } JSC::JSGlobalObject::put(exec, propertyName, value, slot); } bool GlobalObject::deleteProperty(JSC::ExecState* exec, const JSC::Identifier& propertyName) { - if (engine->customGlobalObject) - return engine->customGlobalObject->deleteProperty(exec, propertyName); return JSC::JSGlobalObject::deleteProperty(exec, propertyName); } bool GlobalObject::getPropertyAttributes(JSC::ExecState* exec, const JSC::Identifier& propertyName, unsigned& attributes) const { - if (engine->customGlobalObject) - return engine->customGlobalObject->getPropertyAttributes(exec, propertyName, attributes); return JSC::JSGlobalObject::getPropertyAttributes(exec, propertyName, attributes); } void GlobalObject::getPropertyNames(JSC::ExecState* exec, JSC::PropertyNameArray& propertyNames) { - if (engine->customGlobalObject) { - engine->customGlobalObject->getPropertyNames(exec, propertyNames); - return; - } JSC::JSGlobalObject::getPropertyNames(exec, propertyNames); } @@ -810,7 +796,7 @@ QScriptEnginePrivate::QScriptEnginePrivate() : idGenerator(1) globalData = JSC::JSGlobalData::create().releaseRef(); globalData->clientData = new QScript::GlobalClientData(this); - globalObject = new (globalData)QScript::GlobalObject(this); + JSC::JSGlobalObject *globalObject = new (globalData)QScript::GlobalObject(this); JSC::ExecState* exec = globalObject->globalExec(); @@ -1043,6 +1029,16 @@ void QScriptEnginePrivate::releaseContextForFrame(JSC::ExecState *frame) delete ctx; } +JSC::JSGlobalObject *QScriptEnginePrivate::globalObject() const +{ + return globalData->head; +} + +JSC::ExecState *QScriptEnginePrivate::globalExec() const +{ + return globalObject()->globalExec(); +} + void QScriptEnginePrivate::mark() { if (customGlobalObject && !customGlobalObject->marked()) @@ -1085,14 +1081,14 @@ void QScriptEnginePrivate::mark() bool QScriptEnginePrivate::isCollecting() const { - return globalObject->globalData()->heap.isBusy(); + return globalData->heap.isBusy(); } void QScriptEnginePrivate::collectGarbage() { // ### why isn't the global object always marked by the Collector? - if (!globalObject->marked()) - globalObject->mark(); + if (!globalObject()->marked()) + globalObject()->mark(); JSC::JSLock lock(false); globalData->heap.collect(); } @@ -1370,7 +1366,7 @@ QScriptEngine::~QScriptEngine() QScriptValue QScriptEngine::globalObject() const { Q_D(const QScriptEngine); - JSC::JSObject *result = d->customGlobalObject ? d->customGlobalObject : d->globalObject; + JSC::JSObject *result = d->globalObject(); return const_cast<QScriptEnginePrivate*>(d)->scriptValueFromJSCValue(result); } @@ -1392,10 +1388,8 @@ void QScriptEngine::setGlobalObject(const QScriptValue &object) if (!object.isObject() || globalObject().strictlyEquals(object)) return; JSC::JSObject *jscObject = JSC::asObject(d->scriptValueToJSCValue(object)); - if (jscObject == d->globalObject) - d->customGlobalObject = 0; - else - d->customGlobalObject = jscObject; + qWarning("QScriptEngine::setGlobalObject() is not implemented"); +// d->customGlobalObject = jscObject; } /*! @@ -2416,7 +2410,7 @@ QScriptValue QScriptEnginePrivate::create(int type, const void *ptr) } } if (result.isObject() && info && info->prototype - && JSC::JSValue::strictEqual(scriptValueToJSCValue(result.prototype()), globalObject->objectPrototype())) { + && JSC::JSValue::strictEqual(scriptValueToJSCValue(result.prototype()), globalObject()->objectPrototype())) { result.setPrototype(scriptValueFromJSCValue(info->prototype)); } return result; @@ -2675,17 +2669,18 @@ void QScriptEngine::registerCustomType(int type, MarshalFunction mf, void QScriptEngine::installTranslatorFunctions(const QScriptValue &object) { Q_D(QScriptEngine); - JSC::ExecState* exec = d->globalObject->globalExec(); + JSC::ExecState* exec = d->currentFrame; JSC::JSValue jscObject = d->scriptValueToJSCValue(object); + JSC::JSGlobalObject *glob = d->globalObject(); if (!jscObject || !jscObject.isObject()) - jscObject = d->globalObject; + jscObject = glob; // unsigned attribs = JSC::DontEnum; - JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, d->globalObject->prototypeFunctionStructure(), 5, JSC::Identifier(exec, "qsTranslate"), QScript::functionQsTranslate)); - JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, d->globalObject->prototypeFunctionStructure(), 2, JSC::Identifier(exec, "QT_TRANSLATE_NOOP"), QScript::functionQsTranslateNoOp)); - JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, d->globalObject->prototypeFunctionStructure(), 3, JSC::Identifier(exec, "qsTr"), QScript::functionQsTr)); - JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, d->globalObject->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "QT_TR_NOOP"), QScript::functionQsTrNoOp)); + JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 5, JSC::Identifier(exec, "qsTranslate"), QScript::functionQsTranslate)); + JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 2, JSC::Identifier(exec, "QT_TRANSLATE_NOOP"), QScript::functionQsTranslateNoOp)); + JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 3, JSC::Identifier(exec, "qsTr"), QScript::functionQsTr)); + JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "QT_TR_NOOP"), QScript::functionQsTrNoOp)); - d->globalObject->stringPrototype()->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, d->globalObject->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "arg"), QScript::stringProtoFuncArg)); + glob->stringPrototype()->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "arg"), QScript::stringProtoFuncArg)); } /*! @@ -3286,7 +3281,7 @@ int QScriptEngine::processEventsInterval() const bool QScriptEngine::isEvaluating() const { Q_D(const QScriptEngine); - return (d->currentFrame != d->globalObject->globalExec()); + return (d->currentFrame != d->globalExec()); } /*! diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index d1af106..4db77c0 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -110,6 +110,9 @@ public: QScriptContext *contextForFrame(JSC::ExecState *frame); void releaseContextForFrame(JSC::ExecState *frame); + JSC::JSGlobalObject *globalObject() const; + JSC::ExecState *globalExec() const; + void mark(); bool isCollecting() const; void collectGarbage(); @@ -159,7 +162,6 @@ public: #endif JSC::JSGlobalData *globalData; - JSC::JSGlobalObject *globalObject; JSC::JSObject *customGlobalObject; JSC::ExecState *currentFrame; QHash<JSC::ExecState*, QScriptContext*> contextForFrameHash; diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index 7693af8..5ace14d 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -1982,7 +1982,7 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, JSC::JSValue jscThisObject = eng_p->scriptValueToJSCValue(thisObject); if (!jscThisObject || !jscThisObject.isObject()) - jscThisObject = eng_p->globalObject; + jscThisObject = eng_p->globalObject(); QVector<JSC::JSValue> argsVector; argsVector.resize(args.size()); @@ -2057,7 +2057,7 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, JSC::JSValue jscThisObject = eng_p->scriptValueToJSCValue(thisObject); if (!jscThisObject || !jscThisObject.isObject()) - jscThisObject = eng_p->globalObject; + jscThisObject = eng_p->globalObject(); JSC::JSValue array = eng_p->scriptValueToJSCValue(arguments); // copied from runtime/FunctionPrototype.cpp, functionProtoFuncApply() diff --git a/src/script/api/qscriptvalueiterator.cpp b/src/script/api/qscriptvalueiterator.cpp index 1366c3f..dbf290b 100644 --- a/src/script/api/qscriptvalueiterator.cpp +++ b/src/script/api/qscriptvalueiterator.cpp @@ -114,7 +114,7 @@ public: if (propertyNames != 0) return; QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(object.engine()); - JSC::ExecState *exec = eng_p->globalObject->globalExec(); + JSC::ExecState *exec = eng_p->globalExec(); propertyNames = new JSC::PropertyNameArray(exec); JSC::asObject(QScriptValuePrivate::get(object)->jscValue)->getPropertyNames(exec, *propertyNames); } diff --git a/src/script/bridge/qscriptfunction.cpp b/src/script/bridge/qscriptfunction.cpp index 8d2f0c8..ee5c9c3 100644 --- a/src/script/bridge/qscriptfunction.cpp +++ b/src/script/bridge/qscriptfunction.cpp @@ -32,7 +32,7 @@ namespace QScript FunctionWrapper::FunctionWrapper(QScriptEngine *engine, int length, const JSC::Identifier &name, QScriptEngine::FunctionSignature function) - : JSC::PrototypeFunction(QScriptEnginePrivate::get(engine)->globalObject->globalExec(), + : JSC::PrototypeFunction(QScriptEnginePrivate::get(engine)->globalExec(), length, name, proxyCall), data(new Data()) { data->engine = engine; @@ -85,7 +85,7 @@ JSC::JSObject* FunctionWrapper::proxyConstruct(JSC::ExecState *exec, JSC::JSObje FunctionWithArgWrapper::FunctionWithArgWrapper(QScriptEngine *engine, int length, const JSC::Identifier &name, QScriptEngine::FunctionWithArgSignature function, void *arg) - : JSC::PrototypeFunction(QScriptEnginePrivate::get(engine)->globalObject->globalExec(), + : JSC::PrototypeFunction(QScriptEnginePrivate::get(engine)->globalExec(), length, name, proxyCall), data(new Data()) { data->engine = engine; |