Skip to content
This repository has been archived by the owner on Nov 12, 2022. It is now read-only.

Commit

Permalink
Language changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm committed Mar 13, 2013
1 parent f796ad4 commit 6255878
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 71 deletions.
2 changes: 0 additions & 2 deletions global.rs
Expand Up @@ -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| {
Expand Down
7 changes: 7 additions & 0 deletions glue.rs
Expand Up @@ -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;
}
9 changes: 0 additions & 9 deletions js.rc
Expand Up @@ -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};
Expand All @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
72 changes: 36 additions & 36 deletions jsapi.rs
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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 */;

Expand Down
18 changes: 7 additions & 11 deletions 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;

Expand All @@ -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;
}
}
19 changes: 19 additions & 0 deletions jsglue.cpp
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions jsval.rs
Expand Up @@ -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
}

Expand All @@ -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 *()
}
30 changes: 19 additions & 11 deletions rust.rs
Expand Up @@ -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);
}
Expand All @@ -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)
}
}
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) },
Expand All @@ -300,19 +305,22 @@ 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));
}
}
}

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
}
}
}
Expand Down

0 comments on commit 6255878

Please sign in to comment.