/* THIS FILE IS AUTOGENERATED FROM JSActor.webidl BY Codegen.py - DO NOT EDIT */ #include #include "AtomList.h" #include "JSActorBinding.h" #include "MainThreadUtils.h" #include "js/Array.h" #include "js/CallAndConstruct.h" #include "js/Exception.h" #include "js/ForOfIterator.h" #include "js/MapAndSet.h" #include "js/Object.h" #include "js/PropertyAndElement.h" #include "js/PropertyDescriptor.h" #include "js/experimental/JitInfo.h" #include "mozilla/OwningNonNull.h" #include "mozilla/dom/BindingCallContext.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/NonRefcountedDOMObject.h" #include "mozilla/dom/Nullable.h" #include "mozilla/dom/PrimitiveConversions.h" #include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/SimpleGlobalObject.h" #include "nsContentUtils.h" #include "nsISupports.h" namespace mozilla::dom { namespace binding_detail {}; // Just to make sure it's known as a namespace using namespace mozilla::dom::binding_detail; JSActorOptions::JSActorOptions() { // Safe to pass a null context if we pass a null value Init(nullptr, JS::NullHandleValue); } bool JSActorOptions::InitIds(JSContext* cx, JSActorOptionsAtoms* atomsCache) { MOZ_ASSERT(reinterpret_cast(atomsCache)->isVoid()); // Initialize these in reverse order so that any failure leaves the first one // uninitialized. if (!atomsCache->safeForUntrustedWebProcess_id.init(cx, "safeForUntrustedWebProcess") || !atomsCache->remoteTypes_id.init(cx, "remoteTypes")) { return false; } return true; } bool JSActorOptions::Init(BindingCallContext& cx, JS::Handle val, const char* sourceDescription, bool passedToJSImpl) { // Passing a null JSContext is OK only if we're initing from null, // Since in that case we will not have to do any property gets // Also evaluate isNullOrUndefined in order to avoid false-positive // checkers by static analysis tools MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); JSActorOptionsAtoms* atomsCache = nullptr; if (cx) { atomsCache = GetAtomCache(cx); if (reinterpret_cast(atomsCache)->isVoid() && !InitIds(cx, atomsCache)) { return false; } } if (!IsConvertibleToDictionary(val)) { return cx.ThrowErrorMessage(sourceDescription, "dictionary"); } bool isNull = val.isNullOrUndefined(); // We only need these if !isNull, in which case we have |cx|. Maybe > object; Maybe > temp; if (!isNull) { MOZ_ASSERT(cx); object.emplace(cx, &val.toObject()); temp.emplace(cx); } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->remoteTypes_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mRemoteTypes.Construct(); if (temp.ref().isObject()) { JS::ForOfIterator iter(cx); if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { return false; } if (!iter.valueIsIterable()) { cx.ThrowErrorMessage("'remoteTypes' member of JSActorOptions", "sequence"); return false; } Sequence &arr = (mRemoteTypes.Value()); if (mozilla::Maybe sizeHint = iter.sizeHint()) { if (!arr.SetCapacity(*sizeHint, mozilla::fallible)) { JS_ReportOutOfMemory(cx); return false; } } JS::Rooted temp(cx); while (true) { bool done; if (!iter.next(&temp, &done)) { return false; } if (done) { break; } nsCString* slotPtr = arr.AppendElement(mozilla::fallible); if (!slotPtr) { JS_ReportOutOfMemory(cx); return false; } nsCString& slot = *slotPtr; if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) { return false; } } } else { cx.ThrowErrorMessage("'remoteTypes' member of JSActorOptions", "sequence"); return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->safeForUntrustedWebProcess_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { if (!ValueToPrimitive(cx, temp.ref(), "'safeForUntrustedWebProcess' member of JSActorOptions", &mSafeForUntrustedWebProcess)) { return false; } } else { mSafeForUntrustedWebProcess = false; } mIsAnyMemberPresent = true; return true; } bool JSActorOptions::Init(JSContext* cx_, JS::Handle val, const char* sourceDescription, bool passedToJSImpl) { // We don't want to use sourceDescription for our context here; // that's not really what it's formatted for. BindingCallContext cx(cx_, nullptr); return Init(cx, val, sourceDescription, passedToJSImpl); } void JSActorOptions::TraceDictionary(JSTracer* trc) { } JSActorOptions& JSActorOptions::operator=(const JSActorOptions& aOther) { MaybeEmptyDictionaryBase::operator=(aOther); mRemoteTypes.Reset(); if (aOther.mRemoteTypes.WasPassed()) { mRemoteTypes.Construct(aOther.mRemoteTypes.Value()); } mSafeForUntrustedWebProcess = aOther.mSafeForUntrustedWebProcess; return *this; } JSActorSidedOptions::JSActorSidedOptions() { // Safe to pass a null context if we pass a null value Init(nullptr, JS::NullHandleValue); } bool JSActorSidedOptions::InitIds(JSContext* cx, JSActorSidedOptionsAtoms* atomsCache) { MOZ_ASSERT(reinterpret_cast(atomsCache)->isVoid()); // Initialize these in reverse order so that any failure leaves the first one // uninitialized. if (!atomsCache->esModuleURI_id.init(cx, "esModuleURI")) { return false; } return true; } bool JSActorSidedOptions::Init(BindingCallContext& cx, JS::Handle val, const char* sourceDescription, bool passedToJSImpl) { // Passing a null JSContext is OK only if we're initing from null, // Since in that case we will not have to do any property gets // Also evaluate isNullOrUndefined in order to avoid false-positive // checkers by static analysis tools MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); JSActorSidedOptionsAtoms* atomsCache = nullptr; if (cx) { atomsCache = GetAtomCache(cx); if (reinterpret_cast(atomsCache)->isVoid() && !InitIds(cx, atomsCache)) { return false; } } if (!IsConvertibleToDictionary(val)) { return cx.ThrowErrorMessage(sourceDescription, "dictionary"); } bool isNull = val.isNullOrUndefined(); // We only need these if !isNull, in which case we have |cx|. Maybe > object; Maybe > temp; if (!isNull) { MOZ_ASSERT(cx); object.emplace(cx, &val.toObject()); temp.emplace(cx); } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->esModuleURI_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mEsModuleURI.Construct(); if (!ConvertJSValueToByteString(cx, temp.ref(), false, "'esModuleURI' member of JSActorSidedOptions", (mEsModuleURI.Value()))) { return false; } mIsAnyMemberPresent = true; } return true; } bool JSActorSidedOptions::Init(JSContext* cx_, JS::Handle val, const char* sourceDescription, bool passedToJSImpl) { // We don't want to use sourceDescription for our context here; // that's not really what it's formatted for. BindingCallContext cx(cx_, nullptr); return Init(cx, val, sourceDescription, passedToJSImpl); } void JSActorSidedOptions::TraceDictionary(JSTracer* trc) { } JSActorSidedOptions& JSActorSidedOptions::operator=(const JSActorSidedOptions& aOther) { MaybeEmptyDictionaryBase::operator=(aOther); mEsModuleURI.Reset(); if (aOther.mEsModuleURI.WasPassed()) { mEsModuleURI.Construct(aOther.mEsModuleURI.Value()); } return *this; } void MozJSActorCallback::Call(BindingCallContext& cx, JS::Handle aThisVal, ErrorResult& aRv) { JS::Rooted rval(cx); JS::Rooted callable(cx, JS::ObjectValue(*mCallback)); if (!JS::Call(cx, aThisVal, callable, JS::HandleValueArray::empty(), &rval)) { aRv.NoteJSContextException(cx); return; } } MozJSActorCallbacks::MozJSActorCallbacks() { // Safe to pass a null context if we pass a null value Init(nullptr, JS::NullHandleValue); } bool MozJSActorCallbacks::InitIds(JSContext* cx, MozJSActorCallbacksAtoms* atomsCache) { MOZ_ASSERT(reinterpret_cast(atomsCache)->isVoid()); // Initialize these in reverse order so that any failure leaves the first one // uninitialized. if (!atomsCache->didDestroy_id.init(cx, "didDestroy") || !atomsCache->actorCreated_id.init(cx, "actorCreated")) { return false; } return true; } bool MozJSActorCallbacks::Init(BindingCallContext& cx, JS::Handle val, const char* sourceDescription, bool passedToJSImpl) { // Passing a null JSContext is OK only if we're initing from null, // Since in that case we will not have to do any property gets // Also evaluate isNullOrUndefined in order to avoid false-positive // checkers by static analysis tools MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); MozJSActorCallbacksAtoms* atomsCache = nullptr; if (cx) { atomsCache = GetAtomCache(cx); if (reinterpret_cast(atomsCache)->isVoid() && !InitIds(cx, atomsCache)) { return false; } } if (!IsConvertibleToDictionary(val)) { return cx.ThrowErrorMessage(sourceDescription, "dictionary"); } bool isNull = val.isNullOrUndefined(); // We only need these if !isNull, in which case we have |cx|. Maybe > object; Maybe > temp; if (!isNull) { MOZ_ASSERT(cx); object.emplace(cx, &val.toObject()); temp.emplace(cx); } if (!isNull) { if (nsContentUtils::ThreadsafeIsSystemCaller(cx)) { if (!JS_GetPropertyById(cx, *object, atomsCache->actorCreated_id, temp.ptr())) { return false; } } else { temp->setUndefined(); } } if (!isNull && !temp->isUndefined()) { mActorCreated.Construct(); if (temp.ref().isObject()) { if (JS::IsCallable(&temp.ref().toObject())) { { // scope for tempRoot and tempGlobalRoot if needed JS::Rooted tempRoot(cx, &temp.ref().toObject()); JS::Rooted tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx)); (mActorCreated.Value()) = new MozJSActorCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal()); } } else { cx.ThrowErrorMessage("'actorCreated' member of MozJSActorCallbacks"); return false; } } else { cx.ThrowErrorMessage("'actorCreated' member of MozJSActorCallbacks"); return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (nsContentUtils::ThreadsafeIsSystemCaller(cx)) { if (!JS_GetPropertyById(cx, *object, atomsCache->didDestroy_id, temp.ptr())) { return false; } } else { temp->setUndefined(); } } if (!isNull && !temp->isUndefined()) { mDidDestroy.Construct(); if (temp.ref().isObject()) { if (JS::IsCallable(&temp.ref().toObject())) { { // scope for tempRoot and tempGlobalRoot if needed JS::Rooted tempRoot(cx, &temp.ref().toObject()); JS::Rooted tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx)); (mDidDestroy.Value()) = new MozJSActorCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal()); } } else { cx.ThrowErrorMessage("'didDestroy' member of MozJSActorCallbacks"); return false; } } else { cx.ThrowErrorMessage("'didDestroy' member of MozJSActorCallbacks"); return false; } mIsAnyMemberPresent = true; } return true; } bool MozJSActorCallbacks::Init(JSContext* cx_, JS::Handle val, const char* sourceDescription, bool passedToJSImpl) { // We don't want to use sourceDescription for our context here; // that's not really what it's formatted for. BindingCallContext cx(cx_, nullptr); return Init(cx, val, sourceDescription, passedToJSImpl); } void MozJSActorCallbacks::TraceDictionary(JSTracer* trc) { } void MozObserverCallback::Observe(BindingCallContext& cx, JS::Handle aThisVal, nsISupports* subject, const nsCString& topic, const nsAString& data, ErrorResult& aRv) { JS::Rooted rval(cx); JS::RootedVector argv(cx); if (!argv.resize(3)) { // That threw an exception on the JSContext, and our CallSetup will do // the right thing with that. return; } unsigned argc = 3; do { if (!xpc::StringToJsval(cx, data, argv[2])) { aRv.Throw(NS_ERROR_UNEXPECTED); return; } break; } while (false); do { if (!NonVoidByteStringToJsval(cx, topic, argv[1])) { aRv.Throw(NS_ERROR_UNEXPECTED); return; } break; } while (false); do { if (!WrapObject(cx, subject, argv[0])) { aRv.Throw(NS_ERROR_UNEXPECTED); return; } break; } while (false); bool isCallable = JS::IsCallable(mCallback); JS::Rooted callable(cx); if (isCallable) { callable = JS::ObjectValue(*mCallback); } else { MozObserverCallbackAtoms* atomsCache = GetAtomCache(cx); if ((reinterpret_cast(atomsCache)->isVoid() && !InitIds(cx, atomsCache)) || !GetCallableProperty(cx, atomsCache->observe_id, &callable)) { aRv.Throw(NS_ERROR_UNEXPECTED); return; } } JS::Rooted thisValue(cx, isCallable ? aThisVal.get() : JS::ObjectValue(*mCallback)); if (!JS::Call(cx, thisValue, callable, JS::HandleValueArray::subarray(argv, 0, argc), &rval)) { aRv.NoteJSContextException(cx); return; } } bool MozObserverCallback::InitIds(JSContext* cx, MozObserverCallbackAtoms* atomsCache) { MOZ_ASSERT(reinterpret_cast(atomsCache)->isVoid()); // Initialize these in reverse order so that any failure leaves the first one // uninitialized. if (!atomsCache->observe_id.init(cx, "observe")) { return false; } return true; } } // namespace mozilla::dom