On 9 April 2015 at 19:17, Simon Hausmann <[email protected]> wrote: > > 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.
Thanks for looking it up. Was it a conscious decision to restrict QJSValue::toVariant() to enumerable properties only? What's the rationale? > 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. "name" and "message" are standard :) http://www.ecma-international.org/ecma-262/5.1/#sec-15.11.4 If I've read the spec correctly, all properties of the Error prototype should be non-enumerable, so I think Qt is compliant with this part of the spec. Regards, Sze-Howe _______________________________________________ Development mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/development
