mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Use *mut T for the T* pointers in SpiderMonkey.
This commit is contained in:
parent
3e4b2c1c7b
commit
d5cb4377ef
18 changed files with 294 additions and 308 deletions
|
@ -2,13 +2,12 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::trace::trace_object;
|
||||||
use dom::bindings::utils::Reflectable;
|
use dom::bindings::utils::Reflectable;
|
||||||
use js::jsapi::{JSContext, JSObject, JS_WrapObject, JS_ObjectIsCallable};
|
use js::jsapi::{JSContext, JSObject, JS_WrapObject, JS_ObjectIsCallable};
|
||||||
use js::jsapi::{JS_GetProperty, JSTracer, JS_CallTracer};
|
use js::jsapi::{JS_GetProperty, JSTracer};
|
||||||
use js::jsval::{JSVal, UndefinedValue};
|
use js::jsval::{JSVal, UndefinedValue};
|
||||||
use js::JSTRACE_OBJECT;
|
|
||||||
|
|
||||||
use libc;
|
|
||||||
use std::cast;
|
use std::cast;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
|
@ -27,45 +26,40 @@ pub enum ExceptionHandling {
|
||||||
|
|
||||||
#[deriving(Clone,Eq)]
|
#[deriving(Clone,Eq)]
|
||||||
pub struct CallbackInterface {
|
pub struct CallbackInterface {
|
||||||
pub callback: *JSObject
|
pub callback: *mut JSObject
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Encoder<E>, E> Encodable<S, E> for CallbackInterface {
|
impl<S: Encoder<E>, E> Encodable<S, E> for CallbackInterface {
|
||||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let tracer: *mut JSTracer = cast::transmute(s);
|
let tracer: *mut JSTracer = cast::transmute(s);
|
||||||
"callback".to_c_str().with_ref(|name| {
|
trace_object(tracer, "callback", self.callback);
|
||||||
(*tracer).debugPrinter = ptr::null();
|
}
|
||||||
(*tracer).debugPrintIndex = -1;
|
|
||||||
(*tracer).debugPrintArg = name as *libc::c_void;
|
|
||||||
JS_CallTracer(tracer as *JSTracer, self.callback, JSTRACE_OBJECT as u32);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CallbackContainer {
|
pub trait CallbackContainer {
|
||||||
fn callback(&self) -> *JSObject;
|
fn callback(&self) -> *mut JSObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CallbackContainer for CallbackInterface {
|
impl CallbackContainer for CallbackInterface {
|
||||||
fn callback(&self) -> *JSObject {
|
fn callback(&self) -> *mut JSObject {
|
||||||
self.callback
|
self.callback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CallbackInterface {
|
impl CallbackInterface {
|
||||||
pub fn new(callback: *JSObject) -> CallbackInterface {
|
pub fn new(callback: *mut JSObject) -> CallbackInterface {
|
||||||
CallbackInterface {
|
CallbackInterface {
|
||||||
callback: callback
|
callback: callback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn GetCallableProperty(&self, cx: *JSContext, name: &str) -> Result<JSVal, ()> {
|
pub fn GetCallableProperty(&self, cx: *mut JSContext, name: &str) -> Result<JSVal, ()> {
|
||||||
let mut callable = UndefinedValue();
|
let mut callable = UndefinedValue();
|
||||||
unsafe {
|
unsafe {
|
||||||
if name.to_c_str().with_ref(|name| JS_GetProperty(cx, self.callback, name, &mut callable as *mut JSVal as *JSVal)) == 0 {
|
if name.to_c_str().with_ref(|name| JS_GetProperty(cx, self.callback, name, &mut callable)) == 0 {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,19 +73,19 @@ impl CallbackInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn GetJSObjectFromCallback<T: CallbackContainer>(callback: &T) -> *JSObject {
|
pub fn GetJSObjectFromCallback<T: CallbackContainer>(callback: &T) -> *mut JSObject {
|
||||||
callback.callback()
|
callback.callback()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn WrapCallThisObject<T: 'static + CallbackContainer + Reflectable>(cx: *JSContext,
|
pub fn WrapCallThisObject<T: 'static + CallbackContainer + Reflectable>(cx: *mut JSContext,
|
||||||
_scope: *JSObject,
|
_scope: *mut JSObject,
|
||||||
p: Box<T>) -> *JSObject {
|
p: Box<T>) -> *mut JSObject {
|
||||||
let obj = GetJSObjectFromCallback(p);
|
let mut obj = GetJSObjectFromCallback(p);
|
||||||
assert!(obj.is_not_null());
|
assert!(obj.is_not_null());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
if JS_WrapObject(cx, &obj) == 0 {
|
if JS_WrapObject(cx, &mut obj) == 0 {
|
||||||
return ptr::null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,19 +93,19 @@ pub fn WrapCallThisObject<T: 'static + CallbackContainer + Reflectable>(cx: *JSC
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CallSetup {
|
pub struct CallSetup {
|
||||||
pub cx: *JSContext,
|
pub cx: *mut JSContext,
|
||||||
pub handling: ExceptionHandling
|
pub handling: ExceptionHandling
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CallSetup {
|
impl CallSetup {
|
||||||
pub fn new(cx: *JSContext, handling: ExceptionHandling) -> CallSetup {
|
pub fn new(cx: *mut JSContext, handling: ExceptionHandling) -> CallSetup {
|
||||||
CallSetup {
|
CallSetup {
|
||||||
cx: cx,
|
cx: cx,
|
||||||
handling: handling
|
handling: handling
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn GetContext(&self) -> *JSContext {
|
pub fn GetContext(&self) -> *mut JSContext {
|
||||||
self.cx
|
self.cx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,7 +213,7 @@ class CGMethodCall(CGThing):
|
||||||
# Doesn't matter which of the possible signatures we use, since
|
# Doesn't matter which of the possible signatures we use, since
|
||||||
# they all have the same types up to that point; just use
|
# they all have the same types up to that point; just use
|
||||||
# possibleSignatures[0]
|
# possibleSignatures[0]
|
||||||
caseBody = [CGGeneric("let argv_start = JS_ARGV(cx, vp as *JSVal);")]
|
caseBody = [CGGeneric("let argv_start = JS_ARGV(cx, vp);")]
|
||||||
caseBody.extend([ CGArgumentConverter(possibleSignatures[0][1][i],
|
caseBody.extend([ CGArgumentConverter(possibleSignatures[0][1][i],
|
||||||
i, "argv_start", "argc",
|
i, "argv_start", "argc",
|
||||||
descriptor) for i in
|
descriptor) for i in
|
||||||
|
@ -960,11 +960,11 @@ def getRetvalDeclarationForType(returnType, descriptorProvider):
|
||||||
if returnType.isCallback():
|
if returnType.isCallback():
|
||||||
# XXXbz we're going to assume that callback types are always
|
# XXXbz we're going to assume that callback types are always
|
||||||
# nullable for now.
|
# nullable for now.
|
||||||
return CGGeneric("*JSObject")
|
return CGGeneric("*mut JSObject")
|
||||||
if returnType.isAny():
|
if returnType.isAny():
|
||||||
return CGGeneric("JSVal")
|
return CGGeneric("JSVal")
|
||||||
if returnType.isObject() or returnType.isSpiderMonkeyInterface():
|
if returnType.isObject() or returnType.isSpiderMonkeyInterface():
|
||||||
return CGGeneric("*JSObject")
|
return CGGeneric("*mut JSObject")
|
||||||
if returnType.isSequence():
|
if returnType.isSequence():
|
||||||
raise TypeError("We don't support sequence return values")
|
raise TypeError("We don't support sequence return values")
|
||||||
|
|
||||||
|
@ -1492,14 +1492,7 @@ static PrototypeClass: JSClass = JSClass {
|
||||||
hasInstance: None,
|
hasInstance: None,
|
||||||
construct: None,
|
construct: None,
|
||||||
trace: None,
|
trace: None,
|
||||||
reserved: (0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 05
|
reserved: [0 as *mut libc::c_void, ..40]
|
||||||
0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 10
|
|
||||||
0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 15
|
|
||||||
0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 20
|
|
||||||
0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 25
|
|
||||||
0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 30
|
|
||||||
0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 35
|
|
||||||
0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void) // 40
|
|
||||||
};
|
};
|
||||||
""" % (len(self.descriptor.interface.identifier.name + "Prototype") + 1,
|
""" % (len(self.descriptor.interface.identifier.name + "Prototype") + 1,
|
||||||
str_to_const_array(self.descriptor.interface.identifier.name + "Prototype"))
|
str_to_const_array(self.descriptor.interface.identifier.name + "Prototype"))
|
||||||
|
@ -1726,12 +1719,12 @@ def CreateBindingJSObject(descriptor, parent=None):
|
||||||
create += """
|
create += """
|
||||||
let js_info = aScope.deref().page().js_info();
|
let js_info = aScope.deref().page().js_info();
|
||||||
let handler = js_info.get_ref().dom_static.proxy_handlers.deref().get(&(PrototypeList::id::%s as uint));
|
let handler = js_info.get_ref().dom_static.proxy_handlers.deref().get(&(PrototypeList::id::%s as uint));
|
||||||
let private = PrivateValue(squirrel_away_unique(aObject) as *libc::c_void);
|
let mut private = PrivateValue(squirrel_away_unique(aObject) as *libc::c_void);
|
||||||
let obj = with_compartment(aCx, proto, || {
|
let obj = with_compartment(aCx, proto, || {
|
||||||
NewProxyObject(aCx, *handler,
|
NewProxyObject(aCx, *handler,
|
||||||
&private,
|
&mut private,
|
||||||
proto, %s,
|
proto, %s,
|
||||||
ptr::null(), ptr::null())
|
ptr::mut_null(), ptr::mut_null())
|
||||||
});
|
});
|
||||||
assert!(obj.is_not_null());
|
assert!(obj.is_not_null());
|
||||||
|
|
||||||
|
@ -1754,10 +1747,10 @@ class CGWrapMethod(CGAbstractMethod):
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
assert descriptor.interface.hasInterfacePrototypeObject()
|
assert descriptor.interface.hasInterfacePrototypeObject()
|
||||||
if not descriptor.createGlobal:
|
if not descriptor.createGlobal:
|
||||||
args = [Argument('*JSContext', 'aCx'), Argument('&JSRef<Window>', 'aScope'),
|
args = [Argument('*mut JSContext', 'aCx'), Argument('&JSRef<Window>', 'aScope'),
|
||||||
Argument("Box<%s>" % descriptor.concreteType, 'aObject', mutable=True)]
|
Argument("Box<%s>" % descriptor.concreteType, 'aObject', mutable=True)]
|
||||||
else:
|
else:
|
||||||
args = [Argument('*JSContext', 'aCx'),
|
args = [Argument('*mut JSContext', 'aCx'),
|
||||||
Argument("Box<%s>" % descriptor.concreteType, 'aObject', mutable=True)]
|
Argument("Box<%s>" % descriptor.concreteType, 'aObject', mutable=True)]
|
||||||
retval = 'JS<%s>' % descriptor.concreteType
|
retval = 'JS<%s>' % descriptor.concreteType
|
||||||
CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args, pub=True)
|
CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args, pub=True)
|
||||||
|
@ -1859,9 +1852,9 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
|
||||||
properties should be a PropertyArrays instance.
|
properties should be a PropertyArrays instance.
|
||||||
"""
|
"""
|
||||||
def __init__(self, descriptor, properties):
|
def __init__(self, descriptor, properties):
|
||||||
args = [Argument('*JSContext', 'aCx'), Argument('*JSObject', 'aGlobal'),
|
args = [Argument('*mut JSContext', 'aCx'), Argument('*mut JSObject', 'aGlobal'),
|
||||||
Argument('*JSObject', 'aReceiver')]
|
Argument('*mut JSObject', 'aReceiver')]
|
||||||
CGAbstractMethod.__init__(self, descriptor, 'CreateInterfaceObjects', '*JSObject', args)
|
CGAbstractMethod.__init__(self, descriptor, 'CreateInterfaceObjects', '*mut JSObject', args)
|
||||||
self.properties = properties
|
self.properties = properties
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
protoChain = self.descriptor.prototypeChain
|
protoChain = self.descriptor.prototypeChain
|
||||||
|
@ -1894,9 +1887,9 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
|
||||||
else:
|
else:
|
||||||
prefCache = None
|
prefCache = None
|
||||||
|
|
||||||
getParentProto = ("let parentProto: *JSObject = %s;\n" +
|
getParentProto = ("let parentProto: *mut JSObject = %s;\n" +
|
||||||
"if parentProto.is_null() {\n" +
|
"if parentProto.is_null() {\n" +
|
||||||
" return ptr::null();\n" +
|
" return ptr::mut_null();\n" +
|
||||||
"}\n") % getParentProto
|
"}\n") % getParentProto
|
||||||
|
|
||||||
if self.descriptor.interface.ctor():
|
if self.descriptor.interface.ctor():
|
||||||
|
@ -1956,10 +1949,10 @@ class CGGetPerInterfaceObject(CGAbstractMethod):
|
||||||
constructor object).
|
constructor object).
|
||||||
"""
|
"""
|
||||||
def __init__(self, descriptor, name, idPrefix="", pub=False):
|
def __init__(self, descriptor, name, idPrefix="", pub=False):
|
||||||
args = [Argument('*JSContext', 'aCx'), Argument('*JSObject', 'aGlobal'),
|
args = [Argument('*mut JSContext', 'aCx'), Argument('*mut JSObject', 'aGlobal'),
|
||||||
Argument('*JSObject', 'aReceiver')]
|
Argument('*mut JSObject', 'aReceiver')]
|
||||||
CGAbstractMethod.__init__(self, descriptor, name,
|
CGAbstractMethod.__init__(self, descriptor, name,
|
||||||
'*JSObject', args, pub=pub)
|
'*mut JSObject', args, pub=pub)
|
||||||
self.id = idPrefix + "id::" + self.descriptor.name
|
self.id = idPrefix + "id::" + self.descriptor.name
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
return """
|
return """
|
||||||
|
@ -1973,10 +1966,10 @@ class CGGetPerInterfaceObject(CGAbstractMethod):
|
||||||
assert!(((*JS_GetClass(aGlobal)).flags & JSCLASS_DOM_GLOBAL) != 0);
|
assert!(((*JS_GetClass(aGlobal)).flags & JSCLASS_DOM_GLOBAL) != 0);
|
||||||
|
|
||||||
/* Check to see whether the interface objects are already installed */
|
/* Check to see whether the interface objects are already installed */
|
||||||
let protoOrIfaceArray: *mut *JSObject = GetProtoOrIfaceArray(aGlobal) as *mut *JSObject;
|
let protoOrIfaceArray: *mut *mut JSObject = GetProtoOrIfaceArray(aGlobal) as *mut *mut JSObject;
|
||||||
let cachedObject: *JSObject = *protoOrIfaceArray.offset(%s as int);
|
let cachedObject: *mut JSObject = *protoOrIfaceArray.offset(%s as int);
|
||||||
if cachedObject.is_null() {
|
if cachedObject.is_null() {
|
||||||
let tmp: *JSObject = CreateInterfaceObjects(aCx, aGlobal, aReceiver);
|
let tmp: *mut JSObject = CreateInterfaceObjects(aCx, aGlobal, aReceiver);
|
||||||
*protoOrIfaceArray.offset(%s as int) = tmp;
|
*protoOrIfaceArray.offset(%s as int) = tmp;
|
||||||
tmp
|
tmp
|
||||||
} else {
|
} else {
|
||||||
|
@ -2222,7 +2215,7 @@ class CGPerSignatureCall(CGThing):
|
||||||
def getArgv(self):
|
def getArgv(self):
|
||||||
return "argv" if self.argCount > 0 else ""
|
return "argv" if self.argCount > 0 else ""
|
||||||
def getArgvDecl(self):
|
def getArgvDecl(self):
|
||||||
return "\nlet argv = JS_ARGV(cx, vp as *JSVal);\n"
|
return "\nlet argv = JS_ARGV(cx, vp);\n"
|
||||||
def getArgc(self):
|
def getArgc(self):
|
||||||
return "argc"
|
return "argc"
|
||||||
def getArguments(self):
|
def getArguments(self):
|
||||||
|
@ -2361,7 +2354,7 @@ class CGAbstractBindingMethod(CGAbstractExternMethod):
|
||||||
FakeCastableDescriptor(self.descriptor),
|
FakeCastableDescriptor(self.descriptor),
|
||||||
"obj", self.unwrapFailureCode))
|
"obj", self.unwrapFailureCode))
|
||||||
unwrapThis = CGIndenter(
|
unwrapThis = CGIndenter(
|
||||||
CGGeneric("let obj: *JSObject = JS_THIS_OBJECT(cx, vp as *mut JSVal);\n"
|
CGGeneric("let obj: *mut JSObject = JS_THIS_OBJECT(cx, vp as *mut JSVal);\n"
|
||||||
"if obj.is_null() {\n"
|
"if obj.is_null() {\n"
|
||||||
" return false as JSBool;\n"
|
" return false as JSBool;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
@ -2377,14 +2370,14 @@ class CGGenericMethod(CGAbstractBindingMethod):
|
||||||
A class for generating the C++ code for an IDL method..
|
A class for generating the C++ code for an IDL method..
|
||||||
"""
|
"""
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
args = [Argument('*JSContext', 'cx'), Argument('libc::c_uint', 'argc'),
|
args = [Argument('*mut JSContext', 'cx'), Argument('libc::c_uint', 'argc'),
|
||||||
Argument('*mut JSVal', 'vp')]
|
Argument('*mut JSVal', 'vp')]
|
||||||
CGAbstractBindingMethod.__init__(self, descriptor, 'genericMethod', args)
|
CGAbstractBindingMethod.__init__(self, descriptor, 'genericMethod', args)
|
||||||
|
|
||||||
def generate_code(self):
|
def generate_code(self):
|
||||||
return CGIndenter(CGGeneric(
|
return CGIndenter(CGGeneric(
|
||||||
"let _info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, &*vp));\n"
|
"let _info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp));\n"
|
||||||
"return CallJitMethodOp(_info, cx, obj, this.unsafe_get() as *libc::c_void, argc, &*vp);"))
|
"return CallJitMethodOp(_info, cx, obj, this.unsafe_get() as *libc::c_void, argc, vp);"))
|
||||||
|
|
||||||
class CGSpecializedMethod(CGAbstractExternMethod):
|
class CGSpecializedMethod(CGAbstractExternMethod):
|
||||||
"""
|
"""
|
||||||
|
@ -2394,7 +2387,7 @@ class CGSpecializedMethod(CGAbstractExternMethod):
|
||||||
def __init__(self, descriptor, method):
|
def __init__(self, descriptor, method):
|
||||||
self.method = method
|
self.method = method
|
||||||
name = method.identifier.name
|
name = method.identifier.name
|
||||||
args = [Argument('*JSContext', 'cx'), Argument('JSHandleObject', '_obj'),
|
args = [Argument('*mut JSContext', 'cx'), Argument('JSHandleObject', '_obj'),
|
||||||
Argument('*mut %s' % descriptor.concreteType, 'this'),
|
Argument('*mut %s' % descriptor.concreteType, 'this'),
|
||||||
Argument('libc::c_uint', 'argc'), Argument('*mut JSVal', 'vp')]
|
Argument('libc::c_uint', 'argc'), Argument('*mut JSVal', 'vp')]
|
||||||
CGAbstractExternMethod.__init__(self, descriptor, name, 'JSBool', args)
|
CGAbstractExternMethod.__init__(self, descriptor, name, 'JSBool', args)
|
||||||
|
@ -2411,7 +2404,7 @@ class CGGenericGetter(CGAbstractBindingMethod):
|
||||||
A class for generating the C++ code for an IDL attribute getter.
|
A class for generating the C++ code for an IDL attribute getter.
|
||||||
"""
|
"""
|
||||||
def __init__(self, descriptor, lenientThis=False):
|
def __init__(self, descriptor, lenientThis=False):
|
||||||
args = [Argument('*JSContext', 'cx'), Argument('libc::c_uint', 'argc'),
|
args = [Argument('*mut JSContext', 'cx'), Argument('libc::c_uint', 'argc'),
|
||||||
Argument('*mut JSVal', 'vp')]
|
Argument('*mut JSVal', 'vp')]
|
||||||
if lenientThis:
|
if lenientThis:
|
||||||
name = "genericLenientGetter"
|
name = "genericLenientGetter"
|
||||||
|
@ -2427,8 +2420,8 @@ class CGGenericGetter(CGAbstractBindingMethod):
|
||||||
|
|
||||||
def generate_code(self):
|
def generate_code(self):
|
||||||
return CGIndenter(CGGeneric(
|
return CGIndenter(CGGeneric(
|
||||||
"let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, &*vp));\n"
|
"let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp));\n"
|
||||||
"return CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *libc::c_void, &*vp);\n"))
|
"return CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *libc::c_void, vp);\n"))
|
||||||
|
|
||||||
class CGSpecializedGetter(CGAbstractExternMethod):
|
class CGSpecializedGetter(CGAbstractExternMethod):
|
||||||
"""
|
"""
|
||||||
|
@ -2438,7 +2431,7 @@ class CGSpecializedGetter(CGAbstractExternMethod):
|
||||||
def __init__(self, descriptor, attr):
|
def __init__(self, descriptor, attr):
|
||||||
self.attr = attr
|
self.attr = attr
|
||||||
name = 'get_' + attr.identifier.name
|
name = 'get_' + attr.identifier.name
|
||||||
args = [ Argument('*JSContext', 'cx'),
|
args = [ Argument('*mut JSContext', 'cx'),
|
||||||
Argument('JSHandleObject', '_obj'),
|
Argument('JSHandleObject', '_obj'),
|
||||||
Argument('*mut %s' % descriptor.concreteType, 'this'),
|
Argument('*mut %s' % descriptor.concreteType, 'this'),
|
||||||
Argument('*mut JSVal', 'vp') ]
|
Argument('*mut JSVal', 'vp') ]
|
||||||
|
@ -2462,7 +2455,7 @@ class CGGenericSetter(CGAbstractBindingMethod):
|
||||||
A class for generating the Rust code for an IDL attribute setter.
|
A class for generating the Rust code for an IDL attribute setter.
|
||||||
"""
|
"""
|
||||||
def __init__(self, descriptor, lenientThis=False):
|
def __init__(self, descriptor, lenientThis=False):
|
||||||
args = [Argument('*JSContext', 'cx'), Argument('libc::c_uint', 'argc'),
|
args = [Argument('*mut JSContext', 'cx'), Argument('libc::c_uint', 'argc'),
|
||||||
Argument('*mut JSVal', 'vp')]
|
Argument('*mut JSVal', 'vp')]
|
||||||
if lenientThis:
|
if lenientThis:
|
||||||
name = "genericLenientSetter"
|
name = "genericLenientSetter"
|
||||||
|
@ -2477,9 +2470,9 @@ class CGGenericSetter(CGAbstractBindingMethod):
|
||||||
|
|
||||||
def generate_code(self):
|
def generate_code(self):
|
||||||
return CGIndenter(CGGeneric(
|
return CGIndenter(CGGeneric(
|
||||||
"let undef = UndefinedValue();\n"
|
"let mut undef = UndefinedValue();\n"
|
||||||
"let argv: *JSVal = if argc != 0 { JS_ARGV(cx, vp as *JSVal) } else { &undef as *JSVal };\n"
|
"let argv: *mut JSVal = if argc != 0 { JS_ARGV(cx, vp) } else { &mut undef as *mut JSVal };\n"
|
||||||
"let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp as *JSVal));\n"
|
"let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp));\n"
|
||||||
"if CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *libc::c_void, argv) == 0 {\n"
|
"if CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *libc::c_void, argv) == 0 {\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
@ -2494,7 +2487,7 @@ class CGSpecializedSetter(CGAbstractExternMethod):
|
||||||
def __init__(self, descriptor, attr):
|
def __init__(self, descriptor, attr):
|
||||||
self.attr = attr
|
self.attr = attr
|
||||||
name = 'set_' + attr.identifier.name
|
name = 'set_' + attr.identifier.name
|
||||||
args = [ Argument('*JSContext', 'cx'),
|
args = [ Argument('*mut JSContext', 'cx'),
|
||||||
Argument('JSHandleObject', '_obj'),
|
Argument('JSHandleObject', '_obj'),
|
||||||
Argument('*mut %s' % descriptor.concreteType, 'this'),
|
Argument('*mut %s' % descriptor.concreteType, 'this'),
|
||||||
Argument('*mut JSVal', 'argv')]
|
Argument('*mut JSVal', 'argv')]
|
||||||
|
@ -2604,7 +2597,7 @@ pub static strings: &'static [&'static str] = &[
|
||||||
];
|
];
|
||||||
|
|
||||||
impl ToJSValConvertible for valuelist {
|
impl ToJSValConvertible for valuelist {
|
||||||
fn to_jsval(&self, cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||||
strings[*self as uint].to_owned().to_jsval(cx)
|
strings[*self as uint].to_owned().to_jsval(cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2819,7 +2812,7 @@ class CGUnionConversionStruct(CGThing):
|
||||||
"Err(())" % ", ".join(names)))
|
"Err(())" % ", ".join(names)))
|
||||||
method = CGWrapper(
|
method = CGWrapper(
|
||||||
CGIndenter(CGList(conversions, "\n\n")),
|
CGIndenter(CGList(conversions, "\n\n")),
|
||||||
pre="fn from_jsval(cx: *JSContext, value: JSVal, _option: ()) -> Result<%s, ()> {\n" % self.type,
|
pre="fn from_jsval(cx: *mut JSContext, value: JSVal, _option: ()) -> Result<%s, ()> {\n" % self.type,
|
||||||
post="\n}")
|
post="\n}")
|
||||||
return CGWrapper(
|
return CGWrapper(
|
||||||
CGIndenter(method),
|
CGIndenter(method),
|
||||||
|
@ -2833,7 +2826,7 @@ class CGUnionConversionStruct(CGThing):
|
||||||
|
|
||||||
return CGWrapper(
|
return CGWrapper(
|
||||||
CGIndenter(jsConversion, 4),
|
CGIndenter(jsConversion, 4),
|
||||||
pre="fn TryConvertTo%s(cx: *JSContext, value: JSVal) -> %s {\n" % (t.name, returnType),
|
pre="fn TryConvertTo%s(cx: *mut JSContext, value: JSVal) -> %s {\n" % (t.name, returnType),
|
||||||
post="\n}")
|
post="\n}")
|
||||||
|
|
||||||
def define(self):
|
def define(self):
|
||||||
|
@ -3394,7 +3387,7 @@ class CGProxyNamedSetter(CGProxySpecialOperation):
|
||||||
|
|
||||||
class CGProxyUnwrap(CGAbstractMethod):
|
class CGProxyUnwrap(CGAbstractMethod):
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
args = [Argument('*JSObject', 'obj')]
|
args = [Argument('*mut JSObject', 'obj')]
|
||||||
CGAbstractMethod.__init__(self, descriptor, "UnwrapProxy", '*mut ' + descriptor.concreteType, args, alwaysInline=True)
|
CGAbstractMethod.__init__(self, descriptor, "UnwrapProxy", '*mut ' + descriptor.concreteType, args, alwaysInline=True)
|
||||||
|
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
|
@ -3407,7 +3400,7 @@ class CGProxyUnwrap(CGAbstractMethod):
|
||||||
|
|
||||||
class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
|
class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
args = [Argument('*JSContext', 'cx'), Argument('*JSObject', 'proxy'),
|
args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'),
|
||||||
Argument('jsid', 'id'), Argument('JSBool', 'set'),
|
Argument('jsid', 'id'), Argument('JSBool', 'set'),
|
||||||
Argument('*mut JSPropertyDescriptor', 'desc')]
|
Argument('*mut JSPropertyDescriptor', 'desc')]
|
||||||
CGAbstractExternMethod.__init__(self, descriptor, "getOwnPropertyDescriptor",
|
CGAbstractExternMethod.__init__(self, descriptor, "getOwnPropertyDescriptor",
|
||||||
|
@ -3482,11 +3475,11 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
|
||||||
else:
|
else:
|
||||||
namedGet = ""
|
namedGet = ""
|
||||||
|
|
||||||
return setOrIndexedGet + """let expando: *JSObject = GetExpandoObject(proxy);
|
return setOrIndexedGet + """let expando: *mut JSObject = GetExpandoObject(proxy);
|
||||||
//if (!xpc::WrapperFactory::IsXrayWrapper(proxy) && (expando = GetExpandoObject(proxy))) {
|
//if (!xpc::WrapperFactory::IsXrayWrapper(proxy) && (expando = GetExpandoObject(proxy))) {
|
||||||
if expando.is_not_null() {
|
if expando.is_not_null() {
|
||||||
let flags = if set != 0 { JSRESOLVE_ASSIGNING } else { 0 } | JSRESOLVE_QUALIFIED;
|
let flags = if set != 0 { JSRESOLVE_ASSIGNING } else { 0 } | JSRESOLVE_QUALIFIED;
|
||||||
if JS_GetPropertyDescriptorById(cx, expando, id, flags, desc as *JSPropertyDescriptor) == 0 {
|
if JS_GetPropertyDescriptorById(cx, expando, id, flags, desc) == 0 {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (*desc).obj.is_not_null() {
|
if (*desc).obj.is_not_null() {
|
||||||
|
@ -3496,7 +3489,7 @@ if expando.is_not_null() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
""" + namedGet + """
|
""" + namedGet + """
|
||||||
(*desc).obj = ptr::null();
|
(*desc).obj = ptr::mut_null();
|
||||||
return 1;"""
|
return 1;"""
|
||||||
|
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
|
@ -3504,7 +3497,7 @@ return 1;"""
|
||||||
|
|
||||||
class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
|
class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
args = [Argument('*JSContext', 'cx'), Argument('*JSObject', 'proxy'),
|
args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'),
|
||||||
Argument('jsid', 'id'),
|
Argument('jsid', 'id'),
|
||||||
Argument('*JSPropertyDescriptor', 'desc')]
|
Argument('*JSPropertyDescriptor', 'desc')]
|
||||||
CGAbstractExternMethod.__init__(self, descriptor, "defineProperty", "JSBool", args)
|
CGAbstractExternMethod.__init__(self, descriptor, "defineProperty", "JSBool", args)
|
||||||
|
@ -3562,7 +3555,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
|
||||||
|
|
||||||
class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
|
class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
args = [Argument('*JSContext', 'cx'), Argument('*JSObject', 'proxy'),
|
args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'),
|
||||||
Argument('jsid', 'id'), Argument('*mut JSBool', 'bp')]
|
Argument('jsid', 'id'), Argument('*mut JSBool', 'bp')]
|
||||||
CGAbstractExternMethod.__init__(self, descriptor, "hasOwn", "JSBool", args)
|
CGAbstractExternMethod.__init__(self, descriptor, "hasOwn", "JSBool", args)
|
||||||
self.descriptor = descriptor
|
self.descriptor = descriptor
|
||||||
|
@ -3597,10 +3590,10 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
|
||||||
else:
|
else:
|
||||||
named = ""
|
named = ""
|
||||||
|
|
||||||
return indexed + """let expando: *JSObject = GetExpandoObject(proxy);
|
return indexed + """let expando: *mut JSObject = GetExpandoObject(proxy);
|
||||||
if expando.is_not_null() {
|
if expando.is_not_null() {
|
||||||
let b: JSBool = 1;
|
let mut b: JSBool = 1;
|
||||||
let ok: JSBool = JS_HasPropertyById(cx, expando, id, &b);
|
let ok: JSBool = JS_HasPropertyById(cx, expando, id, &mut b);
|
||||||
*bp = !!b;
|
*bp = !!b;
|
||||||
if ok == 0 || *bp != 0 {
|
if ok == 0 || *bp != 0 {
|
||||||
return ok;
|
return ok;
|
||||||
|
@ -3615,21 +3608,21 @@ return 1;"""
|
||||||
|
|
||||||
class CGDOMJSProxyHandler_get(CGAbstractExternMethod):
|
class CGDOMJSProxyHandler_get(CGAbstractExternMethod):
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
args = [Argument('*JSContext', 'cx'), Argument('*JSObject', 'proxy'),
|
args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'),
|
||||||
Argument('*JSObject', 'receiver'), Argument('jsid', 'id'),
|
Argument('*mut JSObject', 'receiver'), Argument('jsid', 'id'),
|
||||||
Argument('*mut JSVal', 'vp')]
|
Argument('*mut JSVal', 'vp')]
|
||||||
CGAbstractExternMethod.__init__(self, descriptor, "get", "JSBool", args)
|
CGAbstractExternMethod.__init__(self, descriptor, "get", "JSBool", args)
|
||||||
self.descriptor = descriptor
|
self.descriptor = descriptor
|
||||||
def getBody(self):
|
def getBody(self):
|
||||||
getFromExpando = """let expando = GetExpandoObject(proxy);
|
getFromExpando = """let expando = GetExpandoObject(proxy);
|
||||||
if expando.is_not_null() {
|
if expando.is_not_null() {
|
||||||
let hasProp = 0;
|
let mut hasProp = 0;
|
||||||
if JS_HasPropertyById(cx, expando, id, &hasProp) == 0 {
|
if JS_HasPropertyById(cx, expando, id, &mut hasProp) == 0 {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasProp != 0 {
|
if hasProp != 0 {
|
||||||
return JS_GetPropertyById(cx, expando, id, vp as *JSVal);
|
return JS_GetPropertyById(cx, expando, id, vp);
|
||||||
}
|
}
|
||||||
}"""
|
}"""
|
||||||
|
|
||||||
|
@ -3671,7 +3664,7 @@ if expando.is_not_null() {
|
||||||
|
|
||||||
%s
|
%s
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
if !GetPropertyOnPrototype(cx, proxy, id, &mut found, vp as *JSVal) {
|
if !GetPropertyOnPrototype(cx, proxy, id, &mut found, vp) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3687,8 +3680,8 @@ return 1;""" % (getIndexedOrExpando, getNamed)
|
||||||
|
|
||||||
class CGDOMJSProxyHandler_obj_toString(CGAbstractExternMethod):
|
class CGDOMJSProxyHandler_obj_toString(CGAbstractExternMethod):
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
args = [Argument('*JSContext', 'cx'), Argument('*JSObject', 'proxy')]
|
args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy')]
|
||||||
CGAbstractExternMethod.__init__(self, descriptor, "obj_toString", "*JSString", args)
|
CGAbstractExternMethod.__init__(self, descriptor, "obj_toString", "*mut JSString", args)
|
||||||
self.descriptor = descriptor
|
self.descriptor = descriptor
|
||||||
def getBody(self):
|
def getBody(self):
|
||||||
stringifier = self.descriptor.operations['Stringifier']
|
stringifier = self.descriptor.operations['Stringifier']
|
||||||
|
@ -3750,7 +3743,7 @@ class CGClassTraceHook(CGAbstractClassHook):
|
||||||
A hook to trace through our native object; used for GC and CC
|
A hook to trace through our native object; used for GC and CC
|
||||||
"""
|
"""
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
args = [Argument('*mut JSTracer', 'trc'), Argument('*JSObject', 'obj')]
|
args = [Argument('*mut JSTracer', 'trc'), Argument('*mut JSObject', 'obj')]
|
||||||
CGAbstractClassHook.__init__(self, descriptor, TRACE_HOOK_NAME, 'void',
|
CGAbstractClassHook.__init__(self, descriptor, TRACE_HOOK_NAME, 'void',
|
||||||
args)
|
args)
|
||||||
|
|
||||||
|
@ -3762,7 +3755,7 @@ class CGClassConstructHook(CGAbstractExternMethod):
|
||||||
JS-visible constructor for our objects
|
JS-visible constructor for our objects
|
||||||
"""
|
"""
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
args = [Argument('*JSContext', 'cx'), Argument('u32', 'argc'), Argument('*mut JSVal', 'vp')]
|
args = [Argument('*mut JSContext', 'cx'), Argument('u32', 'argc'), Argument('*mut JSVal', 'vp')]
|
||||||
CGAbstractExternMethod.__init__(self, descriptor, CONSTRUCT_HOOK_NAME,
|
CGAbstractExternMethod.__init__(self, descriptor, CONSTRUCT_HOOK_NAME,
|
||||||
'JSBool', args)
|
'JSBool', args)
|
||||||
self._ctor = self.descriptor.interface.ctor()
|
self._ctor = self.descriptor.interface.ctor()
|
||||||
|
@ -3777,7 +3770,7 @@ class CGClassConstructHook(CGAbstractExternMethod):
|
||||||
|
|
||||||
def generate_code(self):
|
def generate_code(self):
|
||||||
preamble = """
|
preamble = """
|
||||||
let global = global_object_for_js_object(JS_CALLEE(cx, &*vp).to_object()).root();
|
let global = global_object_for_js_object(JS_CALLEE(cx, vp).to_object()).root();
|
||||||
let obj = global.deref().reflector().get_jsobject();
|
let obj = global.deref().reflector().get_jsobject();
|
||||||
"""
|
"""
|
||||||
nativeName = MakeNativeName(self._ctor.identifier.name)
|
nativeName = MakeNativeName(self._ctor.identifier.name)
|
||||||
|
@ -3790,7 +3783,7 @@ class CGClassFinalizeHook(CGAbstractClassHook):
|
||||||
A hook for finalize, used to release our native object.
|
A hook for finalize, used to release our native object.
|
||||||
"""
|
"""
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
args = [Argument('*JSFreeOp', 'fop'), Argument('*JSObject', 'obj')]
|
args = [Argument('*mut JSFreeOp', 'fop'), Argument('*mut JSObject', 'obj')]
|
||||||
CGAbstractClassHook.__init__(self, descriptor, FINALIZE_HOOK_NAME,
|
CGAbstractClassHook.__init__(self, descriptor, FINALIZE_HOOK_NAME,
|
||||||
'void', args)
|
'void', args)
|
||||||
|
|
||||||
|
@ -4018,11 +4011,11 @@ class CGDictionary(CGThing):
|
||||||
return string.Template(
|
return string.Template(
|
||||||
"impl<'a, 'b> ${selfName}<'a, 'b> {\n"
|
"impl<'a, 'b> ${selfName}<'a, 'b> {\n"
|
||||||
" pub fn empty() -> ${selfName} {\n"
|
" pub fn empty() -> ${selfName} {\n"
|
||||||
" ${selfName}::new(ptr::null(), NullValue()).unwrap()\n"
|
" ${selfName}::new(ptr::mut_null(), NullValue()).unwrap()\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" pub fn new(cx: *JSContext, val: JSVal) -> Result<${selfName}, ()> {\n"
|
" pub fn new(cx: *mut JSContext, val: JSVal) -> Result<${selfName}, ()> {\n"
|
||||||
" let object = if val.is_null_or_undefined() {\n"
|
" let object = if val.is_null_or_undefined() {\n"
|
||||||
" ptr::null()\n"
|
" ptr::mut_null()\n"
|
||||||
" } else if val.is_object() {\n"
|
" } else if val.is_object() {\n"
|
||||||
" val.to_object()\n"
|
" val.to_object()\n"
|
||||||
" } else {\n"
|
" } else {\n"
|
||||||
|
@ -4616,7 +4609,7 @@ class CGCallback(CGClass):
|
||||||
|
|
||||||
def getConstructors(self):
|
def getConstructors(self):
|
||||||
return [ClassConstructor(
|
return [ClassConstructor(
|
||||||
[Argument("*JSObject", "aCallback")],
|
[Argument("*mut JSObject", "aCallback")],
|
||||||
bodyInHeader=True,
|
bodyInHeader=True,
|
||||||
visibility="pub",
|
visibility="pub",
|
||||||
explicit=False,
|
explicit=False,
|
||||||
|
@ -4629,14 +4622,14 @@ class CGCallback(CGClass):
|
||||||
args = list(method.args)
|
args = list(method.args)
|
||||||
# Strip out the JSContext*/JSObject* args
|
# Strip out the JSContext*/JSObject* args
|
||||||
# that got added.
|
# that got added.
|
||||||
assert args[0].name == "cx" and args[0].argType == "*JSContext"
|
assert args[0].name == "cx" and args[0].argType == "*mut JSContext"
|
||||||
assert args[1].name == "aThisObj" and args[1].argType == "*JSObject"
|
assert args[1].name == "aThisObj" and args[1].argType == "*mut JSObject"
|
||||||
args = args[2:]
|
args = args[2:]
|
||||||
# Record the names of all the arguments, so we can use them when we call
|
# Record the names of all the arguments, so we can use them when we call
|
||||||
# the private method.
|
# the private method.
|
||||||
argnames = [arg.name for arg in args]
|
argnames = [arg.name for arg in args]
|
||||||
argnamesWithThis = ["s.GetContext()", "thisObjJS"] + argnames
|
argnamesWithThis = ["s.GetContext()", "thisObjJS"] + argnames
|
||||||
argnamesWithoutThis = ["s.GetContext()", "ptr::null()"] + argnames
|
argnamesWithoutThis = ["s.GetContext()", "ptr::mut_null()"] + argnames
|
||||||
# Now that we've recorded the argnames for our call to our private
|
# Now that we've recorded the argnames for our call to our private
|
||||||
# method, insert our optional argument for deciding whether the
|
# method, insert our optional argument for deciding whether the
|
||||||
# CallSetup should re-throw exceptions on aRv.
|
# CallSetup should re-throw exceptions on aRv.
|
||||||
|
@ -4662,7 +4655,7 @@ class CGCallback(CGClass):
|
||||||
|
|
||||||
bodyWithThis = string.Template(
|
bodyWithThis = string.Template(
|
||||||
setupCall+
|
setupCall+
|
||||||
"let thisObjJS = WrapCallThisObject(s.GetContext(), ptr::null() /*XXXjdm proper scope*/, thisObj);\n"
|
"let thisObjJS = WrapCallThisObject(s.GetContext(), ptr::mut_null() /*XXXjdm proper scope*/, thisObj);\n"
|
||||||
"if thisObjJS.is_null() {\n"
|
"if thisObjJS.is_null() {\n"
|
||||||
" return Err(FailureUnknown);\n"
|
" return Err(FailureUnknown);\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
@ -4919,8 +4912,8 @@ class CallbackMember(CGNativeMember):
|
||||||
return args
|
return args
|
||||||
# We want to allow the caller to pass in a "this" object, as
|
# We want to allow the caller to pass in a "this" object, as
|
||||||
# well as a JSContext.
|
# well as a JSContext.
|
||||||
return [Argument("*JSContext", "cx"),
|
return [Argument("*mut JSContext", "cx"),
|
||||||
Argument("*JSObject", "aThisObj")] + args
|
Argument("*mut JSObject", "aThisObj")] + args
|
||||||
|
|
||||||
def getCallSetup(self):
|
def getCallSetup(self):
|
||||||
if self.needThisHandling:
|
if self.needThisHandling:
|
||||||
|
@ -4974,7 +4967,7 @@ class CallbackMethod(CallbackMember):
|
||||||
"getCallable": self.getCallableDecl()
|
"getCallable": self.getCallableDecl()
|
||||||
}
|
}
|
||||||
if self.argCount > 0:
|
if self.argCount > 0:
|
||||||
replacements["argv"] = "argv.as_ptr()"
|
replacements["argv"] = "argv.as_mut_ptr()"
|
||||||
replacements["argc"] = "argc"
|
replacements["argc"] = "argc"
|
||||||
else:
|
else:
|
||||||
replacements["argv"] = "nullptr"
|
replacements["argv"] = "nullptr"
|
||||||
|
@ -4982,7 +4975,7 @@ class CallbackMethod(CallbackMember):
|
||||||
return string.Template("${getCallable}"
|
return string.Template("${getCallable}"
|
||||||
"let ok = unsafe {\n"
|
"let ok = unsafe {\n"
|
||||||
" JS_CallFunctionValue(cx, ${thisObj}, callable,\n"
|
" JS_CallFunctionValue(cx, ${thisObj}, callable,\n"
|
||||||
" ${argc}, ${argv}, &rval)\n"
|
" ${argc}, ${argv}, &mut rval)\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"if ok == 0 {\n"
|
"if ok == 0 {\n"
|
||||||
" return Err(FailureUnknown);\n"
|
" return Err(FailureUnknown);\n"
|
||||||
|
|
|
@ -34,24 +34,24 @@ pub trait IDLInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ToJSValConvertible {
|
pub trait ToJSValConvertible {
|
||||||
fn to_jsval(&self, cx: *JSContext) -> JSVal;
|
fn to_jsval(&self, cx: *mut JSContext) -> JSVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FromJSValConvertible<T> {
|
pub trait FromJSValConvertible<T> {
|
||||||
fn from_jsval(cx: *JSContext, val: JSVal, option: T) -> Result<Self, ()>;
|
fn from_jsval(cx: *mut JSContext, val: JSVal, option: T) -> Result<Self, ()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl ToJSValConvertible for () {
|
impl ToJSValConvertible for () {
|
||||||
fn to_jsval(&self, _cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
UndefinedValue()
|
UndefinedValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToJSValConvertible for JSVal {
|
impl ToJSValConvertible for JSVal {
|
||||||
fn to_jsval(&self, cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||||
let mut value = *self;
|
let mut value = *self;
|
||||||
if unsafe { JS_WrapValue(cx, &mut value as *mut JSVal as *JSVal) } == 0 {
|
if unsafe { JS_WrapValue(cx, &mut value) } == 0 {
|
||||||
fail!("JS_WrapValue failed.");
|
fail!("JS_WrapValue failed.");
|
||||||
}
|
}
|
||||||
value
|
value
|
||||||
|
@ -59,10 +59,10 @@ impl ToJSValConvertible for JSVal {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn convert_from_jsval<T: Default>(
|
unsafe fn convert_from_jsval<T: Default>(
|
||||||
cx: *JSContext, value: JSVal,
|
cx: *mut JSContext, value: JSVal,
|
||||||
convert_fn: extern "C" unsafe fn(*JSContext, JSVal, *T) -> JSBool) -> Result<T, ()> {
|
convert_fn: extern "C" unsafe fn(*mut JSContext, JSVal, *mut T) -> JSBool) -> Result<T, ()> {
|
||||||
let mut ret = Default::default();
|
let mut ret = Default::default();
|
||||||
if convert_fn(cx, value, &mut ret as *mut T as *T) == 0 {
|
if convert_fn(cx, value, &mut ret) == 0 {
|
||||||
Err(())
|
Err(())
|
||||||
} else {
|
} else {
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
|
@ -71,95 +71,95 @@ unsafe fn convert_from_jsval<T: Default>(
|
||||||
|
|
||||||
|
|
||||||
impl ToJSValConvertible for bool {
|
impl ToJSValConvertible for bool {
|
||||||
fn to_jsval(&self, _cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
BooleanValue(*self)
|
BooleanValue(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromJSValConvertible<()> for bool {
|
impl FromJSValConvertible<()> for bool {
|
||||||
fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<bool, ()> {
|
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<bool, ()> {
|
||||||
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToBoolean) };
|
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToBoolean) };
|
||||||
result.map(|b| b != 0)
|
result.map(|b| b != 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToJSValConvertible for i8 {
|
impl ToJSValConvertible for i8 {
|
||||||
fn to_jsval(&self, _cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
Int32Value(*self as i32)
|
Int32Value(*self as i32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromJSValConvertible<()> for i8 {
|
impl FromJSValConvertible<()> for i8 {
|
||||||
fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<i8, ()> {
|
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<i8, ()> {
|
||||||
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) };
|
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) };
|
||||||
result.map(|v| v as i8)
|
result.map(|v| v as i8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToJSValConvertible for u8 {
|
impl ToJSValConvertible for u8 {
|
||||||
fn to_jsval(&self, _cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
Int32Value(*self as i32)
|
Int32Value(*self as i32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromJSValConvertible<()> for u8 {
|
impl FromJSValConvertible<()> for u8 {
|
||||||
fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<u8, ()> {
|
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<u8, ()> {
|
||||||
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) };
|
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) };
|
||||||
result.map(|v| v as u8)
|
result.map(|v| v as u8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToJSValConvertible for i16 {
|
impl ToJSValConvertible for i16 {
|
||||||
fn to_jsval(&self, _cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
Int32Value(*self as i32)
|
Int32Value(*self as i32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromJSValConvertible<()> for i16 {
|
impl FromJSValConvertible<()> for i16 {
|
||||||
fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<i16, ()> {
|
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<i16, ()> {
|
||||||
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) };
|
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) };
|
||||||
result.map(|v| v as i16)
|
result.map(|v| v as i16)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToJSValConvertible for u16 {
|
impl ToJSValConvertible for u16 {
|
||||||
fn to_jsval(&self, _cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
Int32Value(*self as i32)
|
Int32Value(*self as i32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromJSValConvertible<()> for u16 {
|
impl FromJSValConvertible<()> for u16 {
|
||||||
fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<u16, ()> {
|
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<u16, ()> {
|
||||||
unsafe { convert_from_jsval(cx, val, JS_ValueToUint16) }
|
unsafe { convert_from_jsval(cx, val, JS_ValueToUint16) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToJSValConvertible for i32 {
|
impl ToJSValConvertible for i32 {
|
||||||
fn to_jsval(&self, _cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
Int32Value(*self)
|
Int32Value(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromJSValConvertible<()> for i32 {
|
impl FromJSValConvertible<()> for i32 {
|
||||||
fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<i32, ()> {
|
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<i32, ()> {
|
||||||
unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) }
|
unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToJSValConvertible for u32 {
|
impl ToJSValConvertible for u32 {
|
||||||
fn to_jsval(&self, _cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
UInt32Value(*self)
|
UInt32Value(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromJSValConvertible<()> for u32 {
|
impl FromJSValConvertible<()> for u32 {
|
||||||
fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<u32, ()> {
|
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<u32, ()> {
|
||||||
unsafe { convert_from_jsval(cx, val, JS_ValueToECMAUint32) }
|
unsafe { convert_from_jsval(cx, val, JS_ValueToECMAUint32) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToJSValConvertible for i64 {
|
impl ToJSValConvertible for i64 {
|
||||||
fn to_jsval(&self, _cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
unsafe {
|
unsafe {
|
||||||
RUST_JS_NumberValue(*self as f64)
|
RUST_JS_NumberValue(*self as f64)
|
||||||
}
|
}
|
||||||
|
@ -167,13 +167,13 @@ impl ToJSValConvertible for i64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromJSValConvertible<()> for i64 {
|
impl FromJSValConvertible<()> for i64 {
|
||||||
fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<i64, ()> {
|
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<i64, ()> {
|
||||||
unsafe { convert_from_jsval(cx, val, JS_ValueToInt64) }
|
unsafe { convert_from_jsval(cx, val, JS_ValueToInt64) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToJSValConvertible for u64 {
|
impl ToJSValConvertible for u64 {
|
||||||
fn to_jsval(&self, _cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
unsafe {
|
unsafe {
|
||||||
RUST_JS_NumberValue(*self as f64)
|
RUST_JS_NumberValue(*self as f64)
|
||||||
}
|
}
|
||||||
|
@ -181,13 +181,13 @@ impl ToJSValConvertible for u64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromJSValConvertible<()> for u64 {
|
impl FromJSValConvertible<()> for u64 {
|
||||||
fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<u64, ()> {
|
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<u64, ()> {
|
||||||
unsafe { convert_from_jsval(cx, val, JS_ValueToUint64) }
|
unsafe { convert_from_jsval(cx, val, JS_ValueToUint64) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToJSValConvertible for f32 {
|
impl ToJSValConvertible for f32 {
|
||||||
fn to_jsval(&self, _cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
unsafe {
|
unsafe {
|
||||||
RUST_JS_NumberValue(*self as f64)
|
RUST_JS_NumberValue(*self as f64)
|
||||||
}
|
}
|
||||||
|
@ -195,14 +195,14 @@ impl ToJSValConvertible for f32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromJSValConvertible<()> for f32 {
|
impl FromJSValConvertible<()> for f32 {
|
||||||
fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<f32, ()> {
|
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<f32, ()> {
|
||||||
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToNumber) };
|
let result = unsafe { convert_from_jsval(cx, val, JS_ValueToNumber) };
|
||||||
result.map(|f| f as f32)
|
result.map(|f| f as f32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToJSValConvertible for f64 {
|
impl ToJSValConvertible for f64 {
|
||||||
fn to_jsval(&self, _cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
unsafe {
|
unsafe {
|
||||||
RUST_JS_NumberValue(*self)
|
RUST_JS_NumberValue(*self)
|
||||||
}
|
}
|
||||||
|
@ -210,13 +210,13 @@ impl ToJSValConvertible for f64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromJSValConvertible<()> for f64 {
|
impl FromJSValConvertible<()> for f64 {
|
||||||
fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result<f64, ()> {
|
fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result<f64, ()> {
|
||||||
unsafe { convert_from_jsval(cx, val, JS_ValueToNumber) }
|
unsafe { convert_from_jsval(cx, val, JS_ValueToNumber) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToJSValConvertible for DOMString {
|
impl ToJSValConvertible for DOMString {
|
||||||
fn to_jsval(&self, cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||||
unsafe {
|
unsafe {
|
||||||
let string_utf16 = self.to_utf16();
|
let string_utf16 = self.to_utf16();
|
||||||
let jsstr = JS_NewUCStringCopyN(cx, string_utf16.as_ptr(), string_utf16.len() as libc::size_t);
|
let jsstr = JS_NewUCStringCopyN(cx, string_utf16.as_ptr(), string_utf16.len() as libc::size_t);
|
||||||
|
@ -241,7 +241,7 @@ impl Default for StringificationBehavior {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromJSValConvertible<StringificationBehavior> for DOMString {
|
impl FromJSValConvertible<StringificationBehavior> for DOMString {
|
||||||
fn from_jsval(cx: *JSContext, value: JSVal, nullBehavior: StringificationBehavior) -> Result<DOMString, ()> {
|
fn from_jsval(cx: *mut JSContext, value: JSVal, nullBehavior: StringificationBehavior) -> Result<DOMString, ()> {
|
||||||
if nullBehavior == Empty && value.is_null() {
|
if nullBehavior == Empty && value.is_null() {
|
||||||
Ok("".to_owned())
|
Ok("".to_owned())
|
||||||
} else {
|
} else {
|
||||||
|
@ -257,7 +257,7 @@ impl FromJSValConvertible<StringificationBehavior> for DOMString {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToJSValConvertible for ByteString {
|
impl ToJSValConvertible for ByteString {
|
||||||
fn to_jsval(&self, cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||||
unsafe {
|
unsafe {
|
||||||
let slice = self.as_slice();
|
let slice = self.as_slice();
|
||||||
let jsstr = JS_NewStringCopyN(cx, slice.as_ptr() as *libc::c_char,
|
let jsstr = JS_NewStringCopyN(cx, slice.as_ptr() as *libc::c_char,
|
||||||
|
@ -271,7 +271,7 @@ impl ToJSValConvertible for ByteString {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromJSValConvertible<()> for ByteString {
|
impl FromJSValConvertible<()> for ByteString {
|
||||||
fn from_jsval(cx: *JSContext, value: JSVal, _option: ()) -> Result<ByteString, ()> {
|
fn from_jsval(cx: *mut JSContext, value: JSVal, _option: ()) -> Result<ByteString, ()> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let string = JS_ValueToString(cx, value);
|
let string = JS_ValueToString(cx, value);
|
||||||
if string.is_null() {
|
if string.is_null() {
|
||||||
|
@ -280,7 +280,7 @@ impl FromJSValConvertible<()> for ByteString {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut length = 0;
|
let mut length = 0;
|
||||||
let chars = JS_GetStringCharsAndLength(cx, string, &mut length as *mut _ as *_);
|
let chars = JS_GetStringCharsAndLength(cx, string, &mut length);
|
||||||
slice::raw::buf_as_slice(chars, length as uint, |char_vec| {
|
slice::raw::buf_as_slice(chars, length as uint, |char_vec| {
|
||||||
if char_vec.iter().any(|&c| c > 0xFF) {
|
if char_vec.iter().any(|&c| c > 0xFF) {
|
||||||
// XXX Throw
|
// XXX Throw
|
||||||
|
@ -294,11 +294,11 @@ impl FromJSValConvertible<()> for ByteString {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToJSValConvertible for Reflector {
|
impl ToJSValConvertible for Reflector {
|
||||||
fn to_jsval(&self, cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||||
let obj = self.get_jsobject();
|
let obj = self.get_jsobject();
|
||||||
assert!(obj.is_not_null());
|
assert!(obj.is_not_null());
|
||||||
let mut value = ObjectValue(unsafe { &*obj });
|
let mut value = ObjectValue(unsafe { &*obj });
|
||||||
if unsafe { JS_WrapValue(cx, &mut value as *mut JSVal as *JSVal) } == 0 {
|
if unsafe { JS_WrapValue(cx, &mut value) } == 0 {
|
||||||
fail!("JS_WrapValue failed.");
|
fail!("JS_WrapValue failed.");
|
||||||
}
|
}
|
||||||
value
|
value
|
||||||
|
@ -306,7 +306,7 @@ impl ToJSValConvertible for Reflector {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Reflectable+IDLInterface> FromJSValConvertible<()> for JS<T> {
|
impl<T: Reflectable+IDLInterface> FromJSValConvertible<()> for JS<T> {
|
||||||
fn from_jsval(_cx: *JSContext, value: JSVal, _option: ()) -> Result<JS<T>, ()> {
|
fn from_jsval(_cx: *mut JSContext, value: JSVal, _option: ()) -> Result<JS<T>, ()> {
|
||||||
if !value.is_object() {
|
if !value.is_object() {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
@ -317,19 +317,19 @@ impl<T: Reflectable+IDLInterface> FromJSValConvertible<()> for JS<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, T: Reflectable> ToJSValConvertible for Root<'a, 'b, T> {
|
impl<'a, 'b, T: Reflectable> ToJSValConvertible for Root<'a, 'b, T> {
|
||||||
fn to_jsval(&self, cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||||
self.reflector().to_jsval(cx)
|
self.reflector().to_jsval(cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Reflectable> ToJSValConvertible for JSRef<'a, T> {
|
impl<'a, T: Reflectable> ToJSValConvertible for JSRef<'a, T> {
|
||||||
fn to_jsval(&self, cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||||
self.reflector().to_jsval(cx)
|
self.reflector().to_jsval(cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ToJSValConvertible> ToJSValConvertible for Option<T> {
|
impl<T: ToJSValConvertible> ToJSValConvertible for Option<T> {
|
||||||
fn to_jsval(&self, cx: *JSContext) -> JSVal {
|
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||||
match self {
|
match self {
|
||||||
&Some(ref value) => value.to_jsval(cx),
|
&Some(ref value) => value.to_jsval(cx),
|
||||||
&None => NullValue(),
|
&None => NullValue(),
|
||||||
|
@ -338,7 +338,7 @@ impl<T: ToJSValConvertible> ToJSValConvertible for Option<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<X: Default, T: FromJSValConvertible<X>> FromJSValConvertible<()> for Option<T> {
|
impl<X: Default, T: FromJSValConvertible<X>> FromJSValConvertible<()> for Option<T> {
|
||||||
fn from_jsval(cx: *JSContext, value: JSVal, _: ()) -> Result<Option<T>, ()> {
|
fn from_jsval(cx: *mut JSContext, value: JSVal, _: ()) -> Result<Option<T>, ()> {
|
||||||
if value.is_null_or_undefined() {
|
if value.is_null_or_undefined() {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use js::jsapi::{JSContext, JSBool};
|
use js::jsapi::{JSContext, JSBool};
|
||||||
use js::jsapi::{JS_IsExceptionPending};
|
use js::jsapi::{JS_IsExceptionPending};
|
||||||
use js::jsapi::{JS_ReportErrorNumber, JSErrorFormatString, struct_JSErrorFormatString, JSEXN_TYPEERR};
|
use js::jsapi::{JS_ReportErrorNumber, JSErrorFormatString, JSEXN_TYPEERR};
|
||||||
use js::glue::{ReportError};
|
use js::glue::{ReportError};
|
||||||
|
|
||||||
use libc;
|
use libc;
|
||||||
|
@ -29,7 +29,7 @@ pub type Fallible<T> = Result<T, Error>;
|
||||||
|
|
||||||
pub type ErrorResult = Fallible<()>;
|
pub type ErrorResult = Fallible<()>;
|
||||||
|
|
||||||
pub fn throw_method_failed_with_details<T>(cx: *JSContext,
|
pub fn throw_method_failed_with_details<T>(cx: *mut JSContext,
|
||||||
result: Result<T, Error>,
|
result: Result<T, Error>,
|
||||||
interface: &'static str,
|
interface: &'static str,
|
||||||
member: &'static str) -> JSBool {
|
member: &'static str) -> JSBool {
|
||||||
|
@ -42,7 +42,7 @@ pub fn throw_method_failed_with_details<T>(cx: *JSContext,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn throw_not_in_union(cx: *JSContext, names: &'static str) -> JSBool {
|
pub fn throw_not_in_union(cx: *mut JSContext, names: &'static str) -> JSBool {
|
||||||
assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
|
assert!(unsafe { JS_IsExceptionPending(cx) } == 0);
|
||||||
let message = format!("argument could not be converted to any of: {}", names);
|
let message = format!("argument could not be converted to any of: {}", names);
|
||||||
message.with_c_str(|string| {
|
message.with_c_str(|string| {
|
||||||
|
@ -58,7 +58,7 @@ static ERROR_FORMAT_STRING_STRING: [libc::c_char, ..4] = [
|
||||||
0 as libc::c_char,
|
0 as libc::c_char,
|
||||||
];
|
];
|
||||||
|
|
||||||
static ERROR_FORMAT_STRING: JSErrorFormatString = struct_JSErrorFormatString {
|
static ERROR_FORMAT_STRING: JSErrorFormatString = JSErrorFormatString {
|
||||||
format: &ERROR_FORMAT_STRING_STRING as *libc::c_char,
|
format: &ERROR_FORMAT_STRING_STRING as *libc::c_char,
|
||||||
argCount: 1,
|
argCount: 1,
|
||||||
exnType: JSEXN_TYPEERR as i16,
|
exnType: JSEXN_TYPEERR as i16,
|
||||||
|
@ -72,9 +72,9 @@ extern fn get_error_message(_user_ref: *mut libc::c_void,
|
||||||
&ERROR_FORMAT_STRING as *JSErrorFormatString
|
&ERROR_FORMAT_STRING as *JSErrorFormatString
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn throw_type_error(cx: *JSContext, error: &str) {
|
pub fn throw_type_error(cx: *mut JSContext, error: &str) {
|
||||||
let error = error.to_c_str();
|
let error = error.to_c_str();
|
||||||
error.with_ref(|error| unsafe {
|
error.with_ref(|error| unsafe {
|
||||||
JS_ReportErrorNumber(cx, get_error_message, ptr::null(), 0, error);
|
JS_ReportErrorNumber(cx, Some(get_error_message), ptr::mut_null(), 0, error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,17 +69,17 @@ impl<T: Reflectable> Drop for Temporary<T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let cx = cx_for_dom_object(&self.inner);
|
let cx = cx_for_dom_object(&self.inner);
|
||||||
unsafe {
|
unsafe {
|
||||||
JS_RemoveObjectRoot(cx, self.inner.reflector().rootable());
|
JS_RemoveObjectRoot(cx, self.inner.mut_reflector().rootable());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Reflectable> Temporary<T> {
|
impl<T: Reflectable> Temporary<T> {
|
||||||
/// Create a new Temporary value from a JS-owned value.
|
/// Create a new Temporary value from a JS-owned value.
|
||||||
pub fn new(inner: JS<T>) -> Temporary<T> {
|
pub fn new(mut inner: JS<T>) -> Temporary<T> {
|
||||||
let cx = cx_for_dom_object(&inner);
|
let cx = cx_for_dom_object(&inner);
|
||||||
unsafe {
|
unsafe {
|
||||||
JS_AddObjectRoot(cx, inner.reflector().rootable());
|
JS_AddObjectRoot(cx, inner.mut_reflector().rootable());
|
||||||
}
|
}
|
||||||
Temporary {
|
Temporary {
|
||||||
inner: inner,
|
inner: inner,
|
||||||
|
@ -351,7 +351,7 @@ impl<T: Assignable<U>, U: Reflectable> TemporaryPushable<T> for Vec<JS<U>> {
|
||||||
|
|
||||||
/// An opaque, LIFO rooting mechanism.
|
/// An opaque, LIFO rooting mechanism.
|
||||||
pub struct RootCollection {
|
pub struct RootCollection {
|
||||||
roots: RefCell<Vec<*JSObject>>,
|
roots: RefCell<Vec<*mut JSObject>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RootCollection {
|
impl RootCollection {
|
||||||
|
@ -396,7 +396,7 @@ pub struct Root<'a, 'b, T> {
|
||||||
/// Pointer to underlying Rust data
|
/// Pointer to underlying Rust data
|
||||||
ptr: RefCell<*mut T>,
|
ptr: RefCell<*mut T>,
|
||||||
/// On-stack JS pointer to assuage conservative stack scanner
|
/// On-stack JS pointer to assuage conservative stack scanner
|
||||||
js_ptr: *JSObject,
|
js_ptr: *mut JSObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, T: Reflectable> Root<'a, 'b, T> {
|
impl<'a, 'b, T: Reflectable> Root<'a, 'b, T> {
|
||||||
|
|
|
@ -21,7 +21,7 @@ use std::mem::size_of;
|
||||||
|
|
||||||
static JSPROXYSLOT_EXPANDO: u32 = 0;
|
static JSPROXYSLOT_EXPANDO: u32 = 0;
|
||||||
|
|
||||||
pub extern fn getPropertyDescriptor(cx: *JSContext, proxy: *JSObject, id: jsid,
|
pub extern fn getPropertyDescriptor(cx: *mut JSContext, proxy: *mut JSObject, id: jsid,
|
||||||
set: libc::c_int, desc: *mut JSPropertyDescriptor) -> libc::c_int {
|
set: libc::c_int, desc: *mut JSPropertyDescriptor) -> libc::c_int {
|
||||||
unsafe {
|
unsafe {
|
||||||
let handler = GetProxyHandler(proxy);
|
let handler = GetProxyHandler(proxy);
|
||||||
|
@ -35,7 +35,7 @@ pub extern fn getPropertyDescriptor(cx: *JSContext, proxy: *JSObject, id: jsid,
|
||||||
//let proto = JS_GetPrototype(proxy);
|
//let proto = JS_GetPrototype(proxy);
|
||||||
let proto = GetObjectProto(proxy);
|
let proto = GetObjectProto(proxy);
|
||||||
if proto.is_null() {
|
if proto.is_null() {
|
||||||
(*desc).obj = ptr::null();
|
(*desc).obj = ptr::mut_null();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ pub extern fn getPropertyDescriptor(cx: *JSContext, proxy: *JSObject, id: jsid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn defineProperty_(cx: *JSContext, proxy: *JSObject, id: jsid,
|
pub fn defineProperty_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid,
|
||||||
desc: *JSPropertyDescriptor) -> JSBool {
|
desc: *JSPropertyDescriptor) -> JSBool {
|
||||||
unsafe {
|
unsafe {
|
||||||
//FIXME: Workaround for https://github.com/mozilla/rust/issues/13385
|
//FIXME: Workaround for https://github.com/mozilla/rust/issues/13385
|
||||||
|
@ -68,18 +68,18 @@ pub fn defineProperty_(cx: *JSContext, proxy: *JSObject, id: jsid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub extern fn defineProperty(cx: *JSContext, proxy: *JSObject, id: jsid,
|
pub extern fn defineProperty(cx: *mut JSContext, proxy: *mut JSObject, id: jsid,
|
||||||
desc: *JSPropertyDescriptor) -> JSBool {
|
desc: *JSPropertyDescriptor) -> JSBool {
|
||||||
defineProperty_(cx, proxy, id, desc)
|
defineProperty_(cx, proxy, id, desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _obj_toString(cx: *JSContext, className: *libc::c_char) -> *JSString {
|
pub fn _obj_toString(cx: *mut JSContext, className: *libc::c_char) -> *mut JSString {
|
||||||
unsafe {
|
unsafe {
|
||||||
let name = str::raw::from_c_str(className);
|
let name = str::raw::from_c_str(className);
|
||||||
let nchars = "[object ]".len() + name.len();
|
let nchars = "[object ]".len() + name.len();
|
||||||
let chars: *mut jschar = JS_malloc(cx, (nchars + 1) as libc::size_t * (size_of::<jschar>() as libc::size_t)) as *mut jschar;
|
let chars: *mut jschar = JS_malloc(cx, (nchars + 1) as libc::size_t * (size_of::<jschar>() as libc::size_t)) as *mut jschar;
|
||||||
if chars.is_null() {
|
if chars.is_null() {
|
||||||
return ptr::null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = "[object ".to_owned() + name + "]";
|
let result = "[object ".to_owned() + name + "]";
|
||||||
|
@ -87,35 +87,36 @@ pub fn _obj_toString(cx: *JSContext, className: *libc::c_char) -> *JSString {
|
||||||
*chars.offset(i as int) = c as jschar;
|
*chars.offset(i as int) = c as jschar;
|
||||||
}
|
}
|
||||||
*chars.offset(nchars as int) = 0;
|
*chars.offset(nchars as int) = 0;
|
||||||
let jsstr = JS_NewUCString(cx, chars as *jschar, nchars as libc::size_t);
|
let jsstr = JS_NewUCString(cx, chars, nchars as libc::size_t);
|
||||||
if jsstr.is_null() {
|
if jsstr.is_null() {
|
||||||
JS_free(cx, chars as *libc::c_void);
|
JS_free(cx, chars as *mut libc::c_void);
|
||||||
}
|
}
|
||||||
jsstr
|
jsstr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn GetExpandoObject(obj: *JSObject) -> *JSObject {
|
pub fn GetExpandoObject(obj: *mut JSObject) -> *mut JSObject {
|
||||||
unsafe {
|
unsafe {
|
||||||
assert!(is_dom_proxy(obj));
|
assert!(is_dom_proxy(obj));
|
||||||
let val = GetProxyExtra(obj, JSPROXYSLOT_EXPANDO);
|
let val = GetProxyExtra(obj, JSPROXYSLOT_EXPANDO);
|
||||||
if val.is_undefined() {
|
if val.is_undefined() {
|
||||||
ptr::null()
|
ptr::mut_null()
|
||||||
} else {
|
} else {
|
||||||
val.to_object()
|
val.to_object()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn EnsureExpandoObject(cx: *JSContext, obj: *JSObject) -> *JSObject {
|
pub fn EnsureExpandoObject(cx: *mut JSContext, obj: *mut JSObject) -> *mut JSObject {
|
||||||
unsafe {
|
unsafe {
|
||||||
assert!(is_dom_proxy(obj));
|
assert!(is_dom_proxy(obj));
|
||||||
let mut expando = GetExpandoObject(obj);
|
let mut expando = GetExpandoObject(obj);
|
||||||
if expando.is_null() {
|
if expando.is_null() {
|
||||||
expando = JS_NewObjectWithGivenProto(cx, ptr::null(), ptr::null(),
|
expando = JS_NewObjectWithGivenProto(cx, ptr::null(),
|
||||||
|
ptr::mut_null(),
|
||||||
GetObjectParent(obj));
|
GetObjectParent(obj));
|
||||||
if expando.is_null() {
|
if expando.is_null() {
|
||||||
return ptr::null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
|
||||||
SetProxyExtra(obj, JSPROXYSLOT_EXPANDO, ObjectValue(&*expando));
|
SetProxyExtra(obj, JSPROXYSLOT_EXPANDO, ObjectValue(&*expando));
|
||||||
|
@ -124,7 +125,7 @@ pub fn EnsureExpandoObject(cx: *JSContext, obj: *JSObject) -> *JSObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn FillPropertyDescriptor(desc: &mut JSPropertyDescriptor, obj: *JSObject, readonly: bool) {
|
pub fn FillPropertyDescriptor(desc: &mut JSPropertyDescriptor, obj: *mut JSObject, readonly: bool) {
|
||||||
desc.obj = obj;
|
desc.obj = obj;
|
||||||
desc.attrs = if readonly { JSPROP_READONLY } else { 0 } | JSPROP_ENUMERATE;
|
desc.attrs = if readonly { JSPROP_READONLY } else { 0 } | JSPROP_ENUMERATE;
|
||||||
desc.getter = None;
|
desc.getter = None;
|
||||||
|
|
|
@ -11,8 +11,6 @@ use js::jsval::JSVal;
|
||||||
use libc;
|
use libc;
|
||||||
use std::cast;
|
use std::cast;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::ptr;
|
|
||||||
use std::ptr::null;
|
|
||||||
use serialize::{Encodable, Encoder};
|
use serialize::{Encodable, Encoder};
|
||||||
|
|
||||||
// IMPORTANT: We rely on the fact that we never attempt to encode DOM objects using
|
// IMPORTANT: We rely on the fact that we never attempt to encode DOM objects using
|
||||||
|
@ -50,11 +48,11 @@ pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: JSVal) {
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
description.to_c_str().with_ref(|name| {
|
description.to_c_str().with_ref(|name| {
|
||||||
(*tracer).debugPrinter = ptr::null();
|
(*tracer).debugPrinter = None;
|
||||||
(*tracer).debugPrintIndex = -1;
|
(*tracer).debugPrintIndex = -1;
|
||||||
(*tracer).debugPrintArg = name as *libc::c_void;
|
(*tracer).debugPrintArg = name as *libc::c_void;
|
||||||
debug!("tracing value {:s}", description);
|
debug!("tracing value {:s}", description);
|
||||||
JS_CallTracer(tracer as *JSTracer, val.to_gcthing(), val.trace_kind());
|
JS_CallTracer(tracer, val.to_gcthing(), val.trace_kind());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,14 +61,14 @@ pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Ref
|
||||||
trace_object(tracer, description, reflector.get_jsobject())
|
trace_object(tracer, description, reflector.get_jsobject())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trace_object(tracer: *mut JSTracer, description: &str, obj: *JSObject) {
|
pub fn trace_object(tracer: *mut JSTracer, description: &str, obj: *mut JSObject) {
|
||||||
unsafe {
|
unsafe {
|
||||||
description.to_c_str().with_ref(|name| {
|
description.to_c_str().with_ref(|name| {
|
||||||
(*tracer).debugPrinter = ptr::null();
|
(*tracer).debugPrinter = None;
|
||||||
(*tracer).debugPrintIndex = -1;
|
(*tracer).debugPrintIndex = -1;
|
||||||
(*tracer).debugPrintArg = name as *libc::c_void;
|
(*tracer).debugPrintArg = name as *libc::c_void;
|
||||||
debug!("tracing {:s}", description);
|
debug!("tracing {:s}", description);
|
||||||
JS_CallTracer(tracer as *JSTracer, obj, JSTRACE_OBJECT as u32);
|
JS_CallTracer(tracer, obj as *mut libc::c_void, JSTRACE_OBJECT);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +146,7 @@ impl<S: Encoder<E>, E, T: Encodable<S, E>+Copy> Encodable<S, E> for Traceable<Ce
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Encoder<E>, E> Encodable<S, E> for Traceable<*JSObject> {
|
impl<S: Encoder<E>, E> Encodable<S, E> for Traceable<*mut JSObject> {
|
||||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||||
trace_object(get_jstracer(s), "object", **self);
|
trace_object(get_jstracer(s), "object", **self);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -67,14 +67,14 @@ fn is_dom_class(clasp: *JSClass) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_dom_proxy(obj: *JSObject) -> bool {
|
pub fn is_dom_proxy(obj: *mut JSObject) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
(js_IsObjectProxyClass(obj) || js_IsFunctionProxyClass(obj)) &&
|
(js_IsObjectProxyClass(obj) || js_IsFunctionProxyClass(obj)) &&
|
||||||
IsProxyHandlerFamily(obj)
|
IsProxyHandlerFamily(obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dom_object_slot(obj: *JSObject) -> u32 {
|
pub unsafe fn dom_object_slot(obj: *mut JSObject) -> u32 {
|
||||||
let clasp = JS_GetClass(obj);
|
let clasp = JS_GetClass(obj);
|
||||||
if is_dom_class(clasp) {
|
if is_dom_class(clasp) {
|
||||||
DOM_OBJECT_SLOT as u32
|
DOM_OBJECT_SLOT as u32
|
||||||
|
@ -84,13 +84,13 @@ pub unsafe fn dom_object_slot(obj: *JSObject) -> u32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn unwrap<T>(obj: *JSObject) -> *mut T {
|
pub unsafe fn unwrap<T>(obj: *mut JSObject) -> *mut T {
|
||||||
let slot = dom_object_slot(obj);
|
let slot = dom_object_slot(obj);
|
||||||
let val = JS_GetReservedSlot(obj, slot);
|
let val = JS_GetReservedSlot(obj, slot);
|
||||||
val.to_private() as *mut T
|
val.to_private() as *mut T
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn get_dom_class(obj: *JSObject) -> Result<DOMClass, ()> {
|
pub unsafe fn get_dom_class(obj: *mut JSObject) -> Result<DOMClass, ()> {
|
||||||
let clasp = JS_GetClass(obj);
|
let clasp = JS_GetClass(obj);
|
||||||
if is_dom_class(clasp) {
|
if is_dom_class(clasp) {
|
||||||
debug!("plain old dom object");
|
debug!("plain old dom object");
|
||||||
|
@ -106,7 +106,7 @@ pub unsafe fn get_dom_class(obj: *JSObject) -> Result<DOMClass, ()> {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unwrap_jsmanaged<T: Reflectable>(mut obj: *JSObject,
|
pub fn unwrap_jsmanaged<T: Reflectable>(mut obj: *mut JSObject,
|
||||||
proto_id: PrototypeList::id::ID,
|
proto_id: PrototypeList::id::ID,
|
||||||
proto_depth: uint) -> Result<JS<T>, ()> {
|
proto_depth: uint) -> Result<JS<T>, ()> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -144,17 +144,17 @@ pub unsafe fn squirrel_away_unique<T>(x: Box<T>) -> *T {
|
||||||
cast::transmute(x)
|
cast::transmute(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn jsstring_to_str(cx: *JSContext, s: *JSString) -> DOMString {
|
pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString {
|
||||||
unsafe {
|
unsafe {
|
||||||
let length = 0;
|
let mut length = 0;
|
||||||
let chars = JS_GetStringCharsAndLength(cx, s, &length);
|
let chars = JS_GetStringCharsAndLength(cx, s, &mut length);
|
||||||
slice::raw::buf_as_slice(chars, length as uint, |char_vec| {
|
slice::raw::buf_as_slice(chars, length as uint, |char_vec| {
|
||||||
str::from_utf16(char_vec).unwrap()
|
str::from_utf16(char_vec).unwrap()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn jsid_to_str(cx: *JSContext, id: jsid) -> DOMString {
|
pub fn jsid_to_str(cx: *mut JSContext, id: jsid) -> DOMString {
|
||||||
unsafe {
|
unsafe {
|
||||||
assert!(RUST_JSID_IS_STRING(id) != 0);
|
assert!(RUST_JSID_IS_STRING(id) != 0);
|
||||||
jsstring_to_str(cx, RUST_JSID_TO_STRING(id))
|
jsstring_to_str(cx, RUST_JSID_TO_STRING(id))
|
||||||
|
@ -206,30 +206,30 @@ pub struct DOMJSClass {
|
||||||
pub dom_class: DOMClass
|
pub dom_class: DOMClass
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn GetProtoOrIfaceArray(global: *JSObject) -> **JSObject {
|
pub fn GetProtoOrIfaceArray(global: *mut JSObject) -> **mut JSObject {
|
||||||
unsafe {
|
unsafe {
|
||||||
assert!(((*JS_GetClass(global)).flags & JSCLASS_DOM_GLOBAL) != 0);
|
assert!(((*JS_GetClass(global)).flags & JSCLASS_DOM_GLOBAL) != 0);
|
||||||
JS_GetReservedSlot(global, DOM_PROTOTYPE_SLOT).to_private() as **JSObject
|
JS_GetReservedSlot(global, DOM_PROTOTYPE_SLOT).to_private() as **mut JSObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSObject,
|
pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiver: *mut JSObject,
|
||||||
protoProto: *JSObject, protoClass: *JSClass,
|
protoProto: *mut JSObject, protoClass: *JSClass,
|
||||||
constructor: Option<JSNative>,
|
constructor: JSNative,
|
||||||
ctorNargs: u32,
|
ctorNargs: u32,
|
||||||
domClass: *DOMClass,
|
domClass: *DOMClass,
|
||||||
methods: *JSFunctionSpec,
|
methods: *JSFunctionSpec,
|
||||||
properties: *JSPropertySpec,
|
properties: *JSPropertySpec,
|
||||||
constants: *ConstantSpec,
|
constants: *ConstantSpec,
|
||||||
staticMethods: *JSFunctionSpec,
|
staticMethods: *JSFunctionSpec,
|
||||||
name: &str) -> *JSObject {
|
name: &str) -> *mut JSObject {
|
||||||
let mut proto = ptr::null();
|
let mut proto = ptr::mut_null();
|
||||||
if protoClass.is_not_null() {
|
if protoClass.is_not_null() {
|
||||||
proto = CreateInterfacePrototypeObject(cx, global, protoProto,
|
proto = CreateInterfacePrototypeObject(cx, global, protoProto,
|
||||||
protoClass, methods,
|
protoClass, methods,
|
||||||
properties, constants);
|
properties, constants);
|
||||||
if proto.is_null() {
|
if proto.is_null() {
|
||||||
return ptr::null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -238,7 +238,7 @@ pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut interface = ptr::null();
|
let mut interface = ptr::mut_null();
|
||||||
if constructor.is_some() {
|
if constructor.is_some() {
|
||||||
interface = name.to_c_str().with_ref(|s| {
|
interface = name.to_c_str().with_ref(|s| {
|
||||||
CreateInterfaceObject(cx, global, receiver,
|
CreateInterfaceObject(cx, global, receiver,
|
||||||
|
@ -246,7 +246,7 @@ pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSO
|
||||||
staticMethods, constants, s)
|
staticMethods, constants, s)
|
||||||
});
|
});
|
||||||
if interface.is_null() {
|
if interface.is_null() {
|
||||||
return ptr::null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,17 +257,17 @@ pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject,
|
fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *mut JSObject,
|
||||||
constructorNative: Option<JSNative>,
|
constructorNative: JSNative,
|
||||||
ctorNargs: u32, proto: *JSObject,
|
ctorNargs: u32, proto: *mut JSObject,
|
||||||
staticMethods: *JSFunctionSpec,
|
staticMethods: *JSFunctionSpec,
|
||||||
constants: *ConstantSpec,
|
constants: *ConstantSpec,
|
||||||
name: *libc::c_char) -> *JSObject {
|
name: *libc::c_char) -> *mut JSObject {
|
||||||
unsafe {
|
unsafe {
|
||||||
let fun = JS_NewFunction(cx, constructorNative, ctorNargs,
|
let fun = JS_NewFunction(cx, constructorNative, ctorNargs,
|
||||||
JSFUN_CONSTRUCTOR, global, name);
|
JSFUN_CONSTRUCTOR, global, name);
|
||||||
if fun.is_null() {
|
if fun.is_null() {
|
||||||
return ptr::null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
|
||||||
let constructor = JS_GetFunctionObject(fun);
|
let constructor = JS_GetFunctionObject(fun);
|
||||||
|
@ -275,34 +275,34 @@ fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject,
|
||||||
|
|
||||||
if staticMethods.is_not_null() &&
|
if staticMethods.is_not_null() &&
|
||||||
!DefineMethods(cx, constructor, staticMethods) {
|
!DefineMethods(cx, constructor, staticMethods) {
|
||||||
return ptr::null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
|
||||||
if constants.is_not_null() &&
|
if constants.is_not_null() &&
|
||||||
!DefineConstants(cx, constructor, constants) {
|
!DefineConstants(cx, constructor, constants) {
|
||||||
return ptr::null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
|
||||||
if proto.is_not_null() && JS_LinkConstructorAndPrototype(cx, constructor, proto) == 0 {
|
if proto.is_not_null() && JS_LinkConstructorAndPrototype(cx, constructor, proto) == 0 {
|
||||||
return ptr::null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
|
||||||
let alreadyDefined = 0;
|
let mut alreadyDefined = 0;
|
||||||
if JS_AlreadyHasOwnProperty(cx, receiver, name, &alreadyDefined) == 0 {
|
if JS_AlreadyHasOwnProperty(cx, receiver, name, &mut alreadyDefined) == 0 {
|
||||||
return ptr::null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
|
||||||
if alreadyDefined == 0 &&
|
if alreadyDefined == 0 &&
|
||||||
JS_DefineProperty(cx, receiver, name, ObjectValue(&*constructor),
|
JS_DefineProperty(cx, receiver, name, ObjectValue(&*constructor),
|
||||||
None, None, 0) == 0 {
|
None, None, 0) == 0 {
|
||||||
return ptr::null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
|
||||||
return constructor;
|
return constructor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn DefineConstants(cx: *JSContext, obj: *JSObject, constants: *ConstantSpec) -> bool {
|
fn DefineConstants(cx: *mut JSContext, obj: *mut JSObject, constants: *ConstantSpec) -> bool {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
loop {
|
loop {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -330,52 +330,52 @@ fn DefineConstants(cx: *JSContext, obj: *JSObject, constants: *ConstantSpec) ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn DefineMethods(cx: *JSContext, obj: *JSObject, methods: *JSFunctionSpec) -> bool {
|
fn DefineMethods(cx: *mut JSContext, obj: *mut JSObject, methods: *JSFunctionSpec) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
JS_DefineFunctions(cx, obj, methods) != 0
|
JS_DefineFunctions(cx, obj, methods) != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn DefineProperties(cx: *JSContext, obj: *JSObject, properties: *JSPropertySpec) -> bool {
|
fn DefineProperties(cx: *mut JSContext, obj: *mut JSObject, properties: *JSPropertySpec) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
JS_DefineProperties(cx, obj, properties) != 0
|
JS_DefineProperties(cx, obj, properties) != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn CreateInterfacePrototypeObject(cx: *JSContext, global: *JSObject,
|
fn CreateInterfacePrototypeObject(cx: *mut JSContext, global: *mut JSObject,
|
||||||
parentProto: *JSObject, protoClass: *JSClass,
|
parentProto: *mut JSObject, protoClass: *JSClass,
|
||||||
methods: *JSFunctionSpec,
|
methods: *JSFunctionSpec,
|
||||||
properties: *JSPropertySpec,
|
properties: *JSPropertySpec,
|
||||||
constants: *ConstantSpec) -> *JSObject {
|
constants: *ConstantSpec) -> *mut JSObject {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ourProto = JS_NewObjectWithUniqueType(cx, protoClass, parentProto, global);
|
let ourProto = JS_NewObjectWithUniqueType(cx, protoClass, parentProto, global);
|
||||||
if ourProto.is_null() {
|
if ourProto.is_null() {
|
||||||
return ptr::null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
|
||||||
if methods.is_not_null() && !DefineMethods(cx, ourProto, methods) {
|
if methods.is_not_null() && !DefineMethods(cx, ourProto, methods) {
|
||||||
return ptr::null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
|
||||||
if properties.is_not_null() && !DefineProperties(cx, ourProto, properties) {
|
if properties.is_not_null() && !DefineProperties(cx, ourProto, properties) {
|
||||||
return ptr::null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
|
||||||
if constants.is_not_null() && !DefineConstants(cx, ourProto, constants) {
|
if constants.is_not_null() && !DefineConstants(cx, ourProto, constants) {
|
||||||
return ptr::null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ourProto;
|
return ourProto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub extern fn ThrowingConstructor(_cx: *JSContext, _argc: c_uint, _vp: *mut JSVal) -> JSBool {
|
pub extern fn ThrowingConstructor(_cx: *mut JSContext, _argc: c_uint, _vp: *mut JSVal) -> JSBool {
|
||||||
//XXX should trigger exception here
|
//XXX should trigger exception here
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initialize_global(global: *JSObject) {
|
pub fn initialize_global(global: *mut JSObject) {
|
||||||
let protoArray = box () ([0 as *JSObject, ..PrototypeList::id::IDCount as uint]);
|
let protoArray = box () ([0 as *mut JSObject, ..PrototypeList::id::IDCount as uint]);
|
||||||
unsafe {
|
unsafe {
|
||||||
let box_ = squirrel_away_unique(protoArray);
|
let box_ = squirrel_away_unique(protoArray);
|
||||||
JS_SetReservedSlot(global,
|
JS_SetReservedSlot(global,
|
||||||
|
@ -392,23 +392,23 @@ pub trait Reflectable {
|
||||||
pub fn reflect_dom_object<T: Reflectable>
|
pub fn reflect_dom_object<T: Reflectable>
|
||||||
(obj: Box<T>,
|
(obj: Box<T>,
|
||||||
window: &JSRef<window::Window>,
|
window: &JSRef<window::Window>,
|
||||||
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<window::Window>, Box<T>) -> JS<T>)
|
wrap_fn: extern "Rust" fn(*mut JSContext, &JSRef<window::Window>, Box<T>) -> JS<T>)
|
||||||
-> Temporary<T> {
|
-> Temporary<T> {
|
||||||
Temporary::new(wrap_fn(window.deref().get_cx(), window, obj))
|
Temporary::new(wrap_fn(window.deref().get_cx(), window, obj))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Eq)]
|
#[deriving(Eq)]
|
||||||
pub struct Reflector {
|
pub struct Reflector {
|
||||||
pub object: *JSObject,
|
pub object: *mut JSObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Reflector {
|
impl Reflector {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_jsobject(&self) -> *JSObject {
|
pub fn get_jsobject(&self) -> *mut JSObject {
|
||||||
self.object
|
self.object
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_jsobject(&mut self, object: *JSObject) {
|
pub fn set_jsobject(&mut self, object: *mut JSObject) {
|
||||||
assert!(self.object.is_null());
|
assert!(self.object.is_null());
|
||||||
assert!(object.is_not_null());
|
assert!(object.is_not_null());
|
||||||
self.object = object;
|
self.object = object;
|
||||||
|
@ -417,19 +417,19 @@ impl Reflector {
|
||||||
/// Return a pointer to the memory location at which the JS reflector object is stored.
|
/// Return a pointer to the memory location at which the JS reflector object is stored.
|
||||||
/// Used by Temporary values to root the reflector, as required by the JSAPI rooting
|
/// Used by Temporary values to root the reflector, as required by the JSAPI rooting
|
||||||
/// APIs.
|
/// APIs.
|
||||||
pub fn rootable<'a>(&'a self) -> &'a *JSObject {
|
pub fn rootable<'a>(&'a mut self) -> &'a mut *mut JSObject {
|
||||||
&self.object
|
&mut self.object
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new() -> Reflector {
|
pub fn new() -> Reflector {
|
||||||
Reflector {
|
Reflector {
|
||||||
object: ptr::null(),
|
object: ptr::mut_null(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn GetPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid, found: *mut bool,
|
pub fn GetPropertyOnPrototype(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, found: *mut bool,
|
||||||
vp: *JSVal) -> bool {
|
vp: *mut JSVal) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
//let proto = GetObjectProto(proxy);
|
//let proto = GetObjectProto(proxy);
|
||||||
let proto = JS_GetPrototype(proxy);
|
let proto = JS_GetPrototype(proxy);
|
||||||
|
@ -437,8 +437,8 @@ pub fn GetPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid, found:
|
||||||
*found = false;
|
*found = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
let hasProp = 0;
|
let mut hasProp = 0;
|
||||||
if JS_HasPropertyById(cx, proto, id, &hasProp) == 0 {
|
if JS_HasPropertyById(cx, proto, id, &mut hasProp) == 0 {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*found = hasProp != 0;
|
*found = hasProp != 0;
|
||||||
|
@ -451,7 +451,7 @@ pub fn GetPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid, found:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn GetArrayIndexFromId(_cx: *JSContext, id: jsid) -> Option<u32> {
|
pub fn GetArrayIndexFromId(_cx: *mut JSContext, id: jsid) -> Option<u32> {
|
||||||
unsafe {
|
unsafe {
|
||||||
if RUST_JSID_IS_INT(id) != 0 {
|
if RUST_JSID_IS_INT(id) != 0 {
|
||||||
return Some(RUST_JSID_TO_INT(id) as u32);
|
return Some(RUST_JSID_TO_INT(id) as u32);
|
||||||
|
@ -474,7 +474,7 @@ pub fn GetArrayIndexFromId(_cx: *JSContext, id: jsid) -> Option<u32> {
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
fn InternJSString(cx: *JSContext, chars: *libc::c_char) -> Option<jsid> {
|
fn InternJSString(cx: *mut JSContext, chars: *libc::c_char) -> Option<jsid> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let s = JS_InternString(cx, chars);
|
let s = JS_InternString(cx, chars);
|
||||||
if s.is_not_null() {
|
if s.is_not_null() {
|
||||||
|
@ -485,7 +485,7 @@ fn InternJSString(cx: *JSContext, chars: *libc::c_char) -> Option<jsid> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn InitIds(cx: *JSContext, specs: &[JSPropertySpec], ids: &mut [jsid]) -> bool {
|
pub fn InitIds(cx: *mut JSContext, specs: &[JSPropertySpec], ids: &mut [jsid]) -> bool {
|
||||||
for (i, spec) in specs.iter().enumerate() {
|
for (i, spec) in specs.iter().enumerate() {
|
||||||
if spec.name.is_null() == true {
|
if spec.name.is_null() == true {
|
||||||
return true;
|
return true;
|
||||||
|
@ -500,7 +500,7 @@ pub fn InitIds(cx: *JSContext, specs: &[JSPropertySpec], ids: &mut [jsid]) -> bo
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn FindEnumStringIndex(cx: *JSContext,
|
pub fn FindEnumStringIndex(cx: *mut JSContext,
|
||||||
v: JSVal,
|
v: JSVal,
|
||||||
values: &[&'static str]) -> Result<Option<uint>, ()> {
|
values: &[&'static str]) -> Result<Option<uint>, ()> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -509,8 +509,8 @@ pub fn FindEnumStringIndex(cx: *JSContext,
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let length = 0;
|
let mut length = 0;
|
||||||
let chars = JS_GetStringCharsAndLength(cx, jsstr, &length);
|
let chars = JS_GetStringCharsAndLength(cx, jsstr, &mut length);
|
||||||
if chars.is_null() {
|
if chars.is_null() {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
@ -524,23 +524,23 @@ pub fn FindEnumStringIndex(cx: *JSContext,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_dictionary_property(cx: *JSContext,
|
pub fn get_dictionary_property(cx: *mut JSContext,
|
||||||
object: *JSObject,
|
object: *mut JSObject,
|
||||||
property: &str) -> Result<Option<JSVal>, ()> {
|
property: &str) -> Result<Option<JSVal>, ()> {
|
||||||
use std::c_str::CString;
|
use std::c_str::CString;
|
||||||
fn has_property(cx: *JSContext, object: *JSObject, property: &CString,
|
fn has_property(cx: *mut JSContext, object: *mut JSObject, property: &CString,
|
||||||
found: &mut JSBool) -> bool {
|
found: &mut JSBool) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
property.with_ref(|s| {
|
property.with_ref(|s| {
|
||||||
JS_HasProperty(cx, object, s, found as *mut _ as *_) != 0
|
JS_HasProperty(cx, object, s, found) != 0
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn get_property(cx: *JSContext, object: *JSObject, property: &CString,
|
fn get_property(cx: *mut JSContext, object: *mut JSObject, property: &CString,
|
||||||
value: &mut JSVal) -> bool {
|
value: &mut JSVal) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
property.with_ref(|s| {
|
property.with_ref(|s| {
|
||||||
JS_GetProperty(cx, object, s, value as *mut _ as *_) != 0
|
JS_GetProperty(cx, object, s, value) != 0
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -567,23 +567,23 @@ pub fn get_dictionary_property(cx: *JSContext,
|
||||||
Ok(Some(value))
|
Ok(Some(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn HasPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid) -> bool {
|
pub fn HasPropertyOnPrototype(cx: *mut JSContext, proxy: *mut JSObject, id: jsid) -> bool {
|
||||||
// MOZ_ASSERT(js::IsProxy(proxy) && js::GetProxyHandler(proxy) == handler);
|
// MOZ_ASSERT(js::IsProxy(proxy) && js::GetProxyHandler(proxy) == handler);
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
return !GetPropertyOnPrototype(cx, proxy, id, &mut found, ptr::null()) || found;
|
return !GetPropertyOnPrototype(cx, proxy, id, &mut found, ptr::mut_null()) || found;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn IsConvertibleToCallbackInterface(cx: *JSContext, obj: *JSObject) -> bool {
|
pub fn IsConvertibleToCallbackInterface(cx: *mut JSContext, obj: *mut JSObject) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
JS_ObjectIsDate(cx, obj) == 0 && JS_ObjectIsRegExp(cx, obj) == 0
|
JS_ObjectIsDate(cx, obj) == 0 && JS_ObjectIsRegExp(cx, obj) == 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn CreateDOMGlobal(cx: *JSContext, class: *JSClass) -> *JSObject {
|
pub fn CreateDOMGlobal(cx: *mut JSContext, class: *JSClass) -> *mut JSObject {
|
||||||
unsafe {
|
unsafe {
|
||||||
let obj = JS_NewGlobalObject(cx, class, ptr::null());
|
let obj = JS_NewGlobalObject(cx, class, ptr::mut_null());
|
||||||
if obj.is_null() {
|
if obj.is_null() {
|
||||||
return ptr::null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
with_compartment(cx, obj, || {
|
with_compartment(cx, obj, || {
|
||||||
JS_InitStandardClasses(cx, obj);
|
JS_InitStandardClasses(cx, obj);
|
||||||
|
@ -593,9 +593,9 @@ pub fn CreateDOMGlobal(cx: *JSContext, class: *JSClass) -> *JSObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub extern fn wrap_for_same_compartment(cx: *JSContext, obj: *JSObject) -> *JSObject {
|
pub extern fn wrap_for_same_compartment(cx: *mut JSContext, obj: *mut JSObject) -> *mut JSObject {
|
||||||
unsafe {
|
unsafe {
|
||||||
JS_ObjectToOuterObject(cx as *mut _, obj as *mut _) as *_
|
JS_ObjectToOuterObject(cx, obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -606,10 +606,10 @@ pub extern fn pre_wrap(cx: *mut JSContext, _scope: *mut JSObject,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub extern fn outerize_global(_cx: *JSContext, obj: JSHandleObject) -> *JSObject {
|
pub extern fn outerize_global(_cx: *mut JSContext, obj: JSHandleObject) -> *mut JSObject {
|
||||||
unsafe {
|
unsafe {
|
||||||
debug!("outerizing");
|
debug!("outerizing");
|
||||||
let obj = *obj.unnamed;
|
let obj = *obj.unnamed_field1;
|
||||||
let win: Root<window::Window> =
|
let win: Root<window::Window> =
|
||||||
unwrap_jsmanaged(obj,
|
unwrap_jsmanaged(obj,
|
||||||
IDLInterface::get_prototype_id(None::<window::Window>),
|
IDLInterface::get_prototype_id(None::<window::Window>),
|
||||||
|
@ -621,17 +621,17 @@ pub extern fn outerize_global(_cx: *JSContext, obj: JSHandleObject) -> *JSObject
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the global object of the realm that the given JS object was created in.
|
/// Returns the global object of the realm that the given JS object was created in.
|
||||||
pub fn global_object_for_js_object(obj: *JSObject) -> JS<window::Window> {
|
pub fn global_object_for_js_object(obj: *mut JSObject) -> JS<window::Window> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let global = GetGlobalForObjectCrossCompartment(obj);
|
let global = GetGlobalForObjectCrossCompartment(obj);
|
||||||
let clasp = JS_GetClass(global);
|
let clasp = JS_GetClass(global);
|
||||||
assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0);
|
assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0);
|
||||||
FromJSValConvertible::from_jsval(ptr::null(), ObjectOrNullValue(global), ())
|
FromJSValConvertible::from_jsval(ptr::mut_null(), ObjectOrNullValue(global), ())
|
||||||
.ok().expect("found DOM global that doesn't unwrap to Window")
|
.ok().expect("found DOM global that doesn't unwrap to Window")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext {
|
fn cx_for_dom_reflector(obj: *mut JSObject) -> *mut JSContext {
|
||||||
let win = global_object_for_js_object(obj).root();
|
let win = global_object_for_js_object(obj).root();
|
||||||
let js_info = win.deref().page().js_info();
|
let js_info = win.deref().page().js_info();
|
||||||
match *js_info {
|
match *js_info {
|
||||||
|
@ -640,7 +640,7 @@ fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cx_for_dom_object<T: Reflectable>(obj: &T) -> *JSContext {
|
pub fn cx_for_dom_object<T: Reflectable>(obj: &T) -> *mut JSContext {
|
||||||
cx_for_dom_reflector(obj.reflector().get_jsobject())
|
cx_for_dom_reflector(obj.reflector().get_jsobject())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ use std::ptr;
|
||||||
pub struct BrowserContext {
|
pub struct BrowserContext {
|
||||||
history: Vec<SessionHistoryEntry>,
|
history: Vec<SessionHistoryEntry>,
|
||||||
active_index: uint,
|
active_index: uint,
|
||||||
window_proxy: Traceable<*JSObject>,
|
window_proxy: Traceable<*mut JSObject>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BrowserContext {
|
impl BrowserContext {
|
||||||
|
@ -27,7 +27,7 @@ impl BrowserContext {
|
||||||
let mut context = BrowserContext {
|
let mut context = BrowserContext {
|
||||||
history: vec!(SessionHistoryEntry::new(document)),
|
history: vec!(SessionHistoryEntry::new(document)),
|
||||||
active_index: 0,
|
active_index: 0,
|
||||||
window_proxy: Traceable::new(ptr::null()),
|
window_proxy: Traceable::new(ptr::mut_null()),
|
||||||
};
|
};
|
||||||
context.window_proxy = Traceable::new(context.create_window_proxy());
|
context.window_proxy = Traceable::new(context.create_window_proxy());
|
||||||
context
|
context
|
||||||
|
@ -42,12 +42,12 @@ impl BrowserContext {
|
||||||
Temporary::new(doc.deref().window.clone())
|
Temporary::new(doc.deref().window.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn window_proxy(&self) -> *JSObject {
|
pub fn window_proxy(&self) -> *mut JSObject {
|
||||||
assert!(self.window_proxy.deref().is_not_null());
|
assert!(self.window_proxy.deref().is_not_null());
|
||||||
*self.window_proxy
|
*self.window_proxy
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_window_proxy(&self) -> *JSObject {
|
pub fn create_window_proxy(&self) -> *mut JSObject {
|
||||||
let win = self.active_window().root();
|
let win = self.active_window().root();
|
||||||
let page = win.deref().page();
|
let page = win.deref().page();
|
||||||
let js_info = page.js_info();
|
let js_info = page.js_info();
|
||||||
|
|
|
@ -27,8 +27,8 @@ impl CustomEventDerived for Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CustomEventMethods {
|
pub trait CustomEventMethods {
|
||||||
fn Detail(&self, _cx: *JSContext) -> JSVal;
|
fn Detail(&self, _cx: *mut JSContext) -> JSVal;
|
||||||
fn InitCustomEvent(&mut self, _cx: *JSContext,
|
fn InitCustomEvent(&mut self, _cx: *mut JSContext,
|
||||||
type_: DOMString, can_bubble: bool,
|
type_: DOMString, can_bubble: bool,
|
||||||
cancelable: bool, detail: JSVal);
|
cancelable: bool, detail: JSVal);
|
||||||
}
|
}
|
||||||
|
@ -59,12 +59,12 @@ impl CustomEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CustomEventMethods for JSRef<'a, CustomEvent> {
|
impl<'a> CustomEventMethods for JSRef<'a, CustomEvent> {
|
||||||
fn Detail(&self, _cx: *JSContext) -> JSVal {
|
fn Detail(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
self.detail.deref().clone()
|
self.detail.deref().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn InitCustomEvent(&mut self,
|
fn InitCustomEvent(&mut self,
|
||||||
_cx: *JSContext,
|
_cx: *mut JSContext,
|
||||||
type_: DOMString,
|
type_: DOMString,
|
||||||
can_bubble: bool,
|
can_bubble: bool,
|
||||||
cancelable: bool,
|
cancelable: bool,
|
||||||
|
|
|
@ -188,7 +188,7 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> {
|
||||||
impl Document {
|
impl Document {
|
||||||
pub fn reflect_document(document: Box<Document>,
|
pub fn reflect_document(document: Box<Document>,
|
||||||
window: &JSRef<Window>,
|
window: &JSRef<Window>,
|
||||||
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<Window>, Box<Document>) -> JS<Document>)
|
wrap_fn: extern "Rust" fn(*mut JSContext, &JSRef<Window>, Box<Document>) -> JS<Document>)
|
||||||
-> Temporary<Document> {
|
-> Temporary<Document> {
|
||||||
assert!(document.reflector().get_jsobject().is_null());
|
assert!(document.reflector().get_jsobject().is_null());
|
||||||
let mut raw_doc = reflect_dom_object(document, window, wrap_fn).root();
|
let mut raw_doc = reflect_dom_object(document, window, wrap_fn).root();
|
||||||
|
|
|
@ -52,8 +52,8 @@ pub trait HTMLElementMethods {
|
||||||
fn SetLang(&mut self, _lang: DOMString);
|
fn SetLang(&mut self, _lang: DOMString);
|
||||||
fn Dir(&self) -> DOMString;
|
fn Dir(&self) -> DOMString;
|
||||||
fn SetDir(&mut self, _dir: DOMString) -> ErrorResult;
|
fn SetDir(&mut self, _dir: DOMString) -> ErrorResult;
|
||||||
fn GetItemValue(&self, _cx: *JSContext) -> Fallible<JSVal>;
|
fn GetItemValue(&self, _cx: *mut JSContext) -> Fallible<JSVal>;
|
||||||
fn SetItemValue(&mut self, _cx: *JSContext, _val: JSVal) -> ErrorResult;
|
fn SetItemValue(&mut self, _cx: *mut JSContext, _val: JSVal) -> ErrorResult;
|
||||||
fn Hidden(&self) -> bool;
|
fn Hidden(&self) -> bool;
|
||||||
fn SetHidden(&mut self, _hidden: bool) -> ErrorResult;
|
fn SetHidden(&mut self, _hidden: bool) -> ErrorResult;
|
||||||
fn Click(&self);
|
fn Click(&self);
|
||||||
|
@ -101,11 +101,11 @@ impl<'a> HTMLElementMethods for JSRef<'a, HTMLElement> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn GetItemValue(&self, _cx: *JSContext) -> Fallible<JSVal> {
|
fn GetItemValue(&self, _cx: *mut JSContext) -> Fallible<JSVal> {
|
||||||
Ok(NullValue())
|
Ok(NullValue())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn SetItemValue(&mut self, _cx: *JSContext, _val: JSVal) -> ErrorResult {
|
fn SetItemValue(&mut self, _cx: *mut JSContext, _val: JSVal) -> ErrorResult {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -637,11 +637,11 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
||||||
|
|
||||||
/// If the given untrusted node address represents a valid DOM node in the given runtime,
|
/// If the given untrusted node address represents a valid DOM node in the given runtime,
|
||||||
/// returns it.
|
/// returns it.
|
||||||
pub fn from_untrusted_node_address(runtime: *JSRuntime, candidate: UntrustedNodeAddress)
|
pub fn from_untrusted_node_address(runtime: *mut JSRuntime, candidate: UntrustedNodeAddress)
|
||||||
-> Temporary<Node> {
|
-> Temporary<Node> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let candidate: uintptr_t = cast::transmute(candidate);
|
let candidate: uintptr_t = cast::transmute(candidate);
|
||||||
let object: *JSObject = jsfriendapi::bindgen::JS_GetAddressableObject(runtime,
|
let object: *mut JSObject = jsfriendapi::bindgen::JS_GetAddressableObject(runtime,
|
||||||
candidate);
|
candidate);
|
||||||
if object.is_null() {
|
if object.is_null() {
|
||||||
fail!("Attempted to create a `JS<Node>` from an invalid pointer!")
|
fail!("Attempted to create a `JS<Node>` from an invalid pointer!")
|
||||||
|
@ -889,7 +889,7 @@ impl Node {
|
||||||
pub fn reflect_node<N: Reflectable+NodeBase>
|
pub fn reflect_node<N: Reflectable+NodeBase>
|
||||||
(node: Box<N>,
|
(node: Box<N>,
|
||||||
document: &JSRef<Document>,
|
document: &JSRef<Document>,
|
||||||
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<Window>, Box<N>) -> JS<N>)
|
wrap_fn: extern "Rust" fn(*mut JSContext, &JSRef<Window>, Box<N>) -> JS<N>)
|
||||||
-> Temporary<N> {
|
-> Temporary<N> {
|
||||||
assert!(node.reflector().get_jsobject().is_null());
|
assert!(node.reflector().get_jsobject().is_null());
|
||||||
let window = document.deref().window.root();
|
let window = document.deref().window.root();
|
||||||
|
|
|
@ -52,8 +52,8 @@ pub trait TestBindingMethods {
|
||||||
fn SetEnumAttribute(&self, _: TestEnum) {}
|
fn SetEnumAttribute(&self, _: TestEnum) {}
|
||||||
fn InterfaceAttribute(&self) -> Temporary<Blob>;
|
fn InterfaceAttribute(&self) -> Temporary<Blob>;
|
||||||
fn SetInterfaceAttribute(&self, _: &JSRef<Blob>) {}
|
fn SetInterfaceAttribute(&self, _: &JSRef<Blob>) {}
|
||||||
fn AnyAttribute(&self, _: *JSContext) -> JSVal { NullValue() }
|
fn AnyAttribute(&self, _: *mut JSContext) -> JSVal { NullValue() }
|
||||||
fn SetAnyAttribute(&self, _: *JSContext, _: JSVal) {}
|
fn SetAnyAttribute(&self, _: *mut JSContext, _: JSVal) {}
|
||||||
|
|
||||||
fn GetBooleanAttributeNullable(&self) -> Option<bool> { Some(false) }
|
fn GetBooleanAttributeNullable(&self) -> Option<bool> { Some(false) }
|
||||||
fn SetBooleanAttributeNullable(&self, _: Option<bool>) {}
|
fn SetBooleanAttributeNullable(&self, _: Option<bool>) {}
|
||||||
|
@ -101,7 +101,7 @@ pub trait TestBindingMethods {
|
||||||
fn ReceiveByteString(&self) -> ByteString { ByteString::new(vec!()) }
|
fn ReceiveByteString(&self) -> ByteString { ByteString::new(vec!()) }
|
||||||
fn ReceiveEnum(&self) -> TestEnum { _empty }
|
fn ReceiveEnum(&self) -> TestEnum { _empty }
|
||||||
fn ReceiveInterface(&self) -> Temporary<Blob>;
|
fn ReceiveInterface(&self) -> Temporary<Blob>;
|
||||||
fn ReceiveAny(&self, _: *JSContext) -> JSVal { NullValue() }
|
fn ReceiveAny(&self, _: *mut JSContext) -> JSVal { NullValue() }
|
||||||
|
|
||||||
fn ReceiveNullableBoolean(&self) -> Option<bool> { Some(false) }
|
fn ReceiveNullableBoolean(&self) -> Option<bool> { Some(false) }
|
||||||
fn ReceiveNullableByte(&self) -> Option<i8> { Some(0) }
|
fn ReceiveNullableByte(&self) -> Option<i8> { Some(0) }
|
||||||
|
@ -118,7 +118,7 @@ pub trait TestBindingMethods {
|
||||||
fn ReceiveNullableByteString(&self) -> Option<ByteString> { Some(ByteString::new(vec!())) }
|
fn ReceiveNullableByteString(&self) -> Option<ByteString> { Some(ByteString::new(vec!())) }
|
||||||
fn ReceiveNullableEnum(&self) -> Option<TestEnum> { Some(_empty) }
|
fn ReceiveNullableEnum(&self) -> Option<TestEnum> { Some(_empty) }
|
||||||
fn ReceiveNullableInterface(&self) -> Option<Temporary<Blob>>;
|
fn ReceiveNullableInterface(&self) -> Option<Temporary<Blob>>;
|
||||||
fn ReceiveNullableAny(&self, _: *JSContext) -> Option<JSVal> { Some(NullValue()) }
|
fn ReceiveNullableAny(&self, _: *mut JSContext) -> Option<JSVal> { Some(NullValue()) }
|
||||||
|
|
||||||
fn PassBoolean(&self, _: bool) {}
|
fn PassBoolean(&self, _: bool) {}
|
||||||
fn PassByte(&self, _: i8) {}
|
fn PassByte(&self, _: i8) {}
|
||||||
|
@ -137,7 +137,7 @@ pub trait TestBindingMethods {
|
||||||
fn PassInterface(&self, _: &JSRef<Blob>) {}
|
fn PassInterface(&self, _: &JSRef<Blob>) {}
|
||||||
fn PassUnion(&self, _: HTMLElementOrLong) {}
|
fn PassUnion(&self, _: HTMLElementOrLong) {}
|
||||||
fn PassUnion2(&self, _: StringOrFormData) {}
|
fn PassUnion2(&self, _: StringOrFormData) {}
|
||||||
fn PassAny(&self, _: *JSContext, _: JSVal) {}
|
fn PassAny(&self, _: *mut JSContext, _: JSVal) {}
|
||||||
|
|
||||||
fn PassNullableBoolean(&self, _: Option<bool>) {}
|
fn PassNullableBoolean(&self, _: Option<bool>) {}
|
||||||
fn PassNullableByte(&self, _: Option<i8>) {}
|
fn PassNullableByte(&self, _: Option<i8>) {}
|
||||||
|
@ -156,7 +156,7 @@ pub trait TestBindingMethods {
|
||||||
fn PassNullableInterface(&self, _: Option<JSRef<Blob>>) {}
|
fn PassNullableInterface(&self, _: Option<JSRef<Blob>>) {}
|
||||||
fn PassNullableUnion(&self, _: Option<HTMLElementOrLong>) {}
|
fn PassNullableUnion(&self, _: Option<HTMLElementOrLong>) {}
|
||||||
fn PassNullableUnion2(&self, _: Option<StringOrFormData>) {}
|
fn PassNullableUnion2(&self, _: Option<StringOrFormData>) {}
|
||||||
fn PassNullableAny(&self, _: *JSContext, _: Option<JSVal>) {}
|
fn PassNullableAny(&self, _: *mut JSContext, _: Option<JSVal>) {}
|
||||||
|
|
||||||
fn PassOptionalBoolean(&self, _: Option<bool>) {}
|
fn PassOptionalBoolean(&self, _: Option<bool>) {}
|
||||||
fn PassOptionalByte(&self, _: Option<i8>) {}
|
fn PassOptionalByte(&self, _: Option<i8>) {}
|
||||||
|
@ -175,7 +175,7 @@ pub trait TestBindingMethods {
|
||||||
fn PassOptionalInterface(&self, _: Option<JSRef<Blob>>) {}
|
fn PassOptionalInterface(&self, _: Option<JSRef<Blob>>) {}
|
||||||
fn PassOptionalUnion(&self, _: Option<HTMLElementOrLong>) {}
|
fn PassOptionalUnion(&self, _: Option<HTMLElementOrLong>) {}
|
||||||
fn PassOptionalUnion2(&self, _: Option<StringOrFormData>) {}
|
fn PassOptionalUnion2(&self, _: Option<StringOrFormData>) {}
|
||||||
fn PassOptionalAny(&self, _: *JSContext, _: Option<JSVal>) {}
|
fn PassOptionalAny(&self, _: *mut JSContext, _: Option<JSVal>) {}
|
||||||
|
|
||||||
fn PassOptionalNullableBoolean(&self, _: Option<Option<bool>>) {}
|
fn PassOptionalNullableBoolean(&self, _: Option<Option<bool>>) {}
|
||||||
fn PassOptionalNullableByte(&self, _: Option<Option<i8>>) {}
|
fn PassOptionalNullableByte(&self, _: Option<Option<i8>>) {}
|
||||||
|
@ -224,7 +224,7 @@ pub trait TestBindingMethods {
|
||||||
fn PassOptionalNullableInterfaceWithDefault(&self, _: Option<JSRef<Blob>>) {}
|
fn PassOptionalNullableInterfaceWithDefault(&self, _: Option<JSRef<Blob>>) {}
|
||||||
fn PassOptionalNullableUnionWithDefault(&self, _: Option<HTMLElementOrLong>) {}
|
fn PassOptionalNullableUnionWithDefault(&self, _: Option<HTMLElementOrLong>) {}
|
||||||
fn PassOptionalNullableUnion2WithDefault(&self, _: Option<StringOrFormData>) {}
|
fn PassOptionalNullableUnion2WithDefault(&self, _: Option<StringOrFormData>) {}
|
||||||
fn PassOptionalAnyWithDefault(&self, _: *JSContext, _: JSVal) {}
|
fn PassOptionalAnyWithDefault(&self, _: *mut JSContext, _: JSVal) {}
|
||||||
|
|
||||||
fn PassOptionalNullableBooleanWithNonNullDefault(&self, _: Option<bool>) {}
|
fn PassOptionalNullableBooleanWithNonNullDefault(&self, _: Option<bool>) {}
|
||||||
fn PassOptionalNullableByteWithNonNullDefault(&self, _: Option<i8>) {}
|
fn PassOptionalNullableByteWithNonNullDefault(&self, _: Option<i8>) {}
|
||||||
|
|
|
@ -82,7 +82,7 @@ pub struct Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn get_cx(&self) -> *JSContext {
|
pub fn get_cx(&self) -> *mut JSContext {
|
||||||
let js_info = self.page().js_info();
|
let js_info = self.page().js_info();
|
||||||
(**js_info.get_ref().js_context).ptr
|
(**js_info.get_ref().js_context).ptr
|
||||||
}
|
}
|
||||||
|
@ -132,10 +132,10 @@ pub trait WindowMethods {
|
||||||
fn Confirm(&self, _message: DOMString) -> bool;
|
fn Confirm(&self, _message: DOMString) -> bool;
|
||||||
fn Prompt(&self, _message: DOMString, _default: DOMString) -> Option<DOMString>;
|
fn Prompt(&self, _message: DOMString, _default: DOMString) -> Option<DOMString>;
|
||||||
fn Print(&self);
|
fn Print(&self);
|
||||||
fn ShowModalDialog(&self, _cx: *JSContext, _url: DOMString, _argument: Option<JSVal>) -> JSVal;
|
fn ShowModalDialog(&self, _cx: *mut JSContext, _url: DOMString, _argument: Option<JSVal>) -> JSVal;
|
||||||
fn SetTimeout(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32;
|
fn SetTimeout(&mut self, _cx: *mut JSContext, callback: JSVal, timeout: i32) -> i32;
|
||||||
fn ClearTimeout(&mut self, handle: i32);
|
fn ClearTimeout(&mut self, handle: i32);
|
||||||
fn SetInterval(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32;
|
fn SetInterval(&mut self, _cx: *mut JSContext, callback: JSVal, timeout: i32) -> i32;
|
||||||
fn ClearInterval(&mut self, handle: i32);
|
fn ClearInterval(&mut self, handle: i32);
|
||||||
fn Window(&self) -> Temporary<Window>;
|
fn Window(&self) -> Temporary<Window>;
|
||||||
fn Self(&self) -> Temporary<Window>;
|
fn Self(&self) -> Temporary<Window>;
|
||||||
|
@ -227,11 +227,11 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
|
||||||
fn Print(&self) {
|
fn Print(&self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ShowModalDialog(&self, _cx: *JSContext, _url: DOMString, _argument: Option<JSVal>) -> JSVal {
|
fn ShowModalDialog(&self, _cx: *mut JSContext, _url: DOMString, _argument: Option<JSVal>) -> JSVal {
|
||||||
NullValue()
|
NullValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn SetTimeout(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32 {
|
fn SetTimeout(&mut self, _cx: *mut JSContext, callback: JSVal, timeout: i32) -> i32 {
|
||||||
self.set_timeout_or_interval(callback, timeout, false)
|
self.set_timeout_or_interval(callback, timeout, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
|
||||||
self.active_timers.remove(&TimerId(handle));
|
self.active_timers.remove(&TimerId(handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn SetInterval(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32 {
|
fn SetInterval(&mut self, _cx: *mut JSContext, callback: JSVal, timeout: i32) -> i32 {
|
||||||
self.set_timeout_or_interval(callback, timeout, true)
|
self.set_timeout_or_interval(callback, timeout, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,7 +394,7 @@ impl<'a> PrivateWindowHelpers for JSRef<'a, Window> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(cx: *JSContext,
|
pub fn new(cx: *mut JSContext,
|
||||||
page: Rc<Page>,
|
page: Rc<Page>,
|
||||||
script_chan: ScriptChan,
|
script_chan: ScriptChan,
|
||||||
compositor: Box<ScriptListener>,
|
compositor: Box<ScriptListener>,
|
||||||
|
|
|
@ -229,7 +229,7 @@ pub trait XMLHttpRequestMethods<'a> {
|
||||||
fn OverrideMimeType(&self, _mime: DOMString);
|
fn OverrideMimeType(&self, _mime: DOMString);
|
||||||
fn ResponseType(&self) -> XMLHttpRequestResponseType;
|
fn ResponseType(&self) -> XMLHttpRequestResponseType;
|
||||||
fn SetResponseType(&mut self, response_type: XMLHttpRequestResponseType);
|
fn SetResponseType(&mut self, response_type: XMLHttpRequestResponseType);
|
||||||
fn Response(&self, _cx: *JSContext) -> JSVal;
|
fn Response(&self, _cx: *mut JSContext) -> JSVal;
|
||||||
fn ResponseText(&self) -> DOMString;
|
fn ResponseText(&self) -> DOMString;
|
||||||
fn GetResponseXML(&self) -> Option<Temporary<Document>>;
|
fn GetResponseXML(&self) -> Option<Temporary<Document>>;
|
||||||
}
|
}
|
||||||
|
@ -368,7 +368,7 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> {
|
||||||
fn SetResponseType(&mut self, response_type: XMLHttpRequestResponseType) {
|
fn SetResponseType(&mut self, response_type: XMLHttpRequestResponseType) {
|
||||||
self.response_type = response_type
|
self.response_type = response_type
|
||||||
}
|
}
|
||||||
fn Response(&self, cx: *JSContext) -> JSVal {
|
fn Response(&self, cx: *mut JSContext) -> JSVal {
|
||||||
match self.response_type {
|
match self.response_type {
|
||||||
_empty | Text => {
|
_empty | Text => {
|
||||||
if self.ready_state == XHRDone || self.ready_state == Loading {
|
if self.ready_state == XHRDone || self.ready_state == Loading {
|
||||||
|
@ -438,14 +438,14 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> {
|
||||||
unsafe fn to_trusted(&mut self) -> TrustedXHRAddress {
|
unsafe fn to_trusted(&mut self) -> TrustedXHRAddress {
|
||||||
assert!(self.pinned == false);
|
assert!(self.pinned == false);
|
||||||
self.pinned = true;
|
self.pinned = true;
|
||||||
JS_AddObjectRoot(self.global.root().get_cx(), self.reflector().rootable());
|
JS_AddObjectRoot(self.global.root().get_cx(), self.mut_reflector().rootable());
|
||||||
TrustedXHRAddress(self.deref() as *XMLHttpRequest as *libc::c_void)
|
TrustedXHRAddress(self.deref() as *XMLHttpRequest as *libc::c_void)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn release(&mut self) {
|
fn release(&mut self) {
|
||||||
assert!(self.pinned);
|
assert!(self.pinned);
|
||||||
unsafe {
|
unsafe {
|
||||||
JS_RemoveObjectRoot(self.global.root().get_cx(), self.reflector().rootable());
|
JS_RemoveObjectRoot(self.global.root().get_cx(), self.mut_reflector().rootable());
|
||||||
}
|
}
|
||||||
self.pinned = false;
|
self.pinned = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -643,7 +643,7 @@ impl ScriptTask {
|
||||||
fn new_rt_and_cx() -> (js::rust::rt, Rc<Cx>) {
|
fn new_rt_and_cx() -> (js::rust::rt, Rc<Cx>) {
|
||||||
let js_runtime = js::rust::rt();
|
let js_runtime = js::rust::rt();
|
||||||
assert!({
|
assert!({
|
||||||
let ptr: *JSRuntime = (*js_runtime).ptr;
|
let ptr: *mut JSRuntime = (*js_runtime).ptr;
|
||||||
ptr.is_not_null()
|
ptr.is_not_null()
|
||||||
});
|
});
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -652,18 +652,18 @@ impl ScriptTask {
|
||||||
// to retrieve the default callback is as the result of
|
// to retrieve the default callback is as the result of
|
||||||
// JS_SetWrapObjectCallbacks, which is why we call it twice.
|
// JS_SetWrapObjectCallbacks, which is why we call it twice.
|
||||||
let callback = JS_SetWrapObjectCallbacks((*js_runtime).ptr,
|
let callback = JS_SetWrapObjectCallbacks((*js_runtime).ptr,
|
||||||
ptr::null(),
|
None,
|
||||||
wrap_for_same_compartment,
|
Some(wrap_for_same_compartment),
|
||||||
None);
|
None);
|
||||||
JS_SetWrapObjectCallbacks((*js_runtime).ptr,
|
JS_SetWrapObjectCallbacks((*js_runtime).ptr,
|
||||||
callback,
|
callback,
|
||||||
wrap_for_same_compartment,
|
Some(wrap_for_same_compartment),
|
||||||
Some(pre_wrap));
|
Some(pre_wrap));
|
||||||
}
|
}
|
||||||
|
|
||||||
let js_context = js_runtime.cx();
|
let js_context = js_runtime.cx();
|
||||||
assert!({
|
assert!({
|
||||||
let ptr: *JSContext = (*js_context).ptr;
|
let ptr: *mut JSContext = (*js_context).ptr;
|
||||||
ptr.is_not_null()
|
ptr.is_not_null()
|
||||||
});
|
});
|
||||||
js_context.set_default_options_and_version();
|
js_context.set_default_options_and_version();
|
||||||
|
@ -675,7 +675,7 @@ impl ScriptTask {
|
||||||
(js_runtime, js_context)
|
(js_runtime, js_context)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_cx(&self) -> *JSContext {
|
pub fn get_cx(&self) -> *mut JSContext {
|
||||||
(**self.js_context.borrow().get_ref()).ptr
|
(**self.js_context.borrow().get_ref()).ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -835,11 +835,11 @@ impl ScriptTask {
|
||||||
// TODO: Support extra arguments. This requires passing a `*JSVal` array as `argv`.
|
// TODO: Support extra arguments. This requires passing a `*JSVal` array as `argv`.
|
||||||
let cx = self.get_cx();
|
let cx = self.get_cx();
|
||||||
with_compartment(cx, this_value, || {
|
with_compartment(cx, this_value, || {
|
||||||
let rval = NullValue();
|
let mut rval = NullValue();
|
||||||
unsafe {
|
unsafe {
|
||||||
JS_CallFunctionValue(cx, this_value,
|
JS_CallFunctionValue(cx, this_value,
|
||||||
*timer_handle.data.funval,
|
*timer_handle.data.funval,
|
||||||
0, ptr::null(), &rval);
|
0, ptr::mut_null(), &mut rval);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1242,7 +1242,7 @@ impl ScriptTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shuts down layout for the given page tree.
|
/// Shuts down layout for the given page tree.
|
||||||
fn shut_down_layout(page_tree: &Rc<Page>, rt: *JSRuntime) {
|
fn shut_down_layout(page_tree: &Rc<Page>, rt: *mut JSRuntime) {
|
||||||
for page in page_tree.iter() {
|
for page in page_tree.iter() {
|
||||||
page.join_layout();
|
page.join_layout();
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit c155a3b433c1e53b47758aec0d4496df3a312875
|
Subproject commit 4d337f8708f256eb4e03226022f6b3944e914fae
|
Loading…
Add table
Add a link
Reference in a new issue