Skip to content

Commit

Permalink
Make JS_THIS_OBJECT avoid C calls when possible. Use C stub pointers …
Browse files Browse the repository at this point in the history
…instead of Rust wrappers.
  • Loading branch information
jdm committed Aug 27, 2012
1 parent a89e042 commit 194d39e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
19 changes: 10 additions & 9 deletions global.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Handy functions for creating class objects and so forth.
"]; "];


import crust::{JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, import glue::bindgen::GetJSClassHookStubPointer;
JS_ResolveStub, JS_ConvertStub}; import glue::{PROPERTY_STUB, STRICT_PROPERTY_STUB, ENUMERATE_STUB,
RESOLVE_STUB, CONVERT_STUB};
import libc::c_uint; import libc::c_uint;
export basic_class; export basic_class;
export global_class; export global_class;
Expand All @@ -15,13 +16,13 @@ export jsval_to_rust_str;
fn basic_class(np: name_pool, -name: ~str) -> JSClass { fn basic_class(np: name_pool, -name: ~str) -> JSClass {
{name: np.add(name), {name: np.add(name),
flags: JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT), flags: JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT),
addProperty: JS_PropertyStub, addProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
delProperty: JS_PropertyStub, delProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
getProperty: JS_PropertyStub, getProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
setProperty: JS_StrictPropertyStub, setProperty: GetJSClassHookStubPointer(STRICT_PROPERTY_STUB) as *u8,
enumerate: JS_EnumerateStub, enumerate: GetJSClassHookStubPointer(ENUMERATE_STUB) as *u8,
resolve: JS_ResolveStub, resolve: GetJSClassHookStubPointer(RESOLVE_STUB) as *u8,
convert: JS_ConvertStub, convert: GetJSClassHookStubPointer(CONVERT_STUB) as *u8,
finalize: null(), finalize: null(),
checkAccess: null(), checkAccess: null(),
call: null(), call: null(),
Expand Down
15 changes: 10 additions & 5 deletions js.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import jsapi::bindgen::{JS_free, JS_AddObjectRoot, JS_DefineFunctions,
JS_DefineProperty, JS_NewObject, JS_ComputeThis}; JS_DefineProperty, JS_NewObject, JS_ComputeThis};
import libc::types::common::c99::{int8_t, int16_t, int32_t, int64_t, uint8_t, import libc::types::common::c99::{int8_t, int16_t, int32_t, int64_t, uint8_t,
uint16_t, uint32_t, uint64_t}; uint16_t, uint32_t, uint64_t};
import glue::bindgen::RUST_JSVAL_TO_OBJECT; import glue::bindgen::{RUST_JSVAL_TO_OBJECT, RUST_JSVAL_IS_PRIMITIVE};
import rust::jsobj; import rust::jsobj;


export JSOPTION_STRICT; export JSOPTION_STRICT;
Expand Down Expand Up @@ -139,7 +139,7 @@ type named_functions = @{
funcs: ~[JSFunctionSpec] funcs: ~[JSFunctionSpec]
}; };


#[always_inline] #[inline(always)]
unsafe fn JS_ARGV(_cx: *JSContext, vp: *jsval) -> *jsval { unsafe fn JS_ARGV(_cx: *JSContext, vp: *jsval) -> *jsval {
ptr::offset(vp, 2u) ptr::offset(vp, 2u)
} }
Expand All @@ -149,9 +149,14 @@ unsafe fn JS_SET_RVAL(_cx: *JSContext, vp: *jsval, v: jsval) {
*vp = v; *vp = v;
} }


#[always_inline] #[inline(always)]
unsafe fn JS_THIS_OBJECT(cx: *JSContext, vp: *jsval) -> *JSObject { unsafe fn JS_THIS_OBJECT(cx: *JSContext, vp: *jsval) -> *JSObject unsafe {
let r = RUST_JSVAL_TO_OBJECT(JS_ComputeThis(cx, vp)); let r = RUST_JSVAL_TO_OBJECT(
if RUST_JSVAL_IS_PRIMITIVE(*ptr::offset(vp, 1)) == 0 {
JS_ComputeThis(cx, vp)
} else {
*ptr::offset(vp, 1)
});
r r
} }


2 changes: 2 additions & 0 deletions jsapi.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ fn JS_InitReflect(++cx: *JSContext, ++global: *JSObject) -> *JSObject;


fn JS_EnumerateDiagnosticMemoryRegions(++callback: JSEnumerateDiagnosticMemoryCallback); fn JS_EnumerateDiagnosticMemoryRegions(++callback: JSEnumerateDiagnosticMemoryCallback);


#[rust_stack]
fn JS_ComputeThis(++cx: *JSContext, ++vp: *jsval) -> jsval; fn JS_ComputeThis(++cx: *JSContext, ++vp: *jsval) -> jsval;


fn JS_MallocInCompartment(++comp: *JSCompartment, ++nbytes: size_t); fn JS_MallocInCompartment(++comp: *JSCompartment, ++nbytes: size_t);
Expand Down Expand Up @@ -1128,6 +1129,7 @@ fn JS_ArrayIterator(++cx: *JSContext, ++argc: c_uint, ++vp: *jsval) -> JSBool;


fn JS_CheckAccess(++cx: *JSContext, ++obj: *JSObject, ++id: jsid, ++mode: JSAccessMode, ++vp: *jsval, ++attrsp: *c_uint) -> JSBool; fn JS_CheckAccess(++cx: *JSContext, ++obj: *JSObject, ++id: jsid, ++mode: JSAccessMode, ++vp: *jsval, ++attrsp: *c_uint) -> JSBool;


#[rust_stack]
fn JS_GetReservedSlot(++obj: JSRawObject, ++index: uint32_t) -> jsval; fn JS_GetReservedSlot(++obj: JSRawObject, ++index: uint32_t) -> jsval;


fn JS_SetReservedSlot(++obj: JSRawObject, ++index: uint32_t, ++v: jsval); fn JS_SetReservedSlot(++obj: JSRawObject, ++index: uint32_t, ++v: jsval);
Expand Down

0 comments on commit 194d39e

Please sign in to comment.