/** Returns a sealed box containing the payload. */
seal: function(payload) {
/**
* Encapsulates the payload, but makes it available to its
* unsealer when provoked.
*/
return caja.freeze({
toString: function() { return '<'+name+' box>'; },
provoke: function() {
squirrel = payload;
flag = true;
}
});
}
});
/**
* Obtains the payload sealed within a box sealer only by our sealer.
*/
unseal: function(box) {
flag = false;
squirrel = null;
box.provoke();
caja.require(flag,'not my box: '+box);
var result = squirrel;
// next two lines are probably unneeded, but just in case
flag = false;
squirrel = null;
return result;
}
});
return caja.freeze({
toString: function() { return '<'+name+' brand>'; },
sealer: sealer,
unsealer: unsealer
});
}