Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Language changes.

  • Loading branch information...
commit 62558783027d1aaccb4e689d3ff5aed057a1f5f5 1 parent f796ad4
@jdm jdm authored
View
2  global.rs
@@ -66,8 +66,6 @@ pub unsafe fn jsval_to_rust_str(cx: *JSContext, vp: *jsapi::JSString) -> ~str {
}
pub extern fn debug(cx: *JSContext, argc: c_uint, vp: *JSVal) -> JSBool {
- use core::io::WriterUtil;
-
unsafe {
let argv = JS_ARGV(cx, vp);
for uint::range(0u, argc as uint) |i| {
View
7 glue.rs
@@ -148,4 +148,11 @@ pub fn RUST_JSID_TO_INT(id: jsid) -> libc::c_int;
pub fn RUST_SET_JITINFO(func: *JSFunction, info: *JSJitInfo);
pub fn RUST_INTERNED_STRING_TO_JSID(cx: *JSContext, str: *JSString) -> jsid;
+
+pub fn DefineFunctionWithReserved(cx: *JSContext, obj: *JSObject,
+ name: *libc::c_char, call: JSNative, nargs: libc::c_uint,
+ attrs: libc::c_uint) -> *JSObject;
+pub fn GetObjectJSClass(obj: *JSObject) -> *JSClass;
+pub fn js_GetErrorMessage(userRef: *libc::c_void, locale: *libc::c_char,
+ errorNumber: libc::c_uint) -> *JSErrorFormatString;
}
View
9 js.rc
@@ -17,9 +17,6 @@ pub mod jsfriendapi;
use core::ptr::{null, addr_of};
use core::result::{Result, Ok, Err};
use core::libc::{c_char, c_uint};
-use name_pool::NamePool;
-use core::str::raw::from_c_str;
-use core::io::WriterUtil;
use jsapi::{JSBool, JSClass, JSContext, JSErrorReport, JSFunctionSpec,
JSObject, JSRuntime, JSString, JSVERSION_LATEST, JSVal, jsid,
JSPropertySpec, JSPropertyOp, JSStrictPropertyOp, JSProto_LIMIT};
@@ -35,7 +32,6 @@ use jsapi::bindgen::{JS_free, JS_AddObjectRoot, JS_DefineFunctions,
use core::libc::types::common::c99::{int8_t, int16_t, int32_t, int64_t, uint8_t,
uint16_t, uint32_t, uint64_t};
use jsval::{JSVAL_TO_OBJECT, JSVAL_IS_PRIMITIVE};
-use glue::bindgen::{RUST_JSVAL_TO_OBJECT, RUST_JSVAL_IS_PRIMITIVE};
use rust::jsobj;
pub use mod rust;
@@ -132,11 +128,6 @@ pub fn result_obj(o: jsobj) -> Result<jsobj, ()> {
if o.ptr != null() {Ok(o)} else {Err(())}
}
-pub type named_functions = @{
- names: ~[~str],
- funcs: ~[JSFunctionSpec]
-};
-
#[inline(always)]
pub unsafe fn JS_ARGV(_cx: *JSContext, vp: *JSVal) -> *JSVal {
ptr::offset(vp, 2u)
View
72 jsapi.rs
@@ -250,29 +250,29 @@ pub type JSVal = u64; //XXXjdm hand modified
pub type moz_static_assert6 = c_int;
-pub type JSHandleObject = {
+pub struct JSHandleObject {
unnamed: **JSObject,
-};
+}
-pub type JSHandleValue = {
+pub struct JSHandleValue {
unnamed: JSVal,
-};
+}
-pub type JSHandleString = {
+pub struct JSHandleString {
unnamed: **JSString,
-};
+}
-pub type JSMutableHandleObject = {
+pub struct JSMutableHandleObject {
unnamed: **JSObject,
-};
+}
-pub type JSHandleId = {
+pub struct JSHandleId {
unnamed: *jsid,
-};
+}
-pub type JSMutableHandleValue = {
+pub struct JSMutableHandleValue {
unnamed: *JSVal,
-};
+}
pub type JSRawObject = *JSObject;
@@ -294,17 +294,17 @@ pub type JSTypeOfOp = *u8;
pub type JSFreeOp = struct_JSFreeOp;
-pub type struct_JSFreeOp = {
+pub struct struct_JSFreeOp {
runtime: *JSRuntime,
-};
+}
pub type JSFinalizeOp = *u8;
pub type JSStringFinalizer = struct_JSStringFinalizer;
-pub type struct_JSStringFinalizer = {
+pub struct struct_JSStringFinalizer {
finalize: *u8,
-};
+}
pub type JSCheckAccessOp = *u8;
@@ -362,11 +362,11 @@ pub const JSEXN_LIMIT: i32 = 8_i32;
pub type JSExnType = enum_JSExnType;
-pub type struct_JSErrorFormatString = {
+pub struct struct_JSErrorFormatString {
format: *c_char,
argCount: uint16_t,
exnType: int16_t,
-};
+}
pub type JSErrorFormatString = struct_JSErrorFormatString;
@@ -430,14 +430,14 @@ pub type JSGCRootMapFun = *u8;
pub type JSTraceCallback = *u8;
-pub type struct_JSTracer = {
+pub struct struct_JSTracer {
runtime: *JSRuntime,
callback: JSTraceCallback,
debugPrinter: JSTraceNamePrinter,
debugPrintArg: *c_void,
debugPrintIndex: size_t,
eagerlyTraceWeakMaps: JSBool,
-};
+}
pub type enum_JSGCParamKey = c_uint;
pub const JSGC_MAX_BYTES: u32 = 0_u32;
@@ -490,12 +490,12 @@ pub struct JSClass {
reserved: (*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void,*c_void),
}
-pub type struct_JSConstDoubleSpec = {
+pub struct struct_JSConstDoubleSpec {
dval: c_double,
name: *c_char,
flags: uint8_t,
spare: (uint8_t,uint8_t,uint8_t),
-};
+}
pub type struct_JSJitInfo = c_void;
@@ -532,25 +532,25 @@ pub struct JSFunctionSpec {
selfHostedName: *c_char,
}
-pub type struct_JSPropertyDescriptor = {
+pub struct struct_JSPropertyDescriptor {
obj: *JSObject,
attrs: c_uint,
shortid: c_uint,
getter: JSPropertyOp,
setter: JSStrictPropertyOp,
value: JSVal,
-};
+}
-pub type struct_JSPrincipals = {
+pub struct struct_JSPrincipals {
refcount: c_int,
-};
+}
-pub type struct_JSSecurityCallbacks = {
+pub struct struct_JSSecurityCallbacks {
checkObjectAccess: JSCheckAccessOp,
subsumePrincipals: JSSubsumePrincipalsOp,
findObjectPrincipals: JSObjectPrincipalsFinder,
contentSecurityPolicyAllows: JSCSPEvalChecker,
-};
+}
pub type enum_JSExecPart = c_uint;
pub const JSEXEC_PROLOG: u32 = 0_u32;
@@ -560,21 +560,21 @@ pub type JSExecPart = enum_JSExecPart;
pub type JSONWriteCallback = *u8;
-pub type struct_JSStructuredCloneCallbacks = {
+pub struct struct_JSStructuredCloneCallbacks {
read: ReadStructuredCloneOp,
write: WriteStructuredCloneOp,
reportError: StructuredCloneErrorOp,
-};
+}
-pub type struct_JSLocaleCallbacks = {
+pub struct struct_JSLocaleCallbacks {
localeToUpperCase: JSLocaleToUpperCase,
localeToLowerCase: JSLocaleToLowerCase,
localeCompare: JSLocaleCompare,
localeToUnicode: JSLocaleToUnicode,
localeGetErrorMessage: JSErrorCallback,
-};
+}
-pub type struct_JSErrorReport = {
+pub struct struct_JSErrorReport {
filename: *c_char,
originPrincipals: *JSPrincipals,
lineno: c_uint,
@@ -588,11 +588,11 @@ pub type struct_JSErrorReport = {
messageArgs: **jschar,
exnType: int16_t,
column: c_uint,
-};
+}
-pub type struct_unnamed1 = {
+pub struct struct_unnamed1 {
payload: union_unnamed2,
-};
+}
pub type union_unnamed2 = c_void /* FIXME: union type */;
View
18 jsfriendapi.rs
@@ -1,5 +1,3 @@
-use jsapi::{JSContext, JSObject, JSNative, JSErrorFormatString, JSClass};
-
//pub type JSJitPropertyOp = *fn(cx: *JSContext, thisObj: *JSObject, specializedThis: *libc::c_void, vp: *JSVal);
pub type JSJitPropertyOp = *u8;
@@ -14,13 +12,11 @@ pub struct JSJitInfo {
//pub type JSJitInfo = JSJitInfo_struct;
#[nolink]
-pub extern mod bindgen {
-pub fn DefineFunctionWithReserved(cx: *JSContext, obj: *JSObject,
- name: *libc::c_char, call: JSNative, nargs: libc::c_uint,
- attrs: libc::c_uint) -> *JSObject;
-pub fn GetObjectJSClass(obj: *JSObject) -> *JSClass;
-pub fn js_GetErrorMessage(userRef: *libc::c_void, locale: *libc::c_char,
- errorNumber: libc::c_uint) -> *JSErrorFormatString;
-pub fn JS_NewObjectWithUniqueType(cx: *JSContext, clasp: *JSClass,
- proto: *JSObject, parent: *JSObject) -> *JSObject;
+pub mod bindgen {
+ use jsapi::{JSContext, JSObject, JSNative, JSErrorFormatString, JSClass};
+
+ pub extern {
+ fn JS_NewObjectWithUniqueType(cx: *JSContext, clasp: *JSClass,
+ proto: *JSObject, parent: *JSObject) -> *JSObject;
+ }
}
View
19 jsglue.cpp
@@ -508,4 +508,23 @@ RUST_INTERNED_STRING_TO_JSID(JSContext* cx, JSString* str) {
return INTERNED_STRING_TO_JSID(cx, str);
}
+JSFunction*
+DefineFunctionWithReserved(JSContext* cx, JSObject* obj, char* name, JSNative call,
+ uint32_t nargs, uint32_t attrs)
+{
+ return js::DefineFunctionWithReserved(cx, obj, name, call, nargs, attrs);
+}
+
+JSClass*
+GetObjectJSClass(JSObject* obj)
+{
+ return js::GetObjectJSClass(obj);
+}
+
+JSErrorFormatString*
+js_GetErrorMessage(void* userRef, char* locale, uint errorNumber)
+{
+ return js_GetErrorMessage(userRef, locale, errorNumber);
+}
+
} // extern "C"
View
4 jsval.rs
@@ -26,7 +26,7 @@ pub fn INT_TO_JSVAL(i: i32) -> JSVal {
#[inline(always)]
pub fn JSVAL_TO_OBJECT(v: JSVal) -> *JSObject {
let bits = (v & JSVAL_PAYLOAD_MASK);
- assert bits & 0x7 == 0;
+ fail_unless!(bits & 0x7 == 0);
bits as *JSObject
}
@@ -37,6 +37,6 @@ pub fn JSVAL_IS_PRIMITIVE(v: JSVal) -> bool {
#[inline(always)]
pub fn JSVAL_TO_PRIVATE(v: JSVal) -> *() {
- assert v & 0x8000000000000000 == 0;
+ fail_unless!(v & 0x8000000000000000 == 0);
(v << 1) as *()
}
View
30 rust.rs
@@ -28,7 +28,10 @@ pub type rt = @rt_rsrc;
pub struct rt_rsrc {
ptr : *JSRuntime,
- drop {
+}
+
+impl Drop for rt_rsrc {
+ fn finalize(&self) {
unsafe {
JS_Finish(self.ptr);
}
@@ -42,9 +45,9 @@ pub fn new_runtime(p: *JSRuntime) -> rt {
}
pub impl rt {
- fn cx(self) -> @Cx {
+ fn cx(&self) -> @Cx {
unsafe {
- new_context(JS_NewContext(self.ptr, default_stacksize as size_t), self)
+ new_context(JS_NewContext(self.ptr, default_stacksize as size_t), *self)
}
}
}
@@ -63,8 +66,10 @@ pub struct Cx {
ptr: *JSContext,
rt: rt,
classes: HashMap<~str, @JSClass>,
+}
- drop {
+impl Drop for Cx {
+ fn finalize(&self) {
unsafe {
JS_DestroyContext(self.ptr);
}
@@ -214,7 +219,7 @@ pub struct Compartment {
pub impl Compartment {
fn define_functions(@mut self,
- specfn: fn(@mut NamePool) -> ~[JSFunctionSpec])
+ specfn: &fn(@mut NamePool) -> ~[JSFunctionSpec])
-> Result<(),()> {
let specvec = @specfn(self.name_pool);
vec::push(&mut self.global_funcs, specvec);
@@ -278,7 +283,7 @@ pub impl Compartment {
fail!(~"Duplicate global prototype registered; you're gonna have a bad time.")
}
}
- fn register_class(@mut self, class_fn: fn(x: @mut Compartment) -> JSClass) {
+ fn register_class(@mut self, class_fn: &fn(x: @mut Compartment) -> JSClass) {
let classptr = @class_fn(self);
if !self.cx.classes.insert(
unsafe { from_c_str(classptr.name) },
@@ -300,7 +305,10 @@ pub struct jsobj_rsrc {
cx: @Cx,
cxptr: *JSContext,
ptr: *JSObject,
- drop {
+}
+
+impl Drop for jsobj_rsrc {
+ fn finalize(&self) {
unsafe {
JS_RemoveObjectRoot(self.cxptr, ptr::to_unsafe_ptr(&self.ptr));
}
@@ -308,11 +316,11 @@ pub struct jsobj_rsrc {
}
impl jsobj_rsrc {
- fn new_object(&self, rec : {cx: @Cx, cxptr: *JSContext, ptr: *JSObject}) -> jsobj {
+ fn new_object(&self, cx: @Cx, cxptr: *JSContext, ptr: *JSObject) -> jsobj {
return @jsobj_rsrc {
- cx: rec.cx,
- cxptr: rec.cxptr,
- ptr: rec.ptr
+ cx: cx,
+ cxptr: cxptr,
+ ptr: ptr
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.