mirror of
https://github.com/servo/servo.git
synced 2025-08-02 12:10:29 +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,
|
%s,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
impl super::%s {
|
||||||
|
pub fn as_str(&self) -> &'static str {
|
||||||
|
strings[*self as usize]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ToJSValConvertible for super::%s {
|
impl ToJSValConvertible for super::%s {
|
||||||
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
|
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
|
||||||
strings[*self as usize].to_jsval(cx, rval);
|
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([
|
self.cgRoot = CGList([
|
||||||
CGGeneric(decl),
|
CGGeneric(decl),
|
||||||
|
|
|
@ -53,8 +53,7 @@ impl DOMParserMethods for DOMParser {
|
||||||
ty: DOMParserBinding::SupportedType)
|
ty: DOMParserBinding::SupportedType)
|
||||||
-> Fallible<Root<Document>> {
|
-> Fallible<Root<Document>> {
|
||||||
let url = self.window.get_url();
|
let url = self.window.get_url();
|
||||||
let content_type =
|
let content_type = DOMString::from(ty.as_str());
|
||||||
DOMString::from(DOMParserBinding::SupportedTypeValues::strings[ty as usize]);
|
|
||||||
let doc = self.window.Document();
|
let doc = self.window.Document();
|
||||||
let loader = DocumentLoader::new(&*doc.loader());
|
let loader = DocumentLoader::new(&*doc.loader());
|
||||||
match ty {
|
match ty {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||||
use dom::bindings::codegen::Bindings::PermissionStatusBinding::{self, PermissionDescriptor, PermissionName};
|
use dom::bindings::codegen::Bindings::PermissionStatusBinding::{self, PermissionDescriptor, PermissionName};
|
||||||
use dom::bindings::codegen::Bindings::PermissionStatusBinding::{PermissionNameValues, PermissionState};
|
use dom::bindings::codegen::Bindings::PermissionStatusBinding::PermissionState;
|
||||||
use dom::bindings::codegen::Bindings::PermissionStatusBinding::PermissionStatusMethods;
|
use dom::bindings::codegen::Bindings::PermissionStatusBinding::PermissionStatusMethods;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::bindings::reflector::reflect_dom_object;
|
use dom::bindings::reflector::reflect_dom_object;
|
||||||
|
@ -57,6 +57,6 @@ impl PermissionStatusMethods for PermissionStatus {
|
||||||
|
|
||||||
impl Display for PermissionName {
|
impl Display for PermissionName {
|
||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
write!(f, "{}", PermissionNameValues::strings[*self as usize].to_string())
|
write!(f, "{}", self.as_str())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue