[Development] [Interest] QJSEngine and error line

Sze Howe Koh szehowe.koh at gmail.com
Wed Apr 8 17:45:29 CEST 2015


On 8 April 2015 at 22:10, Joerg Bornemann
<joerg.bornemann at theqtcompany.com> wrote:
> On 08-Apr-15 16:06, Sze Howe Koh wrote:
>
>> I think we should document this somewhere, if it isn't already done (I
>> searched but couldn't find anything). I'm happy to volunteer if
>> necessary. Could you please provide a list of built-in properties of
>> various QJSValue types?
>
>
> The docs state mention that isError() returns true if the value is an object
> of the Error class. That's a JavaScript class. We shouldn't duplicate the
> JavaScript documentation.

There are two issues here:

1. The "lineNumber" and "fileName" properties are non-standard. They
are Mozilla extensions
(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
), so even some JavaScript devs might not know they exist.

2. The reader might not make the connection, "This is a JavaScript
Error object, therefore it has properties that help me debug" --
especially if they don't have a JavaScript background (which I presume
is true for a significant number of Qt users). Personally, I scoured
the QJSValue page looking for debugging hints, and the only thing that
jumped out at me was QJSValue::toString().

May I suggest adding a bit of documentation on our side to help people
discover the features? Currently,
http://doc.qt.io/qt-5/qjsengine.html#script-exceptions only recommends
using toString() to probe errors. That's an ideal place to add a list
of standard and non-standard properties that users can take advantage
of.


>> Also, what do you think of some API that returns a list of available
>> properties? (similar to QObject::dynamicPropertyNames() )
>
>
> See QJSValueIterator.

Got it, thanks.


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?


Regards,
Sze-Howe



More information about the Development mailing list