[Interest] QJSEngine/QJSValue setProperty and deleteProperty Question

Daniel Hein daniel.hein at adbsafegate.com
Mon Sep 11 15:24:49 CEST 2017


Hi,

I have a question concerning the exact semantics of 
QJSValue::setProperty and QJSValue::deleteProperty functions. 
Specifically, what happens if I do something akin to this example:

*) I evaluate a script using the QJSEngine::evaluate() function. As a 
consequence I now have a set of properties in the global context of the 
script engine corresponding to the script defined properties, such as 
objects and functions
*) I copy? one of these functions into a container object living in the 
global context using container.setProperty("functionName", function)
*) I delete the function object in the global context 
global.deleteProperty("functionName")

My question is, does deleting the property "functionName" in the global 
context also invalidate the copy in the container?

According to the QJSValue documentation:
> Note that a QJSValue for which isObject() is true only carries a 
> reference to an actual object; copying the QJSValue will only copy the 
> object reference, not the object itself. If you want to clone an 
> object (i.e. copy an object's properties to another object), you can 
> do so with the help of a for-in statement in script code, or 
> QJSValueIterator in C++.
copying a QJSValue results in a flat copy, if the QJSValue wraps an 
object. In JavaScript functions are objects. So, I am unsure, if the 
global.deleteProperty("functionName") call just deletes this particular 
object reference, or the object itself.

Thanks for any help,
Daniel







More information about the Interest mailing list