Safe, Closure-free, Serializable functions

Mark S. Miller erights at
Wed Sep 25 18:15:20 PDT 2013

A concrete example of using SES to serialize and unserialize safe closure
free functions is Bob, serializing the escrowExchange function on line 22
of <

    var escrowSrc = ''+escrowExchange;

This works because of <>. Bob
then sends it to the contractHost, who doesn't trust Bob, on line 59 of <

        var tokensP = Q(contractHostP).send('setup', escrowSrc);

in ES5 syntax, or

        var tokensP = contractHostP ! setup(escrowSrc);

in strawman ES7 syntax. The contractHost received this string it its setup
method at line 89 and 90 of <

      setup: function(contractSrc) {
        contractSrc = ''+contractSrc;

which also coerces it to a string. It then evaluates it on line 95, by
calling the previously described confine function from the SES library:

        var contract = confine(contractSrc, {Q: Q});

The contractHost can now treat the unserialized contract as, in your
terminology, safe and closure-free.

Bob could of course have serialized any function, or made up any string he
wanted. But if the contractSrc expression has any free variables other than
the safe globals[1], i.e., if it is not closure-free[1] in your
terminology, then these variable references will only result in
ReferenceErrors when read or TypeErrors when written. As far as the
contractHost is concerned, it can safely assume that this object is closure

[1] Except for Q, which the contractHost explicitly authorizes the
contractSrc to access, in the second argument to confine above.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list