You can try CVS HEAD code -- now Function.apply() and Function.call()
invoked on a function that is itself defined in JS will not leave the
current interpreter loop, therefore the continuations will work as
expected. Well, at least as long as the caller and the callee are in
the same security domain, that is.
You should however be aware that there is plenty of other code in
Rhino that takes a function as an argument and then runs it within
some Java code -- Array methods every(), filter(), forEach(), map(),
some(), sort() are more prominent examples. If you'd need to be able
to capture a continuation from within a function passed to these, you
should probably resort to overwriting them with equivalents
implemented in JS itself using i.e. Array.prototype.filter =
function(...) {...}. Full implementations for these methods in JS can
be found in JS reference for them, i.e. see:
<http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:filter#Compatibility
>
for an example. We don't want to do that out of the box for all these
methods because of performance reasons, and also because it rises a
host of other questions (i.e. when to compile them, what's their
security domain etc.).
apply() and call() are however special in that you can't implement
them in pure JS. Strictly speaking, only apply() needs to be treated
specially because call() can be implemented atop of apply(), but it
was really easy to implement special handling in interpreter for
call() once apply() was done, so there :-)
Attila.
On 2007.11.22., at 18:01, Thomas wrote:
> Thanks! This explains the strange behavior.
> Anyhow, it should be documented somewhere that the implementation of
> continuations in Rhino is only half done and only works on a language
> subset. I mean, how can a normal user know that. It took me quite a
> while
> just to find out what causes the problem. Also, why leaving the
> interpreter
> loop at this point? What's so different to a normal function call
> (other
> than the explicitely defined this object)?
>
> Thanks for your help!
> Cheers, Thomas
>
> "Attila Szegedi" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> ...
>> Hm... that's indeed a problem. Without looking at the code, I
>> actually
>> have an idea why it doesn't work. Continuations work only within a
>> single
>> invocation of Rhino's stackless interpreter loop. If you call out
>> of the
>> interpreter loop into Java code (which call() and apply() will
>> do), and
>> then back into a new instance of interpreter loop (which an
>> interpreted
>> function will do to run its implementation), a continuation will
>> not work
>> correctly. It can only capture/unwind within the current
>> interpreter loop
>> invocation.
>>
>> It'd be possible to apply a bit of a trickery in interpreter loop to
>> detect when call/apply is invoked for an InterpretedFunction
>> instance,
>> and run it in the current interpreter loop.
>>
>> Attila.
>>
>> --
>> home: http://www.szegedi.org
>> weblog: http://constc.blogspot.com
>>
>> On 2007.11.22., at 17:03, Thomas wrote:
>>
>>> I'm heavily using continuations and noticed that they don't work
>>> correctly
>>> if my code uses the call() or apply() functions on Function
>>> objectes to
>>> invoke a function. Just wondering if anybody had similar experience?
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino