On 26/09/2008, at 11.13, Maciej Stachowiak wrote:
>
> I would agree with such a requirement, but only in the case where
> the eval(f.toString()) is performed in the same scope where f was
> originally defined, since toString does not represent the scope chain.
Agreed! The classic variable capture problem ;-)
>
> Note however, that this still allows for some quite significant
> rewrites of the function body, so it might still not be very
> interoperable to rely on parsing and modifying the toString result.
Yes, indeed the result of toString would be distinct in different
implementations but semantically, I would get the same functions,
which is quite a strong guarantee (I think this was originally the
intended meaning of 'implementation dependent' in ECMAScript 3).
For my example application of partial evaluation, if I know that the
result is parseable as a FunctionDeclaration and I know that semantics
is preserved, then I can good ahead and perform optimizations although
the syntax is different. I would then get different performance gains
on different implementations.
However I would have to move from a form:
(function(a,b) {return a+b;}).specialize({ a: 42})
to
(function(a,b) {return a+b;}).specialize([42])
because
(function(a,b) {return a+b;}).toString()
could rewrite names of local variables and yield e.g.,
"function(v1,v2) {return v1+v2;}"
Thanks for your input,
- Karl
_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss