Is there any way to get a list of objects within a running JS engine with a JavaScript command?

36 views
Skip to first unread message

Christoph T.

unread,
Sep 17, 2012, 7:55:13 AM9/17/12
to v8-u...@googlegroups.com
I'd like to code an aspect oriented language extension for JavaScript. My aspects should be defined in JavaScript. To weave in my advices I need a list of all objects which are currently available within the current context, to match their names e.g. against a regular expression to find out if the new advice should be woven in. Is there a function within JavaScript I can call to simply get this list?

Thank you very much for your answer in advance.

Christoph

Stephan Beal

unread,
Sep 18, 2012, 6:27:25 AM9/18/12
to v8-u...@googlegroups.com
On Mon, Sep 17, 2012 at 1:55 PM, Christoph T. <tor...@gmail.com> wrote:
I'd like to code an aspect oriented language extension for JavaScript. My aspects should be defined in JavaScript. To weave in my advices I need a list of all objects which are currently available within the current context, to match their names e.g. against a regular expression to find out if the new advice should be woven in. Is there a function within JavaScript I can call to simply get this list?

This can only be done on a per-object basis, but you can get access to the top-level list of objects via the global object with code similar to the following (run in the global scope):

var k, v;
for( k in this ) {
  if(!this.hasOwnProperty(k)) continue;
  v = this[k];
  ... do your bit here ...

AFAIK there is no standard way to get the names of vars from a scope, e.g.:

function foo(){
  var x, y, z;
  ... there is no standard way to derive the names x/y/z here ...
  ... either you know them or you don't ...
}

and i'm not sure that there's even a non-standard way to do it.

--
----- stephan beal
http://wanderinghorse.net/home/stephan/
Reply all
Reply to author
Forward
0 new messages