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 11, 2013
1 parent fa9a1e3 commit f796ad4
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 38 deletions.
2 changes: 1 addition & 1 deletion crust.rs
Expand Up @@ -30,7 +30,7 @@ pub extern fn JS_ConvertStub(++cx: *JSContext, ++obj: JSHandleObject, ++_type: J
}
}

pub extern fn JS_ArrayIterator(++cx: *JSContext, ++argc: c_uint, ++vp: *JSVal) -> JSBool {
pub extern fn JS_ArrayIterator(++cx: *JSContext, ++argc: libc::c_uint, ++vp: *JSVal) -> JSBool {
unsafe {
bindgen::JS_ArrayIterator(cx, argc, vp)
}
Expand Down
12 changes: 7 additions & 5 deletions global.rs
Expand Up @@ -7,9 +7,11 @@ Handy functions for creating class objects and so forth.
use glue::bindgen::GetJSClassHookStubPointer;
use glue::{PROPERTY_STUB, STRICT_PROPERTY_STUB, ENUMERATE_STUB,
RESOLVE_STUB, CONVERT_STUB};
use libc::c_uint;
use core::libc::c_uint;
use core::str::raw::from_c_str;
use core::cast::reinterpret_cast;
use name_pool::*;
use ptr::null;
use core::ptr::null;
use jsapi;
use jsapi::{JSClass, JSContext, JSVal, JSFunctionSpec, JSBool, JSNativeWrapper};
use jsapi::bindgen::{JS_EncodeString, JS_free, JS_ValueToString};
Expand Down Expand Up @@ -57,14 +59,14 @@ pub unsafe fn jsval_to_rust_str(cx: *JSContext, vp: *jsapi::JSString) -> ~str {
~""
} else {
let bytes = JS_EncodeString(cx, vp);
let s = str::raw::from_c_str(bytes);
JS_free(cx, cast::reinterpret_cast(&bytes));
let s = from_c_str(bytes);
JS_free(cx, reinterpret_cast(&bytes));
s
}
}

pub extern fn debug(cx: *JSContext, argc: c_uint, vp: *JSVal) -> JSBool {
use io::WriterUtil;
use core::io::WriterUtil;

unsafe {
let argv = JS_ARGV(cx, vp);
Expand Down
3 changes: 2 additions & 1 deletion glue.rs
@@ -1,7 +1,8 @@
/* automatically generated by rust-bindgen */

use libc::*;
use core::libc::*;
use jsapi::*;
use jsfriendapi::JSJitInfo;

pub type enum_StubType = c_uint;
pub const PROPERTY_STUB: u32 = 0_u32;
Expand Down
26 changes: 13 additions & 13 deletions js.rc
Expand Up @@ -14,12 +14,12 @@ pub mod crust;
pub mod jsval;
pub mod jsfriendapi;

use ptr::{null, addr_of};
use result::{Result, Ok, Err};
use libc::{c_char, c_uint};
use core::ptr::{null, addr_of};
use core::result::{Result, Ok, Err};
use core::libc::{c_char, c_uint};
use name_pool::NamePool;
use str::raw::from_c_str;
use io::WriterUtil;
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 @@ -32,14 +32,14 @@ use jsapi::bindgen::{JS_free, JS_AddObjectRoot, JS_DefineFunctions,
JS_SetErrorReporter, JS_SetOptions, JS_SetPrivate,
JS_SetVersion, JS_ValueToString, JS_DefineProperties,
JS_DefineProperty, JS_NewObject, JS_ComputeThis};
use libc::types::common::c99::{int8_t, int16_t, int32_t, int64_t, uint8_t,
uint16_t, uint32_t, uint64_t};
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 rust;
pub use mod rust;

pub use NamePool;
pub use name_pool::NamePool;
pub use mod jsapi;
pub use mod glue;
pub use mod crust;
Expand Down Expand Up @@ -195,20 +195,20 @@ mod shadow {
_1: *JSVal,
}

impl Object {
pub impl Object {
#[inline(always)]
pure fn numFixedSlots() -> libc::size_t {
pure fn numFixedSlots(&self) -> libc::size_t {
unsafe { ((*self.shape).slotInfo >> FIXED_SLOTS_SHIFT) as libc::size_t }
}

#[inline(always)]
fn fixedSlots() -> *JSVal {
fn fixedSlots(&self) -> *JSVal {
(ptr::offset(ptr::to_unsafe_ptr(&self), 1)) as *JSVal
}

// Like slotRef, but just returns the value, not a reference
#[inline(always)]
pure fn slotVal(slot: libc::size_t) -> JSVal {
pure fn slotVal(&self, slot: libc::size_t) -> JSVal {
unsafe {
let nfixed : libc::size_t = self.numFixedSlots();
if slot < nfixed {
Expand Down
2 changes: 1 addition & 1 deletion jsapi.rs
@@ -1,6 +1,6 @@
/* automatically generated by rust-bindgen */

use libc::*;
use core::libc::*;
use jsfriendapi::JSJitInfo;

pub type moz_static_assert0 = c_int;
Expand Down
6 changes: 3 additions & 3 deletions jsfriendapi.rs
Expand Up @@ -16,11 +16,11 @@ pub struct JSJitInfo {
#[nolink]
pub extern mod bindgen {
pub fn DefineFunctionWithReserved(cx: *JSContext, obj: *JSObject,
name: *libc::c_char, call: JSNative, nargs: uint,
attrs: uint) -> *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: uint) -> *JSErrorFormatString;
errorNumber: libc::c_uint) -> *JSErrorFormatString;
pub fn JS_NewObjectWithUniqueType(cx: *JSContext, clasp: *JSClass,
proto: *JSObject, parent: *JSObject) -> *JSObject;
}
6 changes: 3 additions & 3 deletions name_pool.rs
@@ -1,5 +1,5 @@
use libc::c_char;
use vec::push;
use core::libc::c_char;
use core::vec::push;

pub struct NamePool {
strbufs: ~[~[u8]]
Expand All @@ -11,7 +11,7 @@ pub fn NamePool() -> @mut NamePool {
}
}

impl NamePool {
pub impl NamePool {
fn add(&mut self, s: ~str) -> *c_char {
unsafe {
let mut strbuf = ~[];
Expand Down
23 changes: 12 additions & 11 deletions rust.rs
Expand Up @@ -3,7 +3,8 @@
#[allow(non_implicitly_copyable_typarams)];

use bg = jsapi::bindgen;
use libc::types::os::arch::c95::{size_t, c_uint};
use core::libc::types::os::arch::c95::{size_t, c_uint};
use core::libc::c_char;
use std::oldmap::HashMap;
use jsapi::*;
use jsapi::bindgen::*;
Expand All @@ -15,10 +16,10 @@ use JSOPTION_TYPE_INFERENCE;
use JSVAL_NULL;
use ERR;
use name_pool::*;
use ptr::null;
use core::ptr::null;
use result;
use result_obj;
use str::raw::from_c_str;
use core::str::raw::from_c_str;

// ___________________________________________________________________________
// friendly Rustic API to runtimes
Expand All @@ -40,8 +41,8 @@ pub fn new_runtime(p: *JSRuntime) -> rt {
}
}

impl rt {
fn cx() -> @Cx {
pub impl rt {
fn cx(self) -> @Cx {
unsafe {
new_context(JS_NewContext(self.ptr, default_stacksize as size_t), self)
}
Expand Down Expand Up @@ -78,7 +79,7 @@ pub fn new_context(ptr: *JSContext, rt: rt) -> @Cx {
}
}

impl Cx {
pub impl Cx {
fn rooted_obj(@self, obj: *JSObject) -> jsobj {
let jsobj = @jsobj_rsrc {cx: self, cxptr: self.ptr, ptr: obj};
unsafe {
Expand Down Expand Up @@ -211,7 +212,7 @@ pub struct Compartment {
global_protos: HashMap<~str, jsobj>
}

impl Compartment {
pub impl Compartment {
fn define_functions(@mut self,
specfn: fn(@mut NamePool) -> ~[JSFunctionSpec])
-> Result<(),()> {
Expand Down Expand Up @@ -280,7 +281,7 @@ impl Compartment {
fn register_class(@mut self, class_fn: fn(x: @mut Compartment) -> JSClass) {
let classptr = @class_fn(self);
if !self.cx.classes.insert(
unsafe { str::raw::from_c_str(classptr.name) },
unsafe { from_c_str(classptr.name) },
classptr) {
fail!(~"Duplicate JSClass registered; you're gonna have a bad time.")
}
Expand All @@ -307,7 +308,7 @@ pub struct jsobj_rsrc {
}

impl jsobj_rsrc {
fn new_object(rec : {cx: @Cx, cxptr: *JSContext, ptr: *JSObject}) -> jsobj {
fn new_object(&self, rec : {cx: @Cx, cxptr: *JSContext, ptr: *JSObject}) -> jsobj {
return @jsobj_rsrc {
cx: rec.cx,
cxptr: rec.cxptr,
Expand All @@ -320,11 +321,11 @@ impl jsobj_rsrc {
// random utilities

pub trait to_jsstr {
fn to_jsstr(cx: @Cx) -> *JSString;
fn to_jsstr(self, cx: @Cx) -> *JSString;
}

impl to_jsstr for ~str {
fn to_jsstr(cx: @Cx) -> *JSString {
fn to_jsstr(self, cx: @Cx) -> *JSString {
str::as_buf(self, |buf, len| {
unsafe {
let cbuf = cast::reinterpret_cast(&buf);
Expand Down

0 comments on commit f796ad4

Please sign in to comment.