Finalise Permissions Model #392
Labels
enhancement
Feature requests, major new features, etc.
server
Things related to the codecity server proper
Milestone
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
andr
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?
$.user
hierarchy. Are there others?#101:bf_chparent
..prototype
objects should be fertile, but ones created from object literals or byObject.create()
are not?proto.isPrototypeOf(instance)
) risky: it would be pretty easy to accidentally create a fertile offspring.Object.getFertilityOf
/Object.setFertilityOf
?isExtensible
:Object.isFertile
?preventExtensions
:Object.preventOffspring
?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?
Main use cases at the moment isDo we have other uses, long-term?$.userDatabase
, which is keyed by login cookie. We could work around this with a closure (at the expense of needing to implement dumping closures inDumper
), and making it rather harder to change the database implementation).Date
value,RegExp
source)?Object.isReadable
/Object.setReadability
?Object.setAttributes
and returned byObject.getAttributes
?Property-level attributes
The three main features we've discussed are:
r
,!c
attributes and verb's!o
attributes, respectively.Cross-cutting concerns
+c
when it was created, even if the prototype property was subsequently made-c
—while Moo Canada overrode#101:bf_set_property_info
to try to ensure that child objects' properties would always be consistent with the initial definition.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?
Object.getOwnPropertyNames
for unauthorised users? Making non-readable properties completely hidden might obviate the need for object-level readability. (DOS hidden files vs. UNIX non-readable directories…)Object.defineProperty
, if not specified explicitly?Property heritability/reservedness/finality
Private fields
Should we just implement the private class fields proposal and be done with it?
Pros:
Cons:
final
method—private fields not accessible outside class, so not useful even as a non-final method!WeakMaps
Alternatively, what if we use WeakMaps, which are equivalent?
.bar
on$.foo
be accessible as$.foo.__map_bar
; the object browser could then surface the value returned by$.foo.__map_bar.get(x)
as if it werex.bar
when browsingx
.Pros:
Cons:
Permissive access
What if we allow write (and maybe read-of-non-readable) property access based on the prototype chain?
u
owns prototypep
of objecto
, then functions controlled byu
have full access too
as ifu
ownedo
.f
is specially tagged as being a method on prototypep
of objecto
, thenf
has full access too
as iff{owner}
controlledo
.class
methods, if we implement them.Pros:
super
keyword, letting methods 'pass' without knowing what their superclass is by doingsuper.method.apply(this, arguments)
(rather than `$.specificClass.method.apply(this, arguments) as they must at the moment).isPrototypeOf
type checking—e.g., if function body begins with"use autoTypeCheck"
, it would verify thatthis
has [[HomeObject]] in its prototype chain.Cons:
!c
properties in LambadaMoo.final
, either.Restrictive access:
reserved
, with full hierarchy survey on-demandWhat about implementing something like a
c
bit (call itreserved
attribute, or maybeheritable
), 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 areserved
property (or reserve an existing one), or when usingObject.setPrototypeOf
to change its prototype.Pros:
readable
attribute) something as good as private fields, but more dynamic, since it can be added (e.g. to descendants) after object creation.final
methods for free.Cons:
IterableWeakSet
of all children of every object (but we were planning to do that anyway).defineProperty
orsetPrototypeOf
operations will fail for (to normie JS programmer) very mysterious reasons.@disinherit
—even absent fertile bit on objects.reserved
properties will interact with arrays.Holy grail:
reserved
, without need for to full hierarchy surveysCould 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?
defineProperty
/getOwnPropertyDescriptor
to access the hidden values?Idea: private fields without special syntax
Here we would implement private fields, except:
.foo
instead of.#foo
.reserved
properties of the same name declared on subclasses)—but if no such properties existed, then thereserved
property would "show through" as if it were a regular property.reserved
property would be approximately like having a #private field plus automatically-created getters and setters with matching names (and suitable security checks)—i.e.,would be approximately equivalent to
Except that, in methods tagged as belonging to
C
, accessingthis.foo
would always really accessthis.#foo
, even if.foo
were overridden on the actualthis
object.Pros:
Cons:
final
methods.o
derives fromp2
which derives fromp1
, andp1
andp2
both declare.foo
reserved, theno
could itself have three separate values for.foo
simultaneously.o
could haveP1
's#foo
,P2
's#foo
, and a regular.foo
too)The text was updated successfully, but these errors were encountered: