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

Why can getter operations can implicitly return undefined? #944

Closed
saschanaz opened this issue Dec 21, 2020 · 2 comments
Closed

Why can getter operations can implicitly return undefined? #944

saschanaz opened this issue Dec 21, 2020 · 2 comments

Comments

@saschanaz
Copy link
Member

There are two types of getter operations in the IDL world: returning null or undefined.

The first one is straightforward, it returns null when there is no item.

[Exposed=(Window,Worker)]
interface DOMStringList {
  readonly attribute unsigned long length;
  getter DOMString? item(unsigned long index);
  boolean contains(DOMString string);
};

But the second one is surprising. Even when the return type must be DOMString, it just returns undefined when there is no item.

[Exposed=Window,
 LegacyOverrideBuiltIns]
interface DOMStringMap {
  getter DOMString (DOMString name);
  [CEReactions] setter undefined (DOMString name, DOMString value);
  [CEReactions] deleter undefined (DOMString name);
};

Does the Web IDL spec allow this, or should this be specced? Or should it just be (DOMString or undefined) as it's now supported?

@annevk
Copy link
Member

annevk commented Dec 22, 2020

Isn't that because the property doesn't exist and therefore the getter is not invoked?

@saschanaz
Copy link
Member Author

Ah thanks, you're right. Confirmed that all named getters either: 1) have nullable return types 2) returns an empty string 3) or just throws, with some exceptions in Web Speech. I'll file an issue there.

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

No branches or pull requests

2 participants