diff options
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/api/qscriptengine.cpp | 62 | ||||
-rw-r--r-- | src/script/api/qscriptengine.h | 2 | ||||
-rw-r--r-- | src/script/api/qscriptengine_p.h | 1 | ||||
-rw-r--r-- | src/script/api/qscriptvalue.cpp | 14 | ||||
-rw-r--r-- | src/script/api/qscriptvalueiterator.cpp | 1 | ||||
-rw-r--r-- | src/script/bridge/qscriptqobject.cpp | 3 | ||||
-rw-r--r-- | src/script/script.pro | 5 |
7 files changed, 79 insertions, 9 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 356b4d0..b322523 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -260,6 +260,22 @@ QT_BEGIN_NAMESPACE whether an engine is currently running a script by calling isEvaluating(). + \section1 Garbage Collection + + Qt Script objects may be garbage collected when they are no longer + referenced. There is no guarantee as to when automatic garbage + collection will take place. + + The collectGarbage() function can be called to explicitly request + garbage collection. + + The reportAdditionalMemoryCost() function can be called to indicate + that a Qt Script object occupies memory that isn't managed by the + scripting environment. Reporting the additional cost makes it more + likely that the garbage collector will be triggered. This can be + useful, for example, when many custom, native Qt Script objects are + allocated. + \section1 Core Debugging/Tracing Facilities Since Qt 4.4, you can be notified of events pertaining to script @@ -292,6 +308,7 @@ QT_BEGIN_NAMESPACE \value ExcludeSuperClassProperties The script object will not expose properties inherited from the superclass. \value ExcludeSuperClassContents Shorthand form for ExcludeSuperClassMethods | ExcludeSuperClassProperties \value ExcludeDeleteLater The script object will not expose the QObject::deleteLater() slot. + \value ExcludeSlots The script object will not expose the QObject's slots. \value AutoCreateDynamicProperties Properties that don't already exist in the QObject will be created as dynamic properties of that object, rather than as properties of the script object. \value PreferExistingWrapperObject If a wrapper object with the requested configuration already exists, return that object. \value SkipMethodsInEnumeration Don't include methods (signals and slots) when enumerating the object's properties. @@ -1192,6 +1209,12 @@ void QScriptEnginePrivate::collectGarbage() globalData->heap.collectAllGarbage(); } +void QScriptEnginePrivate::reportAdditionalMemoryCost(int size) +{ + if (size > 0) + globalData->heap.reportExtraMemoryCost(size); +} + QScript::TimeoutCheckerProxy *QScriptEnginePrivate::timeoutChecker() const { return static_cast<QScript::TimeoutCheckerProxy*>(globalData->timeoutChecker); @@ -1989,7 +2012,7 @@ QScriptValue QScriptEngine::newRegExp(const QRegExp ®exp) prototype; otherwise, the prototype will be the Object prototype object. - \sa setDefaultPrototype(), QScriptValue::toVariant() + \sa setDefaultPrototype(), QScriptValue::toVariant(), reportAdditionalMemoryCost() */ QScriptValue QScriptEngine::newVariant(const QVariant &value) { @@ -2020,6 +2043,8 @@ QScriptValue QScriptEngine::newVariant(const QVariant &value) true), you can pass QScriptContext::thisObject() (the default constructed script object) to this function to initialize the new object. + + \sa reportAdditionalMemoryCost() */ QScriptValue QScriptEngine::newVariant(const QScriptValue &object, const QVariant &value) @@ -2050,7 +2075,7 @@ QScriptValue QScriptEngine::newVariant(const QScriptValue &object, wrapper object (either by script code or C++) will result in a script exception. - \sa QScriptValue::toQObject() + \sa QScriptValue::toQObject(), reportAdditionalMemoryCost() */ QScriptValue QScriptEngine::newQObject(QObject *object, ValueOwnership ownership, const QObjectWrapOptions &options) @@ -2084,6 +2109,8 @@ QScriptValue QScriptEngine::newQObject(QObject *object, ValueOwnership ownership (QScriptContext::isCalledAsConstructor() returns true), you can pass QScriptContext::thisObject() (the default constructed script object) to this function to initialize the new object. + + \sa reportAdditionalMemoryCost() */ QScriptValue QScriptEngine::newQObject(const QScriptValue &scriptObject, QObject *qtObject, @@ -2137,7 +2164,7 @@ QScriptValue QScriptEngine::newObject() \a data, if specified, is set as the internal data of the new object (using QScriptValue::setData()). - \sa QScriptValue::scriptClass() + \sa QScriptValue::scriptClass(), reportAdditionalMemoryCost() */ QScriptValue QScriptEngine::newObject(QScriptClass *scriptClass, const QScriptValue &data) @@ -3843,6 +3870,8 @@ QStringList QScriptEngine::importedExtensions() const been created). However, you can call this function to explicitly request that garbage collection should be performed as soon as possible. + + \sa reportAdditionalMemoryCost() */ void QScriptEngine::collectGarbage() { @@ -3851,6 +3880,33 @@ void QScriptEngine::collectGarbage() } /*! + \since 4.7 + + Reports an additional memory cost of the given \a size, measured in + bytes, to the garbage collector. + + This function can be called to indicate that a Qt Script object has + memory associated with it that isn't managed by Qt Script itself. + Reporting the additional cost makes it more likely that the garbage + collector will be triggered. + + Note that if the additional memory is shared with objects outside + the scripting environment, the cost should not be reported, since + collecting the Qt Script object would not cause the memory to be + freed anyway. + + Negative \a size values are ignored, i.e. this function can't be + used to report that the additional memory has been deallocated. + + \sa collectGarbage() +*/ +void QScriptEngine::reportAdditionalMemoryCost(int size) +{ + Q_D(QScriptEngine); + d->reportAdditionalMemoryCost(size); +} + +/*! Sets the interval between calls to QCoreApplication::processEvents to \a interval milliseconds. diff --git a/src/script/api/qscriptengine.h b/src/script/api/qscriptengine.h index 2ce3183..3212ed5 100644 --- a/src/script/api/qscriptengine.h +++ b/src/script/api/qscriptengine.h @@ -125,6 +125,7 @@ public: ExcludeSuperClassContents = 0x0006, SkipMethodsInEnumeration = 0x0008, ExcludeDeleteLater = 0x0010, + ExcludeSlots = 0x0020, AutoCreateDynamicProperties = 0x0100, PreferExistingWrapperObject = 0x0200 @@ -232,6 +233,7 @@ public: QStringList importedExtensions() const; void collectGarbage(); + void reportAdditionalMemoryCost(int size); void setProcessEventsInterval(int interval); int processEventsInterval() const; diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index 47e5d8a..70ab7c9 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -244,6 +244,7 @@ public: void mark(JSC::MarkStack& markStack); bool isCollecting() const; void collectGarbage(); + void reportAdditionalMemoryCost(int size); //flags that we set on the return value register for native function. (ie when codeBlock is 0) enum ContextFlags { diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index 5db1165..4cd84a4 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -1505,8 +1505,9 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, const QScriptValueList &args) { Q_D(const QScriptValue); - if (!d || !d->isJSC()) + if (!d || !d->isObject()) return QScriptValue(); + QScript::APIShim shim(d->engine); JSC::JSValue callee = d->jscValue; JSC::CallData callData; JSC::CallType callType = callee.getCallData(callData); @@ -1582,8 +1583,9 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, const QScriptValue &arguments) { Q_D(QScriptValue); - if (!d || !d->isJSC()) + if (!d || !d->isObject()) return QScriptValue(); + QScript::APIShim shim(d->engine); JSC::JSValue callee = d->jscValue; JSC::CallData callData; JSC::CallType callType = callee.getCallData(callData); @@ -1656,8 +1658,9 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, QScriptValue QScriptValue::construct(const QScriptValueList &args) { Q_D(const QScriptValue); - if (!d || !d->isJSC()) + if (!d || !d->isObject()) return QScriptValue(); + QScript::APIShim shim(d->engine); JSC::JSValue callee = d->jscValue; JSC::ConstructData constructData; JSC::ConstructType constructType = callee.getConstructData(constructData); @@ -1705,8 +1708,9 @@ QScriptValue QScriptValue::construct(const QScriptValueList &args) QScriptValue QScriptValue::construct(const QScriptValue &arguments) { Q_D(QScriptValue); - if (!d || !d->isJSC()) + if (!d || !d->isObject()) return QScriptValue(); + QScript::APIShim shim(d->engine); JSC::JSValue callee = d->jscValue; JSC::ConstructData constructData; JSC::ConstructType constructType = callee.getConstructData(constructData); @@ -1966,6 +1970,8 @@ QScriptValue QScriptValue::data() const this function to set object-specific data that won't be directly accessible to scripts, but may be retrieved in C++ using the data() function. + + \sa QScriptEngine::reportAdditionalMemoryCost() */ void QScriptValue::setData(const QScriptValue &data) { diff --git a/src/script/api/qscriptvalueiterator.cpp b/src/script/api/qscriptvalueiterator.cpp index 5c1e6f2..7fd7093 100644 --- a/src/script/api/qscriptvalueiterator.cpp +++ b/src/script/api/qscriptvalueiterator.cpp @@ -100,6 +100,7 @@ public: if (initialized) return; QScriptEnginePrivate *eng_p = engine(); + QScript::APIShim shim(eng_p); JSC::ExecState *exec = eng_p->globalExec(); JSC::PropertyNameArray propertyNamesArray(exec); JSC::asObject(object()->jscValue)->getOwnPropertyNames(exec, propertyNamesArray, JSC::IncludeDontEnumProperties); diff --git a/src/script/bridge/qscriptqobject.cpp b/src/script/bridge/qscriptqobject.cpp index 765e074..83a811b 100644 --- a/src/script/bridge/qscriptqobject.cpp +++ b/src/script/bridge/qscriptqobject.cpp @@ -151,7 +151,8 @@ private: static bool hasMethodAccess(const QMetaMethod &method, int index, const QScriptEngine::QObjectWrapOptions &opt) { return (method.access() != QMetaMethod::Private) - && ((index != 2) || !(opt & QScriptEngine::ExcludeDeleteLater)); + && ((index != 2) || !(opt & QScriptEngine::ExcludeDeleteLater)) + && (!(opt & QScriptEngine::ExcludeSlots) || (method.methodType() != QMetaMethod::Slot)); } static bool isEnumerableMetaProperty(const QMetaProperty &prop, diff --git a/src/script/script.pro b/src/script/script.pro index df5dbf3..55217e0 100644 --- a/src/script/script.pro +++ b/src/script/script.pro @@ -73,10 +73,13 @@ solaris-g++:isEqual(QT_ARCH,sparc) { } # Avoid JSC C API functions being exported. -DEFINES += JS_NO_EXPORT JS_EXPORTDATA="" +DEFINES += JS_NO_EXPORT INCLUDEPATH += $$PWD include(script.pri) symbian:TARGET.UID3=0x2001B2E1 + +# WebKit doesn't compile in C++0x mode +*-g++*:QMAKE_CXXFLAGS -= -std=c++0x -std=gnu++0x |