/* THIS FILE IS AUTOGENERATED FROM LockManager.webidl BY Codegen.py - DO NOT EDIT */ #include #include "AtomList.h" #include "LockManagerBinding.h" #include "MainThreadUtils.h" #include "WrapperFactory.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 "jsapi.h" #include "mozilla/Atomics.h" #include "mozilla/OwningNonNull.h" #include "mozilla/ProfilerLabels.h" #include "mozilla/dom/BindingCallContext.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/DOMJSClass.h" #include "mozilla/dom/Lock.h" #include "mozilla/dom/LockManager.h" #include "mozilla/dom/NonRefcountedDOMObject.h" #include "mozilla/dom/Nullable.h" #include "mozilla/dom/PrimitiveConversions.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/SimpleGlobalObject.h" #include "mozilla/dom/ToJSValue.h" #include "mozilla/dom/WebIDLPrefs.h" #include "mozilla/dom/XrayExpandoClass.h" namespace mozilla { namespace dom { namespace binding_detail {}; // Just to make sure it's known as a namespace using namespace mozilla::dom::binding_detail; namespace binding_detail { constexpr nsLiteralCString EnumStrings::Values[2]; } // namespace binding_detail bool ToJSValue(JSContext* aCx, LockMode aArgument, JS::MutableHandle aValue) { MOZ_ASSERT(uint32_t(aArgument) < std::size(binding_detail::EnumStrings::Values)); JSString* resultStr = JS_NewStringCopyN(aCx, binding_detail::EnumStrings::Values[uint32_t(aArgument)].BeginReading(), binding_detail::EnumStrings::Values[uint32_t(aArgument)].Length()); if (!resultStr) { return false; } aValue.setString(resultStr); return true; } MOZ_CAN_RUN_SCRIPT already_AddRefed LockGrantedCallback::Call(BindingCallContext& cx, JS::Handle aThisVal, Lock* lock, ErrorResult& aRv) { JS::Rooted rval(cx); JS::RootedVector argv(cx); if (!argv.resize(1)) { // That threw an exception on the JSContext, and our CallSetup will do // the right thing with that. return nullptr; } unsigned argc = 1; do { if (!lock) { argv[0].setNull(); break; } if (!GetOrCreateDOMReflector(cx, lock, argv[0])) { MOZ_ASSERT(JS_IsExceptionPending(cx)); // Convert exception to a rejected promise. // See https://heycam.github.io/webidl/#call-a-user-objects-operation // step 10 and step 15.5. return CreateRejectedPromiseFromThrownException(cx, aRv); } break; } while (false); JS::Rooted callable(cx, JS::ObjectValue(*mCallback)); if (!JS::Call(cx, aThisVal, callable, JS::HandleValueArray::subarray(argv, 0, argc), &rval)) { // Convert exception to a rejected promise. // See https://heycam.github.io/webidl/#call-a-user-objects-operation // step 12 and step 15.5. return CreateRejectedPromiseFromThrownException(cx, aRv); } RefPtr rvalDecl; { // Scope for our GlobalObject, FastErrorResult, JSAutoRealm, // etc. JS::Rooted globalObj(cx); // We basically want our entry global here. Play it safe // and use GetEntryGlobal() to get it, with whatever // principal-clamping it ends up doing. globalObj = GetEntryGlobal()->GetGlobalJSObject(); JSAutoRealm ar(cx, globalObj); GlobalObject promiseGlobal(cx, globalObj); if (promiseGlobal.Failed()) { aRv.Throw(NS_ERROR_UNEXPECTED); return nullptr; } JS::Rooted valueToResolve(cx, rval); if (!JS_WrapValue(cx, &valueToResolve)) { aRv.Throw(NS_ERROR_UNEXPECTED); return nullptr; } binding_detail::FastErrorResult promiseRv; nsCOMPtr global = do_QueryInterface(promiseGlobal.GetAsSupports()); if (!global) { promiseRv.Throw(NS_ERROR_UNEXPECTED); MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx)); aRv.Throw(NS_ERROR_UNEXPECTED); return nullptr; } rvalDecl = Promise::Resolve(global, cx, valueToResolve, promiseRv); if (promiseRv.MaybeSetPendingException(cx)) { aRv.Throw(NS_ERROR_UNEXPECTED); return nullptr; } } return rvalDecl.forget(); } LockInfo::LockInfo() { // Safe to pass a null context if we pass a null value Init(); } bool LockInfo::InitIds(JSContext* cx, LockInfoAtoms* atomsCache) { MOZ_ASSERT(reinterpret_cast(atomsCache)->isVoid()); // Initialize these in reverse order so that any failure leaves the first one // uninitialized. if (!atomsCache->name_id.init(cx, "name") || !atomsCache->mode_id.init(cx, "mode") || !atomsCache->clientId_id.init(cx, "clientId")) { return false; } return true; } bool LockInfo::Init(const char* sourceDescription, bool passedToJSImpl) { return true; } bool LockInfo::ToObjectInternal(JSContext* cx, JS::MutableHandle rval) const { LockInfoAtoms* atomsCache = GetAtomCache(cx); if (reinterpret_cast(atomsCache)->isVoid() && !InitIds(cx, atomsCache)) { return false; } JS::Rooted obj(cx, JS_NewPlainObject(cx)); if (!obj) { return false; } rval.setObject(*obj); if (mClientId.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); nsString const & currentValue = mClientId.InternalValue(); if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->clientId_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mMode.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); LockMode const & currentValue = mMode.InternalValue(); if (!ToJSValue(cx, currentValue, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->mode_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mName.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); nsString const & currentValue = mName.InternalValue(); if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } return true; } void LockInfo::TraceDictionary(JSTracer* trc) { } LockInfo& LockInfo::operator=(const LockInfo& aOther) { DictionaryBase::operator=(aOther); mClientId.Reset(); if (aOther.mClientId.WasPassed()) { mClientId.Construct(aOther.mClientId.Value()); } mMode.Reset(); if (aOther.mMode.WasPassed()) { mMode.Construct(aOther.mMode.Value()); } mName.Reset(); if (aOther.mName.WasPassed()) { mName.Construct(aOther.mName.Value()); } return *this; } LockOptions::LockOptions() { // Safe to pass a null context if we pass a null value Init(nullptr, JS::NullHandleValue); } bool LockOptions::InitIds(JSContext* cx, LockOptionsAtoms* atomsCache) { MOZ_ASSERT(reinterpret_cast(atomsCache)->isVoid()); // Initialize these in reverse order so that any failure leaves the first one // uninitialized. if (!atomsCache->steal_id.init(cx, "steal") || !atomsCache->signal_id.init(cx, "signal") || !atomsCache->mode_id.init(cx, "mode") || !atomsCache->ifAvailable_id.init(cx, "ifAvailable")) { return false; } return true; } bool LockOptions::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()); LockOptionsAtoms* 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->ifAvailable_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { if (!ValueToPrimitive(cx, temp.ref(), "'ifAvailable' member of LockOptions", &mIfAvailable)) { return false; } } else { mIfAvailable = false; } mIsAnyMemberPresent = true; if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->mode_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { { int index; if (!binding_detail::FindEnumStringIndex(cx, temp.ref(), binding_detail::EnumStrings::Values, "LockMode", "'mode' member of LockOptions", &index)) { return false; } MOZ_ASSERT(index >= 0); mMode = static_cast(index); } } else { mMode = LockMode::Exclusive; } mIsAnyMemberPresent = true; if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->signal_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mSignal.Construct(); if (temp.ref().isObject()) { static_assert(IsRefcounted::value, "We can only store refcounted classes."); { // Our JSContext should be in the right global to do unwrapping in. nsresult rv = UnwrapObject(temp.ptr(), (mSignal.Value()), cx); if (NS_FAILED(rv)) { cx.ThrowErrorMessage("'signal' member of LockOptions", "AbortSignal"); return false; } } } else { cx.ThrowErrorMessage("'signal' member of LockOptions"); return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->steal_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { if (!ValueToPrimitive(cx, temp.ref(), "'steal' member of LockOptions", &mSteal)) { return false; } } else { mSteal = false; } mIsAnyMemberPresent = true; return true; } bool LockOptions::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 LockOptions::TraceDictionary(JSTracer* trc) { } LockOptions& LockOptions::operator=(const LockOptions& aOther) { MaybeEmptyDictionaryBase::operator=(aOther); mIfAvailable = aOther.mIfAvailable; mMode = aOther.mMode; mSignal.Reset(); if (aOther.mSignal.WasPassed()) { mSignal.Construct(aOther.mSignal.Value()); } mSteal = aOther.mSteal; return *this; } LockManagerSnapshot::LockManagerSnapshot() { // Safe to pass a null context if we pass a null value Init(); } bool LockManagerSnapshot::InitIds(JSContext* cx, LockManagerSnapshotAtoms* atomsCache) { MOZ_ASSERT(reinterpret_cast(atomsCache)->isVoid()); // Initialize these in reverse order so that any failure leaves the first one // uninitialized. if (!atomsCache->pending_id.init(cx, "pending") || !atomsCache->held_id.init(cx, "held")) { return false; } return true; } bool LockManagerSnapshot::Init(const char* sourceDescription, bool passedToJSImpl) { return true; } bool LockManagerSnapshot::ToObjectInternal(JSContext* cx, JS::MutableHandle rval) const { LockManagerSnapshotAtoms* atomsCache = GetAtomCache(cx); if (reinterpret_cast(atomsCache)->isVoid() && !InitIds(cx, atomsCache)) { return false; } JS::Rooted obj(cx, JS_NewPlainObject(cx)); if (!obj) { return false; } rval.setObject(*obj); if (mHeld.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); Sequence const & currentValue = mHeld.InternalValue(); uint32_t length = currentValue.Length(); JS::Rooted returnArray(cx, JS::NewArrayObject(cx, length)); if (!returnArray) { return false; } // Scope for 'tmp' { JS::Rooted tmp(cx); for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { // Control block to let us common up the JS_DefineElement calls when there // are different ways to succeed at wrapping the object. do { if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { return false; } break; } while (false); if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, JSPROP_ENUMERATE)) { return false; } } } temp.setObject(*returnArray); if (!JS_DefinePropertyById(cx, obj, atomsCache->held_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mPending.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); Sequence const & currentValue = mPending.InternalValue(); uint32_t length = currentValue.Length(); JS::Rooted returnArray(cx, JS::NewArrayObject(cx, length)); if (!returnArray) { return false; } // Scope for 'tmp' { JS::Rooted tmp(cx); for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { // Control block to let us common up the JS_DefineElement calls when there // are different ways to succeed at wrapping the object. do { if (!currentValue[sequenceIdx0].ToObjectInternal(cx, &tmp)) { return false; } break; } while (false); if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, JSPROP_ENUMERATE)) { return false; } } } temp.setObject(*returnArray); if (!JS_DefinePropertyById(cx, obj, atomsCache->pending_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } return true; } void LockManagerSnapshot::TraceDictionary(JSTracer* trc) { } LockManagerSnapshot& LockManagerSnapshot::operator=(const LockManagerSnapshot& aOther) { DictionaryBase::operator=(aOther); mHeld.Reset(); if (aOther.mHeld.WasPassed()) { mHeld.Construct(aOther.mHeld.Value()); } mPending.Reset(); if (aOther.mPending.WasPassed()) { mPending.Construct(aOther.mPending.Value()); } return *this; } namespace LockManager_Binding { MOZ_CAN_RUN_SCRIPT static bool request(JSContext* cx_, JS::Handle obj, void* void_self, const JSJitMethodCallArgs& args) { BindingCallContext cx(cx_, "LockManager.request"); AUTO_PROFILER_LABEL_DYNAMIC_FAST( "LockManager", "request", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); unsigned argcount = std::min(args.length(), 3u); switch (argcount) { case 2: { nsAutoString arg0; if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { return false; } RootedCallback> arg1(cx); if (args[1].isObject()) { if (JS::IsCallable(&args[1].toObject())) { { // scope for tempRoot and tempGlobalRoot if needed arg1 = new binding_detail::FastLockGrantedCallback(&args[1].toObject(), JS::CurrentGlobalOrNull(cx)); } } else { cx.ThrowErrorMessage("Argument 2"); return false; } } else { cx.ThrowErrorMessage("Argument 2"); return false; } FastErrorResult rv; auto result(StrongOrRawPtr(MOZ_KnownLive(self)->Request(NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), rv))); if (rv.MaybeSetPendingException(cx, "LockManager.request")) [[unlikely]] { return false; } MOZ_ASSERT(!JS_IsExceptionPending(cx)); static_assert(!std::is_pointer_v, "NewObject implies that we need to keep the object alive with a strong reference."); if (!ToJSValue(cx, result, args.rval())) { return false; } return true; break; } case 3: { nsAutoString arg0; if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { return false; } binding_detail::FastLockOptions arg1; if (!arg1.Init(cx, args[1], "Argument 2", false)) { return false; } RootedCallback> arg2(cx); if (args[2].isObject()) { if (JS::IsCallable(&args[2].toObject())) { { // scope for tempRoot and tempGlobalRoot if needed arg2 = new binding_detail::FastLockGrantedCallback(&args[2].toObject(), JS::CurrentGlobalOrNull(cx)); } } else { cx.ThrowErrorMessage("Argument 3"); return false; } } else { cx.ThrowErrorMessage("Argument 3"); return false; } FastErrorResult rv; auto result(StrongOrRawPtr(MOZ_KnownLive(self)->Request(NonNullHelper(Constify(arg0)), Constify(arg1), MOZ_KnownLive(NonNullHelper(arg2)), rv))); if (rv.MaybeSetPendingException(cx, "LockManager.request")) [[unlikely]] { return false; } MOZ_ASSERT(!JS_IsExceptionPending(cx)); static_assert(!std::is_pointer_v, "NewObject implies that we need to keep the object alive with a strong reference."); if (!ToJSValue(cx, result, args.rval())) { return false; } return true; break; } default: { // Using nsPrintfCString here would require including that // header. Let's not worry about it. nsAutoCString argCountStr; argCountStr.AppendPrintf("%u", args.length()); return cx.ThrowErrorMessage(argCountStr.get()); } } MOZ_CRASH("We have an always-returning default case"); return false; } MOZ_CAN_RUN_SCRIPT static bool request_promiseWrapper(JSContext* cx, JS::Handle obj, void* void_self, const JSJitMethodCallArgs& args) { bool ok = request(cx, obj, void_self, args); if (ok) { return true; } return ConvertExceptionToPromise(cx, args.rval()); } static const JSJitInfo request_methodinfo = { { (JSJitGetterOp)request_promiseWrapper }, { prototypes::id::LockManager }, { PrototypeTraits::Depth }, JSJitInfo::Method, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ false, /* isInfallible. False in setters. */ false, /* isMovable. Not relevant for setters. */ false, /* isEliminatable. Not relevant for setters. */ false, /* isAlwaysInSlot. Only relevant for getters. */ false, /* isLazilyCachedInSlot. Only relevant for getters. */ false, /* isTypedMethod. Only relevant for methods. */ 0 /* Reserved slot index, if we're stored in a slot, else 0. */ }; MOZ_CAN_RUN_SCRIPT static bool query(JSContext* cx, JS::Handle obj, void* void_self, const JSJitMethodCallArgs& args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "LockManager", "query", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); FastErrorResult rv; auto result(StrongOrRawPtr(MOZ_KnownLive(self)->Query(rv))); if (rv.MaybeSetPendingException(cx, "LockManager.query")) [[unlikely]] { return false; } MOZ_ASSERT(!JS_IsExceptionPending(cx)); static_assert(!std::is_pointer_v, "NewObject implies that we need to keep the object alive with a strong reference."); if (!ToJSValue(cx, result, args.rval())) { return false; } return true; } MOZ_CAN_RUN_SCRIPT static bool query_promiseWrapper(JSContext* cx, JS::Handle obj, void* void_self, const JSJitMethodCallArgs& args) { bool ok = query(cx, obj, void_self, args); if (ok) { return true; } return ConvertExceptionToPromise(cx, args.rval()); } static const JSJitInfo query_methodinfo = { { (JSJitGetterOp)query_promiseWrapper }, { prototypes::id::LockManager }, { PrototypeTraits::Depth }, JSJitInfo::Method, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ false, /* isInfallible. False in setters. */ false, /* isMovable. Not relevant for setters. */ false, /* isEliminatable. Not relevant for setters. */ false, /* isAlwaysInSlot. Only relevant for getters. */ false, /* isLazilyCachedInSlot. Only relevant for getters. */ false, /* isTypedMethod. Only relevant for methods. */ 0 /* Reserved slot index, if we're stored in a slot, else 0. */ }; static void _finalize(JS::GCContext* gcx, JSObject* obj) { mozilla::dom::LockManager* self = UnwrapPossiblyNotInitializedDOMObject(obj); if (self) { JS::SetNativeObjectReservedSlot(obj, DOM_OBJECT_SLOT, JS::UndefinedValue()); ClearWrapper(self, self, obj); if (size_t mallocBytes = BindingJSObjectMallocBytes(self)) { JS::RemoveAssociatedMemory(obj, mallocBytes, JS::MemoryUse::DOMBinding); } AddForDeferredFinalization(self); } } MOZ_GLOBINIT static const JSFunctionSpec sMethods_specs[] = { JS_FNSPEC("request", (GenericMethod), reinterpret_cast(&request_methodinfo), 2, JSPROP_ENUMERATE, nullptr), JS_FNSPEC("query", (GenericMethod), reinterpret_cast(&query_methodinfo), 0, JSPROP_ENUMERATE, nullptr), JS_FS_END }; static const PrefableDisablers sMethods_disablers0 = { WebIDLPrefIndex::NoPref, 0, true, OriginTrial(0), nullptr }; static const Prefable sMethods[] = { { &sMethods_disablers0, &sMethods_specs[0] }, { nullptr, nullptr } }; static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); static uint16_t sNativeProperties_sortedPropertyIndices[2]; static PropertyInfo sNativeProperties_propertyInfos[2]; static const NativePropertiesN<1> sNativeProperties = { false, 0, false, 0, true, 0 /* sMethods */, false, 0, false, 0, false, 0, false, 0, -1, 2, sNativeProperties_sortedPropertyIndices, { { sMethods, &sNativeProperties_propertyInfos[0] } } }; static_assert(2 < 1ull << (CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount)), "We have a property info count that is oversized"); bool sNativePropertiesInited = false; const NativePropertyHooks sNativePropertyHooks = { nullptr, { sNativeProperties.Upcast(), nullptr, &sNativePropertiesInited }, prototypes::id::LockManager, constructors::id::LockManager, &DefaultXrayExpandoObjectClass }; static const DOMInterfaceInfo sInterfaceObjectInfo = { { ThrowingConstructor, &sNativePropertyHooks }, JS::GetRealmFunctionPrototypeHandle, PrototypeTraits::Depth, prototypes::id::LockManager, true, 0, "LockManager", }; static const DOMIfaceAndProtoJSClass sPrototypeClass = { { "LockManagerPrototype", JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), JS_NULL_CLASS_OPS, JS_NULL_CLASS_SPEC, JS_NULL_CLASS_EXT, JS_NULL_OBJECT_OPS }, eInterfacePrototype, prototypes::id::LockManager, PrototypeTraits::Depth, &sNativePropertyHooks, JS::GetRealmObjectPrototype }; bool ConstructorEnabled(JSContext* aCx, JS::Handle aObj) { return mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(aCx, aObj); } static JS::Handle GetProtoObjectHandle(JSContext* aCx); static const JSClassOps sClassOps = { nullptr, /* addProperty */ nullptr, /* delProperty */ nullptr, /* enumerate */ nullptr, /* newEnumerate */ nullptr, /* resolve */ nullptr, /* mayResolve */ _finalize, /* finalize */ nullptr, /* call */ nullptr, /* construct */ nullptr, /* trace */ }; static const DOMJSClass sClass = { { "LockManager", JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_PRESERVES_WRAPPER, &sClassOps, JS_NULL_CLASS_SPEC, &NativeTypeHelpers::sClassExtension, JS_NULL_OBJECT_OPS }, { prototypes::id::LockManager, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, std::is_base_of_v, &sNativePropertyHooks, GetProtoObjectHandle, GetCCParticipant::Get(), nullptr, NativeTypeHelpers::GetWrapperCache }; static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, "Must have the right minimal number of reserved slots."); static_assert(1 >= 1, "Must have enough reserved slots."); bool Wrap(JSContext* aCx, mozilla::dom::LockManager* aObject, nsWrapperCache* aCache, JS::Handle aGivenProto, JS::MutableHandle aReflector) { static_assert(!std::is_base_of_v, "Shouldn't have wrappercached things that are not refcounted."); static_assert(std::is_same_v); MOZ_ASSERT(ToSupportsIsCorrect(aObject)); MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); MOZ_ASSERT(!aCache->GetWrapper(), "You should probably not be using Wrap() directly; use " "GetOrCreateDOMReflector instead"); MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), "nsISupports must be on our primary inheritance chain"); // If the wrapper cache contains a dead reflector then finalize that // now, ensuring that the finalizer for the old reflector always // runs before the new reflector is created and attached. This // avoids the awkward situation where there are multiple reflector // objects that contain pointers to the same native. if (JSObject* oldReflector = aCache->GetWrapperMaybeDead()) { _finalize(nullptr /* unused */, oldReflector); MOZ_ASSERT(!aCache->GetWrapperMaybeDead()); } JS::Rooted global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); if (!global) { return false; } MOZ_ASSERT(JS_IsGlobalObject(global)); JS::AssertObjectIsNotGray(global); // That might have ended up wrapping us already, due to the wonders // of XBL. Check for that, and bail out as needed. aReflector.set(aCache->GetWrapper()); if (aReflector) { #ifdef DEBUG AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); #endif // DEBUG return true; } JSAutoRealm ar(aCx, global); JS::Handle canonicalProto = GetProtoObjectHandle(aCx); if (!canonicalProto) { return false; } JS::Rooted proto(aCx); if (aGivenProto) { proto = aGivenProto; // Unfortunately, while aGivenProto was in the compartment of aCx // coming in, we changed compartments to that of "parent" so may need // to wrap the proto here. if (js::GetContextCompartment(aCx) != JS::GetCompartment(proto)) { if (!JS_WrapObject(aCx, &proto)) { return false; } } } else { proto = canonicalProto; } BindingJSObjectCreator creator(aCx); creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); if (!aReflector) { return false; } aCache->SetWrapper(aReflector); creator.InitializationSucceeded(); MOZ_ASSERT(aCache->GetWrapperPreserveColor() && aCache->GetWrapperPreserveColor() == aReflector); // If proto != canonicalProto, we have to preserve our wrapper; // otherwise we won't be able to properly recreate it later, since // we won't know what proto to use. Note that we don't check // aGivenProto here, since it's entirely possible (and even // somewhat common) to have a non-null aGivenProto which is the // same as canonicalProto. if (proto != canonicalProto) { PreserveWrapper(aObject); } return true; } void CreateInterfaceObjects(JSContext* aCx, JS::Handle aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, DefineInterfaceProperty aDefineOnGlobal) { JS::Heap* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::LockManager); JS::Heap* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::LockManager); JS::Handle parentProto(JS::GetRealmObjectPrototypeHandle(aCx)); if (!parentProto) { return; } JS::Handle constructorProto(JS::GetRealmFunctionPrototypeHandle(aCx)); if (!constructorProto) { return; } dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, &sPrototypeClass, protoCache, constructorProto, &sInterfaceObjectInfo, 0, false, Span{}, interfaceCache, sNativeProperties.Upcast(), nullptr, "LockManager", ShouldExpose(aCx, aGlobal, aDefineOnGlobal), nullptr, false, nullptr); } static JS::Handle GetProtoObjectHandle(JSContext* aCx) { /* Get the interface prototype object for this class. This will create the object as needed. */ return GetPerInterfaceObjectHandle(aCx, prototypes::id::LockManager, &CreateInterfaceObjects, DefineInterfaceProperty::CheckExposure); } JS::Handle GetConstructorObjectHandle(JSContext* aCx) { /* Get the interface object for this class. This will create the object as needed. */ return GetPerInterfaceObjectHandle(aCx, constructors::id::LockManager, &CreateInterfaceObjects, DefineInterfaceProperty::CheckExposure); } } // namespace LockManager_Binding } // namespace dom } // namespace mozilla