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
How do I get this list ?
Many thanks in advance,
Aaron
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
I want to a list of all the functions/classes/objects in a document.
GArlington said:Look at the DOM structure and iterate through it...
Aaron said:I want to a list of all the functions/classes/objects in a document.
How do I get this list ?
<snip>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.
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?
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).
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 ?
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.
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
Ah, thanks Thomas, you have verified what I was thinking about the
javascript environment(s).
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 ?
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.
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.