►
From YouTube: SES-mtg: Decorators and private state
Description
Recorded at the "SES Strategy Meeting" on Jan 24, 2019. See https://github.com/erights/PNLSOWNSF/blob/master/PrivateName.js
Bradley observed that a class decorator can obtain the source of the class, rewrite it, evaluate that, and replace the original class with the result. This means there's no loss of security providing a class decorator with access to the internal PrivateName.
However, the decorator can only do an indirect eval. It cannot access the lexical scope that the class appears in. Thus, a "private" declaration that appears outside the class remains protected.
B
Is
the
ability
to
entirely
replace
the
class
meaning
you
could
replace
a
class
which
is
only
able
to
be
constructed
with
new,
with
a
function
which
you
could
call
or
apply
to
and
get
something
else,
so
the
common
term,
for
that
is
a
callable
constructor.
That
is
one
of
the
driving
use
cases
of
classes.
There
are
a
few
other
ones
or
why
you
may
want
to
replace
the
class
entirely
mix-ins,
abstract
superclass
is
that
kind
of
stuff?
B
A
A
B
That's
my
claim,
but
I
want
to
make
a
further
claim
if
we
can
skip
ahead
due
to
time
constraints.
Okay,
we
do
have
a
need
for
a
different
structure
of
private
private
state
where
just
like.
If
we
use
an
evaluator,
we
can
reevaluate
the
classes
source
text.
We
can't
access
its
closure,
so
if
it
is
referencing
an
external
binding,
we
can't
really
wait
it
and
maintain
that
binding.
B
Yes,
that's
great,
so
I've
added
an
agenda
item
which
it's
very
relevant,
at
least
to
this
discussion
about
private
declarations
and
the
ability
to
produce
a
private
binding,
not
within
the
class
source
text
itself,
but
outside
of
it.
Okay,
so
it
would
be
only
able
to
be
gotten
to
via
this
closure
mechanism.
So
in.
A
A
B
B
Can
we
see
this
I'm
assuming
so
yeah
when
it's
being
recorded
sure?
That's
why
we're
gonna
present
this
next
week?
But
it
comes
from
two
or
three
now
driving
questions.
Well,
do
we
want
to
be
able
to
pass
the
keys
the
ways
to
access
our
private
data
round
as
a
first
class
value,
which
decorators,
by
their
very
nature,
need
to
have
it
as
a
first
class
value?
So
the
question
is:
what
can
we
do
for
cases
where
it
doesn't
need
decoration?
B
B
When
you
access
a
field,
this
dot,
who
it
is
accessing
the
public
property
to
when
you
use
a
computed
property,
it
is
this
open
bracket,
foo
close
bracket
for
whatever
fuels.
If
it's
a
symbol,
if
it's
a
string,
it
doesn't
really
matter
if
it's
available
under
public
reflection.
Okay,
when
you
access
things
through
private
fields,
it's
always
through
dot
hash.
B
A
B
Gonna
go
very
fast
at
this
because
we're
running
short
on
time,
but
there
are
some
problems
with
doing
this
with
week:
maps
yep
mutating
state
yep.
The
idea
here
is
what,
if
we
introduced
a
declaration
private
bar
and
we
allowed
people
to
start
accessing
bar
on
other
values,
other
bindings
within
the
scope
and
the
values
contained
within,
and
so
if
we
have
this
private
bar,
which
is
a
way
of
declaring
a
private
field,
not
within
a
class
but
within
a
scope,
we
can
kind
of
start
to
do
some
interesting
things.
A
A
B
Hope,
I
don't
get
asked
questions
about
it,
but
I
might
so
we
could
assign
to
bar
in
all
this,
but
there's
a
problem
here
where
we
don't
want
to
add
a
private
private
field
to
something
unintentionally,
yeah
and
assignment
is
generally
going
to
be
unintentional
right.
We
all
don't
want
to
reinitialize.
This
is
bad
and
more
important.
We
don't
want
to
reinitialize
a
private
field,
yep
and
so
classes
are
proposing
something
called
class
dot
initialize
for
this
problem
for
some
web
compatibility
reasons
and
so
piggybacking
off
the
same
idea.
B
A
B
Similar
to
how
a
week
map
can
take
an
object
and
attach
a
value
mapping
to
it,
I
want
to
be
able
to
use
these
private
fields
or
private
declarations.
Sorry
in
such
a
way
that
I
could
attach
them
to
a
object
in
the
same
manner
where
it's
not
at
instantiation
time,
it's
not
when
the
object
is
allocated,
but
potentially
later,
okay.
B
B
So
similar
here
we're
separating
out
the
initialization
thing:
do
it
multiple
times
you
get
errors,
don't
do
it.
You
can't
access
it.
So
one
of
the
questions
that
gets
brought
up
whenever
we
bring
this
up
is
shadowing.
We
already
have
computer
properties
within
classes,
use
the
external
scope
for
fields
mm-hmm-hmm
same
same
idea
here.
If
you
have
a
bar
private
field
for
the
class
foo,
you
know
it's
not
computed,
it
accesses
it
within
it.
So
you
have
a
bar
field.
That's
from
the
outer
scope.
You
could
use
the
same
syntax
in
it.
A
B
B
B
A
So
let
me
so
so,
with
this
code,
I
can
ask
the
question
that
I
was
thinking
about
with
the
previous
code,
which
is
the
way
this
would
evaluate.
Is
that
the
object
literal
would
evaluate
to
an
object,
and
then
the
pound
bar
private
state
map
object
would
be
invoked.
Its
initialized
method
would
be
invoked
to
register
the
instance
with
bar
yes,
okay,
good
and
store.
B
B
B
A
B
I
had
a
quick
question
on
the
code
that
Bradley
showed
before
we
move
on,
we
don't
have
to
switch
back
screens
or
anything.
Just
a
really
quick
question.
Are
you
thinking
of
blocks
Cote
private
so
could
I
create
like
like
Latin
koncak,
an
I
have
nested
blocks
cope
with
its
own
private
and
anything
outside
that
block
scope
cannot
affect
the
private
bindings
that
occur
within
that
block
school
correct.
This
also
gets
into
something
we
saw
in
the
last
meeting
where
roll-up
is
trying
to
eliminate
scopes,
and
we
don't
want
that
yeah.
B
A
So,
switching
to
my
screen,
I've
got
let's
just
let's
just
take
a
look
at
lines:
3
through
22
I'll
expand
it.
This
is
a
adequate
expression
of
the
semantics
I
have
in
mind,
so
this
make
boot.
Private
name
makes
an
object
like
a
week
map
and
it
does
it
by
wrapping
a
week.
Map
and
week
map.
Has
these
four
methods:
I'm.
Sorry,
three
methods.
A
So,
first
of
all,
I
just
want
to
check
with
Bradley
that
this
is
precisely
mirroring
the
semantics
he
has
in
mind.
So
in
it.
If
the
underlying
week,
map
already
has
the
key
we
throw,
and
otherwise
we
set
it
on
the
week
on
the
underlying
week,
map
get
if
it's
not
there,
rather
than
returning
undefined
we
throw,
and
otherwise
we
do
a
get
and
and
for
asset.
If
it's
not
there,
then
we
throw
and
otherwise
do
asset.
B
A
Good,
but
this
this
is
the
semantics
you
would
like
correct,
good
good
and
then
the
bottom
of
this
file.
What
I'm
doing
here
is
I'm.
Just
you
know.
The
thing
up
here
at
the
top
of
the
file
is
doing
it
as
an
object
literal,
where
the
four
methods
are
owned,
properties,
which
is
not
the
JavaScript
style
for
it's
not
well.
First,
let's
not
week
map
like
in
the
sense
that
week
map
is
following
the
class
pattern,
not
the
objects
as
closure
pattern,
so
I
used
to
make
boot
private.
It
turned
out.
A
That
was
the
right
first
thing
to
do
to
say
such
that
I
can
then
do
a
private
name
in
terms
of
that
and
I'm
doing
it.
This
way,
because
I'm
writing
this
code,
not
using
primitive
private
names,
because
I'm
using
this
to
explain
the
semantics
of
the
private
name
that
we
would
introduce
so
I'm
trying
to
do
it
only
with
existing
abstractions
and
then.
A
Yeah,
so
so,
using
it,
the
current
private
name
proposal
I
can
model
it
in
terms
of
the
private
name
object.
If
we
imagine
that
ampersand
pound
state
just
represents
some
mangling
of
of
the
the
pound
state
variable
into
a
lexical
name
that
is
not
otherwise
mentioned.
You
know
standard
trick
of
explaining
something
by
expansion.
A
B
A
So
so
the
following
does
not
answer
your
question,
but
just
now
that
I'm,
looking
at
the
looking
more
carefully
at
the
code
that
I
wrote
so
there's
the
gimme
special
access
method
at
the
bottom,
where
I'm
now
not
treating
ampersand
pound
anymore
as
a
as
an
assumed
mangle,
but
rather
as
explicit
syntax
for
reapplying,
and
so
that
would
that
would
give
you
the
private
name,
object
itself,
which
is
reifying.
That
does
not,
but
that
does
of
course
does
not
answer
your
question.
A
A
B
B
There's
a
whole
lot
of
trust
going
on
when
you
do
it
when
you
put
actual
getters
and
setters.
This
is
what
languages
which
don't
have
friend
access.
Do
they
expose
getters
and
setters,
either
by
decorators
annotations
or
like
well
for
test
builds
things
like
that
I'm
actually
fairly
uninterested
in
that,
because
getting
people
to
run
things
in
the
right
environment
was
proving
to
be
interesting.
For
now,.
B
So
the
real
question
is:
how
do
we
limit
who
can
get
access
to
things
right
if
we
had
exports
that
only
applied
to
other
module
records?
This
would
be
less
problematic,
saying
that
oh
only
my
test
files
can
access
this
and
not
actually
prefetching
those
files
or
anything
for
coming
today.
Well
in
this
in
a
similar
way,
we
already
have
kind
of
this
interesting
aliasing
mechanism
for
imports,
and
we
can
do
these
export
statements
separate
from
declarations.
Oh
I'm,.
A
B
A
So
this
so
so
by
just
providing
reification
directly
you're
kind
of
reducing
it
to
within
a
module,
a
previously
solved
problem
and
then
between
modules,
when
you're
trying
to
restrict
who
can
who
can
import
it.
Let's
say
we're
reducing
it
to
a
previously
unsolved
problem,
but
it's
a
problem
that
we
need
to
address
in
general,
not
just
fruitless
mechanism
and
and
for
is
interesting.
I've,
never
considered
that.
Do
you
know
Mike
Samuels
module,
Kees
proposal.
Yes,
I
do
okay,.
B
B
In
c-sharp
and
well,
c-sharp
is
where
it's
mostly
seeing.
This
in
tests
builds
they'll
expose
private
state
as
getters
and
setters,
and
so,
if
we
had
a
private
say
where
a
person
dot
social
security
number
was
private.
Normally
during
the
test
build
that
social
security
number
would
not
be
private.
Would.
A
A
A
B
A
A
A
B
I
was
just
bring
this
up
with
regards
to
the
problem
that
was
seen
with
decorators
the
concern
about
how
to
enable
this
private
state,
and
we
should
look
at
a
new
feature
to
do
it,
because
I
can't
think
of
a
way
to
solve
the
problem.
You
brought
up
about
decorators
without
introducing
a
way
to
put
the
private
binding
in
the
closure.
Okay,.
A
A
B
A
A
Okay,
yeah
yeah,
okay
lever:
this
is
heading
once
the
scoping
product.
A
we
clarify
that
week,
map
asset
call
as
a
return
value
of
the
week
map
ditto
for
the
Matt
I.
So
that's
a
a
criticism
of
my
private
name,
abstraction
at
being
unnecessarily
divergent
from
the
week
map
API.
That's
correct.
I
should
fix
that.
Okay
on
I
think
that
at
this
point
we
can
go
ahead
and
stop
recording.