-
Notifications
You must be signed in to change notification settings - Fork 115
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
Let RTCCertificate.expires have type DOMTimeStamp #324
Comments
If you refer to the
|
Wouldn't it make more sense for cases like this if expires was a getter method expires()? Then it's not strange that you get a new object every time. |
That suggests that |
I'm suggesting that any time we want something to be read-only, so we make that something return defensive copies of itself, should be a method and not an attribute. If we have a Date that is not read-only then exposing it as an attribute makes sense. But implementing method behavior on (seemingly) non-methods, like attributes, also seems strange. I would argue strange-er. Though I'm a total javascript and spec newbie so I don't know how things are normally done and I could be confused about something :), but it sounds broken to me atm. |
So it seems that WebIDL requires returning defensive copies, that obj.dateAttribute !== obj.dateAttribute unless the platform does special tricks, and that programmers should just learn to live with it :-) (in other news, == should die....) |
so the code that we can't have looks like this: |
Interesting. By the way, I'm not against defensive copies, I'm against attributes that act like methods, sounds like that would be against how javascript is supposed to work, language-wise. Having cert.expires this way is like having a pointer in C++ or a reference variable in java that changed value every time you read from it. It's like... that's not how pointers/references are supposed to work in that language. And neither are attributes (because they're just "vars", right?). But if "cert.expires" changed to "cert.expires()" everything would make sense. Unless I'm speaking out of ignorance, which is a possibility (note: I'm not a javascript programmer!). Anyway that's my two cents, I'll leave the discussion to you guys. Cheers. |
@henbos, I generally agree, but if you have to concede that an integer attribute is returned by value, why not accept that Date is special in the same fashion? It's just another ---ed up quirk of JavaScript. |
@martinthomson Because an integer really is a special case according to the language whereas a Date is an object (just like primitive types and objects are handled differently in Java), and because the equality would still hold for the integer comparison. If this was an integer nothing would be strange. I feel like this "JavaScript quirk" in particular was introduced by us; not inherent by the language. But yeah, JavaScript is pretty ---ed up. If we were able to obtain a similar behavior in say Java, our API would be filed as a JVM bug. (A variable acting like a "return new Something();" method). I see this as the same thing, but maybe I'm confused about what attributes are in JavaScript. If attributes are more than mere variables then getting method-like behavior wouldn't be as strange to me. But that's not what they're supposed to be, right? :S |
This isn't the first attribute on the web platform that returns a new object every time it is accessed, there's also In other words, it's frowned upon at least some of the time, even if all cases haven't been solved. As for Date-returning attributes and functions in the web platform, I can find these via Blink's IDL files:
For a more recent and not-yet-implemented example, there's the Based on all of this, I would recommend either a function returning Date or using some other type to represent the date, maybe |
@domenic, returning new objects from attributes and how to represent dates both seem like something that might be useful in https://w3ctag.github.io/design-principles/ |
So a few things:
|
So should I change the subject line of this bug to be "Should RTCCertificate.expires have type "long long"? |
@alvestrand yes |
The guidance in https://w3ctag.github.io/design-principles/#times-and-dates makes sense to me, so I'll change the issue title to suggest using DOMTimeStamp instead. |
http://w3c.github.io/webrtc-pc/#rtccertificate-interface
Is it the intention that this attribute return the same object every time, or a new object every time? It is generally frowned upon to have APIs where
obj.attr==obj.attr
doesn't hold true, so using[SameObject]
would be most neutral choice here.The text was updated successfully, but these errors were encountered: