Skip to content

Instantly share code, notes, and snippets.

View tvcutsem's full-sized avatar

Tom Van Cutsem tvcutsem

View GitHub Profile
@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:
*
@tvcutsem
tvcutsem / simpler-layer-cake.js
Created November 2, 2019 21:54
layer-cake without generators
// https://github.com/Agoric/layer-cake without generators
const {
create: objCreate,
getOwnPropertyDescriptors: gopds,
defineProperties,
prototype: objPrototype,
freeze,
} = Object;

Keybase proof

I hereby claim:

  • I am tvcutsem on github.
  • I am tvcutsem (https://keybase.io/tvcutsem) on keybase.
  • I have a public key ASCtXaBpDeiI_yfsA4ztoHV6TUELTu7GkAnyhL5GT-XY9go

To claim this, I am signing this object:

@tvcutsem
tvcutsem / doublelifting.js
Created September 12, 2013 12:18
An ES6 proxy making use of "double-lifting" (i.e. a proxy whose handler is a proxy). Allows you to write generic handlers that only have to implement a single trap, yet can intercept all possible operations.
// a proxy making use of "double-lifting" (i.e. a proxy whose handler is a proxy)
var metaHandler = {
get: function(dummyTarget, trapName, dummyReceiver) {
return function(...trapArgs) { // function acting as a generic trap, its this-binding is irrelevant
console.log("intercepting "+trapName);
return Reflect[trapName](...trapArgs); // forward manually
}
},
};
@tvcutsem
tvcutsem / membrane_dummy_getPrototypeOf.js
Created October 9, 2012 10:51
membranes with dummy target and getPrototypeOf
load('reflect.js'); // https://github.com/tvcutsem/harmony-reflect/blob/master/reflect.js
function makeMembrane(initTarget) {
var cache = new WeakMap();
var revoked = false;
function wrap(target) {
if (Object(target) !== target) return target; // primitives are passed through
var wrapper = cache.get(target);
if (wrapper) return wrapper;
@tvcutsem
tvcutsem / membrane_getPrototypeOf.js
Created October 8, 2012 18:18
membranes and getPrototypeOf
load('reflect.js'); // https://github.com/tvcutsem/harmony-reflect/blob/master/reflect.js
function makeMembrane(initTarget) {
var cache = new WeakMap();
var revoked = false;
function wrap(obj) {
if (Object(obj) !== obj) return obj; // primitives are passed through
var wrapper = cache.get(obj);
if (wrapper) return wrapper;
@tvcutsem
tvcutsem / Constructor.js
Created August 31, 2011 13:15
Constructor Function Proxies
/**
* A convenience method to create a proper Constructor Function
* implemented as a function proxy
*/
Proxy.createConstructor = function(handler, callTrap) {
var proto = new Object();
var ctor = Proxy.createFunction(
handler,
callTrap,
function() {
@tvcutsem
tvcutsem / deferredtest.html
Created June 22, 2011 18:08
Deferred functions in Javascript using Generators
<!DOCTYPE html>
<html>
<head>
<!-- using Kris Kowal's Q library, based on CommonJS Promises/B
https://github.com/kriskowal/q
http://wiki.commonjs.org/wiki/Promises/B
Code based on ideas by Mark S. Miller and Dave Herman. The animation example
was taken from <http://wiki.ecmascript.org/doku.php?id=strawman:deferred_functions>
-->