ajvincent / es-membrane

An ECMAScript implementation of a Membrane, allowing users to dynamically hide, override, or extend objects in JavaScript with controlled effects on the original objects.
ISC License
108 stars 13 forks source link

Hardening membrane #197

Open michaelfig opened 5 years ago

michaelfig commented 5 years ago

Hi Alex. This is a support request, not an issue.

I'm thinking of a convenience membrane for Agoric/Jessie, that has "interior" and "exterior" graphs, and when objects cross from interior to exterior they are hardened (a la Agoric/harden). This separation should be transitive over time so that the membrane also wraps interior function returns and exceptions before they escape to the exterior.

Also, when an exterior method captures an interior this, it should throw an exception.

In this formulation, I regard global variables/endowments as neither interior nor exterior.

I'm entirely naive in regards to es-membrane. Is there a straightforward way to implement this kind of membrane (with distortions or somesuch)? If so, I would happily use es-membrane to do the work.

Thank you, Michael.

ajvincent commented 5 years ago

I believe the answer is "yes". A custom ChainHandler, created via membrane.modifyRules.createChainHandler() and implemented in source/ModifyRulesAPI.js, will allow you to define whatever custom rules you wish to enforce.

I would suggest starting with the Distortions GUI. It allows you to manually configure a membrane using es-membrane based on version 0.9.

Also, take a look at source/dogfood/build-membrane.js as an example of a good starting point. The code there evolved from an attempt to build a membrane to protect the Membrane library itself (hence the subdirectory name). I used the Distortions GUI to build that file up, along with its JSON sibling, source/membrane-distortions-gui.json.

ajvincent commented 5 years ago

With all the above said, be advised:

In short, you're going to be on your own a lot more than you might like. I'll answer questions, of course, but it may take days for me to do so. There's also a long list of bugs, both filed and undiscovered...

I strongly recommend forking this project so that you're free to work on this as you see fit. I will happily review pull requests.