mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Simplify InterfaceObjectToString.
This commit is contained in:
parent
610d1649cd
commit
255864a843
1 changed files with 18 additions and 3 deletions
|
@ -40,6 +40,21 @@ use js;
|
||||||
static TOSTRING_CLASS_RESERVED_SLOT: libc::size_t = 0;
|
static TOSTRING_CLASS_RESERVED_SLOT: libc::size_t = 0;
|
||||||
static TOSTRING_NAME_RESERVED_SLOT: libc::size_t = 1;
|
static TOSTRING_NAME_RESERVED_SLOT: libc::size_t = 1;
|
||||||
|
|
||||||
|
mod jsval {
|
||||||
|
use js::glue::{RUST_JSVAL_IS_STRING, RUST_JSVAL_TO_STRING};
|
||||||
|
use js::jsapi::{JSVal, JSString};
|
||||||
|
|
||||||
|
#[fixed_stack_segment]
|
||||||
|
pub fn is_string(v: JSVal) -> bool {
|
||||||
|
unsafe { RUST_JSVAL_IS_STRING(v) == 1 }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[fixed_stack_segment]
|
||||||
|
pub unsafe fn to_string(v: JSVal) -> *JSString {
|
||||||
|
RUST_JSVAL_TO_STRING(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct GlobalStaticData {
|
pub struct GlobalStaticData {
|
||||||
proxy_handlers: HashMap<uint, *libc::c_void>,
|
proxy_handlers: HashMap<uint, *libc::c_void>,
|
||||||
attribute_ids: HashMap<uint, ~[jsid]>,
|
attribute_ids: HashMap<uint, ~[jsid]>,
|
||||||
|
@ -70,8 +85,6 @@ extern fn InterfaceObjectToString(cx: *JSContext, _argc: c_uint, vp: *mut JSVal)
|
||||||
let v = GetFunctionNativeReserved(callee, TOSTRING_CLASS_RESERVED_SLOT);
|
let v = GetFunctionNativeReserved(callee, TOSTRING_CLASS_RESERVED_SLOT);
|
||||||
let clasp: *JSClass = cast::transmute(RUST_JSVAL_TO_PRIVATE(*v));
|
let clasp: *JSClass = cast::transmute(RUST_JSVAL_TO_PRIVATE(*v));
|
||||||
|
|
||||||
let v = GetFunctionNativeReserved(callee, TOSTRING_NAME_RESERVED_SLOT);
|
|
||||||
|
|
||||||
if GetObjectJSClass(obj) != clasp {
|
if GetObjectJSClass(obj) != clasp {
|
||||||
/*let jsname: *JSString = RUST_JSVAL_TO_STRING(*v);
|
/*let jsname: *JSString = RUST_JSVAL_TO_STRING(*v);
|
||||||
let length = 0;
|
let length = 0;
|
||||||
|
@ -83,7 +96,9 @@ extern fn InterfaceObjectToString(cx: *JSContext, _argc: c_uint, vp: *mut JSVal)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = jsval_to_str(cx, *v).unwrap();
|
let v = *GetFunctionNativeReserved(callee, TOSTRING_NAME_RESERVED_SLOT);
|
||||||
|
assert!(jsval::is_string(v));
|
||||||
|
let name = jsstring_to_str(cx, jsval::to_string(v));
|
||||||
let retval = Some(~"function " + name + "() {\n [native code]\n}");
|
let retval = Some(~"function " + name + "() {\n [native code]\n}");
|
||||||
*vp = domstring_to_jsval(cx, &retval);
|
*vp = domstring_to_jsval(cx, &retval);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue