Skip to content

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
membranes with dummy target and getPrototypeOf
load('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;
var dummyTarget;
if (typeof target === "function") {
dummyTarget = target;
} else {
dummyTarget = Object.create(wrap(Object.getPrototypeOf(target)));
wrapper = Proxy(dummyTarget, Proxy(dummyTarget, { // "double lifting"
get: function(dummyTarget, trapName) {
if (revoked) throw new TypeError("membrane revoked");
return function(dummyTarget /*, ...args*/) { // generic trap
var args =, 1).map(wrap);
return wrap(Reflect[trapName].apply(undefined, [target].concat(args)));
cache.set(target, wrapper);
return wrapper;
function revoke() { revoked = true; }
return {revoke: revoke, target: wrap(initTarget)};
function C(){};
var membrane = makeMembrane(C);
var wrappedC =;
// the invariant is preserved across the membrane (both return true)
print(Object.getPrototypeOf(new C()) !== C.prototype.constructor);
print(Object.getPrototypeOf(new wrappedC()) !== wrappedC.prototype.constructor);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.