Add getters and setters (#235) - #701
Conversation
|
Should this be emoji-gated? With resource instance getters/setters spec'ed & implemented, how big do you expect the jump will be to supporting static resource getters/setters and interface-level getters/setters as well?. E.g. interface a {
foo: get() -> u64;
foo: set(value: u64);
resource r {
bar: get() -> u64;
bar: set(value: u64);
baz: static get() -> u64;
baz: static set(value: u64);
}
}If not too much, it might be nice to include these at the same time. Especially interface-level getters/setters already have a couple of use cases in WASI:
|
That seems overkill to me, since getters and setters are basically sugar with a couple extra validation rules.
I was initially surprised by this question, but on further review, it seems like this happens in WebIDL often enough that we should probably go ahead and spec it right away. For example, The same goes for interface getters with properties like My main concern is codegen; I would expect that many languages don't have any kind of native syntax for interface-level getters and setters in particular. A cursory LLM exploration indicates that newer versions of Python, for example, forbid you to combine But, if some languages have to fall back to plain old functions with
To actually answer the question...probably not that hard. As far as validation, it's just dropping |
|
Another fun thing to consider: WebIDL's interface mixin ElementCSSInlineStyle {
[SameObject, PutForwards=cssText] readonly attribute CSSStyleProperties style;
};In other words, the setter for |
|
Per our new WASI 0.3.* CM feature release process, even small additions (e.g., recently, For "static getters/setters": could we instead consider cases like
I think this makes sense. |
Ryan dug into this a bit and these properties don't even require a As for the getter/setter agreement rule, I'll just go ahead and drop that. Bindings generators can just check the type agreement themselves when deciding what code to generate, and the majority of the time they should agree. |
Ah, ok. So I guess this is unlike Having to fall back to explicit |
From what I could see in #235 (comment) (see bottom of comment), the answer seems to be: |
It seems like Python might be an exception - per this page, |
|
PR is updated with emoji-gating, new canonicalization rules to match #702, a rule requiring getters to precede setters for the same property, and without the rule requiring getter and setter types to agree. I would appreciate guidance on how to specify names for static getters. How do you combine |
Adds
getandsetto WIT and adds[get]and[set]annotations to function names, along with validation conditions.Right now my strongly-unique rules forbid
[get]foo.propand[static]foo.propfrom existing on the same resource. This seems like a reasonable and conservative choice to me. It does not forbid[get]foo.propfrom existing alongside[method]foo.get-propor[static]foo.get-prop, since we need to keep that WASI migration path open. This could be pretty easily added in the future but will make me sad because it will make the strongly-unique rules even more bonkers to implement than they already are >:(Resolves #235.