Closed Bug 443316 Opened 16 years ago Closed 13 years ago

XPIDL should support constant string members

Categories

(Core :: XPCOM, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: jcranmer, Unassigned)

Details

In one of our interfaces (see bug 413260) it would be very helpful to be able to define a string constant. Because of the string APIs, it would probably make the most sense to limit such members to string types and maybe wstring instead of A{C,UTF8,}String constants.

Example:
interface nsIInterface {
    const string property = "Property";
}
FWIW, OMG IDL supports string types (see §3.10.1) as well.
Component: xpidl → XPCOM
QA Contact: xpidl → xpcom
We need this for some new web APIs (e.g. visibility API).
(In reply to Boris Zbarsky (:bz) from comment #2)
> We need this for some new web APIs (e.g. visibility API).

Telephony and other APIs will also use string constants.
I don't think we're going to implement this before the new WebIDL world, and after that I don't think we'll care to backport it to XPIDL.
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → WONTFIX
For what it's worth, having string constants seems to be considered an antipattern nowadays.  WebIDL is dropping support for them, and they will not be present in the visibility API.  I suggest not using them in telephony either.
Do you have any pointer to a discussion explaining why that's considered as an anti-pattern? What should be used instead? integer constants?
See at least discussion starting http://lists.w3.org/Archives/Public/public-script-coord/2011OctDec/0040.html

The point is that making named constants for strings just means you have to type more to use the constant than you do to use the string directly, and the constant often hides what's really going on.
You need to log in before you can comment on or make changes to this bug.