mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Use an enum to pass the index value for interfaces/protos.
This commit is contained in:
parent
747a99d3f6
commit
7d9dc458af
2 changed files with 27 additions and 9 deletions
|
@ -537,10 +537,24 @@ unsafe extern "C" fn non_new_constructor(
|
|||
false
|
||||
}
|
||||
|
||||
pub enum ProtoOrIfaceIndex {
|
||||
ID(PrototypeList::ID),
|
||||
Constructor(PrototypeList::Constructor),
|
||||
}
|
||||
|
||||
impl Into<usize> for ProtoOrIfaceIndex {
|
||||
fn into(self) -> usize {
|
||||
match self {
|
||||
ProtoOrIfaceIndex::ID(id) => id as usize,
|
||||
ProtoOrIfaceIndex::Constructor(constructor) => constructor as usize,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_per_interface_object_handle(
|
||||
cx: SafeJSContext,
|
||||
global: HandleObject,
|
||||
id: usize,
|
||||
id: ProtoOrIfaceIndex,
|
||||
creator: unsafe fn(SafeJSContext, HandleObject, *mut ProtoOrIfaceArray),
|
||||
mut rval: MutableHandleObject,
|
||||
) {
|
||||
|
@ -549,13 +563,14 @@ pub fn get_per_interface_object_handle(
|
|||
|
||||
/* Check to see whether the interface objects are already installed */
|
||||
let proto_or_iface_array = get_proto_or_iface_array(global.get());
|
||||
rval.set((*proto_or_iface_array)[id]);
|
||||
let index: usize = id.into();
|
||||
rval.set((*proto_or_iface_array)[index]);
|
||||
if !rval.get().is_null() {
|
||||
return;
|
||||
}
|
||||
|
||||
creator(cx, global, proto_or_iface_array);
|
||||
rval.set((*proto_or_iface_array)[id]);
|
||||
rval.set((*proto_or_iface_array)[index]);
|
||||
assert!(!rval.get().is_null());
|
||||
}
|
||||
}
|
||||
|
@ -563,7 +578,7 @@ pub fn get_per_interface_object_handle(
|
|||
pub fn define_dom_interface(
|
||||
cx: SafeJSContext,
|
||||
global: HandleObject,
|
||||
id: usize,
|
||||
id: ProtoOrIfaceIndex,
|
||||
creator: unsafe fn(SafeJSContext, HandleObject, *mut ProtoOrIfaceArray),
|
||||
enabled: fn(SafeJSContext, HandleObject) -> bool,
|
||||
) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue