Permalink
Browse files

Make JS_THIS_OBJECT avoid C calls when possible. Use C stub pointers …

…instead of Rust wrappers.
  • Loading branch information...
jdm committed Aug 27, 2012
1 parent a89e042 commit 194d39e0c4afd38705f0fafa212ea25bb6712201
Showing with 22 additions and 14 deletions.
  1. +10 −9 global.rs
  2. +10 −5 js.rs
  3. +2 −0 jsapi.rs
View
@@ -4,8 +4,9 @@ Handy functions for creating class objects and so forth.
"];
-import crust::{JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub,
- JS_ResolveStub, JS_ConvertStub};
+import glue::bindgen::GetJSClassHookStubPointer;
+import glue::{PROPERTY_STUB, STRICT_PROPERTY_STUB, ENUMERATE_STUB,
+ RESOLVE_STUB, CONVERT_STUB};
import libc::c_uint;
export basic_class;
export global_class;
@@ -15,13 +16,13 @@ export jsval_to_rust_str;
fn basic_class(np: name_pool, -name: ~str) -> JSClass {
{name: np.add(name),
flags: JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT),
- addProperty: JS_PropertyStub,
- delProperty: JS_PropertyStub,
- getProperty: JS_PropertyStub,
- setProperty: JS_StrictPropertyStub,
- enumerate: JS_EnumerateStub,
- resolve: JS_ResolveStub,
- convert: JS_ConvertStub,
+ addProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
+ delProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
+ getProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
+ setProperty: GetJSClassHookStubPointer(STRICT_PROPERTY_STUB) as *u8,
+ enumerate: GetJSClassHookStubPointer(ENUMERATE_STUB) as *u8,
+ resolve: GetJSClassHookStubPointer(RESOLVE_STUB) as *u8,
+ convert: GetJSClassHookStubPointer(CONVERT_STUB) as *u8,
finalize: null(),
checkAccess: null(),
call: null(),
View
15 js.rs
@@ -18,7 +18,7 @@ import jsapi::bindgen::{JS_free, JS_AddObjectRoot, JS_DefineFunctions,
JS_DefineProperty, JS_NewObject, JS_ComputeThis};
import libc::types::common::c99::{int8_t, int16_t, int32_t, int64_t, uint8_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;
export JSOPTION_STRICT;
@@ -139,7 +139,7 @@ type named_functions = @{
funcs: ~[JSFunctionSpec]
};
-#[always_inline]
+#[inline(always)]
unsafe fn JS_ARGV(_cx: *JSContext, vp: *jsval) -> *jsval {
ptr::offset(vp, 2u)
}
@@ -149,9 +149,14 @@ unsafe fn JS_SET_RVAL(_cx: *JSContext, vp: *jsval, v: jsval) {
*vp = v;
}
-#[always_inline]
-unsafe fn JS_THIS_OBJECT(cx: *JSContext, vp: *jsval) -> *JSObject {
- let r = RUST_JSVAL_TO_OBJECT(JS_ComputeThis(cx, vp));
+#[inline(always)]
+unsafe fn JS_THIS_OBJECT(cx: *JSContext, vp: *jsval) -> *JSObject unsafe {
+ 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
}
View
@@ -816,6 +816,7 @@ fn JS_InitReflect(++cx: *JSContext, ++global: *JSObject) -> *JSObject;
fn JS_EnumerateDiagnosticMemoryRegions(++callback: JSEnumerateDiagnosticMemoryCallback);
+#[rust_stack]
fn JS_ComputeThis(++cx: *JSContext, ++vp: *jsval) -> jsval;
fn JS_MallocInCompartment(++comp: *JSCompartment, ++nbytes: size_t);
@@ -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;
+#[rust_stack]
fn JS_GetReservedSlot(++obj: JSRawObject, ++index: uint32_t) -> jsval;
fn JS_SetReservedSlot(++obj: JSRawObject, ++index: uint32_t, ++v: jsval);

0 comments on commit 194d39e

Please sign in to comment.