mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
auto merge of #1951 : Ms2ger/servo/castable, r=jdm
This commit is contained in:
commit
5dbde0c5c5
3 changed files with 22 additions and 52 deletions
|
@ -93,7 +93,6 @@ class CastableObjectUnwrapper():
|
|||
codeOnFailure is the code to run if unwrapping fails.
|
||||
"""
|
||||
def __init__(self, descriptor, source, target, codeOnFailure, isOptional=False):
|
||||
assert descriptor.castable
|
||||
self.substitution = { "type" : descriptor.nativeType,
|
||||
"depth": descriptor.interface.inheritanceDepth(),
|
||||
"prototype": "PrototypeList::id::" + descriptor.name,
|
||||
|
@ -383,7 +382,6 @@ class CGMethodCall(CGThing):
|
|||
|
||||
class FakeCastableDescriptor():
|
||||
def __init__(self, descriptor):
|
||||
self.castable = True
|
||||
self.nativeType = "*%s" % descriptor.concreteType
|
||||
self.name = descriptor.name
|
||||
class FakeInterface:
|
||||
|
@ -630,35 +628,23 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
|||
typePtr = descriptor.nativeType
|
||||
|
||||
templateBody = ""
|
||||
if descriptor.castable:
|
||||
if descriptor.interface.isConsequential():
|
||||
raise TypeError("Consequential interface %s being used as an "
|
||||
"argument but flagged as castable" %
|
||||
descriptor.interface.identifier.name)
|
||||
if failureCode is not None:
|
||||
templateBody += str(CastableObjectUnwrapper(
|
||||
descriptor,
|
||||
"(${val}).to_object()",
|
||||
"${declName}",
|
||||
failureCode,
|
||||
isOptional or type.nullable()))
|
||||
else:
|
||||
templateBody += str(FailureFatalCastableObjectUnwrapper(
|
||||
descriptor,
|
||||
"(${val}).to_object()",
|
||||
"${declName}",
|
||||
isOptional or type.nullable()))
|
||||
if descriptor.interface.isConsequential():
|
||||
raise TypeError("Consequential interface %s being used as an "
|
||||
"argument" % descriptor.interface.identifier.name)
|
||||
|
||||
if failureCode is not None:
|
||||
templateBody += str(CastableObjectUnwrapper(
|
||||
descriptor,
|
||||
"(${val}).to_object()",
|
||||
"${declName}",
|
||||
failureCode,
|
||||
isOptional or type.nullable()))
|
||||
else:
|
||||
templateBody += (
|
||||
"match unwrap_value::<" + typePtr + ">(&${val} as *JSVal, "
|
||||
"PrototypeList::id::%s, %d) {\n" % (descriptor.name, descriptor.interface.inheritanceDepth() if descriptor.concrete else 0) +
|
||||
" Err(()) => {")
|
||||
templateBody += CGIndenter(onFailureBadType(failureCode,
|
||||
descriptor.interface.identifier.name)).define()
|
||||
templateBody += (
|
||||
" }\n"
|
||||
" Ok(unwrapped) => ${declName} = Some(unwrapped)\n"
|
||||
"}\n")
|
||||
templateBody += str(FailureFatalCastableObjectUnwrapper(
|
||||
descriptor,
|
||||
"(${val}).to_object()",
|
||||
"${declName}",
|
||||
isOptional or type.nullable()))
|
||||
|
||||
templateBody = wrapObjectTemplate(templateBody, isDefinitelyObject,
|
||||
type, failureCode)
|
||||
|
@ -2662,7 +2648,7 @@ class CGAbstractBindingMethod(CGAbstractExternMethod):
|
|||
" return false as JSBool;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"let this: *%s;" % self.descriptor.concreteType))
|
||||
"let this: *mut %s;" % self.descriptor.concreteType))
|
||||
|
||||
def generate_code(self):
|
||||
assert(False) # Override me
|
||||
|
@ -4170,7 +4156,7 @@ class CGAbstractClassHook(CGAbstractExternMethod):
|
|||
|
||||
def definition_body_prologue(self):
|
||||
return """
|
||||
let this: *%s = unwrap::<*%s>(obj);
|
||||
let this: *mut %s = unwrap::<%s>(obj);
|
||||
""" % (self.descriptor.concreteType, self.descriptor.concreteType)
|
||||
|
||||
def definition_body(self):
|
||||
|
|
|
@ -137,15 +137,6 @@ class Descriptor(DescriptorProvider):
|
|||
self.concreteType = desc.get('concreteType', ifaceName)
|
||||
self.needsAbstract = desc.get('needsAbstract', [])
|
||||
self.createGlobal = desc.get('createGlobal', False)
|
||||
|
||||
if self.interface.isCallback():
|
||||
if 'castable' in desc:
|
||||
raise TypeError("%s is callback but has a castable "
|
||||
"setting" % self.interface.identifier.name)
|
||||
self.castable = False
|
||||
else:
|
||||
self.castable = desc.get('castable', True)
|
||||
|
||||
self.register = desc.get('register', True)
|
||||
|
||||
# If we're concrete, we need to crawl our ancestor interfaces and mark
|
||||
|
|
|
@ -81,10 +81,10 @@ pub unsafe fn dom_object_slot(obj: *JSObject) -> u32 {
|
|||
}
|
||||
}
|
||||
|
||||
pub unsafe fn unwrap<T>(obj: *JSObject) -> T {
|
||||
pub unsafe fn unwrap<T>(obj: *JSObject) -> *mut T {
|
||||
let slot = dom_object_slot(obj);
|
||||
let val = JS_GetReservedSlot(obj, slot);
|
||||
cast::transmute(val.to_private())
|
||||
val.to_private() as *mut T
|
||||
}
|
||||
|
||||
pub unsafe fn get_dom_class(obj: *JSObject) -> Result<DOMClass, ()> {
|
||||
|
@ -103,7 +103,7 @@ pub unsafe fn get_dom_class(obj: *JSObject) -> Result<DOMClass, ()> {
|
|||
return Err(());
|
||||
}
|
||||
|
||||
pub fn unwrap_object<T>(obj: *JSObject, proto_id: PrototypeList::id::ID, proto_depth: uint) -> Result<T, ()> {
|
||||
pub fn unwrap_object<T>(obj: *JSObject, proto_id: PrototypeList::id::ID, proto_depth: uint) -> Result<*mut T, ()> {
|
||||
unsafe {
|
||||
get_dom_class(obj).and_then(|dom_class| {
|
||||
if dom_class.interface_chain[proto_depth] == proto_id {
|
||||
|
@ -128,13 +128,6 @@ pub fn unwrap_jsmanaged<T: Reflectable>(obj: *JSObject,
|
|||
})
|
||||
}
|
||||
|
||||
pub fn unwrap_value<T>(val: *JSVal, proto_id: PrototypeList::id::ID, proto_depth: uint) -> Result<T, ()> {
|
||||
unsafe {
|
||||
let obj = (*val).to_object();
|
||||
unwrap_object(obj, proto_id, proto_depth)
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn squirrel_away_unique<T>(x: ~T) -> *T {
|
||||
cast::transmute(x)
|
||||
}
|
||||
|
@ -644,7 +637,7 @@ pub fn global_object_for_js_object(obj: *JSObject) -> JS<window::Window> {
|
|||
let clasp = JS_GetClass(global);
|
||||
assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0);
|
||||
// FIXME(jdm): Either don't hardcode or sanity assert prototype stuff.
|
||||
match unwrap_object::<*mut window::Window>(global, PrototypeList::id::Window, 1) {
|
||||
match unwrap_object(global, PrototypeList::id::Window, 1) {
|
||||
Ok(win) => JS::from_raw(win),
|
||||
Err(_) => fail!("found DOM global that doesn't unwrap to Window"),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue