Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML - getting the code of a JS function as a string

It seems like it is possible to get the code of a function in JavaScript, and that it is as simple as:

function foo() {...}
foo.toString()

However, doing that in QML gives me a rather uninspiring function () { [code] }

So is there a way to get the [code] part as well? I also tried JSON.stringify() but it didn't do any good.

like image 960
dtech Avatar asked Nov 21 '15 20:11

dtech


1 Answers

I'd like to sum up the discussion that took place in the comments, for this can be a good response for future searches.

As already stated in the comments, it looks to be a noticeable bug of QML. Here they claim that:

the QML runtime implements the ECMAScript Language Specification standard

Anyway, it actually doesn't.

Thanks to Meetfe, here is the link to the open bug regarding the issue.

The same error seems to be here, where they suggest to look at the reference for further details:

For a detailed description, see the ECMA-262 specification.

It is (at least, it looks to me) a claim of full compatibility and once more it makes me think to a bug, rather than a partial implementation of the specification.

So, unfortunately that is the intended way to stringify a function (it makes sense indeed, for it is an Ecmascript compliant environment), but it doesn't work correctly in QML, even though it should as stated in the documentation.

like image 51
skypjack Avatar answered Oct 16 '22 05:10

skypjack