Skip to content

Instantly share code, notes, and snippets.

@tvcutsem
tvcutsem / horton.js
Created May 25, 2023 23:06
Horton in JavaScript: delegation with blame attribution in an object-capability language
/*
* Horton in JavaScript: delegation with blame attribution in an object-capability language
*
* See http://erights.org/elib/capability/horton/index.html for idea and paper.
*
* Implementation based on: http://erights.org/elib/capability/horton
* (with N-ary message support, lexical nesting and rights amplification)
*
* To run:
*

SharedStructs are to be declarations, like class declarations, that may appear in module source text. Instances of a shared struct are JavaScript primitives and, like all other JavaScript primitives, share a per-Realm prototype instance. So, like 1..toString() looks up the %NumberPrototype% intrinsic for the realm in the current execution context in order to call its toString method, when we have a struct instance s, calling s.toString() will look up the struct’s corresponding prototype on the realm in the current execution context. The key space for that table closes over the key space of the realm’s module map and also includes the position of the struct declaration. Consequently, shared struct declarations must instantiate all contained prototypes once per evaluation of a module in the realm’s module map.

I am comfortable with this strategy in anticipation of a suitable intersection semantics for Module Harmony proposa