Re: [Caja] Functional auditor for Cajita

David-Sarah Hopwood <[email protected]>
Newsgroups gmane.comp.lang.e.general
Message-ID <[email protected]>
Mike Samuel wrote:
> Is the following copacetic by that definition?
> 
>   (function (eval, s) {
>     eval(s);
>   })

Trivially no, since it isn't annotated as functional nor pure.
Also, Cajita is a subset of ES5-strict, which prohibits 'eval' from
being used as a formal parameter name:

# It is a SyntaxError if the identifier eval or arguments appears
# within a FormalParameterList of a strict mode FunctionDeclaration
# or FunctionExpression (13.1)

Let's fix these problems first:

  var f = /*@functional*/ function (evil, s) {
    evil(s);
  };

f is now copacetic.

> If passed the arguments (freeze(eval), 'a = 0') it will modify the
> lexical environment, and I think both arguments are copacetic
> according to the frozen functions definition,

In

  f(cajita.freeze(eval), 'a = 0;');

there is a free variable reference 'eval', and the global eval is
not accessible to Cajita code. So this program is not valid Cajita.

Suppose that a hypothetical Cajita were extended with a restricted
cajita.eval function. (It would be frozen so we don't need to explicitly
freeze it.) Then cajita.eval could not be marked as copacetic. Still,

  f(cajita.eval, 'a = 0;');

would succeed up to the point where it calls cajita.eval('a = 0;')
(because f is only marked as functional, not pure, so its
cajita.eval argument is not required to be copacetic). But then it
would fail because 'a = 0;' is not a valid Cajita program (it tries to
assign to a free variable).

Even if it did not fail for that reason, cajita.eval would presumably
be modelled on ES5-strict "global eval", which cannot directly modify
its lexical environment.

OTOH,

  f(cajita.eval, 'var a = 0;');

would succeed, but is harmless.

Note that single-argument cajita.eval would have to treat its code as
being in an empty lexical environment (apart from safe globals).
There could potentially be a variant that would support evaluation
in an explicitly specified environment:

  var f2 = /*@functional*/ function (evil, s, e) {
    evil(s, e);
  };

  var env = {a: undefined};
  f(cajita.eval, 'a = 0;', env);

but since env is not frozen (and neither cajita.eval nor f are pure),
there is no reason to expect this code to be prevented from mutating
env.a.

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com

_______________________________________________
e-lang mailing list
[email protected]
http://www.eros-os.org/mailman/listinfo/e-lang
signature.asc (application/pgp-signature, 292 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.12 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iF4EAREIAAYFAkse/CsACgkQWUc8YzyzqAcdGQD7BgaBiyB2kwM7kg0tySODfmSq
bTWDwbi+VyihDA0xnn8A/3l15kU0M6OVdSpbjEvkE0p2FlmAQ5MF93RUpt0KMn6X
=KhXl
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.