mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
auto merge of #1473 : metajack/servo/rustup-20131219, r=jdm
This commit is contained in:
commit
943ab4a4f0
127 changed files with 1892 additions and 2501 deletions
|
@ -43,7 +43,6 @@ impl CallbackInterface {
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn GetCallableProperty(&self, cx: *JSContext, name: *libc::c_char, callable: &mut JSVal) -> bool {
|
||||
unsafe {
|
||||
if JS_GetProperty(cx, self.callback, name, &*callable) == 0 {
|
||||
|
@ -65,7 +64,6 @@ pub fn GetJSObjectFromCallback<T: CallbackContainer>(callback: &T) -> *JSObject
|
|||
callback.callback()
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn WrapCallThisObject<T: 'static + CallbackContainer + Reflectable>(cx: *JSContext,
|
||||
_scope: *JSObject,
|
||||
p: @mut T) -> *JSObject {
|
||||
|
|
|
@ -1091,7 +1091,7 @@ for (uint32_t i = 0; i < length; ++i) {
|
|||
return handleDefault(
|
||||
conversionCode,
|
||||
("static data: [u8, ..%s] = [ %s ];\n"
|
||||
"%s = str::from_utf8(data)" %
|
||||
"%s = str::from_utf8(data).to_owned()" %
|
||||
(len(defaultValue.value) + 1,
|
||||
", ".join(["'" + char + "' as u8" for char in defaultValue.value] + ["0"]),
|
||||
varName)))
|
||||
|
@ -2173,7 +2173,7 @@ class CGImports(CGWrapper):
|
|||
# Allow unreachable_code because we use 'break' in a way that sometimes produces
|
||||
# two 'break's in a row. See for example CallbackMember.getArgConversions.
|
||||
return '\n'.join([
|
||||
'#[allow(unreachable_code,non_uppercase_statics,unused_imports,unused_variable,unused_unsafe,unused_mut,dead_assignment)];',
|
||||
'#[allow(unreachable_code,non_uppercase_statics,unused_imports,unused_variable,unused_unsafe,unused_mut,dead_assignment,dead_code)];',
|
||||
''.join('use %s;\n' % i for i in imports),
|
||||
''])
|
||||
CGWrapper.__init__(self, child,
|
||||
|
@ -2454,16 +2454,14 @@ class CGAbstractMethod(CGThing):
|
|||
def _decorators(self):
|
||||
decorators = []
|
||||
if self.alwaysInline:
|
||||
# FIXME Rust #8801 #[inline(always)] and #[fixed_stack_segment] not compatible
|
||||
# decorators.append('#[inline(always)]')
|
||||
pass
|
||||
decorators.append('#[inline(always)]')
|
||||
elif self.inline:
|
||||
#decorators.append('inline')
|
||||
pass
|
||||
if self.extern:
|
||||
decorators.append('extern')
|
||||
if not self.extern:
|
||||
decorators.append('#[fixed_stack_segment]')
|
||||
pass
|
||||
if self.static:
|
||||
#decorators.append('static')
|
||||
pass
|
||||
|
@ -3522,6 +3520,7 @@ class CGEnum(CGThing):
|
|||
|
||||
def define(self):
|
||||
return """
|
||||
#[repr(uint)]
|
||||
pub enum valuelist {
|
||||
%s
|
||||
}
|
||||
|
@ -3576,7 +3575,7 @@ class ClassMethod(ClassItem):
|
|||
ClassItem.__init__(self, name, visibility)
|
||||
|
||||
def getDecorators(self, declaring):
|
||||
decorators = ['#[fixed_stack_segment]']
|
||||
decorators = []
|
||||
if self.inline:
|
||||
decorators.append('inline')
|
||||
if declaring:
|
||||
|
@ -4150,8 +4149,8 @@ class CGProxyUnwrap(CGAbstractMethod):
|
|||
obj = js::UnwrapObject(obj);
|
||||
}*/
|
||||
//MOZ_ASSERT(IsProxy(obj));
|
||||
let box: *Box<%s> = cast::transmute(RUST_JSVAL_TO_PRIVATE(GetProxyPrivate(obj)));
|
||||
return ptr::to_unsafe_ptr(&(*box).data);""" % (self.descriptor.concreteType)
|
||||
let box_: *Box<%s> = cast::transmute(RUST_JSVAL_TO_PRIVATE(GetProxyPrivate(obj)));
|
||||
return ptr::to_unsafe_ptr(&(*box_).data);""" % (self.descriptor.concreteType)
|
||||
|
||||
class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
|
||||
def __init__(self, descriptor):
|
||||
|
@ -4443,9 +4442,9 @@ class CGDOMJSProxyHandler_obj_toString(CGAbstractExternMethod):
|
|||
JSString* jsresult;
|
||||
return xpc_qsStringToJsstring(cx, result, &jsresult) ? jsresult : NULL;"""
|
||||
|
||||
return """ do "%s".to_c_str().with_ref |s| {
|
||||
return """ "%s".to_c_str().with_ref(|s| {
|
||||
_obj_toString(cx, s)
|
||||
}""" % self.descriptor.name
|
||||
})""" % self.descriptor.name
|
||||
|
||||
def definition_body(self):
|
||||
return self.getBody()
|
||||
|
@ -4907,7 +4906,6 @@ class CGDictionary(CGThing):
|
|||
" return true;\n"
|
||||
" }\n"
|
||||
"\n" if not self.workers else "") +
|
||||
" #[fixed_stack_segment]\n" +
|
||||
" pub fn Init(&mut self, cx: *JSContext, val: JSVal) -> JSBool {\n"
|
||||
" unsafe {\n" +
|
||||
# NOTE: jsids are per-runtime, so don't use them in workers
|
||||
|
|
|
@ -13,14 +13,12 @@ pub trait JSValConvertible {
|
|||
|
||||
|
||||
impl JSValConvertible for i64 {
|
||||
#[fixed_stack_segment]
|
||||
fn to_jsval(&self) -> JSVal {
|
||||
unsafe {
|
||||
RUST_DOUBLE_TO_JSVAL(*self as f64)
|
||||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
fn from_jsval(val: JSVal) -> Option<i64> {
|
||||
unsafe {
|
||||
Some(RUST_JSVAL_TO_DOUBLE(val) as i64)
|
||||
|
@ -29,14 +27,12 @@ impl JSValConvertible for i64 {
|
|||
}
|
||||
|
||||
impl JSValConvertible for u32 {
|
||||
#[fixed_stack_segment]
|
||||
fn to_jsval(&self) -> JSVal {
|
||||
unsafe {
|
||||
RUST_UINT_TO_JSVAL(*self)
|
||||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
fn from_jsval(val: JSVal) -> Option<u32> {
|
||||
unsafe {
|
||||
Some(RUST_JSVAL_TO_INT(val) as u32)
|
||||
|
@ -45,14 +41,12 @@ impl JSValConvertible for u32 {
|
|||
}
|
||||
|
||||
impl JSValConvertible for i32 {
|
||||
#[fixed_stack_segment]
|
||||
fn to_jsval(&self) -> JSVal {
|
||||
unsafe {
|
||||
RUST_UINT_TO_JSVAL(*self as u32)
|
||||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
fn from_jsval(val: JSVal) -> Option<i32> {
|
||||
unsafe {
|
||||
Some(RUST_JSVAL_TO_INT(val) as i32)
|
||||
|
@ -61,14 +55,12 @@ impl JSValConvertible for i32 {
|
|||
}
|
||||
|
||||
impl JSValConvertible for u16 {
|
||||
#[fixed_stack_segment]
|
||||
fn to_jsval(&self) -> JSVal {
|
||||
unsafe {
|
||||
RUST_UINT_TO_JSVAL(*self as u32)
|
||||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
fn from_jsval(val: JSVal) -> Option<u16> {
|
||||
unsafe {
|
||||
Some(RUST_JSVAL_TO_INT(val) as u16)
|
||||
|
@ -97,14 +89,12 @@ impl JSValConvertible for bool {
|
|||
}
|
||||
|
||||
impl JSValConvertible for f32 {
|
||||
#[fixed_stack_segment]
|
||||
fn to_jsval(&self) -> JSVal {
|
||||
unsafe {
|
||||
RUST_DOUBLE_TO_JSVAL(*self as f64)
|
||||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
fn from_jsval(val: JSVal) -> Option<f32> {
|
||||
unsafe {
|
||||
Some(RUST_JSVAL_TO_DOUBLE(val) as f32)
|
||||
|
@ -113,14 +103,12 @@ impl JSValConvertible for f32 {
|
|||
}
|
||||
|
||||
impl JSValConvertible for f64 {
|
||||
#[fixed_stack_segment]
|
||||
fn to_jsval(&self) -> JSVal {
|
||||
unsafe {
|
||||
RUST_DOUBLE_TO_JSVAL(*self as f64)
|
||||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
fn from_jsval(val: JSVal) -> Option<f64> {
|
||||
unsafe {
|
||||
Some(RUST_JSVAL_TO_DOUBLE(val) as f64)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::utils::{Reflectable, Reflector, Traceable};
|
||||
use dom::bindings::utils::{Reflectable, Reflector, Traceable, trace_reflector};
|
||||
use dom::types::*;
|
||||
use dom::node::AbstractNode;
|
||||
|
||||
|
@ -23,7 +23,6 @@ impl Reflectable for AbstractNode {
|
|||
|
||||
impl Traceable for Node {
|
||||
fn trace(&self, tracer: *mut JSTracer) {
|
||||
#[fixed_stack_segment]
|
||||
fn trace_node(tracer: *mut JSTracer, node: Option<AbstractNode>, name: &str) {
|
||||
if node.is_none() {
|
||||
return;
|
||||
|
@ -35,10 +34,10 @@ impl Traceable for Node {
|
|||
unsafe {
|
||||
(*tracer).debugPrinter = ptr::null();
|
||||
(*tracer).debugPrintIndex = -1;
|
||||
do name.to_c_str().with_ref |name| {
|
||||
name.to_c_str().with_ref(|name| {
|
||||
(*tracer).debugPrintArg = name as *libc::c_void;
|
||||
JS_CallTracer(cast::transmute(tracer), obj, JSTRACE_OBJECT as u32);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
debug!("tracing {:p}?:", self.reflector().get_jsobject());
|
||||
|
@ -47,5 +46,7 @@ impl Traceable for Node {
|
|||
trace_node(tracer, self.last_child, "last child");
|
||||
trace_node(tracer, self.next_sibling, "next sibling");
|
||||
trace_node(tracer, self.prev_sibling, "prev sibling");
|
||||
let owner_doc = self.owner_doc();
|
||||
trace_reflector(tracer, "document", owner_doc.reflector());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@ pub extern fn getPropertyDescriptor(cx: *JSContext, proxy: *JSObject, id: jsid,
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn defineProperty_(cx: *JSContext, proxy: *JSObject, id: jsid,
|
||||
desc: *JSPropertyDescriptor) -> JSBool {
|
||||
unsafe {
|
||||
|
@ -72,7 +71,6 @@ pub extern fn defineProperty(cx: *JSContext, proxy: *JSObject, id: jsid,
|
|||
defineProperty_(cx, proxy, id, desc)
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn _obj_toString(cx: *JSContext, className: *libc::c_char) -> *JSString {
|
||||
unsafe {
|
||||
let name = str::raw::from_c_str(className);
|
||||
|
@ -83,7 +81,7 @@ pub fn _obj_toString(cx: *JSContext, className: *libc::c_char) -> *JSString {
|
|||
}
|
||||
|
||||
let result = ~"[object " + name + "]";
|
||||
for (i, c) in result.iter().enumerate() {
|
||||
for (i, c) in result.chars().enumerate() {
|
||||
*chars.offset(i as int) = c as jschar;
|
||||
}
|
||||
*chars.offset(nchars as int) = 0;
|
||||
|
@ -95,7 +93,6 @@ pub fn _obj_toString(cx: *JSContext, className: *libc::c_char) -> *JSString {
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn GetExpandoObject(obj: *JSObject) -> *JSObject {
|
||||
unsafe {
|
||||
assert!(is_dom_proxy(obj));
|
||||
|
@ -108,7 +105,6 @@ pub fn GetExpandoObject(obj: *JSObject) -> *JSObject {
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn EnsureExpandoObject(cx: *JSContext, obj: *JSObject) -> *JSObject {
|
||||
unsafe {
|
||||
assert!(is_dom_proxy(obj));
|
||||
|
|
|
@ -29,7 +29,7 @@ use js::jsapi::{JS_NewUCStringCopyN, JS_DefineFunctions, JS_DefineProperty};
|
|||
use js::jsapi::{JS_ValueToString, JS_GetReservedSlot, JS_SetReservedSlot};
|
||||
use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass, JSNative, JSTracer};
|
||||
use js::jsapi::{JSFunctionSpec, JSPropertySpec, JSVal, JSPropertyDescriptor};
|
||||
use js::jsapi::{JSPropertyOp, JSStrictPropertyOp, JS_NewGlobalObject, JS_InitStandardClasses};
|
||||
use js::jsapi::{JS_NewGlobalObject, JS_InitStandardClasses};
|
||||
use js::jsapi::{JSString, JS_CallTracer, JSTRACE_OBJECT};
|
||||
use js::jsapi::{JS_IsExceptionPending};
|
||||
use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType;
|
||||
|
@ -47,22 +47,18 @@ mod jsval {
|
|||
use js::glue::{RUST_JSVAL_IS_STRING, RUST_JSVAL_TO_STRING};
|
||||
use js::jsapi::{JSVal, JSString};
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn is_null(v: JSVal) -> bool {
|
||||
unsafe { RUST_JSVAL_IS_NULL(v) == 1 }
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn is_undefined(v: JSVal) -> bool {
|
||||
unsafe { RUST_JSVAL_IS_VOID(v) == 1 }
|
||||
}
|
||||
|
||||
#[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)
|
||||
}
|
||||
|
@ -149,7 +145,6 @@ fn is_dom_class(clasp: *JSClass) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn is_dom_proxy(obj: *JSObject) -> bool {
|
||||
unsafe {
|
||||
(js_IsObjectProxyClass(obj) || js_IsFunctionProxyClass(obj)) &&
|
||||
|
@ -157,7 +152,6 @@ pub fn is_dom_proxy(obj: *JSObject) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub unsafe fn dom_object_slot(obj: *JSObject) -> u32 {
|
||||
let clasp = JS_GetClass(obj);
|
||||
if is_dom_class(clasp) {
|
||||
|
@ -168,14 +162,12 @@ pub unsafe fn dom_object_slot(obj: *JSObject) -> u32 {
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub unsafe fn unwrap<T>(obj: *JSObject) -> T {
|
||||
let slot = dom_object_slot(obj);
|
||||
let val = JS_GetReservedSlot(obj, slot);
|
||||
cast::transmute(RUST_JSVAL_TO_PRIVATE(val))
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub unsafe fn get_dom_class(obj: *JSObject) -> Result<DOMClass, ()> {
|
||||
let clasp = JS_GetClass(obj);
|
||||
if is_dom_class(clasp) {
|
||||
|
@ -194,7 +186,7 @@ pub unsafe fn get_dom_class(obj: *JSObject) -> Result<DOMClass, ()> {
|
|||
|
||||
pub fn unwrap_object<T>(obj: *JSObject, proto_id: PrototypeList::id::ID, proto_depth: uint) -> Result<T, ()> {
|
||||
unsafe {
|
||||
do get_dom_class(obj).and_then |dom_class| {
|
||||
get_dom_class(obj).and_then(|dom_class| {
|
||||
if dom_class.interface_chain[proto_depth] == proto_id {
|
||||
debug!("good prototype");
|
||||
Ok(unwrap(obj))
|
||||
|
@ -202,11 +194,10 @@ pub fn unwrap_object<T>(obj: *JSObject, proto_id: PrototypeList::id::ID, proto_d
|
|||
debug!("bad prototype");
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn unwrap_value<T>(val: *JSVal, proto_id: PrototypeList::id::ID, proto_depth: uint) -> Result<T, ()> {
|
||||
unsafe {
|
||||
let obj = RUST_JSVAL_TO_OBJECT(*val);
|
||||
|
@ -216,22 +207,19 @@ pub fn unwrap_value<T>(val: *JSVal, proto_id: PrototypeList::id::ID, proto_depth
|
|||
|
||||
pub unsafe fn squirrel_away<T>(x: @mut T) -> *Box<T> {
|
||||
let y: *Box<T> = cast::transmute(x);
|
||||
cast::forget(x);
|
||||
y
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn jsstring_to_str(cx: *JSContext, s: *JSString) -> ~str {
|
||||
unsafe {
|
||||
let length = 0;
|
||||
let chars = JS_GetStringCharsAndLength(cx, s, &length);
|
||||
do vec::raw::buf_as_slice(chars, length as uint) |char_vec| {
|
||||
vec::raw::buf_as_slice(chars, length as uint, |char_vec| {
|
||||
str::from_utf16(char_vec)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn jsid_to_str(cx: *JSContext, id: jsid) -> ~str {
|
||||
unsafe {
|
||||
assert!(RUST_JSID_IS_STRING(id) != 0);
|
||||
|
@ -245,7 +233,6 @@ pub enum StringificationBehavior {
|
|||
Empty,
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn jsval_to_str(cx: *JSContext, v: JSVal,
|
||||
nullBehavior: StringificationBehavior) -> Result<~str, ()> {
|
||||
if jsval::is_null(v) && nullBehavior == Empty {
|
||||
|
@ -261,7 +248,6 @@ pub fn jsval_to_str(cx: *JSContext, v: JSVal,
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn jsval_to_domstring(cx: *JSContext, v: JSVal) -> Result<Option<DOMString>, ()> {
|
||||
if jsval::is_null(v) || jsval::is_undefined(v) {
|
||||
Ok(None)
|
||||
|
@ -276,20 +262,17 @@ pub fn jsval_to_domstring(cx: *JSContext, v: JSVal) -> Result<Option<DOMString>,
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub unsafe fn str_to_jsval(cx: *JSContext, string: DOMString) -> JSVal {
|
||||
do string.to_utf16().as_imm_buf |buf, len| {
|
||||
let jsstr = JS_NewUCStringCopyN(cx, buf, len as libc::size_t);
|
||||
if jsstr.is_null() {
|
||||
// FIXME: is there something else we should do on failure?
|
||||
JSVAL_NULL
|
||||
} else {
|
||||
RUST_STRING_TO_JSVAL(jsstr)
|
||||
}
|
||||
let string_utf16 = string.to_utf16();
|
||||
let jsstr = JS_NewUCStringCopyN(cx, string_utf16.as_ptr(), string_utf16.len() as libc::size_t);
|
||||
if jsstr.is_null() {
|
||||
// FIXME: is there something else we should do on failure?
|
||||
JSVAL_NULL
|
||||
} else {
|
||||
RUST_STRING_TO_JSVAL(jsstr)
|
||||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub unsafe fn domstring_to_jsval(cx: *JSContext, string: Option<DOMString>) -> JSVal {
|
||||
match string {
|
||||
None => JSVAL_NULL,
|
||||
|
@ -313,7 +296,7 @@ pub static DOM_PROTOTYPE_SLOT: u32 = js::JSCLASS_GLOBAL_SLOT_COUNT;
|
|||
// NOTE: This is baked into the Ion JIT as 0 in codegen for LGetDOMProperty and
|
||||
// LSetDOMProperty. Those constants need to be changed accordingly if this value
|
||||
// changes.
|
||||
static JSCLASS_DOM_GLOBAL: u32 = js::JSCLASS_USERBIT1;
|
||||
pub static JSCLASS_DOM_GLOBAL: u32 = js::JSCLASS_USERBIT1;
|
||||
|
||||
pub struct NativeProperties {
|
||||
staticMethods: *JSFunctionSpec,
|
||||
|
@ -379,7 +362,6 @@ pub struct DOMJSClass {
|
|||
dom_class: DOMClass
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn GetProtoOrIfaceArray(global: *JSObject) -> **JSObject {
|
||||
unsafe {
|
||||
/*assert ((*JS_GetClass(global)).flags & JSCLASS_DOM_GLOBAL) != 0;*/
|
||||
|
@ -387,7 +369,6 @@ pub fn GetProtoOrIfaceArray(global: *JSObject) -> **JSObject {
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSObject,
|
||||
protoProto: *JSObject, protoClass: *JSClass,
|
||||
constructorClass: *JSClass, constructor: Option<JSNative>,
|
||||
|
@ -415,11 +396,11 @@ pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSO
|
|||
|
||||
let mut interface = ptr::null();
|
||||
if constructorClass.is_not_null() || constructor.is_some() {
|
||||
interface = do name.to_c_str().with_ref |s| {
|
||||
interface = name.to_c_str().with_ref(|s| {
|
||||
CreateInterfaceObject(cx, global, receiver, constructorClass,
|
||||
constructor, ctorNargs, proto,
|
||||
staticMethods, constants, s)
|
||||
};
|
||||
});
|
||||
if interface.is_null() {
|
||||
return ptr::null();
|
||||
}
|
||||
|
@ -432,7 +413,6 @@ pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSO
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject,
|
||||
constructorClass: *JSClass, constructorNative: Option<JSNative>,
|
||||
ctorNargs: u32, proto: *JSObject,
|
||||
|
@ -467,11 +447,11 @@ fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject,
|
|||
}
|
||||
|
||||
if constructorClass.is_not_null() {
|
||||
let toString = do "toString".to_c_str().with_ref |s| {
|
||||
let toString = "toString".to_c_str().with_ref(|s| {
|
||||
DefineFunctionWithReserved(cx, constructor, s,
|
||||
InterfaceObjectToString,
|
||||
0, 0)
|
||||
};
|
||||
});
|
||||
if toString.is_null() {
|
||||
return ptr::null();
|
||||
}
|
||||
|
@ -511,7 +491,6 @@ fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject,
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
fn DefineConstants(cx: *JSContext, obj: *JSObject, constants: *ConstantSpec) -> bool {
|
||||
let mut i = 0;
|
||||
loop {
|
||||
|
@ -541,21 +520,18 @@ fn DefineConstants(cx: *JSContext, obj: *JSObject, constants: *ConstantSpec) ->
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
fn DefineMethods(cx: *JSContext, obj: *JSObject, methods: *JSFunctionSpec) -> bool {
|
||||
unsafe {
|
||||
JS_DefineFunctions(cx, obj, methods) != 0
|
||||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
fn DefineProperties(cx: *JSContext, obj: *JSObject, properties: *JSPropertySpec) -> bool {
|
||||
unsafe {
|
||||
JS_DefineProperties(cx, obj, properties) != 0
|
||||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
fn CreateInterfacePrototypeObject(cx: *JSContext, global: *JSObject,
|
||||
parentProto: *JSObject, protoClass: *JSClass,
|
||||
methods: *JSFunctionSpec,
|
||||
|
@ -592,17 +568,16 @@ pub trait Traceable {
|
|||
fn trace(&self, trc: *mut JSTracer);
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Reflector) {
|
||||
unsafe {
|
||||
do description.to_c_str().with_ref |name| {
|
||||
description.to_c_str().with_ref(|name| {
|
||||
(*tracer).debugPrinter = ptr::null();
|
||||
(*tracer).debugPrintIndex = -1;
|
||||
(*tracer).debugPrintArg = name as *libc::c_void;
|
||||
debug!("tracing {:s}", description);
|
||||
JS_CallTracer(tracer as *JSTracer, reflector.get_jsobject(),
|
||||
JSTRACE_OBJECT as u32);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -610,13 +585,12 @@ pub fn trace_option<T: Reflectable>(tracer: *mut JSTracer, description: &str, op
|
|||
option.map(|some| trace_reflector(tracer, description, some.reflector()));
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn initialize_global(global: *JSObject) {
|
||||
let protoArray = @mut ([0 as *JSObject, ..PrototypeList::id::_ID_Count as uint]);
|
||||
unsafe {
|
||||
//XXXjdm we should be storing the box pointer instead of the inner
|
||||
let box = squirrel_away(protoArray);
|
||||
let inner = ptr::to_unsafe_ptr(&(*box).data);
|
||||
let box_ = squirrel_away(protoArray);
|
||||
let inner = ptr::to_unsafe_ptr(&(*box_).data);
|
||||
JS_SetReservedSlot(global,
|
||||
DOM_PROTOTYPE_SLOT,
|
||||
RUST_PRIVATE_TO_JSVAL(inner as *libc::c_void));
|
||||
|
@ -668,7 +642,6 @@ impl Reflector {
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn GetReflector(cx: *JSContext, reflector: &Reflector,
|
||||
vp: *mut JSVal) -> JSBool {
|
||||
let obj = reflector.get_jsobject();
|
||||
|
@ -679,7 +652,6 @@ pub fn GetReflector(cx: *JSContext, reflector: &Reflector,
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn GetPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid, found: *mut bool,
|
||||
vp: *JSVal) -> bool {
|
||||
unsafe {
|
||||
|
@ -703,7 +675,6 @@ pub fn GetPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid, found:
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn GetArrayIndexFromId(_cx: *JSContext, id: jsid) -> Option<u32> {
|
||||
unsafe {
|
||||
if RUST_JSID_IS_INT(id) != 0 {
|
||||
|
@ -727,7 +698,6 @@ pub fn GetArrayIndexFromId(_cx: *JSContext, id: jsid) -> Option<u32> {
|
|||
}*/
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn XrayResolveProperty(cx: *JSContext,
|
||||
wrapper: *JSObject,
|
||||
id: jsid,
|
||||
|
@ -754,7 +724,7 @@ pub fn XrayResolveProperty(cx: *JSContext,
|
|||
|
||||
RUST_SET_JITINFO(fun, attr.getter.info);
|
||||
let funobj = JS_GetFunctionObject(fun);
|
||||
(*desc).getter = Some(funobj as JSPropertyOp);
|
||||
(*desc).getter = Some(cast::transmute(funobj));
|
||||
(*desc).attrs |= JSPROP_GETTER;
|
||||
if attr.setter.op.is_some() {
|
||||
let fun = JS_NewFunction(cx, attr.setter.op, 1, 0, global, ptr::null());
|
||||
|
@ -764,7 +734,7 @@ pub fn XrayResolveProperty(cx: *JSContext,
|
|||
|
||||
RUST_SET_JITINFO(fun, attr.setter.info);
|
||||
let funobj = JS_GetFunctionObject(fun);
|
||||
(*desc).setter = Some(funobj as JSStrictPropertyOp);
|
||||
(*desc).setter = Some(cast::transmute(funobj));
|
||||
(*desc).attrs |= JSPROP_SETTER;
|
||||
} else {
|
||||
(*desc).setter = None;
|
||||
|
@ -777,7 +747,6 @@ pub fn XrayResolveProperty(cx: *JSContext,
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
fn InternJSString(cx: *JSContext, chars: *libc::c_char) -> Option<jsid> {
|
||||
unsafe {
|
||||
let s = JS_InternString(cx, chars);
|
||||
|
@ -824,7 +793,6 @@ pub struct EnumEntry {
|
|||
length: uint
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn FindEnumStringIndex(cx: *JSContext,
|
||||
v: JSVal,
|
||||
values: &[EnumEntry]) -> Result<uint, ()> {
|
||||
|
@ -865,14 +833,12 @@ pub fn HasPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid) -> boo
|
|||
return !GetPropertyOnPrototype(cx, proxy, id, &mut found, ptr::null()) || found;
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn IsConvertibleToCallbackInterface(cx: *JSContext, obj: *JSObject) -> bool {
|
||||
unsafe {
|
||||
JS_ObjectIsDate(cx, obj) == 0 && JS_ObjectIsRegExp(cx, obj) == 0
|
||||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn CreateDOMGlobal(cx: *JSContext, class: *JSClass) -> *JSObject {
|
||||
unsafe {
|
||||
let obj = JS_NewGlobalObject(cx, class, ptr::null());
|
||||
|
@ -886,7 +852,6 @@ pub fn CreateDOMGlobal(cx: *JSContext, class: *JSClass) -> *JSObject {
|
|||
}
|
||||
|
||||
/// Returns the global object of the realm that the given JS object was created in.
|
||||
#[fixed_stack_segment]
|
||||
fn global_object_for_js_object(obj: *JSObject) -> *Box<window::Window> {
|
||||
unsafe {
|
||||
let global = GetGlobalForObjectCrossCompartment(obj);
|
||||
|
@ -900,7 +865,6 @@ fn global_object_for_js_object(obj: *JSObject) -> *Box<window::Window> {
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext {
|
||||
unsafe {
|
||||
let win = global_object_for_js_object(obj);
|
||||
|
@ -912,7 +876,6 @@ fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext {
|
|||
}
|
||||
|
||||
/// Returns the global object of the realm that the given DOM object was created in.
|
||||
#[fixed_stack_segment]
|
||||
pub fn global_object_for_dom_object<T: Reflectable>(obj: &mut T) -> *Box<window::Window> {
|
||||
global_object_for_js_object(obj.reflector().get_jsobject())
|
||||
}
|
||||
|
@ -921,7 +884,6 @@ pub fn cx_for_dom_object<T: Reflectable>(obj: &mut T) -> *JSContext {
|
|||
cx_for_dom_reflector(obj.reflector().get_jsobject())
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub fn throw_method_failed_with_details<T>(cx: *JSContext,
|
||||
result: Result<T, Error>,
|
||||
interface: &'static str,
|
||||
|
@ -929,9 +891,9 @@ pub fn throw_method_failed_with_details<T>(cx: *JSContext,
|
|||
assert!(result.is_err());
|
||||
assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
|
||||
let message = format!("Method failed: {}.{}", interface, member);
|
||||
do message.with_c_str |string| {
|
||||
message.with_c_str(|string| {
|
||||
unsafe { ReportError(cx, string) };
|
||||
}
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -979,7 +941,7 @@ pub fn xml_name_type(name: &str) -> XMLName {
|
|||
}
|
||||
}
|
||||
|
||||
let mut iter = name.iter();
|
||||
let mut iter = name.chars();
|
||||
let mut non_qname_colons = false;
|
||||
let mut seen_colon = false;
|
||||
match iter.next() {
|
||||
|
@ -994,7 +956,7 @@ pub fn xml_name_type(name: &str) -> XMLName {
|
|||
}
|
||||
}
|
||||
|
||||
for c in name.iter() {
|
||||
for c in name.chars() {
|
||||
if !is_valid_continuation(c) {
|
||||
return InvalidXMLName;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue