aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2014-04-16 11:48:46 +0200
committerMs2ger <ms2ger@gmail.com>2014-04-16 11:54:46 +0200
commitf77b775e62494b68677dad526520a2862bb206f3 (patch)
tree57c11ae7b7310fe2f114c1e6d181eb668d9ddbbe
parent7149a25e91695465321371a4f235d2951c6212fe (diff)
downloadservo-f77b775e62494b68677dad526520a2862bb206f3.tar.gz
servo-f77b775e62494b68677dad526520a2862bb206f3.zip
Remove unwrap_object.
There is no good reason to have both unwrap_object and unwrap_jsmanaged. Removing unwrap_object simplifies the codegen and makes further simplifications easier.
-rw-r--r--src/components/script/dom/bindings/codegen/CodegenRust.py15
-rw-r--r--src/components/script/dom/bindings/utils.rs17
2 files changed, 11 insertions, 21 deletions
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py
index f7bac17bf35..61efa579241 100644
--- a/src/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/src/components/script/dom/bindings/codegen/CodegenRust.py
@@ -100,12 +100,11 @@ class CastableObjectUnwrapper():
"source" : source,
"target" : target,
"codeOnFailure" : CGIndenter(CGGeneric(codeOnFailure), 4).define(),
- "unwrapped_val" : "Some(val)" if isOptional else "val",
- "unwrapFn": "unwrap_jsmanaged" if 'JS' in descriptor.nativeType else "unwrap_object"}
+ "unwrapped_val" : "Some(val)" if isOptional else "val"}
def __str__(self):
return string.Template(
-"""match ${unwrapFn}(${source}, ${prototype}, ${depth}) {
+"""match unwrap_jsmanaged(${source}, ${prototype}, ${depth}) {
Ok(val) => ${target} = ${unwrapped_val},
Err(()) => {
${codeOnFailure}
@@ -2496,7 +2495,7 @@ class CGAbstractBindingMethod(CGAbstractExternMethod):
" return false as JSBool;\n"
"}\n"
"\n"
- "let this: *mut %s;" % self.descriptor.concreteType))
+ "let this: JS<%s>;" % self.descriptor.concreteType))
def generate_code(self):
assert(False) # Override me
@@ -2513,7 +2512,7 @@ class CGGenericMethod(CGAbstractBindingMethod):
def generate_code(self):
return CGIndenter(CGGeneric(
"let _info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, &*vp));\n"
- "return CallJitMethodOp(_info, cx, obj, this as *libc::c_void, argc, &*vp);"))
+ "return CallJitMethodOp(_info, cx, obj, this.unsafe_get() as *libc::c_void, argc, &*vp);"))
class CGSpecializedMethod(CGAbstractExternMethod):
"""
@@ -2565,7 +2564,7 @@ class CGGenericGetter(CGAbstractBindingMethod):
return CGIndenter(CGGeneric(
"return with_gc_disabled(cx, || {\n"
" let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, &*vp));\n"
- " CallJitPropertyOp(info, cx, obj, this as *libc::c_void, &*vp)\n"
+ " CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *libc::c_void, &*vp)\n"
"});\n"))
class CGSpecializedGetter(CGAbstractExternMethod):
@@ -2625,7 +2624,7 @@ class CGGenericSetter(CGAbstractBindingMethod):
"let argv: *JSVal = if argc != 0 { JS_ARGV(cx, vp as *JSVal) } else { &undef as *JSVal };\n"
"let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp as *JSVal));\n"
"let ok = with_gc_disabled(cx, || {\n"
- " CallJitPropertyOp(info, cx, obj, this as *libc::c_void, argv)\n"
+ " CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *libc::c_void, argv)\n"
"});\n"
"if ok == 0 {\n"
" return 0;\n"
@@ -4514,7 +4513,7 @@ class CGBindingRoot(CGThing):
'dom::bindings::utils::{Reflectable}',
'dom::bindings::utils::{squirrel_away_unique}',
'dom::bindings::utils::{ThrowingConstructor, unwrap, unwrap_jsmanaged}',
- 'dom::bindings::utils::{unwrap_object, VoidVal, with_gc_disabled}',
+ 'dom::bindings::utils::{VoidVal, with_gc_disabled}',
'dom::bindings::utils::{with_gc_enabled}',
'dom::bindings::trace::Traceable',
'dom::bindings::callback::{CallbackContainer,CallbackInterface}',
diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs
index 46b6175fbfe..ec1472bac28 100644
--- a/src/components/script/dom/bindings/utils.rs
+++ b/src/components/script/dom/bindings/utils.rs
@@ -97,12 +97,14 @@ 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<*mut T, ()> {
+pub fn unwrap_jsmanaged<T: Reflectable>(obj: *JSObject,
+ proto_id: PrototypeList::id::ID,
+ proto_depth: uint) -> Result<JS<T>, ()> {
unsafe {
get_dom_class(obj).and_then(|dom_class| {
if dom_class.interface_chain[proto_depth] == proto_id {
debug!("good prototype");
- Ok(unwrap(obj))
+ Ok(JS::from_raw(unwrap(obj)))
} else {
debug!("bad prototype");
Err(())
@@ -111,17 +113,6 @@ pub fn unwrap_object<T>(obj: *JSObject, proto_id: PrototypeList::id::ID, proto_d
}
}
-pub fn unwrap_jsmanaged<T: Reflectable>(obj: *JSObject,
- proto_id: PrototypeList::id::ID,
- proto_depth: uint) -> Result<JS<T>, ()> {
- let result: Result<*mut T, ()> = unwrap_object(obj, proto_id, proto_depth);
- result.map(|unwrapped| {
- unsafe {
- JS::from_raw(unwrapped)
- }
- })
-}
-
pub unsafe fn squirrel_away_unique<T>(x: ~T) -> *T {
cast::transmute(x)
}