Consecutive call to @context seem to be stateless
dcolley opened this issue · 2 comments
dcolley commented
Given some javascript
function Calc() {
var total = 0; // private variable
this.clear = function(){ total = 0; }; //public function
this.add = function(a){ total += a; };
this.getTotal = function(){ return String(total); }
};
var mycal = new Calc();
And some ruby
source = open( Dir.pwd+"/lib/calc.js" ).read
@context = ExecJS.compile( source )
@context.call 'mycal.clear'
puts @context.call( 'mycal.getTotal' )
@context.call 'mycal.add', 1
@context.call 'mycal.add', 1
puts @context.call( 'mycal.getTotal' )
... why does @context.call( 'mycal.getTotal' )
always return 0?
dcolley commented
is there any explanation for closing this issue?
sobakasu commented
I've found that using a context compile with therubyracer
as a backend maintains state, but using the nodejs
backend doesn't maintain state. it might be worth adding to the documentation that you can't rely on state being maintained with context calls.