google / CodeCity

Google's Code City is a social programming environment. It offers a comic book inspired virtual world where programmers can write code collaboratively.
https://codecity.world/
Apache License 2.0
188 stars 37 forks source link

Finalise Permissions Model #392

Open cpcallen opened 4 years ago

cpcallen commented 4 years ago

What features do we need, and how should they work?

Here are some features we've discussed as being potentially useful / necessary, along with a discussion of open questions about how they should be implemented.

Object-Level Attributes

The two main attributes we've discussed for objects are fertility and readability, equivalent to LambdaMoo Object's f and r properties.

Object Fertility

Do we want objects to have a 'fertile' attribute that, if false, prevents them from being made the prototype of another object without sufficient authorisation?

Object Readability

Do we want objects to have a 'readable' attribute that, if false, prevents obtaining or iterating over the list of property names without sufficient authorisation?

Property-level attributes

The three main features we've discussed are:

Cross-cutting concerns

Property readability

Do we want properties to have a 'readable' attribute that, if false, prevents obtaining or iterating over the list of property names without sufficient authorisation?

Property heritability/reservedness/finality

Private fields

Should we just implement the private class fields proposal and be done with it?

Pros:

Cons:

WeakMaps

Alternatively, what if we use WeakMaps, which are equivalent?

Pros:

Cons:

Permissive access

What if we allow write (and maybe read-of-non-readable) property access based on the prototype chain?

  1. Simple approach: if u owns prototype p of object o, then functions controlled by u have full access to o as if u owned o.
  2. Fancier: if function f is specially tagged as being a method on prototype p of object o, then f has full access to o as if f{owner} controlled o.

Pros:

Cons:

Restrictive access: reserved, with full hierarchy survey on-demand

What about implementing something like a c bit (call it reserved attribute, or maybe heritable), following the LambdaMOO implementation as closely as possible?

We'd need to examine all the descendants of an object when using Object.defineProperty to create a reserved property (or reserve an existing one), or when using Object.setPrototypeOf to change its prototype.

Pros:

Cons:

Holy grail: reserved, without need for to full hierarchy surveys

Could there be some way to get the semantics of the previous option, without the cost of having certain operations be very slow and/or inconvenient?

Idea: private fields without special syntax

Here we would implement private fields, except:

Pros:

Cons:

cpcallen commented 4 years ago

Summary of last night's discussion:

Objects:

Properties: