I have what I hope is a quick and naive question. I've written (in
JavaScript) an interactive read-eval-print-loop that's encapsulated
within an object. However, I recently noticed that toplevel function
definitions specified to the interpreter do not appear to be
'remembered' by the interpreter. After some diagnostic work, I've
reduced the core problem to this:
var evaler = {
eval: function (str)
{
return eval(str);
},
};
eval("function t1() { return 1; }"); // GOOD
evaler.eval("function t2() { return 2; }"); // FAIL
After running this script, I have a definition for t1, and no
defintion for t2. The act of calling eval from within evaler is
sufficiently different from the toplevel call that the global
definition does not get recorded. What does happen is that the call to
evaler.eval returns a function object, so I'm presuming that t2 is
being defined and stored in some other set of bindings that I don't
have access to. (It's not defined in evaler.)
Is there any easy fix for this? I've tried all sorts of fixes, and
haven't stumbled upon one that works. (Most of what I've done has
centered around putting the call to eval in an anonymous function, and
altering the way that's called, chainging __parent__, etc.)
My suspicion is that I'm missing something fundamental (that I need to
know anyway).
Thanks,
Mike
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino