Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of ES5 descriptor attributes #79

Open
fholm opened this issue Jul 14, 2011 · 2 comments
Open

Implementation of ES5 descriptor attributes #79

fholm opened this issue Jul 14, 2011 · 2 comments

Comments

@fholm
Copy link
Owner

fholm commented Jul 14, 2011

So I've been looking at the descriptor attributes for ES5, even pushed my initial implementation to the ecmascript5-branch. There is a subtle difference between the attributes between ES3 and ES5, basically:

In ES3, the attributes are called DontEnum, DontDelete and ReadOnly. In ES5 they are called Enumerable, Configurable and Writable. They map like this to eachother:

DontEnum = Enumerable
DontDelete = Configurable (actually means more then just not delete-able in ES5, but not important here)
ReadOnly = Writable

The main difference is that the ES3 attributes are make up a "black list" of non-allowed actions, while the ES5 attributes make up a "white list" of allowed actions. The most common state in ES3 is that no attributes are set, since 99% of all properties allow all three actions. The most common state in ES5 is that all attributes are set, for the same reasons as ES5.

Having bit-flags to signal "set" state in ES5, since this is the most common case, would require us to set the three common flags on every descriptor that is created. This would cost performance, so I choose a different route.

I kept the semantics of the ES3 attributes in place: a non set bit signals an allowed action, and a set bit signals a disallowed action. However I renamed the attributes to better match the ES5 ones, and they are called NotWritable, NotEnumerable and NotConfigurable.

This basically forces you to do a boolean not operation when you test if something is writable, since the bit flag will be zero. An added benefit is also that we don't have to re-write any of our already existing code that works with these attributes, since the semantics are the same as ES3.

Confusing?

@ChaosPandion
Copy link
Collaborator

I've thought about this and believe that it will cause a small amount of confusion. That being said I don't believe this will be an issue for experienced developers.

@asbjornu
Copy link
Collaborator

asbjornu commented Aug 4, 2011

I'm not sure I like this shortcut. If it's too much work adding the ES5 attributes everywhere manually, can't it be done through AOP with LinFu, PostSharp or something similar (as a post-build process, for example)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants