[Development] [Interest] QJSEngine and error line
Simon Hausmann
simon.hausmann at theqtcompany.com
Thu Apr 9 13:17:45 CEST 2015
On Thursday 9. April 2015 11.52.31 Simon Hausmann wrote:
> On Wednesday 8. April 2015 23.45.29 Sze Howe Koh wrote:
> [...]
>
> > Going off on a slight tangent:
> > https://doc.qt.io/qt-5/qjsvalue.html#toVariant says that an Object "is
> > converted to a QVariantMap. Each property is converted to a QVariant,
> > recursively". However, calling toVariant() on an Error object
> > (isError() == isObject() == true) produces an empty QVariantMap event
> > though QJSValueIterator gets the properties just fine (using Qt
> > 5.4.1). Is this expected?
>
> That could be a bug. You should see the enumerable properties, which I think
> include message and name. If a strack trace was producible at constructor
> time, then you should also see the fileName and lineNumber properties.
> "stack" however will not be visible.
Ah, I had another look and I have to correct myself here:
The properties in question ("message", "name", etc.) are defined as being non-
enumerable [1], which is why the are not visible in the toVariant()
conversion. Similarly those properties are not visible if you do
for (propName in error) {
console.log(propName)
}
QJSValueIterator - as a C++ tool - lists _all_ properties of an object, even
the non-enumerable ones.
Simon
[1] Although those properties are technically vendor extensions and non-
standard, they are commonly implemented across web browser oriented JavaScript
engines and _there_ they are non-enumerable.
More information about the Development
mailing list