mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
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:
parent
4a0b730caf
commit
4d205f00b0
3 changed files with 10 additions and 5 deletions
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue