Page 1 of 1

enumerating JS API features

Posted: 01 Mar 2012, 15:22
by aubergine
Hi,

Anyone know how I can enumerate all the JS API functions / properties defined in the scripting environment?

I can check for existence of one using something like this:

Code: Select all

if (!!chat) console("yay, we can chat");
But how do I get a list of all the functions/properties defined by JS API, from within my script, in the environment in which my script is running?

"for (i in this)" on the global scope just tells me what's in the global object. Likewise (just incase you were about to mention the enumerable flag) "Object.getOwnPropertyNames(this)" on the global scope doesn't list any of the JS API stuff either.

Any ideas?

Re: enumerating JS API features

Posted: 06 Mar 2012, 01:00
by milo christiansen
I wrote a script that prints the API for my JavaScript host (which also uses QScript) using a for-in loop to enumerate all the functions and properties.

The secret is to make the function take an object parameter and pass it "this" from the global scope, then call the function recursively on everything for which typeof === "object" :)

or you could make it use "this" as the object if nothing is passed in :wink:

Re: enumerating JS API features

Posted: 06 Mar 2012, 08:50
by aubergine
I found that in QtScript the Object.getOwnPropertyNames() behaves oddly on the global object ("this" from the global scope) and in the end found I could enumerate the JS API features using Object.keys().

I documented my travels:

https://warzone.atlassian.net/wiki/page ... Id=1671765

https://warzone.atlassian.net/wiki/disp ... the+JS+API

I'd be interested to learn more about your script.

Re: enumerating JS API features

Posted: 06 Mar 2012, 17:21
by milo christiansen
I'll post a copy soon :wink:

Re: enumerating JS API features

Posted: 19 Mar 2012, 16:51
by milo christiansen
Sorry I forgot :oops:

Anyway here is the copy promised.