diff --git a/global.rs b/global.rs index 718a3b772..07827cae6 100644 --- a/global.rs +++ b/global.rs @@ -8,10 +8,11 @@ Handy functions for creating class objects and so forth. "]; +use crust; use glue::GetJSClassHookStubPointer; use glue::{PROPERTY_STUB, STRICT_PROPERTY_STUB, ENUMERATE_STUB, RESOLVE_STUB, CONVERT_STUB}; -use std::libc::c_uint; +use std::libc::{c_uint, c_void}; use std::str::raw::from_c_str; use std::cast::transmute; use std::ptr::null; @@ -23,11 +24,40 @@ use jsapi::{JS_ReportError, JS_ValueToSource, JS_GC, JS_GetRuntime}; use jsfriendapi::JSJitInfo; use JSCLASS_IS_GLOBAL; use JSCLASS_HAS_RESERVED_SLOTS; +use JSCLASS_RESERVED_SLOTS_MASK; +use JSCLASS_RESERVED_SLOTS_SHIFT; use JSCLASS_GLOBAL_SLOT_COUNT; use JS_ARGV; use JSVAL_VOID; use JS_SET_RVAL; +static global_name: [i8, ..7] = ['g' as i8, 'l' as i8, 'o' as i8, 'b' as i8, 'a' as i8, 'l' as i8, 0 as i8]; +pub static BASIC_GLOBAL: JSClass = JSClass { + name: &global_name as *i8, + flags: JSCLASS_IS_GLOBAL | (((JSCLASS_GLOBAL_SLOT_COUNT + 1) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT), + addProperty: Some(crust::JS_PropertyStub), + delProperty: Some(crust::JS_PropertyStub), + getProperty: Some(crust::JS_PropertyStub), + setProperty: Some(crust::JS_StrictPropertyStub), + enumerate: Some(crust::JS_EnumerateStub), + resolve: Some(crust::JS_ResolveStub), + convert: Some(crust::JS_ConvertStub), + finalize: None, + checkAccess: None, + call: None, + hasInstance: None, + construct: None, + trace: None, + reserved: (0 as *c_void, 0 as *c_void, 0 as *c_void, 0 as *c_void, 0 as *c_void, // 05 + 0 as *c_void, 0 as *c_void, 0 as *c_void, 0 as *c_void, 0 as *c_void, // 10 + 0 as *c_void, 0 as *c_void, 0 as *c_void, 0 as *c_void, 0 as *c_void, // 15 + 0 as *c_void, 0 as *c_void, 0 as *c_void, 0 as *c_void, 0 as *c_void, // 20 + 0 as *c_void, 0 as *c_void, 0 as *c_void, 0 as *c_void, 0 as *c_void, // 25 + 0 as *c_void, 0 as *c_void, 0 as *c_void, 0 as *c_void, 0 as *c_void, // 30 + 0 as *c_void, 0 as *c_void, 0 as *c_void, 0 as *c_void, 0 as *c_void, // 35 + 0 as *c_void, 0 as *c_void, 0 as *c_void, 0 as *c_void, 0 as *c_void) // 40 +}; + pub fn basic_class(name: &'static str) -> JSClass { JSClass { name: name.as_ptr() as *i8, diff --git a/rust.rs b/rust.rs index 4a1e6bc1d..e49a71d09 100644 --- a/rust.rs +++ b/rust.rs @@ -337,15 +337,15 @@ pub mod test { pub fn dummy() { let rt = rt(); let cx = rt.cx(); - cx.set_default_options_and_version(); - cx.set_logging_error_reporter(); - cx.new_compartment(global::global_class).and_then(|comp| { - unsafe { JS_GC(JS_GetRuntime(comp.cx.ptr)); } + cx.borrow().set_default_options_and_version(); + cx.borrow().set_logging_error_reporter(); + cx.new_compartment(&global::BASIC_GLOBAL).and_then(|comp| { + unsafe { JS_GC(JS_GetRuntime(cx.borrow().ptr)); } - comp.define_functions(global::debug_fns); + comp.borrow().define_functions(global::DEBUG_FNS); let s = ~"debug(22);"; - cx.evaluate_script(comp.global_obj, s, ~"test", 1u) + cx.borrow().evaluate_script(comp.borrow().global_obj.clone(), s, ~"test", 1u) }); }