diff options
author | Gregory Katz <gregkatz@gmail.com> | 2017-02-16 10:15:33 -0500 |
---|---|---|
committer | Gregory Katz <gregkatz@gmail.com> | 2017-02-16 10:59:07 -0500 |
commit | 4d205f00b08db289db41b3e4c79d6c9a02f9c8a0 (patch) | |
tree | bf92f43685fefde3f13e6fbb64d182b39e2e074c /components/script/dom/bindings/codegen/CodegenRust.py | |
parent | 4a0b730cafd09fbd6e5cbc00727caef9b3cae315 (diff) | |
download | servo-4d205f00b08db289db41b3e4c79d6c9a02f9c8a0.tar.gz servo-4d205f00b08db289db41b3e4c79d6c9a02f9c8a0.zip |
Adds an `as_str()` method to WebIDL enums to hide slice of strings from callers. Uses the new method in two places.
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index e4448ff834c..b184cce76b2 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -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), |