JSBool XPC_COW_RewrapForChrome(JSContext *cx, JSObject *wrapperObj, jsval *vp) { jsval v = *vp; if (JSVAL_IS_PRIMITIVE(v)) { return JS_TRUE; } // We're rewrapping for chrome, so this is safe. JSObject *obj = GetWrappedJSObject(cx, JSVAL_TO_OBJECT(v)); if (!obj) { *vp = JSVAL_NULL; return JS_TRUE; } XPCWrappedNative *wn; if (IS_WRAPPER_CLASS(STOBJ_GET_CLASS(obj)) && (wn = XPCWrappedNative::GetWrappedNativeOfJSObject(cx, obj)) && !nsXPCWrappedJSClass::IsWrappedJS(wn->Native())) { // Return an explicit XPCNativeWrapper in case "chrome" code happens to be // XBL code cloned into an untrusted context. return XPCNativeWrapperCtor(cx, obj, 1, vp, vp); } return XPC_SJOW_Construct(cx, obj, 1, vp, vp); }
static XPCWrappedNativeScope* GetScopeOfObject(JSObject* obj) { nsISupports* supports; js::Class* clazz = js::GetObjectClass(obj); JSBool isWrapper = IS_WRAPPER_CLASS(clazz); if (isWrapper && IS_SLIM_WRAPPER_OBJECT(obj)) return GetSlimWrapperProto(obj)->GetScope(); if (!isWrapper || !(supports = (nsISupports*) xpc_GetJSPrivate(obj))) return nsnull; #ifdef DEBUG { nsCOMPtr<nsIXPConnectWrappedNative> iface = do_QueryInterface(supports); NS_ASSERTION(iface, "Uh, how'd this happen?"); } #endif // obj is one of our nsXPConnectWrappedNative objects. return ((XPCWrappedNative*)supports)->GetScope(); }
/** * Get the interface name and member name (for error messages). * * We could instead have each quick stub pass its name to the error-handling * functions, as that name is statically known. But that would be redundant; * the information is handy at runtime anyway. Also, this code often produces * a more specific error message, e.g. "[nsIDOMHTMLDocument.appendChild]" * rather than "[nsIDOMNode.appendChild]". */ static void GetMemberInfo(JSObject *obj, jsval memberId, const char **ifaceName, const char **memberName) { // Get the interface name. From DefinePropertyIfFound (in // xpcwrappednativejsops.cpp) and XPCThrower::Verbosify. // // We could instead make the quick stub could pass in its interface name, // but this code often produces a more specific error message, e.g. *ifaceName = "Unknown"; NS_ASSERTION(IS_WRAPPER_CLASS(STOBJ_GET_CLASS(obj)) || STOBJ_GET_CLASS(obj) == &XPC_WN_Tearoff_JSClass || IS_SLIM_WRAPPER(obj), "obj must be a wrapper"); XPCWrappedNativeProto *proto; if(IS_SLIM_WRAPPER(obj)) { proto = GetSlimWrapperProto(obj); } else { XPCWrappedNative *wrapper = (XPCWrappedNative *) obj->getPrivate(); proto = wrapper->GetProto(); } if(proto) { XPCNativeSet *set = proto->GetSet(); if(set) { XPCNativeMember *member; XPCNativeInterface *iface; if(set->FindMember(memberId, &member, &iface)) *ifaceName = iface->GetNameString(); } } *memberName = (JSVAL_IS_STRING(memberId) ? JS_GetStringBytes(JSVAL_TO_STRING(memberId)) : "unknown"); }
static XPCWrappedNativeScope* GetScopeOfObject(JSObject* obj) { nsISupports* supports; JSClass* clazz = STOBJ_GET_CLASS(obj); if(!IS_WRAPPER_CLASS(clazz) || !(supports = (nsISupports*) xpc_GetJSPrivate(obj))) { #ifdef DEBUG { if(!(~clazz->flags & (JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS)) && (supports = (nsISupports*) xpc_GetJSPrivate(obj)) && !XPCNativeWrapper::IsNativeWrapperClass(clazz)) { nsCOMPtr<nsIXPConnectWrappedNative> iface = do_QueryInterface(supports); NS_ASSERTION(!iface, "Uh, how'd this happen?"); } } #endif return nsnull; } #ifdef DEBUG { nsCOMPtr<nsIXPConnectWrappedNative> iface = do_QueryInterface(supports); NS_ASSERTION(iface, "Uh, how'd this happen?"); } #endif // obj is one of our nsXPConnectWrappedNative objects. return ((XPCWrappedNative*)supports)->GetScope(); }