Adds an as_str() method to WebIDL enums to hide slice of strings from callers. Uses the new method in two places.

This commit is contained in:
Gregory Katz 2017-02-16 10:15:33 -05:00
parent 4a0b730caf
commit 4d205f00b0
3 changed files with 10 additions and 5 deletions

View file

@ -3992,12 +3992,18 @@ pub const strings: &'static [&'static str] = &[
%s,
];
impl super::%s {
pub fn as_str(&self) -> &'static str {
strings[*self as usize]
}
}
impl ToJSValConvertible for super::%s {
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
strings[*self as usize].to_jsval(cx, rval);
}
}
""" % (",\n ".join(['"%s"' % val for val in enum.values()]), enum.identifier.name)
""" % (",\n ".join(['"%s"' % val for val in enum.values()]), enum.identifier.name, enum.identifier.name)
self.cgRoot = CGList([
CGGeneric(decl),