On 14 feb, 16:16, Christophe Grand <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] a écrit :
>
>
>
> > Ok, I understand why it was not working. The example I tried was :
>
> > js> eval("2+2")
> > 2+2
> > 4
> > js> eval("var t=1+1+1+1")
> > var t=1+1+1+1
> > js> t
> > js: "<stdin>", line 11: uncaught JavaScript runtime exception:
> > ReferenceError: "t" is not defined.
>
> > I got the argument printed, but the variable t was not defined when
> > trying to access it afterwards. But I remembered that eval changes the
> > scope (am I right??), then it is logical that the variable t does not
> > exist in the current scope.
>
> > Thanks a lot for your help;)
>
> You're right! I didn't think about this: eval doesn't introduce a new
> scope, my "printing eval" does...
>
> If you only need eval to mutate global variables or evaluate an
> expression to a value, this "printing eval" will suffice. If not, you'll
> need some java.

That is my problem right now, since I am trying your solution in my
program. What I am doing is using rhino to execute JavaScript embedded
in web pages. So, I extract JavaScript between script tags or src
files, and so to execute it in the interpreter I use eval.

But here comes the problem: imagine the JavaScript code I want to
execute is this:

i=3;
eval("i=8")

It containes eval, and since I use eval so to execute the code, then I
have nested evals. So, to try this in the interpreter I write:

js> var i
js> eval("i=3;eval(\"i=8\");")
i=3;eval("i=8");
8

The result is that the parameter is printed, as well as evaluated, but
the problem is that the nested eval function is the native one from
JavaScript. Therefore "i=8"is not printed. What I want is that each
time it is called the argument is printed, regardless the nesting of
eval functions.

My idea was to change Rhino so to change the eval function and add a
printing statement.

Is it feasable?

Thanks a lot!!!!

_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to