J
Jocke P
Hi,
I had the idea to create a walkthrough sessions for users,
printing statements, then executing one by one.
I find that eval on separate strings doesn't put values in the same scope,
so any statement using an earlier value throws ReferenceError.
Here's a minimal session:
session = [
"/* Hit enter to execute next statement.\nType 'quit' to stop session. */",
"x = 'test'",
"if (x == 'test') alert('wohoo!')"
]
Here's code to execute it. It uses a custom method in my V8 shell:
for(line in session) {
input = prompt(session[line]); // prompt wraps C getline()
if (input == 'quit') break;
eval(session[line]);
}
Apparently eval operates on each line separately,
so I get reference error on the last line in session.
How could I connect the evals so they operate on the same scope?
Thanks,
Jocke
I had the idea to create a walkthrough sessions for users,
printing statements, then executing one by one.
I find that eval on separate strings doesn't put values in the same scope,
so any statement using an earlier value throws ReferenceError.
Here's a minimal session:
session = [
"/* Hit enter to execute next statement.\nType 'quit' to stop session. */",
"x = 'test'",
"if (x == 'test') alert('wohoo!')"
]
Here's code to execute it. It uses a custom method in my V8 shell:
for(line in session) {
input = prompt(session[line]); // prompt wraps C getline()
if (input == 'quit') break;
eval(session[line]);
}
Apparently eval operates on each line separately,
so I get reference error on the last line in session.
How could I connect the evals so they operate on the same scope?
Thanks,
Jocke