Subj : Re: Is it possible to serialize Continuation function? To : Andrei Tchijov From : Igor Bukanov Date : Fri Dec 31 2004 07:04 pm Andrei Tchijov wrote: > What will happen if > I will create Continuation object inside one of "get/set/call" methods > of host object? From which point execution will restart when this > Continuation object gets invoked? Rhino has no support for restoring continuations across native Java calls. Continuation instances in Rhino effectively capture the JS stack until the nearest native Java frame so when you transfer the control to the captured continuation only the stack frames after the Java frame is recreated. For example, consider Script A calls JS function B which call native Java method N which calls JS function C which calls JS function D so the stack would look like: function D function C *native code* function B script A Now suppose D executes the following code: storedContinuation = get_current_continuation(); where get_current_continuation() is: function get_current_continuation() { return new Continuation(); } Then when control get back to A and it executes storedContinuation() then Rhino would recreate only the stack frames for D and C and throw away A completely so the stack would look like: function D function C Now when C finishes the control would go back to the application. > More to the point, is it possible to > create continuation object in such way that it will restart execution > either just before host object method gets invoked or will "mimic" > invocation of host object method in the same way as it does invocation > of "normal" JS function (so execution restarted from the moment control > returned from host object method). Everything is possible with enough efforts. For example, Cocoon supports Java continuation via rewriting JVM bytecode on the fly. But Rhino has 0 support for that. Regards, Igor .