-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
Generic property descriptors confusing to create #1426
Comments
PropertyDescriptor
design
With #1419 we have the option to check if Do you think that may be sufficient for the time being? |
Yes, that would be the first solution I propose. The problem with that is now a
Personally I don't like this solution because it goes against the reasons for having an enum; now we need to check at runtime if a descriptor is generic or not, the enum should remove the need for that. |
Now that I examined the spec in detail, there are two places where a https://tc39.es/ecma262/#sec-createglobalfunctionbinding So, we would need to refactor every flag to be |
Here I'm in favour of option 2. If I understand it correctly, generic descriptors can have a value, but can be empty. That can be represented by an I think we should use the Rust type system to our advantage to make sure that invalid values cannot be created. Edit: I would like to know the thoughts of @HalidOdat or @RageKnify |
There is currently no support for generic property descriptors. According to the spec:
"A generic Property Descriptor is a Property Descriptor value that is neither a data Property Descriptor nor an accessor Property Descriptor."
This type of descriptor appears on some places in the spec:
https://tc39.es/ecma262/#sec-setintegritylevel
and some descriptors assign
DataDescriptor
attributes without defining aValue
:https://tc39.es/ecma262/#sec-regexpalloc
https://tc39.es/ecma262/#sec-arraysetlength
However, the current design of
PropertyDescriptor
forces every descriptor to be eitherDataDescriptor
orAccesorDescriptor
, making the api to create a generic descriptor confusing (you need to make aDataDescriptor
withoutvalue
or anAccesorDescriptor
withoutget
andset
). There are some alternatives to solve this:Preserve the current design and make a method to create a generic descriptor. This partially solves the problem but now the types don't represent exactly what type of descriptor you have.
Extend the current enum design with a
Generic
variant and liftProperties
to be insideGenericDescriptor
, possibly creating another struct in the way. This preserves the meaning of the types but now the match complicates a little more. You would have to doPropertyDescriptor::{properties, PropertyType::Data(data_desc)}
to get the internalDataDescriptor
.Remove
(Accesor/Data)Descriptor
and useOption<Field>
for every field exclusive to either descriptor. This completely removes the use ofmatch
but now we would need to obtain the type of a descriptor on runtime, possibly impacting the performance.The advantage of this approach is that now those strange cases with attributes without an explicit(@raskad made possible to represent this on Fix DataDescriptor Value to possibly be empty #1419).Value
are possible to represent.Please let me know what you think and if you have any other solution.
The text was updated successfully, but these errors were encountered: