endojs / Jessie

Tiny subset of JavaScript for ocap-safe universal mobile code
Apache License 2.0
281 stars 16 forks source link

Maps and Sets without new operator? #17

Closed michaelfig closed 5 years ago

michaelfig commented 5 years ago

Hi,

I was wondering how Jessie code is expected to use Maps/WeakMaps/Sets/WeakSets, given that there is no new operator?

I would like to use these collections without freezing them. Is that possible in Jessie?

Thanks, Michael.

erights commented 5 years ago

Thanks for raising it. It's been in my head but not yet stated anywhere:

Make available, likely via imports from the SES module, makeMap etc factory functions that wrap the corresponding constructors. These modules would be written in SES, not Jessie, but their exported factory functions are designed to be used from Jessie.

Besides working around Jessie's lack of new, these functions would also freeze the instance, so that the instance can be shared without worry that someone will override one of the method names on the instance.

Separately, we're likely going to rename def into harden, so I'll use that below.

export const makeMap = harden((...args) => harden(new Map(...args)));
export const makeSet = harden((...args) => harden(new Set(...args)));
...
michaelfig commented 5 years ago

I am closing this issue in favour of #29.