Symbols as WeakMap keys
For Stage 2
Daniel Ehrenberg
Igalia in partnership with Bloomberg
July 2020 TC39 meeting
Why?
Details
Spec text
Why not add a Box type?
Boxmaker, Boxmaker....
Intuition: Box objects in a primitive
const obj = { hello: "world" };
const box = Box(obj);
assert(typeof box === "box", "boxes are a new primitive type");
assert(obj !== box, "boxes are not their boxed object");
assert(obj.hello === box.deref().hello, "boxes can deref props");
assert(obj === box.deref(), "boxes can deref the full object");
const server = #{
port: 8080,
handler: Box(function handler(req) { /* ... */ }),
};
server.handler.deref()({ /* ... */ });
Box semantics in more detail
Sharing and isolating with Boxes
Problem: isolating within a Realm
delete Box.prototype.deref
Symbols as WeakMap keys omits Realm-wide mapping.�Manage your own mapping!
Stage 2?