Getting list of all functions/classes/object

A

Aaron Gray

I want to a list of all the functions/classes/objects in a document.

How do I get this list ?

Many thanks in advance,

Aaron
 
G

GArlington

I want to a list of all the functions/classes/objects in a document.

How do I get this list ?

Many thanks in advance,

Aaron

Look at the DOM structure and iterate through it...
 
S

SAM

Aaron Gray a écrit :
I want to a list of all the functions/classes/objects in a document.

document.write( '<table border=1>');
for ( var i in window)
document.write( '<tr><td>'+ window.name + '<\/td><td>' +
typeof window + '<\/td><td>'+ window+'<\/td\/tr>');
document.write( '<\/table>');
 
T

Thomas 'PointedEars' Lahn

Aaron said:
I want to a list of all the functions/classes/objects in a document.

How do I get this list ?

There is no such list, and you cannot create it. First, there are no
classes in client-side ECMAScript implementations as of yet; those are
languages that use prototype-based inheritance.

However, you can iterate recursively over the enumerable properties of the
Global Object which in most cases allows you to retrieve information about
many properties (functions are first-class objects; methods are callable
properties, IOW functions, but not necessarily Function objects).

Note however, that many properties of objects are not enumerable (in
ECMAScript terms, they have the DontEnum attribute set); this means that you
can only find the non-enumerable properties that you know the name of, and
even then you have to rely on that the property exhibits a behavior that
allows you to detect it as being existent. This is especially difficult
with host objects.

As you can see, although your question might seem simple to you, the task
that follows from answering it is not a trivial one at all. Intimate
knowledge of the inner workings of the Specification, its implementations
and the several host environments is required to accomplish it.
Nevertheless, having almost accomplished it with my ObjectInspector (which I
had to take offline for the time being, sorry), I would say it has been and
still is a very good exercise :)


HTH

PointedEars
 
R

Richard Cornford

Thomas 'PointedEars' Lahn wrote:
Note however, that many properties of objects are not enumerable
(in ECMAScript terms, they have the DontEnum attribute set); this
means that you can only find the non-enumerable properties that
you know the name of, and even then you have to rely on that the
property exhibits a behavior that allows you to detect it as being
existent. This is especially difficult with host objects.
<snip>

Not only the properties you can know the name of but also the properties
that you can guess the name of. That is, it is possible to create an
extensive list of 'likely' property names (particularly including those
observed to exist in other browsers and their documentation) and then
try each item in that list out as a property of any given object. Those
that exist (and where existence can be observed) could then be know to
exist, though there will be plenty of exceptions thrown along the way
(and some browser crashes (for a short while (fixed by an update) IE 6
could be made to crash (literally) if you attempted to access -
'appendChild' - on an attribute node (even for a typeof operation))).

Richard.
 
T

Thomas 'PointedEars' Lahn

Richard said:
Thomas 'PointedEars' Lahn wrote:

<snip>

Not only the properties you can know the name of but also the properties
that you can guess the name of. That is, it is possible to create an ^^
extensive list of 'likely' property names (particularly including those ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
observed to exist in other browsers and their documentation) and then ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
try each item in that list out as a property of any given object. Those
that exist (and where existence can be observed) could then be know to
exist, though there will be plenty of exceptions thrown along the way
(and some browser crashes (for a short while (fixed by an update) IE 6
could be made to crash (literally) if you attempted to access -
'appendChild' - on an attribute node (even for a typeof operation))).

Is that not exactly what I just said?


PointedEars
 
R

Richard Cornford

Is that not exactly what I just said?

No because the list can include some 'good candidate' names and
unless/until you find them you do not *know* if those names are then
names of properties. The list I use, for example, contains all of the
names of methods of the Object class in Java, which I had no reason to
expect to find exposed in a browser object model, but still I found that
IceBrowser 5 exposed quite a number of them (uniquely to date).

Richard.
 
T

Thomas 'PointedEars' Lahn

Richard said:
No because the list can include some 'good candidate' names and
unless/until you find them you do not *know* if those names are then
names of properties. The list I use, for example, contains all of the
names of methods of the Object class in Java, which I had no reason to
expect to find exposed in a browser object model, but still I found that
IceBrowser 5 exposed quite a number of them (uniquely to date).

OK, this is what I *meant*, then. My ObjectInspector also uses such a list;
thank you for pointing out the IceBrowser 5 peculiarity.


Regards,

PointedEars
 
L

Lasse Reichstein Nielsen

Aaron Gray said:
One way I was thinking was to parse the <html><head><script> and
<html><body><script> texts and get any functions from the "function
*", is this possible ?

IF you can get the script text (not all browsers allow that, even
for inline scripts, and even less for scripts from separate files:
<script src="...">) then you are dealing with a program. Simple
text analysis is won't cut it.

Looking for just the pattern "function *" will find:
- matching text inside strings
- matching text inside comments
- functions inside other functions (which represent a created function
*per call* to the outer function)
- function expressions (which don't create a named function in their
scope, but might be assigned to variables)
It won't find (unless found in a string):
- anything created in a script written using document.write
- functions created using the Function method
- functions created using eval

Program analysis is hard. In general, you can't even know whether
a specific part of a program is even executed.
Trying to do it using only text parsing is reckless :)

You should at least parse the program text so you can now what
is genuine code and what is just text.

/L
 
A

Aaron Gray

Lasse Reichstein Nielsen said:
IF you can get the script text (not all browsers allow that, even
for inline scripts, and even less for scripts from separate files:
<script src="...">) then you are dealing with a program. Simple
text analysis is won't cut it.

Looking for just the pattern "function *" will find:
- matching text inside strings
- matching text inside comments
- functions inside other functions (which represent a created function
*per call* to the outer function)
- function expressions (which don't create a named function in their
scope, but might be assigned to variables)
It won't find (unless found in a string):
- anything created in a script written using document.write
- functions created using the Function method
- functions created using eval

Program analysis is hard. In general, you can't even know whether
a specific part of a program is even executed.
Trying to do it using only text parsing is reckless :)

You should at least parse the program text so you can now what
is genuine code and what is just text.

Sorry I was actually thinking of a PEG parser, but did not say that. But
whether you could get the innerText of a <script> element is another thing.

Aaron
 
T

Thomas 'PointedEars' Lahn

Aaron said:
Thomas 'PointedEars' Lahn" said:
[...]
As you can see, although your question might seem simple to you, the task
that follows from answering it is not a trivial one at all. Intimate
knowledge of the inner workings of the Specification, its implementations
and the several host environments is required to accomplish it.
Nevertheless, having almost accomplished it with my ObjectInspector (which
I
had to take offline for the time being, sorry), I would say it has been
and
still is a very good exercise :)

Please trim your quotes more, and get a decent newsreader.
Ah, thanks Thomas, you have verified what I was thinking about the
javascript environment(s).

Only that there is no such thing.
One way I was thinking was to parse the <html><head><script> and
<html><body><script> texts and get any functions from the "function *", is
this possible ?

See Lasse's answer.
Out of interest Thomas, do you have a web site at all ? I will be interested
in your ObjectInspector when you put it back online.

Header's looking at you, kid ;-)


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top