diff --git a/glue.rs b/glue.rs index aa48d9433..c7ef7c539 100644 --- a/glue.rs +++ b/glue.rs @@ -5,7 +5,6 @@ /* automatically generated by rust-bindgen */ use libc; -use libc::*; use jsapi::*; use jsfriendapi::JSJitInfo; use jsval::JSVal; @@ -13,35 +12,35 @@ use jsval::JSVal; type c_bool = libc::c_int; pub struct ProxyTraps { - getPropertyDescriptor: extern "C" fn(*JSContext, *JSObject, jsid, c_bool, *mut JSPropertyDescriptor) -> c_bool, - getOwnPropertyDescriptor: extern "C" fn(*JSContext, *JSObject, jsid, JSBool, *mut JSPropertyDescriptor) -> JSBool, - defineProperty: extern "C" fn(*JSContext, *JSObject, jsid, *JSPropertyDescriptor) -> JSBool, - getOwnPropertyNames: *u8, - delete_: *u8, - enumerate: *u8, - - has: *u8, - hasOwn: extern "C" fn(*JSContext, *JSObject, jsid, *mut JSBool) -> JSBool, - get: extern "C" fn(*JSContext, *JSObject, *JSObject, jsid, *mut JSVal) -> JSBool, - set: *u8, - keys: *u8, - iterate: *u8, - - call: *u8, - construct: *u8, - nativeCall: *u8, - hasInstance: *u8, - typeOf: *u8, - objectClassIs: *u8, - obj_toString: extern "C" fn(*JSContext, *JSObject) -> *JSString, - fun_toString: *u8, + pub getPropertyDescriptor: Option c_bool>, + pub getOwnPropertyDescriptor: Option JSBool>, + pub defineProperty: Option JSBool>, + pub getOwnPropertyNames: *u8, //XXX need a representation for AutoIdVector& + pub delete_: Option JSBool>, + pub enumerate: *u8, //XXX need a representation for AutoIdVector& + + pub has: Option JSBool>, + pub hasOwn: Option JSBool>, + pub get: Option JSBool>, + pub set: Option JSBool>, + pub keys: *u8, //XXX need a representation for AutoIdVector& + pub iterate: Option JSBool>, + + pub call: Option JSBool>, + pub construct: Option JSBool>, + pub nativeCall: *u8, //XXX need a representation for IsAcceptableThis, NativeImpl, and CallArgs + pub hasInstance: Option JSBool>, + pub typeOf: Option uint>, //XXX JSType enum + pub objectClassIs: Option JSBool>, //XXX ESClassValue enum + pub obj_toString: Option *JSString>, + pub fun_toString: Option *JSString>, //regexp_toShared: *u8, - defaultValue: *u8, - iteratorNext: *u8, - finalize: extern "C" fn(*JSFreeOp, *JSObject), - getElementIfPresent: *u8, - getPrototypeOf: *u8, - trace: Option + pub defaultValue: Option JSBool>, //XXX JSType enum + pub iteratorNext: Option JSBool>, + pub finalize: Option, + pub getElementIfPresent: Option JSBool>, + pub getPrototypeOf: Option JSBool>, + pub trace: Option, } #[cfg(not(target_os = "android"))] @@ -71,13 +70,15 @@ pub fn SetFunctionNativeReserved(fun: *JSObject, which: libc::size_t, val: *JSVa pub fn GetFunctionNativeReserved(fun: *JSObject, which: libc::size_t) -> *JSVal; pub fn CreateProxyHandler(traps: *ProxyTraps, extra: *libc::c_void) -> *libc::c_void; +pub fn CreateWrapperProxyHandler(traps: *ProxyTraps) -> *libc::c_void; pub fn NewProxyObject(cx: *JSContext, handler: *libc::c_void, priv_: *JSVal, proto: *JSObject, parent: *JSObject, call: *JSObject, construct: *JSObject) -> *JSObject; +pub fn WrapperNew(cx: *JSContext, parent: *JSObject, handler: *libc::c_void) -> *JSObject; -pub fn GetProxyExtra(obj: *JSObject, slot: c_uint) -> JSVal; +pub fn GetProxyExtra(obj: *JSObject, slot: libc::c_uint) -> JSVal; pub fn GetProxyPrivate(obj: *JSObject) -> JSVal; -pub fn SetProxyExtra(obj: *JSObject, slot: c_uint, val: JSVal); +pub fn SetProxyExtra(obj: *JSObject, slot: libc::c_uint, val: JSVal); pub fn GetObjectProto(obj: *JSObject) -> *JSObject; pub fn GetObjectParent(obj: *JSObject) -> *JSObject; @@ -104,5 +105,7 @@ pub fn GetProxyHandlerExtra(obj: *JSObject) -> *libc::c_void; pub fn GetProxyHandler(obj: *JSObject) -> *libc::c_void; pub fn InvokeGetOwnPropertyDescriptor(handler: *libc::c_void, cx: *JSContext, proxy: *JSObject, id: jsid, set: JSBool, desc: *mut JSPropertyDescriptor) -> JSBool; pub fn GetGlobalForObjectCrossCompartment(obj: *JSObject) -> *JSObject; -pub fn ReportError(cx: *JSContext, error: *c_char); +pub fn ReportError(cx: *JSContext, error: *libc::c_char); +pub fn IsWrapper(obj: *JSObject) -> JSBool; +pub fn UnwrapObject(obj: *JSObject, stopAtOuter: JSBool, flags: *libc::c_uint) -> *JSObject; } diff --git a/js.rc b/js.rc index 6524d24a0..b7da9165e 100644 --- a/js.rc +++ b/js.rc @@ -24,9 +24,9 @@ use libc::types::common::c99::uint32_t; use std::cast; use std::ptr::null; use std::result::{Result, Ok, Err}; -use jsapi::{JSBool, JSContext, - JSObject, jsid, - JSProto_LIMIT}; +use jsapi::{JSBool, JSContext, JSPropertyOp, JSStrictPropertyOp, JSEnumerateOp, + JSObject, jsid, JSResolveOp, JSConvertOp, JSFinalizeOp, JSTraceOp, + JSProto_LIMIT, JSHandleObject, JSCheckAccessOp, JSNative, JSHasInstanceOp}; use jsapi::JS_ComputeThis; use jsval::JSVal; use rust::jsobj; @@ -153,3 +153,71 @@ pub unsafe fn JS_CALLEE(_cx: *JSContext, vp: *JSVal) -> JSVal { fn start(argc: int, argv: **u8) -> int { green::start(argc, argv, rustuv::event_loop, __test::main) } + +pub type JSObjectOp = extern "C" fn(*JSContext, JSHandleObject) -> *JSObject; + +pub struct Class { + pub name: *libc::c_char, + pub flags: uint32_t, + pub addProperty: Option, + pub delProperty: Option, + pub getProperty: Option, + pub setProperty: Option, + pub enumerate: Option, + pub resolve: Option, + pub convert: Option, + pub finalize: Option, + pub checkAccess: Option, + pub call: Option, + pub hasInstance: Option, + pub construct: Option, + pub trace: Option, + + pub ext: ClassExtension, + pub ops: ObjectOps, +} + +pub struct ClassExtension { + pub equality: *u8, + pub outerObject: Option, + pub innerObject: Option, + pub iteratorObject: *u8, + pub unused: *u8, + pub isWrappedNative: *u8, +} + +pub struct ObjectOps { + pub lookupGeneric: *u8, + pub lookupProperty: *u8, + pub lookupElement: *u8, + pub lookupSpecial: *u8, + pub defineGeneric: *u8, + pub defineProperty: *u8, + pub defineElement: *u8, + pub defineSpecial: *u8, + pub getGeneric: *u8, + pub getProperty: *u8, + pub getElement: *u8, + pub getElementIfPresent: *u8, + pub getSpecial: *u8, + pub setGeneric: *u8, + pub setProperty: *u8, + pub setElement: *u8, + pub setSpecial: *u8, + pub getGenericAttributes: *u8, + pub getPropertyAttributes: *u8, + pub getElementAttributes: *u8, + pub getSpecialAttributes: *u8, + pub setGenericAttributes: *u8, + pub setPropertyAttributes: *u8, + pub setElementAttributes: *u8, + pub setSpecialAttributes: *u8, + pub deleteProperty: *u8, + pub deleteElement: *u8, + pub deleteSpecial: *u8, + + pub enumerate: *u8, + pub typeOf: *u8, + pub thisObject: Option, + pub clear: *u8, +} diff --git a/jsapi.rs b/jsapi.rs index 48343969f..e66541259 100644 --- a/jsapi.rs +++ b/jsapi.rs @@ -256,27 +256,27 @@ pub type moz_static_assert5 = c_int; pub type moz_static_assert6 = c_int; pub struct JSHandleObject { - unnamed: **JSObject, + pub unnamed: **JSObject, } pub struct JSHandleValue { - unnamed: JSVal, + pub unnamed: JSVal, } pub struct JSHandleString { - unnamed: **JSString, + pub unnamed: **JSString, } pub struct JSMutableHandleObject { - unnamed: **JSObject, + pub unnamed: **JSObject, } pub struct JSHandleId { - unnamed: *jsid, + pub unnamed: *jsid, } pub struct JSMutableHandleValue { - unnamed: *JSVal, + pub unnamed: *JSVal, } pub type JSRawObject = *JSObject; @@ -300,7 +300,7 @@ pub type JSTypeOfOp = *u8; pub type JSFreeOp = struct_JSFreeOp; pub struct struct_JSFreeOp { - runtime: *JSRuntime, + pub runtime: *JSRuntime, } pub type JSFinalizeOp = extern "C" fn(*JSFreeOp, *JSObject); @@ -308,7 +308,7 @@ pub type JSFinalizeOp = extern "C" fn(*JSFreeOp, *JSObject); pub type JSStringFinalizer = struct_JSStringFinalizer; pub struct struct_JSStringFinalizer { - finalize: *u8, + pub finalize: *u8, } //XXXjdm JSAccessMode is an enum; uint32_t may not be correct. @@ -369,9 +369,9 @@ pub static JSEXN_LIMIT: i32 = 8_i32; pub type JSExnType = enum_JSExnType; pub struct struct_JSErrorFormatString { - format: *c_char, - argCount: uint16_t, - exnType: int16_t, + pub format: *c_char, + pub argCount: uint16_t, + pub exnType: int16_t, } pub type JSErrorFormatString = struct_JSErrorFormatString; @@ -398,7 +398,7 @@ pub type JSWrapObjectCallback = *u8; pub type JSPreWrapCallback = *u8; -pub type JSSameCompartmentWrapObjectCallback = *u8; +pub type JSSameCompartmentWrapObjectCallback = extern "C" fn(*JSContext, *JSObject) -> *JSObject; pub type JSDestroyCompartmentCallback = *u8; @@ -437,12 +437,12 @@ pub type JSGCRootMapFun = *u8; pub type JSTraceCallback = *u8; pub struct struct_JSTracer { - runtime: *JSRuntime, - callback: JSTraceCallback, - debugPrinter: JSTraceNamePrinter, - debugPrintArg: *c_void, - debugPrintIndex: size_t, - eagerlyTraceWeakMaps: JSBool, + pub runtime: *JSRuntime, + pub callback: JSTraceCallback, + pub debugPrinter: JSTraceNamePrinter, + pub debugPrintArg: *c_void, + pub debugPrintIndex: size_t, + pub eagerlyTraceWeakMaps: JSBool, } pub type enum_JSGCParamKey = c_uint; @@ -497,10 +497,10 @@ pub struct JSClass { } pub struct struct_JSConstDoubleSpec { - dval: c_double, - name: *c_char, - flags: uint8_t, - spare: (uint8_t,uint8_t,uint8_t), + pub dval: c_double, + pub name: *c_char, + pub flags: uint8_t, + pub spare: (uint8_t,uint8_t,uint8_t), } pub type struct_JSJitInfo = c_void; @@ -510,8 +510,8 @@ pub type struct_JSJitInfo = c_void; // FIXME: We need these Clone impls for certain operations in Servo, // but do they really make sense? pub struct JSStrictPropertyOpWrapper { - op: Option, - info: *JSJitInfo, + pub op: Option, + pub info: *JSJitInfo, } impl Clone for JSStrictPropertyOpWrapper { @@ -524,8 +524,8 @@ impl Clone for JSStrictPropertyOpWrapper { } pub struct JSPropertyOpWrapper { - op: Option, - info: *JSJitInfo, + pub op: Option, + pub info: *JSJitInfo, } impl Clone for JSPropertyOpWrapper { @@ -553,11 +553,11 @@ impl Clone for JSNativeWrapper { #[deriving(Clone)] pub struct JSPropertySpec { - name: *c_char, - tinyid: int8_t, - flags: uint8_t, - getter: JSPropertyOpWrapper, - setter: JSStrictPropertyOpWrapper, + pub name: *c_char, + pub tinyid: int8_t, + pub flags: uint8_t, + pub getter: JSPropertyOpWrapper, + pub setter: JSStrictPropertyOpWrapper, } #[deriving(Clone)] @@ -570,23 +570,23 @@ pub struct JSFunctionSpec { } pub struct struct_JSPropertyDescriptor { - obj: *JSObject, - attrs: c_uint, - shortid: c_uint, - getter: Option, - setter: Option, - value: JSVal, + pub obj: *JSObject, + pub attrs: c_uint, + pub shortid: c_uint, + pub getter: Option, + pub setter: Option, + pub value: JSVal, } pub struct struct_JSPrincipals { - refcount: c_int, + pub refcount: c_int, } pub struct struct_JSSecurityCallbacks { - checkObjectAccess: JSCheckAccessOp, - subsumePrincipals: JSSubsumePrincipalsOp, - findObjectPrincipals: JSObjectPrincipalsFinder, - contentSecurityPolicyAllows: JSCSPEvalChecker, + pub checkObjectAccess: JSCheckAccessOp, + pub subsumePrincipals: JSSubsumePrincipalsOp, + pub findObjectPrincipals: JSObjectPrincipalsFinder, + pub contentSecurityPolicyAllows: JSCSPEvalChecker, } pub type enum_JSExecPart = c_uint; @@ -598,17 +598,17 @@ pub type JSExecPart = enum_JSExecPart; pub type JSONWriteCallback = *u8; pub struct struct_JSStructuredCloneCallbacks { - read: ReadStructuredCloneOp, - write: WriteStructuredCloneOp, - reportError: StructuredCloneErrorOp, + pub read: ReadStructuredCloneOp, + pub write: WriteStructuredCloneOp, + pub reportError: StructuredCloneErrorOp, } pub struct struct_JSLocaleCallbacks { - localeToUpperCase: JSLocaleToUpperCase, - localeToLowerCase: JSLocaleToLowerCase, - localeCompare: JSLocaleCompare, - localeToUnicode: JSLocaleToUnicode, - localeGetErrorMessage: JSErrorCallback, + pub localeToUpperCase: JSLocaleToUpperCase, + pub localeToLowerCase: JSLocaleToLowerCase, + pub localeCompare: JSLocaleCompare, + pub localeToUnicode: JSLocaleToUnicode, + pub localeGetErrorMessage: JSErrorCallback, } pub struct struct_JSErrorReport { @@ -628,7 +628,7 @@ pub struct struct_JSErrorReport { } pub struct struct_unnamed1 { - payload: union_unnamed2, + pub payload: union_unnamed2, } pub type union_unnamed2 = c_void /* FIXME: union type */; diff --git a/jsfriendapi.rs b/jsfriendapi.rs index e051edcb4..3b0f30caa 100644 --- a/jsfriendapi.rs +++ b/jsfriendapi.rs @@ -5,11 +5,11 @@ pub type JSJitPropertyOp = *u8; pub struct JSJitInfo { - op: JSJitPropertyOp, - protoID: u32, - depth: u32, - isInfallible: bool, - isConstant: bool + pub op: JSJitPropertyOp, + pub protoID: u32, + pub depth: u32, + pub isInfallible: bool, + pub isConstant: bool } //pub type JSJitInfo = JSJitInfo_struct; diff --git a/jsglue.cpp b/jsglue.cpp index 79a8d61e6..4dbd3ed07 100644 --- a/jsglue.cpp +++ b/jsglue.cpp @@ -9,6 +9,7 @@ #include "jsfriendapi.h" #include "jsproxy.h" #include "jsclass.h" +#include "jswrapper.h" #include "assert.h" @@ -56,6 +57,219 @@ struct ProxyTraps { int HandlerFamily = js::JSSLOT_PROXY_EXTRA + 0 /*JSPROXYSLOT_EXPANDO*/; +class WrapperProxyHandler : public js::DirectWrapper +{ + ProxyTraps mTraps; + public: + WrapperProxyHandler(const ProxyTraps& aTraps) + : js::DirectWrapper(0), mTraps(aTraps) {} + + virtual bool isOuterWindow() { + return true; + } + + virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, + bool set, JSPropertyDescriptor *desc) + { + return mTraps.getPropertyDescriptor ? + mTraps.getPropertyDescriptor(cx, proxy, id, set, desc) : + DirectWrapper::getPropertyDescriptor(cx, proxy, id, set, desc); + } + + virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, + jsid id, bool set, + JSPropertyDescriptor *desc) + { + return mTraps.getOwnPropertyDescriptor ? + mTraps.getOwnPropertyDescriptor(cx, proxy, id, set, desc) : + DirectWrapper::getOwnPropertyDescriptor(cx, proxy, id, set, desc); + } + + virtual bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, + JSPropertyDescriptor *desc) + { + return mTraps.defineProperty ? + mTraps.defineProperty(cx, proxy, id, desc) : + DirectWrapper::defineProperty(cx, proxy, id, desc); + } + + virtual bool getOwnPropertyNames(JSContext *cx, JSObject *proxy, + JS::AutoIdVector &props) + { + return mTraps.getOwnPropertyNames ? + mTraps.getOwnPropertyNames(cx, proxy, props) : + DirectWrapper::getOwnPropertyNames(cx, proxy, props); + } + + virtual bool delete_(JSContext *cx, JSObject *proxy, jsid id, bool *bp) + { + return mTraps.delete_ ? + mTraps.delete_(cx, proxy, id, bp) : + DirectWrapper::delete_(cx, proxy, id, bp); + } + + virtual bool enumerate(JSContext *cx, JSObject *proxy, + JS::AutoIdVector &props) + { + return mTraps.enumerate ? + mTraps.enumerate(cx, proxy, props) : + DirectWrapper::enumerate(cx, proxy, props); + } + + /* ES5 Harmony derived proxy traps. */ + virtual bool has(JSContext *cx, JSObject *proxy, jsid id, bool *bp) + { + return mTraps.has ? + mTraps.has(cx, proxy, id, bp) : + DirectWrapper::has(cx, proxy, id, bp); + } + + virtual bool hasOwn(JSContext *cx, JSObject *proxy, jsid id, bool *bp) + { + return mTraps.hasOwn ? + mTraps.hasOwn(cx, proxy, id, bp) : + DirectWrapper::hasOwn(cx, proxy, id, bp); + } + + virtual bool get(JSContext *cx, JSObject *proxy, JSObject *receiver, + jsid id, JS::Value *vp) + { + return mTraps.get ? + mTraps.get(cx, proxy, receiver, id, vp) : + DirectWrapper::get(cx, proxy, receiver, id, vp); + } + + virtual bool set(JSContext *cx, JSObject *proxy, JSObject *receiver, + jsid id, bool strict, JS::Value *vp) + { + return mTraps.set ? + mTraps.set(cx, proxy, receiver, id, strict, vp) : + DirectWrapper::set(cx, proxy, receiver, id, strict, vp); + } + + virtual bool keys(JSContext *cx, JSObject *proxy, JS::AutoIdVector &props) + { + return mTraps.keys ? + mTraps.keys(cx, proxy, props) : + DirectWrapper::keys(cx, proxy, props); + } + + virtual bool iterate(JSContext *cx, JSObject *proxy, unsigned flags, + JS::Value *vp) + { + return mTraps.iterate ? + mTraps.iterate(cx, proxy, flags, vp) : + DirectWrapper::iterate(cx, proxy, flags, vp); + } + + /* Spidermonkey extensions. */ + virtual bool call(JSContext *cx, JSObject *proxy, unsigned argc, JS::Value *vp) + { + return mTraps.call ? + mTraps.call(cx, proxy, argc, vp) : + DirectWrapper::call(cx, proxy, argc, vp); + } + + virtual bool construct(JSContext *cx, JSObject *proxy, unsigned argc, JS::Value *argv, JS::Value *rval) + { + return mTraps.construct ? + mTraps.construct(cx, proxy, argc, argv, rval) : + DirectWrapper::construct(cx, proxy, argc, argv, rval); + } + + virtual bool nativeCall(JSContext *cx, JS::IsAcceptableThis test, JS::NativeImpl impl, JS::CallArgs args) + { + return mTraps.nativeCall ? + mTraps.nativeCall(cx, test, impl, args) : + DirectWrapper::nativeCall(cx, test, impl, args); + } + + virtual bool hasInstance(JSContext *cx, JSObject *proxy, const JS::Value *vp, bool *bp) + { + return mTraps.hasInstance ? + mTraps.hasInstance(cx, proxy, vp, bp) : + DirectWrapper::hasInstance(cx, proxy, vp, bp); + } + + virtual JSType typeOf(JSContext *cx, JSObject *proxy) + { + return mTraps.typeOf ? + mTraps.typeOf(cx, proxy) : + DirectWrapper::typeOf(cx, proxy); + } + + virtual bool objectClassIs(JSObject *obj, js::ESClassValue classValue, JSContext *cx) + { + return mTraps.objectClassIs ? + mTraps.objectClassIs(obj, classValue, cx) : + DirectWrapper::objectClassIs(obj, classValue, cx); + } + + virtual JSString *obj_toString(JSContext *cx, JSObject *proxy) + { + return mTraps.obj_toString ? + mTraps.obj_toString(cx, proxy) : + DirectWrapper::obj_toString(cx, proxy); + } + + virtual JSString *fun_toString(JSContext *cx, JSObject *proxy, unsigned indent) + { + return mTraps.fun_toString ? + mTraps.fun_toString(cx, proxy, indent) : + DirectWrapper::fun_toString(cx, proxy, indent); + } + + /*virtual bool regexp_toShared(JSContext *cx, JSObject *proxy, RegExpGuard *g) + { + return mTraps.regexp_toShared ? + mTraps.regexp_toShared(cx, proxy, g) : + DirectWrapper::regexp_toShared(cx, proxy, g); + }*/ + + virtual bool defaultValue(JSContext *cx, JSObject *obj, JSType hint, JS::Value *vp) + { + return mTraps.defaultValue ? + mTraps.defaultValue(cx, obj, hint, vp) : + DirectWrapper::defaultValue(cx, obj, hint, vp); + } + + virtual bool iteratorNext(JSContext *cx, JSObject *proxy, JS::Value *vp) + { + return mTraps.iteratorNext ? + mTraps.iteratorNext(cx, proxy, vp) : + DirectWrapper::iteratorNext(cx, proxy, vp); + } + + virtual void finalize(JSFreeOp *fop, JSObject *proxy) + { + return mTraps.finalize ? + mTraps.finalize(fop, proxy) : + DirectWrapper::finalize(fop, proxy); + } + + virtual bool getElementIfPresent(JSContext *cx, JSObject *obj, JSObject *receiver, + uint32_t index, JS::Value *vp, bool *present) + { + return mTraps.getElementIfPresent ? + mTraps.getElementIfPresent(cx, obj, receiver, index, vp, present) : + DirectWrapper::getElementIfPresent(cx, obj, receiver, index, vp, present); + } + + virtual bool getPrototypeOf(JSContext *cx, JSObject *proxy, JSObject **proto) + { + return mTraps.getPrototypeOf ? + mTraps.getPrototypeOf(cx, proxy, proto) : + DirectWrapper::getPrototypeOf(cx, proxy, proto); + } + + virtual void trace(JSTracer *trc, JSObject *proxy) + { + return mTraps.trace ? + mTraps.trace(trc, proxy) : + DirectWrapper::trace(trc, proxy); + } +}; + class ForwardingProxyHandler : public js::BaseProxyHandler { ProxyTraps mTraps; @@ -320,15 +534,28 @@ CreateProxyHandler(const ProxyTraps* aTraps, void* aExtra) return new ForwardingProxyHandler(*aTraps, aExtra); } +const void* +CreateWrapperProxyHandler(const ProxyTraps* aTraps) +{ + return new WrapperProxyHandler(*aTraps); +} + JSObject* -NewProxyObject(JSContext* aCx, void* aHandler, const js::Value* priv, +NewProxyObject(JSContext* aCx, void* aHandler, const js::Value* aPriv, JSObject* proto, JSObject* parent, JSObject* call, JSObject* construct) { - return js::NewProxyObject(aCx, (js::BaseProxyHandler*)aHandler, *priv, proto, + const js::Value &priv = aPriv ? *aPriv : JS::NullValue(); + return js::NewProxyObject(aCx, (js::BaseProxyHandler*)aHandler, priv, proto, parent, call, construct); } +JSObject* +WrapperNew(JSContext* aCx, JSObject* aParent, void* aHandler) +{ + return js::Wrapper::New(aCx, aParent, js::GetObjectProto(aParent), aParent, (js::Wrapper*)aHandler); +} + jsval GetProxyExtra(JSObject* obj, uint32_t slot) { @@ -463,4 +690,16 @@ ReportError(JSContext* aCx, const char* aError) JS_ReportError(aCx, aError); } +JSBool +IsWrapper(JSObject* obj) +{ + return js::IsWrapper(obj); +} + +JSObject* +UnwrapObject(JSObject* obj, JSBool stopAtOuter, unsigned* flags) +{ + return js::UnwrapObject(obj, stopAtOuter, flags); +} + } // extern "C" diff --git a/jsval.rs b/jsval.rs index caf36b241..2d400c378 100644 --- a/jsval.rs +++ b/jsval.rs @@ -58,7 +58,7 @@ static JSVAL_PAYLOAD_MASK: u64 = 0x00007FFFFFFFFFFF; // now this become {u64} because of the union abi issue on ARM arch. See #398. #[deriving(Eq,Clone)] pub struct JSVal { - v: u64 + pub v: u64 } #[inline(always)] diff --git a/rust.rs b/rust.rs index 53c0ab740..204d90901 100644 --- a/rust.rs +++ b/rust.rs @@ -30,7 +30,7 @@ use green::task::GreenTask; pub type rt = rc::Rc; pub struct rt_rsrc { - ptr : *JSRuntime, + pub ptr : *JSRuntime, } impl Drop for rt_rsrc { @@ -85,8 +85,8 @@ pub fn rt() -> rt { // contexts pub struct Cx { - ptr: *JSContext, - rt: rt, + pub ptr: *JSContext, + pub rt: rt, } #[unsafe_destructor] @@ -227,8 +227,8 @@ pub extern fn reportError(_cx: *JSContext, msg: *c_char, report: *JSErrorReport) // compartment pub struct Compartment { - cx: rc::Rc, - global_obj: *JSObject, + pub cx: rc::Rc, + pub global_obj: *JSObject, } impl Compartment {