static JSBool XPC_XOW_Enumerate(JSContext *cx, JSObject *obj) { obj = GetWrapper(obj); JSObject *wrappedObj = GetWrappedObject(cx, obj); if (!wrappedObj) { // Nothing to enumerate. return JS_TRUE; } XPCCallContext ccx(JS_CALLER, cx); if (!ccx.IsValid()) { return ThrowException(NS_ERROR_FAILURE, cx); } nsresult rv = CanAccessWrapper(cx, wrappedObj, nsnull); if (NS_FAILED(rv)) { if (rv == NS_ERROR_DOM_PROP_ACCESS_DENIED) { // Can't enumerate on foreign objects. return ThrowException(rv, cx); } return JS_FALSE; } return XPCWrapper::Enumerate(cx, obj, wrappedObj); }
static JSBool XPC_XOW_Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { JSObject *realObj = GetWrapper(JSVAL_TO_OBJECT(argv[-2])); JSObject *wrappedObj = GetWrappedObject(cx, realObj); if (!wrappedObj) { // Nothing to construct. return JS_TRUE; } XPCCallContext ccx(JS_CALLER, cx); if (!ccx.IsValid()) { return ThrowException(NS_ERROR_FAILURE, cx); } nsresult rv = CanAccessWrapper(cx, wrappedObj, nsnull); if (NS_FAILED(rv)) { if (rv == NS_ERROR_DOM_PROP_ACCESS_DENIED) { // Can't construct. return ThrowException(rv, cx); } return JS_FALSE; } if (!JS_CallFunctionValue(cx, obj, OBJECT_TO_JSVAL(wrappedObj), argc, argv, rval)) { return JS_FALSE; } return XPC_XOW_RewrapIfNeeded(cx, wrappedObj, rval); }
static JSBool XPC_COW_NewResolve(JSContext *cx, JSObject *obj, jsval idval, uintN flags, JSObject **objp) { obj = GetWrapper(obj); JSObject *wrappedObj = GetWrappedObject(cx, obj); if (!wrappedObj) { // No wrappedObj means that this is probably the prototype. *objp = nsnull; return JS_TRUE; } XPCCallContext ccx(JS_CALLER, cx); if (!ccx.IsValid()) { return ThrowException(NS_ERROR_FAILURE, cx); } jsid id; JSBool canTouch; if (!JS_ValueToId(cx, idval, &id) || !CanTouchProperty(cx, obj, id, (flags & JSRESOLVE_ASSIGNING) != 0, &canTouch)) { return JS_FALSE; } if (!canTouch) { return ThrowException(NS_ERROR_XPC_SECURITY_MANAGER_VETO, cx); } return XPCWrapper::NewResolve(cx, obj, JS_TRUE, wrappedObj, id, flags, objp); }
static JSBool XPC_XOW_FunctionWrapper(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { JSObject *wrappedObj, *outerObj = obj; // Allow 'this' to be either an XOW, in which case we unwrap it. // We disallow invalid XOWs that have no wrapped object. Otherwise, // if it isn't an XOW, then pass it through as-is. wrappedObj = GetWrapper(obj); if (wrappedObj) { wrappedObj = GetWrappedObject(cx, wrappedObj); if (!wrappedObj) { return ThrowException(NS_ERROR_ILLEGAL_VALUE, cx); } } else { wrappedObj = obj; } JSObject *funObj = JSVAL_TO_OBJECT(argv[-2]); jsval funToCall; if (!JS_GetReservedSlot(cx, funObj, XPCWrapper::eWrappedFunctionSlot, &funToCall)) { return JS_FALSE; } JSFunction *fun = JS_ValueToFunction(cx, funToCall); if (!fun) { return ThrowException(NS_ERROR_ILLEGAL_VALUE, cx); } XPCCallContext ccx(JS_CALLER, cx); if (!ccx.IsValid()) { return ThrowException(NS_ERROR_FAILURE, cx); } nsresult rv = CanAccessWrapper(cx, JSVAL_TO_OBJECT(funToCall), nsnull); if (NS_FAILED(rv) && rv != NS_ERROR_DOM_PROP_ACCESS_DENIED) { return ThrowException(rv, cx); } #ifdef DEBUG JSNative native = JS_GetFunctionNative(cx, fun); NS_ASSERTION(native, "How'd we get here with a scripted function?"); #endif if (!JS_CallFunctionValue(cx, wrappedObj, funToCall, argc, argv, rval)) { return JS_FALSE; } if (NS_SUCCEEDED(rv)) { return WrapSameOriginProp(cx, outerObj, rval); } return XPC_XOW_RewrapIfNeeded(cx, obj, rval); }
int libusb_cancel_transfer(struct libusb_transfer* transfer) { transfer_wrapper* wrapper = GetWrapper(transfer); transfer->status = LIBUSB_TRANSFER_CANCELLED; int ret = usb_cancel_async(wrapper->usb); // 0 on success // LIBUSB_ERROR_NOT_FOUND if the transfer is already complete or cancelled. // a LIBUSB_ERROR code on failure return(ret); }
void libusb_free_transfer(struct libusb_transfer* transfer) { transfer_wrapper* wrapper = GetWrapper(transfer); if (wrapper->libusb.flags & LIBUSB_TRANSFER_FREE_TRANSFER) free_wrapper(wrapper); else if (TListTransfers::Orphan(wrapper)) free_wrapper(wrapper); else wrapper->libusb.flags |= LIBUSB_TRANSFER_FREE_TRANSFER; }
static JSBool XPC_COW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp, JSBool isSet) { obj = GetWrapper(obj); if (!obj) { return ThrowException(NS_ERROR_ILLEGAL_VALUE, cx); } XPCCallContext ccx(JS_CALLER, cx); if (!ccx.IsValid()) { return ThrowException(NS_ERROR_FAILURE, cx); } AUTO_MARK_JSVAL(ccx, vp); JSObject *wrappedObj = GetWrappedObject(cx, obj); if (!wrappedObj) { return ThrowException(NS_ERROR_ILLEGAL_VALUE, cx); } jsid interned_id; if (!JS_ValueToId(cx, id, &interned_id)) { return JS_FALSE; } if (interned_id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_PROTO) || interned_id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_PARENT) || interned_id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_EXPOSEDPROPS)) { // No getting or setting __proto__ or __parent__ on my object. return ThrowException(NS_ERROR_INVALID_ARG, cx); // XXX better error message } JSBool canTouch; if (!CanTouchProperty(cx, obj, interned_id, isSet, &canTouch)) { return JS_FALSE; } if (!canTouch) { return ThrowException(NS_ERROR_XPC_SECURITY_MANAGER_VETO, cx); } if (!XPC_COW_RewrapForChrome(cx, obj, vp)) { return JS_FALSE; } JSBool ok = isSet ? JS_SetPropertyById(cx, wrappedObj, interned_id, vp) : JS_GetPropertyById(cx, wrappedObj, interned_id, vp); if (!ok) { return JS_FALSE; } return XPC_COW_RewrapForContent(cx, obj, vp); }
void JSWindowActor::DestroyCallback(DestroyCallbackFunction callback) { AutoEntryScript aes(xpc::PrivilegedJunkScope(), "JSWindowActor destroy callback"); JSContext* cx = aes.cx(); MozActorDestroyCallbacks callbacksHolder; NS_ENSURE_TRUE_VOID(GetWrapper()); JS::Rooted<JS::Value> val(cx, JS::ObjectValue(*GetWrapper())); if (NS_WARN_IF(!callbacksHolder.Init(cx, val))) { return; } // Destroy callback is optional. if (callback == DestroyCallbackFunction::WillDestroy) { if (callbacksHolder.mWillDestroy.WasPassed()) { callbacksHolder.mWillDestroy.Value()->Call(); } } else { if (callbacksHolder.mDidDestroy.WasPassed()) { callbacksHolder.mDidDestroy.Value()->Call(); } } }
JNIEXPORT void JNICALL Java_com_opensubdiv_OpenSubdivViewer_OpenSubdiv_UpdatePoints( JNIEnv * env, jclass, jint meshHandleId, jint level, jfloatArray pointsArray) { int pointsSize = env->GetArrayLength(pointsArray); jfloat *points = env->GetFloatArrayElements(pointsArray, 0); OsdMeshWrapperSharedPtr wrapper = GetWrapper(meshHandleId); wrapper->UpdatePoints(level, points); env->ReleaseFloatArrayElements(pointsArray, points, 0); }
int libusb_submit_transfer(struct libusb_transfer* transfer) { transfer_wrapper* wrapper = GetWrapper(transfer); void*& context = wrapper->usb; if (NULL == context) { int ret (LIBUSB_ERROR_OTHER); switch(transfer->type) { case LIBUSB_TRANSFER_TYPE_CONTROL : fprintf(stderr, "ERROR: libusb_submit_transfer() with LIBUSB_TRANSFER_TYPE_CONTROL; use libusb_control_transfer() instead.\n"); return(LIBUSB_ERROR_INVALID_PARAM); case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS : ret = usb_isochronous_setup_async(translate(transfer->dev_handle), &context, transfer->endpoint, transfer->iso_packet_desc[0].length); break; case LIBUSB_TRANSFER_TYPE_BULK : ret = usb_bulk_setup_async(translate(transfer->dev_handle), &context, transfer->endpoint); break; case LIBUSB_TRANSFER_TYPE_INTERRUPT : ret = usb_interrupt_setup_async(translate(transfer->dev_handle), &context, transfer->endpoint); break; default : return(LIBUSB_ERROR_INVALID_PARAM); } if (ret < 0) { // TODO: better error handling... // what do the functions usb_***_setup_async() actually return on error? return(ret); } TMapIsocTransfers::iterator it = mIsocTransfers.find(transfer->endpoint); if (it == mIsocTransfers.end()) mIsocTransfers.insert(std::make_pair(transfer->endpoint, new TListTransfers())); } mIsocTransfers[transfer->endpoint]->Append(wrapper); transfer->status = LIBUSB_TRANSFER_COMPLETED; int ret = usb_submit_async(context, (char*)transfer->buffer, transfer->length); if (ret < 0) { // TODO: better error handling... // what does usb_submit_async() actually returns on error? // LIBUSB_ERROR_NO_DEVICE if the device has been disconnected // LIBUSB_ERROR_BUSY if the transfer has already been submitted. // another LIBUSB_ERROR code on other failure return(ret); } // 0 on success return(0); }
nsresult nsDOMDocumentType::BindToTree(nsIDocument *aDocument, nsIContent *aParent, nsIContent *aBindingParent, PRBool aCompileEventHandlers) { if (!HasSameOwnerDoc(NODE_FROM(aParent, aDocument))) { NS_ASSERTION(!GetOwnerDoc(), "Need to adopt or import first!"); // DocumentType nodes are the only nodes that can have a null ownerDocument // according to the DOM spec, so we need to give them a new nodeinfo in that // case. // XXX We may want to move this to nsDOMImplementation::CreateDocument if // we want to rely on the nodeinfo and wrappers being right before // getting into ReplaceOrInsertBefore or doInsertChildAt. That would // break inserting DOMDocumentType nodes through other DOM methods // though. nsNodeInfoManager *nimgr = aParent ? aParent->NodeInfo()->NodeInfoManager() : aDocument->NodeInfoManager(); nsCOMPtr<nsINodeInfo> newNodeInfo; newNodeInfo = nimgr->GetNodeInfo(mNodeInfo->NameAtom(), mNodeInfo->GetPrefixAtom(), mNodeInfo->NamespaceID()); NS_ENSURE_TRUE(newNodeInfo, NS_ERROR_OUT_OF_MEMORY); mNodeInfo.swap(newNodeInfo); JSObject *oldScope = GetWrapper(); if (oldScope) { nsIXPConnect *xpc = nsContentUtils::XPConnect(); JSContext *cx = nsnull; JSObject *newScope = nsnull; nsresult rv = nsContentUtils::GetContextAndScope(nsnull, nimgr->GetDocument(), &cx, &newScope); if (cx && xpc) { nsISupports *node = NS_ISUPPORTS_CAST(nsIContent*, this); nsCOMPtr<nsIXPConnectJSObjectHolder> oldWrapper; rv = xpc->ReparentWrappedNativeIfFound(cx, oldScope, newScope, node, getter_AddRefs(oldWrapper)); } if (NS_FAILED(rv)) { mNodeInfo.swap(newNodeInfo); return rv; } }
HRESULT DirectDraw::QueryInterface( REFIID riid, LPVOID* obp ) { std::ostringstream str; str << this << " " << __FUNCTION__; str << tostr_GUID(&riid); HRESULT hr = this->_original->QueryInterface(riid, obp); if (SUCCEEDED(hr)) { void* wrapper = GetWrapper(*obp); if (wrapper) { *obp = wrapper; } else if (riid == IID_IDirectDraw2) { *obp = CreateWrapperT(DirectDraw2, *obp); } else if (riid == IID_IDirectDraw4) { *obp = CreateWrapperT(DirectDraw4, *obp); } else if (riid == IID_IDirect3D) { *obp = CreateWrapperT(Direct3D, *obp); } else { str << std::endl; str << "\tNOT WRAPPED"; } } str << std::endl; str << tostr_HR(hr); if (obp) { str << " " << *obp; } LogText(str.str()); return hr; }
static JSBool XPC_COW_Enumerate(JSContext *cx, JSObject *obj) { obj = GetWrapper(obj); JSObject *wrappedObj = GetWrappedObject(cx, obj); if (!wrappedObj) { // Nothing to enumerate. return JS_TRUE; } XPCCallContext ccx(JS_CALLER, cx); if (!ccx.IsValid()) { return ThrowException(NS_ERROR_FAILURE, cx); } return XPCWrapper::Enumerate(cx, obj, wrappedObj); }
static JSBool XPC_XOW_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { obj = GetWrapper(obj); if (!obj) { return ThrowException(NS_ERROR_UNEXPECTED, cx); } JSObject *wrappedObj = GetWrappedObject(cx, obj); if (!wrappedObj) { // Someone's calling toString on our prototype. NS_NAMED_LITERAL_CSTRING(protoString, "[object XPCCrossOriginWrapper]"); JSString *str = JS_NewStringCopyN(cx, protoString.get(), protoString.Length()); if (!str) { return JS_FALSE; } *rval = STRING_TO_JSVAL(str); return JS_TRUE; } XPCCallContext ccx(JS_CALLER, cx); if (!ccx.IsValid()) { return ThrowException(NS_ERROR_FAILURE, cx); } nsresult rv = CanAccessWrapper(cx, wrappedObj, nsnull); if (rv == NS_ERROR_DOM_PROP_ACCESS_DENIED) { nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager(); if (!ssm) { return ThrowException(NS_ERROR_NOT_INITIALIZED, cx); } rv = ssm->CheckPropertyAccess(cx, wrappedObj, STOBJ_GET_CLASS(wrappedObj)->name, GetRTStringByIndex(cx, XPCJSRuntime::IDX_TO_STRING), nsIXPCSecurityManager::ACCESS_GET_PROPERTY); } if (NS_FAILED(rv)) { return JS_FALSE; } XPCWrappedNative *wn = XPCWrappedNative::GetWrappedNativeOfJSObject(cx, wrappedObj); return XPCWrapper::NativeToString(cx, wn, argc, argv, rval, JS_FALSE); }
void JSWindowActor::ReceiveMessageOrQuery( JSContext* aCx, const JSWindowActorMessageMeta& aMetadata, JS::Handle<JS::Value> aData, ErrorResult& aRv) { // The argument which we want to pass to IPC. RootedDictionary<ReceiveMessageArgument> argument(aCx); argument.mObjects = JS_NewPlainObject(aCx); argument.mTarget = this; argument.mName = aMetadata.messageName(); argument.mData = aData; argument.mJson = aData; argument.mSync = false; JS::Rooted<JSObject*> self(aCx, GetWrapper()); JS::Rooted<JSObject*> global(aCx, JS::GetNonCCWObjectGlobal(self)); // We only need to create a promise if we're dealing with a query here. It // will be resolved or rejected once the listener has been called. Our // listener on this promise will then send the reply. RefPtr<Promise> promise; if (aMetadata.kind() == JSWindowActorMessageKind::Query) { promise = Promise::Create(xpc::NativeGlobal(global), aRv); if (NS_WARN_IF(aRv.Failed())) { return; } RefPtr<QueryHandler> handler = new QueryHandler(this, aMetadata); promise->AppendNativeHandler(handler); } // Invoke the actual callback. JS::Rooted<JS::Value> retval(aCx); RefPtr<MessageListener> messageListener = new MessageListener(self, global, nullptr, nullptr); messageListener->ReceiveMessage(argument, &retval, aRv, "JSWindowActor receive message"); // If we have a promise, resolve or reject it respectively. if (promise) { if (aRv.Failed()) { promise->MaybeReject(aRv); } else { promise->MaybeResolve(aCx, retval); } } }
static JSBool XPC_COW_AddProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { obj = GetWrapper(obj); jsval resolving; if (!JS_GetReservedSlot(cx, obj, XPCWrapper::sFlagsSlot, &resolving)) { return JS_FALSE; } if (HAS_FLAGS(resolving, FLAG_RESOLVING)) { // Allow us to define a property on ourselves. return JS_TRUE; } // Someone's adding a property to us. We need to protect ourselves from // getters and setters. JSObject *wrappedObj = GetWrappedObject(cx, obj); if (!wrappedObj) { return ThrowException(NS_ERROR_ILLEGAL_VALUE, cx); } jsid interned_id; JSPropertyDescriptor desc; if (!JS_ValueToId(cx, id, &interned_id) || !XPCWrapper::GetPropertyAttrs(cx, obj, interned_id, JSRESOLVE_QUALIFIED, JS_TRUE, &desc)) { return JS_FALSE; } NS_ASSERTION(desc.obj == obj, "The JS engine lies!"); if (desc.attrs & (JSPROP_GETTER | JSPROP_SETTER)) { // Only chrome is allowed to add getters or setters to our object. if (!AllowedToAct(cx, id)) { return JS_FALSE; } } return XPC_COW_RewrapForChrome(cx, obj, vp) && JS_DefinePropertyById(cx, wrappedObj, interned_id, *vp, desc.getter, desc.setter, desc.attrs); }
NS_INTERFACE_MAP_END void PropertyNodeList::GetValues(JSContext* aCx, nsTArray<JS::Value >& aResult, ErrorResult& aError) { EnsureFresh(); JSObject* wrapper = GetWrapper(); JSAutoCompartment ac(aCx, wrapper); uint32_t length = mElements.Length(); for (uint32_t i = 0; i < length; ++i) { JS::Value v = mElements.ElementAt(i)->GetItemValue(aCx, wrapper, aError); if (aError.Failed()) { return; } aResult.AppendElement(v); } }
static JSBool XPC_XOW_AddProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { // All AddProperty needs to do is pass on addProperty requests to // same-origin objects, and throw for all else. obj = GetWrapper(obj); jsval resolving; if (!JS_GetReservedSlot(cx, obj, XPCWrapper::sFlagsSlot, &resolving)) { return JS_FALSE; } if (HAS_FLAGS(resolving, FLAG_RESOLVING)) { // Allow us to define a property on ourselves. return JS_TRUE; } JSObject *wrappedObj = GetWrappedObject(cx, obj); if (!wrappedObj) { return ThrowException(NS_ERROR_ILLEGAL_VALUE, cx); } XPCCallContext ccx(JS_CALLER, cx); if (!ccx.IsValid()) { return ThrowException(NS_ERROR_FAILURE, cx); } JSBool privilegeEnabled = JS_FALSE; nsresult rv = CanAccessWrapper(cx, wrappedObj, &privilegeEnabled); if (NS_FAILED(rv)) { if (rv == NS_ERROR_DOM_PROP_ACCESS_DENIED) { // Can't override properties on foreign objects. return ThrowException(rv, cx); } return JS_FALSE; } // Same origin, pass this request along. return XPCWrapper::AddProperty(cx, obj, JS_TRUE, wrappedObj, id, vp); }
JS::Value DataTransfer::MozGetDataAt(JSContext* aCx, const nsAString& aFormat, uint32_t aIndex, mozilla::ErrorResult& aRv) { nsCOMPtr<nsIVariant> data; aRv = MozGetDataAt(aFormat, aIndex, getter_AddRefs(data)); if (aRv.Failed()) { return JS::UndefinedValue(); } if (!data) { return JS::NullValue(); } JS::Rooted<JS::Value> result(aCx); JS::Rooted<JSObject*> scope(aCx, GetWrapper()); if (!VariantToJsval(aCx, scope, data, &result)) { aRv = NS_ERROR_FAILURE; return JS::UndefinedValue(); } return result; }
static JSBool XPC_COW_FunctionWrapper(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { JSObject *wrappedObj; // Allow 'this' to be either a COW, in which case we unwrap it or something // that isn't a COW. We disallow invalid COWs that have no wrapped object. wrappedObj = GetWrapper(obj); if (wrappedObj) { wrappedObj = GetWrappedObject(cx, wrappedObj); if (!wrappedObj) { return ThrowException(NS_ERROR_ILLEGAL_VALUE, cx); } } else { wrappedObj = obj; } jsval funToCall; if (!JS_GetReservedSlot(cx, JSVAL_TO_OBJECT(argv[-2]), XPCWrapper::eWrappedFunctionSlot, &funToCall)) { return JS_FALSE; } for (uintN i = 0; i < argc; ++i) { if (!XPC_COW_RewrapForChrome(cx, obj, &argv[i])) { return JS_FALSE; } } if (!JS_CallFunctionValue(cx, wrappedObj, funToCall, argc, argv, rval)) { return JS_FALSE; } return XPC_COW_RewrapForContent(cx, obj, rval); }
static JSBool XPC_XOW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp, JSBool isSet) { if (id == GetRTStringByIndex(cx, XPCJSRuntime::IDX_TO_STRING)) { return JS_TRUE; } // Don't do anything if we already resolved to a wrapped function in // NewResolve. In practice, this means that this is a wrapped eval // function. jsval v = *vp; if (!JSVAL_IS_PRIMITIVE(v) && JS_ObjectIsFunction(cx, JSVAL_TO_OBJECT(v)) && JS_GetFunctionNative(cx, JS_ValueToFunction(cx, v)) == XPC_XOW_FunctionWrapper) { return JS_TRUE; } JSObject *origObj = obj; obj = GetWrapper(obj); if (!obj) { return ThrowException(NS_ERROR_ILLEGAL_VALUE, cx); } XPCCallContext ccx(JS_CALLER, cx); if (!ccx.IsValid()) { return ThrowException(NS_ERROR_FAILURE, cx); } AUTO_MARK_JSVAL(ccx, vp); JSObject *wrappedObj = GetWrappedObject(cx, obj); if (!wrappedObj) { return ThrowException(NS_ERROR_ILLEGAL_VALUE, cx); } JSBool privilegeEnabled; nsresult rv = CanAccessWrapper(cx, wrappedObj, &privilegeEnabled); if (NS_FAILED(rv)) { if (rv != NS_ERROR_DOM_PROP_ACCESS_DENIED) { return JS_FALSE; } // This is a request to get a property across origins. We need to // determine if this property is allAccess. If it is, then we need to // actually get the property. If not, we simply need to throw an // exception. XPCWrappedNative *wn = XPCWrappedNative::GetWrappedNativeOfJSObject(cx, wrappedObj); NS_ASSERTION(wn, "How did we wrap a non-WrappedNative?"); if (!IsValFrame(wrappedObj, id, wn)) { nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager(); if (!ssm) { return ThrowException(NS_ERROR_NOT_INITIALIZED, cx); } rv = ssm->CheckPropertyAccess(cx, wrappedObj, STOBJ_GET_CLASS(wrappedObj)->name, id, isSet ? XPCWrapper::sSecMgrSetProp : XPCWrapper::sSecMgrGetProp); if (NS_FAILED(rv)) { // The security manager threw an exception for us. return JS_FALSE; } } return XPCWrapper::GetOrSetNativeProperty(cx, obj, wn, id, vp, isSet, JS_FALSE); } JSObject *proto = nsnull; // Initialize this to quiet GCC. JSBool checkProto = (isSet && id == GetRTStringByIndex(cx, XPCJSRuntime::IDX_PROTO)); if (checkProto) { proto = STOBJ_GET_PROTO(wrappedObj); } // Same origin, pass this request along as though nothing interesting // happened. jsid asId; if (!JS_ValueToId(cx, id, &asId)) { return JS_FALSE; } JSBool ok = isSet ? JS_SetPropertyById(cx, wrappedObj, asId, vp) : JS_GetPropertyById(cx, wrappedObj, asId, vp); if (!ok) { return JS_FALSE; } if (checkProto) { JSObject *newProto = STOBJ_GET_PROTO(wrappedObj); // If code is trying to set obj.__proto__ and we're on obj's // prototype chain, then the JS_GetPropertyById above will do the // wrong thing if wrappedObj still delegates to Object.prototype. // However, it's hard to figure out if wrappedObj still does // delegate to Object.prototype so check to see if proto changed as a // result of setting __proto__. if (origObj != obj) { // Undo the damage. if (!JS_SetPrototype(cx, wrappedObj, proto) || !JS_SetPrototype(cx, origObj, newProto)) { return JS_FALSE; } } else if (newProto) { // __proto__ setting is a bad hack, people shouldn't do it. In // this case we're setting the direct prototype of a XOW object, // in the interests of sanity only allow it to be set to null in // this case. JS_SetPrototype(cx, wrappedObj, proto); JS_ReportError(cx, "invalid __proto__ value (can only be set to null)"); return JS_FALSE; } } return WrapSameOriginProp(cx, obj, vp); }
JNIEXPORT jint JNICALL Java_com_opensubdiv_OpenSubdivViewer_OpenSubdiv_GetTrianglesIndexCount( JNIEnv * env, jclass, jint meshHandleId) { OsdMeshWrapperSharedPtr wrapper = GetWrapper(meshHandleId); return jint(wrapper->GetTrianglesIndexCount()); }
static JSBool XPC_XOW_NewResolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp) { obj = GetWrapper(obj); JSObject *wrappedObj = GetWrappedObject(cx, obj); if (!wrappedObj) { // No wrappedObj means that this is probably the prototype. *objp = nsnull; return JS_TRUE; } XPCCallContext ccx(JS_CALLER, cx); if (!ccx.IsValid()) { return ThrowException(NS_ERROR_FAILURE, cx); } JSBool privilegeEnabled; nsresult rv = CanAccessWrapper(cx, wrappedObj, &privilegeEnabled); if (NS_FAILED(rv)) { if (rv != NS_ERROR_DOM_PROP_ACCESS_DENIED) { return JS_FALSE; } // We're dealing with a cross-origin lookup. Ensure that we're allowed to // resolve this property and resolve it if so. Otherwise, we deny access // and throw a security error. Note that this code does not actually check // to see if the property exists, that's dealt with below. XPCWrappedNative *wn = XPCWrappedNative::GetWrappedNativeOfJSObject(cx, wrappedObj); NS_ASSERTION(wn, "How did we wrap a non-WrappedNative?"); if (!IsValFrame(wrappedObj, id, wn)) { nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager(); if (!ssm) { return ThrowException(NS_ERROR_NOT_INITIALIZED, cx); } PRUint32 action = (flags & JSRESOLVE_ASSIGNING) ? XPCWrapper::sSecMgrSetProp : XPCWrapper::sSecMgrGetProp; rv = ssm->CheckPropertyAccess(cx, wrappedObj, STOBJ_GET_CLASS(wrappedObj)->name, id, action); if (NS_FAILED(rv)) { // The security manager threw an exception for us. return JS_FALSE; } } // We're out! We're allowed to resolve this property. return XPCWrapper::ResolveNativeProperty(cx, obj, wrappedObj, wn, id, flags, objp, JS_FALSE); } if (privilegeEnabled && !(obj = GetUXPCObject(cx, obj))) { return JS_FALSE; } if (id == GetRTStringByIndex(cx, XPCJSRuntime::IDX_TO_STRING)) { jsval oldSlotVal; if (!JS_GetReservedSlot(cx, obj, XPCWrapper::sFlagsSlot, &oldSlotVal) || !JS_SetReservedSlot(cx, obj, XPCWrapper::sFlagsSlot, INT_TO_JSVAL(JSVAL_TO_INT(oldSlotVal) | FLAG_RESOLVING))) { return JS_FALSE; } JSBool ok = JS_DefineFunction(cx, obj, "toString", XPC_XOW_toString, 0, 0) != nsnull; JS_SetReservedSlot(cx, obj, XPCWrapper::sFlagsSlot, oldSlotVal); if (ok) { *objp = obj; } return ok; } return XPCWrapper::NewResolve(cx, obj, JS_TRUE, wrappedObj, id, flags, objp); }
JNIEXPORT jint JNICALL Java_com_opensubdiv_OpenSubdivViewer_OpenSubdiv_GetVertexBufferId( JNIEnv * env, jclass, jint meshHandleId) { OsdMeshWrapperSharedPtr wrapper = GetWrapper(meshHandleId); return jint(wrapper->GetVertexBufferId()); }