diff options
-rw-r--r-- | src/script/bridge/qscriptglobalobject.cpp | 9 | ||||
-rw-r--r-- | src/script/bridge/qscriptglobalobject_p.h | 4 | ||||
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 25 |
3 files changed, 38 insertions, 0 deletions
diff --git a/src/script/bridge/qscriptglobalobject.cpp b/src/script/bridge/qscriptglobalobject.cpp index c929e12..3fa5879 100644 --- a/src/script/bridge/qscriptglobalobject.cpp +++ b/src/script/bridge/qscriptglobalobject.cpp @@ -100,6 +100,15 @@ void GlobalObject::put(JSC::ExecState* exec, const JSC::Identifier& propertyName JSC::JSGlobalObject::put(exec, propertyName, value, slot); } +void GlobalObject::putWithAttributes(JSC::ExecState* exec, const JSC::Identifier& propertyName, + JSC::JSValue value, unsigned attributes) +{ + if (customGlobalObject) + customGlobalObject->putWithAttributes(exec, propertyName, value, attributes); + else + JSC::JSGlobalObject::putWithAttributes(exec, propertyName, value, attributes); +} + bool GlobalObject::deleteProperty(JSC::ExecState* exec, const JSC::Identifier& propertyName, bool checkDontDelete) { diff --git a/src/script/bridge/qscriptglobalobject_p.h b/src/script/bridge/qscriptglobalobject_p.h index eff24a2..11b1482 100644 --- a/src/script/bridge/qscriptglobalobject_p.h +++ b/src/script/bridge/qscriptglobalobject_p.h @@ -74,6 +74,8 @@ public: JSC::PropertySlot&); virtual void put(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::JSValue, JSC::PutPropertySlot&); + virtual void putWithAttributes(JSC::ExecState* exec, const JSC::Identifier& propertyName, + JSC::JSValue value, unsigned attributes); virtual bool deleteProperty(JSC::ExecState*, const JSC::Identifier& propertyName, bool checkDontDelete = true); @@ -115,6 +117,8 @@ public: virtual void put(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::JSValue value, JSC::PutPropertySlot& slot) { originalGlobalObject->JSC::JSGlobalObject::put(exec, propertyName, value, slot); } + virtual void putWithAttributes(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::JSValue value, unsigned attributes) + { originalGlobalObject->JSC::JSGlobalObject::putWithAttributes(exec, propertyName, value, attributes); } virtual bool deleteProperty(JSC::ExecState* exec, const JSC::Identifier& propertyName, bool checkDontDelete = true) { return originalGlobalObject->JSC::JSGlobalObject::deleteProperty(exec, propertyName, checkDontDelete); } diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index df74144..b0ba922 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -1107,6 +1107,31 @@ void tst_QScriptEngine::globalObjectProperties() } } QVERIFY(remainingNames.isEmpty()); + + // create property with no attributes + { + QString name = QString::fromLatin1("foo"); + QVERIFY(!global.property(name).isValid()); + QScriptValue val(123); + global.setProperty(name, val); + QVERIFY(global.property(name).equals(val)); + QVERIFY(global.propertyFlags(name) == 0); + global.setProperty(name, QScriptValue()); + QVERIFY(!global.property(name).isValid()); + } + // create property with attributes + { + QString name = QString::fromLatin1("bar"); + QVERIFY(!global.property(name).isValid()); + QScriptValue val(QString::fromLatin1("ciao")); + QScriptValue::PropertyFlags flags = QScriptValue::ReadOnly | QScriptValue::SkipInEnumeration; + global.setProperty(name, val, flags); + QVERIFY(global.property(name).equals(val)); + QEXPECT_FAIL("", "custom Global Object properties don't retain attributes", Continue); + QCOMPARE(global.propertyFlags(name), flags); + global.setProperty(name, QScriptValue()); + QVERIFY(!global.property(name).isValid()); + } } void tst_QScriptEngine::globalObjectGetterSetterProperty() |