ecmascript-types icon indicating copy to clipboard operation
ecmascript-types copied to clipboard

Typed Object, partial classes and member order, and sizes and throwing when creating views of non-explicitly typed untyped objects

Open sirisian opened this issue 7 years ago • 2 comments

This is similar to this: https://github.com/sirisian/ecmascript-types/issues/11

Dynamically typed objects that aren't sealed prevent a complication for placement new syntax and array views into them.

I'm thinking that objects should be classified possibly supporting a kind of sealed of frozen state or simply ignoring dynamically allocated members when in a view.

I can probably write more here later. Partial classes pose an interesting design decision also maybe because the order of members matters.

sirisian avatar Jun 29 '17 08:06 sirisian

C# specifically states that member ordering is undefined when using partial classes. I think it makes sense then that in Javascript it too would be undefined. It's just not a common situation to have plain old data defined in multiple independent classes.

So the spec needs to state that partial classes create undefined order. The @offset decorator specifically if supported would need to throw inside of a partial class. Creating views of partial class types would also be invalid so MyType would throw a TypeError "Cannot create a view of a partial class. Member ordering is undefined in partial classes. Consider using inheritance."

The spec also needs to very clearly explain the ordering of members in inherited objects as covered by #17.

sirisian avatar Jul 06 '17 17:07 sirisian

I renamed the section on "Partial Class" to "Class Extension" and moved down the definition of a partial class to be defined in a later spec. It's not important for types and few people ever use them, but as a consideration I think it's important to not conflict with any syntax they might use. There are no conflicts currently.

sirisian avatar Jul 07 '17 03:07 sirisian