Given the four relationships we seek between ES5 and a future
Cajita-like language (bottom of
<http://code.google.com/p/google-caja/wiki/SubsetRelationships>), does
this argue for one of these possibilities over the other?


---------- Forwarded message ----------
From: Allen Wirfs-Brock <[email protected]>
Date: Mon, Jul 20, 2009 at 4:45 PM
Subject: bug or feature: global declarations create configurable
properties on global object
To: "[email protected]" <[email protected]>


I’ve found what is probably a bug in the ES5 spec. that could also be
considered a feature…



ES3 says (10.2.1): “Variable instantiation is performed using the
global object as the variable object and using property attributes {
DontDelete }.”   In ES5 terms, the attributes of an ES3 global
declaration are {writable: true, enumerable: true, configurable:
false}. This means that in ES3 global var statements or function
declarations create properties on the global object that cannot be
deleted.



The current ES5 draft, following the logic starting in Declaration
Binding Instantiation (10.5) step 4.d or 5.c.i for global declarations
goes through CreateMutableBinding for ObjectEnviornmentRecords  where
we see that  [[Put]] is used to create the global object property.
(note this only happens with the property doesn’t already exist).
[[Put]] sets the attributes of a new property to {writable: true,
enumerable: true, configurable: false}.  This means that as currently
written ES5 global var statements or function declarations create
properties on the global object that can be deleted.



If the ES5 spec. is left as written this would be a “breaking change”
(although perhaps a very minor one) from ES3  that conceivably might
break somebody’s existing code.  On the other hand, setting an ES5
property’s configurable attribute to true has broader implications
than those associated with the ES3 DontDelete attribute.  In
particular, if global declarations create properties on the global
object with configurable: true then the following would be precluded
for those properties:

·        They cannot be deleted (same as in ES3)

·        Their enumerable attribute cannot be set to false.

·        They cannot be converted into a accessor properties.

Of course, there would  be an easy work around to such limitations.
Instead of using a var or function declaration to create such
properties use a Object.defineProperty(this,…) at the global level.



I don’t recall that we ever discussed this issue.  The ES5 change is
probably just a compatibility bug that creeped in when I rewrote
section 10 however I might have intentionally made the change with the
intention of bringing it up for discussion and then have forgotten to
do so.



What do people think?  Is this a feature or a bug?  I either need to
add a new item to Annex E explaining the incompatibility or make
appropriate changes to section 10 to make it match the ES3 semantics.
Which should I do?



Allen

_______________________________________________
es5-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es5-discuss



-- 
    Cheers,
    --MarkM

Reply via email to