/* THIS FILE IS AUTOGENERATED FROM MediaStreamTrack.webidl BY Codegen.py - DO NOT EDIT */ #include #include "AtomList.h" #include "EventHandlerBinding.h" #include "EventTargetBinding.h" #include "MainThreadUtils.h" #include "MediaStreamTrackBinding.h" #include "MediaTrackCapabilitiesBinding.h" #include "MediaTrackSettingsBinding.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/FloatingPoint.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/MediaStreamTrack.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/XrayExpandoClass.h" #include "nsContentUtils.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[4]; } // namespace binding_detail bool ToJSValue(JSContext* aCx, VideoFacingModeEnum 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; } namespace binding_detail { constexpr nsLiteralCString EnumStrings::Values[2]; } // namespace binding_detail bool ToJSValue(JSContext* aCx, VideoResizeModeEnum 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; } namespace binding_detail { constexpr nsLiteralCString EnumStrings::Values[8]; } // namespace binding_detail bool ToJSValue(JSContext* aCx, MediaSourceEnum 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; } namespace binding_detail { constexpr nsLiteralCString EnumStrings::Values[2]; } // namespace binding_detail bool ToJSValue(JSContext* aCx, MediaStreamTrackState 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; } ConstrainBooleanParameters::ConstrainBooleanParameters() { // Safe to pass a null context if we pass a null value Init(nullptr, JS::NullHandleValue); } bool ConstrainBooleanParameters::InitIds(JSContext* cx, ConstrainBooleanParametersAtoms* atomsCache) { MOZ_ASSERT(reinterpret_cast(atomsCache)->isVoid()); // Initialize these in reverse order so that any failure leaves the first one // uninitialized. if (!atomsCache->ideal_id.init(cx, "ideal") || !atomsCache->exact_id.init(cx, "exact")) { return false; } return true; } bool ConstrainBooleanParameters::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()); ConstrainBooleanParametersAtoms* 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->exact_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mExact.Construct(); if (!ValueToPrimitive(cx, temp.ref(), "'exact' member of ConstrainBooleanParameters", &(mExact.Value()))) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->ideal_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mIdeal.Construct(); if (!ValueToPrimitive(cx, temp.ref(), "'ideal' member of ConstrainBooleanParameters", &(mIdeal.Value()))) { return false; } mIsAnyMemberPresent = true; } return true; } bool ConstrainBooleanParameters::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); } bool ConstrainBooleanParameters::ToObjectInternal(JSContext* cx, JS::MutableHandle rval) const { ConstrainBooleanParametersAtoms* 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 (mExact.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); bool const & currentValue = mExact.InternalValue(); temp.setBoolean(currentValue); if (!JS_DefinePropertyById(cx, obj, atomsCache->exact_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mIdeal.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); bool const & currentValue = mIdeal.InternalValue(); temp.setBoolean(currentValue); if (!JS_DefinePropertyById(cx, obj, atomsCache->ideal_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } return true; } void ConstrainBooleanParameters::TraceDictionary(JSTracer* trc) { } ConstrainBooleanParameters& ConstrainBooleanParameters::operator=(const ConstrainBooleanParameters& aOther) { MaybeEmptyDictionaryBase::operator=(aOther); mExact.Reset(); if (aOther.mExact.WasPassed()) { mExact.Construct(aOther.mExact.Value()); } mIdeal.Reset(); if (aOther.mIdeal.WasPassed()) { mIdeal.Construct(aOther.mIdeal.Value()); } return *this; } ConstrainDOMStringParameters::ConstrainDOMStringParameters() { // Safe to pass a null context if we pass a null value Init(nullptr, JS::NullHandleValue); } bool ConstrainDOMStringParameters::InitIds(JSContext* cx, ConstrainDOMStringParametersAtoms* atomsCache) { MOZ_ASSERT(reinterpret_cast(atomsCache)->isVoid()); // Initialize these in reverse order so that any failure leaves the first one // uninitialized. if (!atomsCache->ideal_id.init(cx, "ideal") || !atomsCache->exact_id.init(cx, "exact")) { return false; } return true; } bool ConstrainDOMStringParameters::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()); ConstrainDOMStringParametersAtoms* 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->exact_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mExact.Construct(); if (!(mExact.Value()).Init(cx, temp.ref(), "'exact' member of ConstrainDOMStringParameters", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->ideal_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mIdeal.Construct(); if (!(mIdeal.Value()).Init(cx, temp.ref(), "'ideal' member of ConstrainDOMStringParameters", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } return true; } bool ConstrainDOMStringParameters::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); } bool ConstrainDOMStringParameters::ToObjectInternal(JSContext* cx, JS::MutableHandle rval) const { ConstrainDOMStringParametersAtoms* 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 (mExact.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningStringOrStringSequence const & currentValue = mExact.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->exact_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mIdeal.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningStringOrStringSequence const & currentValue = mIdeal.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->ideal_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } return true; } void ConstrainDOMStringParameters::TraceDictionary(JSTracer* trc) { } ConstrainDOMStringParameters& ConstrainDOMStringParameters::operator=(const ConstrainDOMStringParameters& aOther) { MaybeEmptyDictionaryBase::operator=(aOther); mExact.Reset(); if (aOther.mExact.WasPassed()) { mExact.Construct(aOther.mExact.Value()); } mIdeal.Reset(); if (aOther.mIdeal.WasPassed()) { mIdeal.Construct(aOther.mIdeal.Value()); } return *this; } ConstrainDoubleRange::ConstrainDoubleRange() { // Safe to pass a null context if we pass a null value Init(nullptr, JS::NullHandleValue); } bool ConstrainDoubleRange::InitIds(JSContext* cx, ConstrainDoubleRangeAtoms* atomsCache) { MOZ_ASSERT(reinterpret_cast(atomsCache)->isVoid()); // Initialize these in reverse order so that any failure leaves the first one // uninitialized. if (!atomsCache->min_id.init(cx, "min") || !atomsCache->max_id.init(cx, "max") || !atomsCache->ideal_id.init(cx, "ideal") || !atomsCache->exact_id.init(cx, "exact")) { return false; } return true; } bool ConstrainDoubleRange::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()); ConstrainDoubleRangeAtoms* 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->exact_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mExact.Construct(); if (!ValueToPrimitive(cx, temp.ref(), "'exact' member of ConstrainDoubleRange", &(mExact.Value()))) { return false; } else if (!std::isfinite((mExact.Value()))) { cx.ThrowErrorMessage("'exact' member of ConstrainDoubleRange"); return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->ideal_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mIdeal.Construct(); if (!ValueToPrimitive(cx, temp.ref(), "'ideal' member of ConstrainDoubleRange", &(mIdeal.Value()))) { return false; } else if (!std::isfinite((mIdeal.Value()))) { cx.ThrowErrorMessage("'ideal' member of ConstrainDoubleRange"); return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->max_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mMax.Construct(); if (!ValueToPrimitive(cx, temp.ref(), "'max' member of ConstrainDoubleRange", &(mMax.Value()))) { return false; } else if (!std::isfinite((mMax.Value()))) { cx.ThrowErrorMessage("'max' member of ConstrainDoubleRange"); return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->min_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mMin.Construct(); if (!ValueToPrimitive(cx, temp.ref(), "'min' member of ConstrainDoubleRange", &(mMin.Value()))) { return false; } else if (!std::isfinite((mMin.Value()))) { cx.ThrowErrorMessage("'min' member of ConstrainDoubleRange"); return false; } mIsAnyMemberPresent = true; } return true; } bool ConstrainDoubleRange::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); } bool ConstrainDoubleRange::ToObjectInternal(JSContext* cx, JS::MutableHandle rval) const { ConstrainDoubleRangeAtoms* 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 (mExact.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); double const & currentValue = mExact.InternalValue(); temp.set(JS::NumberValue(double(currentValue))); if (!JS_DefinePropertyById(cx, obj, atomsCache->exact_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mIdeal.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); double const & currentValue = mIdeal.InternalValue(); temp.set(JS::NumberValue(double(currentValue))); if (!JS_DefinePropertyById(cx, obj, atomsCache->ideal_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mMax.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); double const & currentValue = mMax.InternalValue(); temp.set(JS::NumberValue(double(currentValue))); if (!JS_DefinePropertyById(cx, obj, atomsCache->max_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mMin.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); double const & currentValue = mMin.InternalValue(); temp.set(JS::NumberValue(double(currentValue))); if (!JS_DefinePropertyById(cx, obj, atomsCache->min_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } return true; } void ConstrainDoubleRange::TraceDictionary(JSTracer* trc) { } ConstrainDoubleRange& ConstrainDoubleRange::operator=(const ConstrainDoubleRange& aOther) { MaybeEmptyDictionaryBase::operator=(aOther); mExact.Reset(); if (aOther.mExact.WasPassed()) { mExact.Construct(aOther.mExact.Value()); } mIdeal.Reset(); if (aOther.mIdeal.WasPassed()) { mIdeal.Construct(aOther.mIdeal.Value()); } mMax.Reset(); if (aOther.mMax.WasPassed()) { mMax.Construct(aOther.mMax.Value()); } mMin.Reset(); if (aOther.mMin.WasPassed()) { mMin.Construct(aOther.mMin.Value()); } return *this; } ConstrainLongRange::ConstrainLongRange() { // Safe to pass a null context if we pass a null value Init(nullptr, JS::NullHandleValue); } bool ConstrainLongRange::InitIds(JSContext* cx, ConstrainLongRangeAtoms* atomsCache) { MOZ_ASSERT(reinterpret_cast(atomsCache)->isVoid()); // Initialize these in reverse order so that any failure leaves the first one // uninitialized. if (!atomsCache->min_id.init(cx, "min") || !atomsCache->max_id.init(cx, "max") || !atomsCache->ideal_id.init(cx, "ideal") || !atomsCache->exact_id.init(cx, "exact")) { return false; } return true; } bool ConstrainLongRange::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()); ConstrainLongRangeAtoms* 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->exact_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mExact.Construct(); if (!ValueToPrimitive(cx, temp.ref(), "'exact' member of ConstrainLongRange", &(mExact.Value()))) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->ideal_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mIdeal.Construct(); if (!ValueToPrimitive(cx, temp.ref(), "'ideal' member of ConstrainLongRange", &(mIdeal.Value()))) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->max_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mMax.Construct(); if (!ValueToPrimitive(cx, temp.ref(), "'max' member of ConstrainLongRange", &(mMax.Value()))) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->min_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mMin.Construct(); if (!ValueToPrimitive(cx, temp.ref(), "'min' member of ConstrainLongRange", &(mMin.Value()))) { return false; } mIsAnyMemberPresent = true; } return true; } bool ConstrainLongRange::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); } bool ConstrainLongRange::ToObjectInternal(JSContext* cx, JS::MutableHandle rval) const { ConstrainLongRangeAtoms* 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 (mExact.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); int32_t const & currentValue = mExact.InternalValue(); temp.setInt32(int32_t(currentValue)); if (!JS_DefinePropertyById(cx, obj, atomsCache->exact_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mIdeal.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); int32_t const & currentValue = mIdeal.InternalValue(); temp.setInt32(int32_t(currentValue)); if (!JS_DefinePropertyById(cx, obj, atomsCache->ideal_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mMax.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); int32_t const & currentValue = mMax.InternalValue(); temp.setInt32(int32_t(currentValue)); if (!JS_DefinePropertyById(cx, obj, atomsCache->max_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mMin.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); int32_t const & currentValue = mMin.InternalValue(); temp.setInt32(int32_t(currentValue)); if (!JS_DefinePropertyById(cx, obj, atomsCache->min_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } return true; } void ConstrainLongRange::TraceDictionary(JSTracer* trc) { } ConstrainLongRange& ConstrainLongRange::operator=(const ConstrainLongRange& aOther) { MaybeEmptyDictionaryBase::operator=(aOther); mExact.Reset(); if (aOther.mExact.WasPassed()) { mExact.Construct(aOther.mExact.Value()); } mIdeal.Reset(); if (aOther.mIdeal.WasPassed()) { mIdeal.Construct(aOther.mIdeal.Value()); } mMax.Reset(); if (aOther.mMax.WasPassed()) { mMax.Construct(aOther.mMax.Value()); } mMin.Reset(); if (aOther.mMin.WasPassed()) { mMin.Construct(aOther.mMin.Value()); } return *this; } bool BooleanOrConstrainBooleanParameters::TrySetToBoolean(JSContext* cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot bool& memberSlot = RawSetAsBoolean(); if (!ValueToPrimitive(cx, value, "Boolean branch of (boolean or ConstrainBooleanParameters)", &memberSlot)) { return false; } } return true; } bool BooleanOrConstrainBooleanParameters::TrySetToConstrainBooleanParameters(BindingCallContext& cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot binding_detail::FastConstrainBooleanParameters& memberSlot = RawSetAsConstrainBooleanParameters(); if (!IsConvertibleToDictionary(value)) { DestroyConstrainBooleanParameters(); tryNext = true; return true; } if (!memberSlot.Init(cx, value, "ConstrainBooleanParameters branch of (boolean or ConstrainBooleanParameters)", passedToJSImpl)) { return false; } } return true; } bool BooleanOrConstrainBooleanParameters::TrySetToConstrainBooleanParameters(JSContext* cx_, JS::Handle value, bool& tryNext, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return TrySetToConstrainBooleanParameters(cx, value, tryNext, passedToJSImpl); } bool BooleanOrConstrainBooleanParameters::Init(BindingCallContext& cx, JS::Handle value, const char* sourceDescription, bool passedToJSImpl) { MOZ_ASSERT(mType == eUninitialized); bool done = false, failed = false, tryNext; if (!done) { done = (failed = !TrySetToConstrainBooleanParameters(cx, value, tryNext, passedToJSImpl)) || !tryNext; } if (!done) { do { done = (failed = !TrySetToBoolean(cx, value, tryNext)) || !tryNext; break; } while (false); } if (failed) { return false; } if (!done) { cx.ThrowErrorMessage(sourceDescription, "ConstrainBooleanParameters"); return false; } return true; } bool BooleanOrConstrainBooleanParameters::Init(JSContext* cx_, JS::Handle value, const char* sourceDescription, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return Init(cx, value, sourceDescription, passedToJSImpl); } bool BooleanOrConstrainBooleanParameters::ToJSVal(JSContext* cx, JS::Handle scopeObj, JS::MutableHandle rval) const { switch (mType) { case eUninitialized: { return false; } case eBoolean: { rval.setBoolean(mValue.mBoolean.Value()); return true; } case eConstrainBooleanParameters: { if (!mValue.mConstrainBooleanParameters.Value().ToObjectInternal(cx, rval)) { return false; } return true; } default: { return false; } } } OwningBooleanOrConstrainBooleanParameters::OwningBooleanOrConstrainBooleanParameters(OwningBooleanOrConstrainBooleanParameters&& aOther) : mType(eUninitialized) { switch (aOther.mType) { case eUninitialized: { MOZ_ASSERT(mType == eUninitialized, "We need to destroy ourselves?"); break; } case eBoolean: { mType = eBoolean; mValue.mBoolean.SetValue(std::move(aOther.mValue.mBoolean.Value())); break; } case eConstrainBooleanParameters: { mType = eConstrainBooleanParameters; mValue.mConstrainBooleanParameters.SetValue(std::move(aOther.mValue.mConstrainBooleanParameters.Value())); break; } } } bool OwningBooleanOrConstrainBooleanParameters::TrySetToBoolean(JSContext* cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot bool& memberSlot = RawSetAsBoolean(); if (!ValueToPrimitive(cx, value, "Boolean branch of (boolean or ConstrainBooleanParameters)", &memberSlot)) { return false; } } return true; } [[nodiscard]] bool& OwningBooleanOrConstrainBooleanParameters::RawSetAsBoolean() { if (mType == eBoolean) { return mValue.mBoolean.Value(); } MOZ_ASSERT(mType == eUninitialized); mType = eBoolean; return mValue.mBoolean.SetValue(); } [[nodiscard]] bool& OwningBooleanOrConstrainBooleanParameters::SetAsBoolean() { if (mType == eBoolean) { return mValue.mBoolean.Value(); } Uninit(); mType = eBoolean; return mValue.mBoolean.SetValue(); } void OwningBooleanOrConstrainBooleanParameters::DestroyBoolean() { MOZ_RELEASE_ASSERT(IsBoolean(), "Wrong type!"); mValue.mBoolean.Destroy(); mType = eUninitialized; } bool OwningBooleanOrConstrainBooleanParameters::TrySetToConstrainBooleanParameters(BindingCallContext& cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot ConstrainBooleanParameters& memberSlot = RawSetAsConstrainBooleanParameters(); if (!IsConvertibleToDictionary(value)) { DestroyConstrainBooleanParameters(); tryNext = true; return true; } if (!memberSlot.Init(cx, value, "ConstrainBooleanParameters branch of (boolean or ConstrainBooleanParameters)", passedToJSImpl)) { return false; } } return true; } bool OwningBooleanOrConstrainBooleanParameters::TrySetToConstrainBooleanParameters(JSContext* cx_, JS::Handle value, bool& tryNext, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return TrySetToConstrainBooleanParameters(cx, value, tryNext, passedToJSImpl); } [[nodiscard]] ConstrainBooleanParameters& OwningBooleanOrConstrainBooleanParameters::RawSetAsConstrainBooleanParameters() { if (mType == eConstrainBooleanParameters) { return mValue.mConstrainBooleanParameters.Value(); } MOZ_ASSERT(mType == eUninitialized); mType = eConstrainBooleanParameters; return mValue.mConstrainBooleanParameters.SetValue(); } [[nodiscard]] ConstrainBooleanParameters& OwningBooleanOrConstrainBooleanParameters::SetAsConstrainBooleanParameters() { if (mType == eConstrainBooleanParameters) { return mValue.mConstrainBooleanParameters.Value(); } Uninit(); mType = eConstrainBooleanParameters; return mValue.mConstrainBooleanParameters.SetValue(); } void OwningBooleanOrConstrainBooleanParameters::DestroyConstrainBooleanParameters() { MOZ_RELEASE_ASSERT(IsConstrainBooleanParameters(), "Wrong type!"); mValue.mConstrainBooleanParameters.Destroy(); mType = eUninitialized; } bool OwningBooleanOrConstrainBooleanParameters::Init(BindingCallContext& cx, JS::Handle value, const char* sourceDescription, bool passedToJSImpl) { MOZ_ASSERT(mType == eUninitialized); bool done = false, failed = false, tryNext; if (!done) { done = (failed = !TrySetToConstrainBooleanParameters(cx, value, tryNext, passedToJSImpl)) || !tryNext; } if (!done) { do { done = (failed = !TrySetToBoolean(cx, value, tryNext)) || !tryNext; break; } while (false); } if (failed) { return false; } if (!done) { cx.ThrowErrorMessage(sourceDescription, "ConstrainBooleanParameters"); return false; } return true; } bool OwningBooleanOrConstrainBooleanParameters::Init(JSContext* cx_, JS::Handle value, const char* sourceDescription, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return Init(cx, value, sourceDescription, passedToJSImpl); } void OwningBooleanOrConstrainBooleanParameters::Uninit() { switch (mType) { case eUninitialized: { break; } case eBoolean: { DestroyBoolean(); break; } case eConstrainBooleanParameters: { DestroyConstrainBooleanParameters(); break; } } } bool OwningBooleanOrConstrainBooleanParameters::ToJSVal(JSContext* cx, JS::Handle scopeObj, JS::MutableHandle rval) const { switch (mType) { case eUninitialized: { return false; } case eBoolean: { rval.setBoolean(mValue.mBoolean.Value()); return true; } case eConstrainBooleanParameters: { if (!mValue.mConstrainBooleanParameters.Value().ToObjectInternal(cx, rval)) { return false; } return true; } default: { return false; } } } OwningBooleanOrConstrainBooleanParameters& OwningBooleanOrConstrainBooleanParameters::operator=(OwningBooleanOrConstrainBooleanParameters&& aOther) { this->~OwningBooleanOrConstrainBooleanParameters(); new (this) OwningBooleanOrConstrainBooleanParameters (std::move(aOther)); return *this; } OwningBooleanOrConstrainBooleanParameters& OwningBooleanOrConstrainBooleanParameters::operator=(const OwningBooleanOrConstrainBooleanParameters& aOther) { switch (aOther.mType) { case eUninitialized: { MOZ_ASSERT(mType == eUninitialized, "We need to destroy ourselves?"); break; } case eBoolean: { SetAsBoolean() = aOther.GetAsBoolean(); break; } case eConstrainBooleanParameters: { SetAsConstrainBooleanParameters() = aOther.GetAsConstrainBooleanParameters(); break; } } return *this; } bool DoubleOrConstrainDoubleRange::TrySetToDouble(BindingCallContext& cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot double& memberSlot = RawSetAsDouble(); if (!ValueToPrimitive(cx, value, "Double branch of (double or ConstrainDoubleRange)", &memberSlot)) { return false; } else if (!std::isfinite(memberSlot)) { cx.ThrowErrorMessage("Double branch of (double or ConstrainDoubleRange)"); return false; } } return true; } bool DoubleOrConstrainDoubleRange::TrySetToDouble(JSContext* cx_, JS::Handle value, bool& tryNext, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return TrySetToDouble(cx, value, tryNext, passedToJSImpl); } bool DoubleOrConstrainDoubleRange::TrySetToConstrainDoubleRange(BindingCallContext& cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot binding_detail::FastConstrainDoubleRange& memberSlot = RawSetAsConstrainDoubleRange(); if (!IsConvertibleToDictionary(value)) { DestroyConstrainDoubleRange(); tryNext = true; return true; } if (!memberSlot.Init(cx, value, "ConstrainDoubleRange branch of (double or ConstrainDoubleRange)", passedToJSImpl)) { return false; } } return true; } bool DoubleOrConstrainDoubleRange::TrySetToConstrainDoubleRange(JSContext* cx_, JS::Handle value, bool& tryNext, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return TrySetToConstrainDoubleRange(cx, value, tryNext, passedToJSImpl); } bool DoubleOrConstrainDoubleRange::Init(BindingCallContext& cx, JS::Handle value, const char* sourceDescription, bool passedToJSImpl) { MOZ_ASSERT(mType == eUninitialized); bool done = false, failed = false, tryNext; if (!done) { done = (failed = !TrySetToConstrainDoubleRange(cx, value, tryNext, passedToJSImpl)) || !tryNext; } if (!done) { do { done = (failed = !TrySetToDouble(cx, value, tryNext)) || !tryNext; break; } while (false); } if (failed) { return false; } if (!done) { cx.ThrowErrorMessage(sourceDescription, "ConstrainDoubleRange"); return false; } return true; } bool DoubleOrConstrainDoubleRange::Init(JSContext* cx_, JS::Handle value, const char* sourceDescription, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return Init(cx, value, sourceDescription, passedToJSImpl); } bool DoubleOrConstrainDoubleRange::ToJSVal(JSContext* cx, JS::Handle scopeObj, JS::MutableHandle rval) const { switch (mType) { case eUninitialized: { return false; } case eDouble: { rval.set(JS::NumberValue(double(mValue.mDouble.Value()))); return true; } case eConstrainDoubleRange: { if (!mValue.mConstrainDoubleRange.Value().ToObjectInternal(cx, rval)) { return false; } return true; } default: { return false; } } } OwningDoubleOrConstrainDoubleRange::OwningDoubleOrConstrainDoubleRange(OwningDoubleOrConstrainDoubleRange&& aOther) : mType(eUninitialized) { switch (aOther.mType) { case eUninitialized: { MOZ_ASSERT(mType == eUninitialized, "We need to destroy ourselves?"); break; } case eDouble: { mType = eDouble; mValue.mDouble.SetValue(std::move(aOther.mValue.mDouble.Value())); break; } case eConstrainDoubleRange: { mType = eConstrainDoubleRange; mValue.mConstrainDoubleRange.SetValue(std::move(aOther.mValue.mConstrainDoubleRange.Value())); break; } } } bool OwningDoubleOrConstrainDoubleRange::TrySetToDouble(BindingCallContext& cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot double& memberSlot = RawSetAsDouble(); if (!ValueToPrimitive(cx, value, "Double branch of (double or ConstrainDoubleRange)", &memberSlot)) { return false; } else if (!std::isfinite(memberSlot)) { cx.ThrowErrorMessage("Double branch of (double or ConstrainDoubleRange)"); return false; } } return true; } bool OwningDoubleOrConstrainDoubleRange::TrySetToDouble(JSContext* cx_, JS::Handle value, bool& tryNext, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return TrySetToDouble(cx, value, tryNext, passedToJSImpl); } [[nodiscard]] double& OwningDoubleOrConstrainDoubleRange::RawSetAsDouble() { if (mType == eDouble) { return mValue.mDouble.Value(); } MOZ_ASSERT(mType == eUninitialized); mType = eDouble; return mValue.mDouble.SetValue(); } [[nodiscard]] double& OwningDoubleOrConstrainDoubleRange::SetAsDouble() { if (mType == eDouble) { return mValue.mDouble.Value(); } Uninit(); mType = eDouble; return mValue.mDouble.SetValue(); } void OwningDoubleOrConstrainDoubleRange::DestroyDouble() { MOZ_RELEASE_ASSERT(IsDouble(), "Wrong type!"); mValue.mDouble.Destroy(); mType = eUninitialized; } bool OwningDoubleOrConstrainDoubleRange::TrySetToConstrainDoubleRange(BindingCallContext& cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot ConstrainDoubleRange& memberSlot = RawSetAsConstrainDoubleRange(); if (!IsConvertibleToDictionary(value)) { DestroyConstrainDoubleRange(); tryNext = true; return true; } if (!memberSlot.Init(cx, value, "ConstrainDoubleRange branch of (double or ConstrainDoubleRange)", passedToJSImpl)) { return false; } } return true; } bool OwningDoubleOrConstrainDoubleRange::TrySetToConstrainDoubleRange(JSContext* cx_, JS::Handle value, bool& tryNext, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return TrySetToConstrainDoubleRange(cx, value, tryNext, passedToJSImpl); } [[nodiscard]] ConstrainDoubleRange& OwningDoubleOrConstrainDoubleRange::RawSetAsConstrainDoubleRange() { if (mType == eConstrainDoubleRange) { return mValue.mConstrainDoubleRange.Value(); } MOZ_ASSERT(mType == eUninitialized); mType = eConstrainDoubleRange; return mValue.mConstrainDoubleRange.SetValue(); } [[nodiscard]] ConstrainDoubleRange& OwningDoubleOrConstrainDoubleRange::SetAsConstrainDoubleRange() { if (mType == eConstrainDoubleRange) { return mValue.mConstrainDoubleRange.Value(); } Uninit(); mType = eConstrainDoubleRange; return mValue.mConstrainDoubleRange.SetValue(); } void OwningDoubleOrConstrainDoubleRange::DestroyConstrainDoubleRange() { MOZ_RELEASE_ASSERT(IsConstrainDoubleRange(), "Wrong type!"); mValue.mConstrainDoubleRange.Destroy(); mType = eUninitialized; } bool OwningDoubleOrConstrainDoubleRange::Init(BindingCallContext& cx, JS::Handle value, const char* sourceDescription, bool passedToJSImpl) { MOZ_ASSERT(mType == eUninitialized); bool done = false, failed = false, tryNext; if (!done) { done = (failed = !TrySetToConstrainDoubleRange(cx, value, tryNext, passedToJSImpl)) || !tryNext; } if (!done) { do { done = (failed = !TrySetToDouble(cx, value, tryNext)) || !tryNext; break; } while (false); } if (failed) { return false; } if (!done) { cx.ThrowErrorMessage(sourceDescription, "ConstrainDoubleRange"); return false; } return true; } bool OwningDoubleOrConstrainDoubleRange::Init(JSContext* cx_, JS::Handle value, const char* sourceDescription, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return Init(cx, value, sourceDescription, passedToJSImpl); } void OwningDoubleOrConstrainDoubleRange::Uninit() { switch (mType) { case eUninitialized: { break; } case eDouble: { DestroyDouble(); break; } case eConstrainDoubleRange: { DestroyConstrainDoubleRange(); break; } } } bool OwningDoubleOrConstrainDoubleRange::ToJSVal(JSContext* cx, JS::Handle scopeObj, JS::MutableHandle rval) const { switch (mType) { case eUninitialized: { return false; } case eDouble: { rval.set(JS::NumberValue(double(mValue.mDouble.Value()))); return true; } case eConstrainDoubleRange: { if (!mValue.mConstrainDoubleRange.Value().ToObjectInternal(cx, rval)) { return false; } return true; } default: { return false; } } } OwningDoubleOrConstrainDoubleRange& OwningDoubleOrConstrainDoubleRange::operator=(OwningDoubleOrConstrainDoubleRange&& aOther) { this->~OwningDoubleOrConstrainDoubleRange(); new (this) OwningDoubleOrConstrainDoubleRange (std::move(aOther)); return *this; } OwningDoubleOrConstrainDoubleRange& OwningDoubleOrConstrainDoubleRange::operator=(const OwningDoubleOrConstrainDoubleRange& aOther) { switch (aOther.mType) { case eUninitialized: { MOZ_ASSERT(mType == eUninitialized, "We need to destroy ourselves?"); break; } case eDouble: { SetAsDouble() = aOther.GetAsDouble(); break; } case eConstrainDoubleRange: { SetAsConstrainDoubleRange() = aOther.GetAsConstrainDoubleRange(); break; } } return *this; } bool LongOrConstrainLongRange::TrySetToLong(JSContext* cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot int32_t& memberSlot = RawSetAsLong(); if (!ValueToPrimitive(cx, value, "Long branch of (long or ConstrainLongRange)", &memberSlot)) { return false; } } return true; } bool LongOrConstrainLongRange::TrySetToConstrainLongRange(BindingCallContext& cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot binding_detail::FastConstrainLongRange& memberSlot = RawSetAsConstrainLongRange(); if (!IsConvertibleToDictionary(value)) { DestroyConstrainLongRange(); tryNext = true; return true; } if (!memberSlot.Init(cx, value, "ConstrainLongRange branch of (long or ConstrainLongRange)", passedToJSImpl)) { return false; } } return true; } bool LongOrConstrainLongRange::TrySetToConstrainLongRange(JSContext* cx_, JS::Handle value, bool& tryNext, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return TrySetToConstrainLongRange(cx, value, tryNext, passedToJSImpl); } bool LongOrConstrainLongRange::Init(BindingCallContext& cx, JS::Handle value, const char* sourceDescription, bool passedToJSImpl) { MOZ_ASSERT(mType == eUninitialized); bool done = false, failed = false, tryNext; if (!done) { done = (failed = !TrySetToConstrainLongRange(cx, value, tryNext, passedToJSImpl)) || !tryNext; } if (!done) { do { done = (failed = !TrySetToLong(cx, value, tryNext)) || !tryNext; break; } while (false); } if (failed) { return false; } if (!done) { cx.ThrowErrorMessage(sourceDescription, "ConstrainLongRange"); return false; } return true; } bool LongOrConstrainLongRange::Init(JSContext* cx_, JS::Handle value, const char* sourceDescription, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return Init(cx, value, sourceDescription, passedToJSImpl); } bool LongOrConstrainLongRange::ToJSVal(JSContext* cx, JS::Handle scopeObj, JS::MutableHandle rval) const { switch (mType) { case eUninitialized: { return false; } case eLong: { rval.setInt32(int32_t(mValue.mLong.Value())); return true; } case eConstrainLongRange: { if (!mValue.mConstrainLongRange.Value().ToObjectInternal(cx, rval)) { return false; } return true; } default: { return false; } } } OwningLongOrConstrainLongRange::OwningLongOrConstrainLongRange(OwningLongOrConstrainLongRange&& aOther) : mType(eUninitialized) { switch (aOther.mType) { case eUninitialized: { MOZ_ASSERT(mType == eUninitialized, "We need to destroy ourselves?"); break; } case eLong: { mType = eLong; mValue.mLong.SetValue(std::move(aOther.mValue.mLong.Value())); break; } case eConstrainLongRange: { mType = eConstrainLongRange; mValue.mConstrainLongRange.SetValue(std::move(aOther.mValue.mConstrainLongRange.Value())); break; } } } bool OwningLongOrConstrainLongRange::TrySetToLong(JSContext* cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot int32_t& memberSlot = RawSetAsLong(); if (!ValueToPrimitive(cx, value, "Long branch of (long or ConstrainLongRange)", &memberSlot)) { return false; } } return true; } [[nodiscard]] int32_t& OwningLongOrConstrainLongRange::RawSetAsLong() { if (mType == eLong) { return mValue.mLong.Value(); } MOZ_ASSERT(mType == eUninitialized); mType = eLong; return mValue.mLong.SetValue(); } [[nodiscard]] int32_t& OwningLongOrConstrainLongRange::SetAsLong() { if (mType == eLong) { return mValue.mLong.Value(); } Uninit(); mType = eLong; return mValue.mLong.SetValue(); } void OwningLongOrConstrainLongRange::DestroyLong() { MOZ_RELEASE_ASSERT(IsLong(), "Wrong type!"); mValue.mLong.Destroy(); mType = eUninitialized; } bool OwningLongOrConstrainLongRange::TrySetToConstrainLongRange(BindingCallContext& cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot ConstrainLongRange& memberSlot = RawSetAsConstrainLongRange(); if (!IsConvertibleToDictionary(value)) { DestroyConstrainLongRange(); tryNext = true; return true; } if (!memberSlot.Init(cx, value, "ConstrainLongRange branch of (long or ConstrainLongRange)", passedToJSImpl)) { return false; } } return true; } bool OwningLongOrConstrainLongRange::TrySetToConstrainLongRange(JSContext* cx_, JS::Handle value, bool& tryNext, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return TrySetToConstrainLongRange(cx, value, tryNext, passedToJSImpl); } [[nodiscard]] ConstrainLongRange& OwningLongOrConstrainLongRange::RawSetAsConstrainLongRange() { if (mType == eConstrainLongRange) { return mValue.mConstrainLongRange.Value(); } MOZ_ASSERT(mType == eUninitialized); mType = eConstrainLongRange; return mValue.mConstrainLongRange.SetValue(); } [[nodiscard]] ConstrainLongRange& OwningLongOrConstrainLongRange::SetAsConstrainLongRange() { if (mType == eConstrainLongRange) { return mValue.mConstrainLongRange.Value(); } Uninit(); mType = eConstrainLongRange; return mValue.mConstrainLongRange.SetValue(); } void OwningLongOrConstrainLongRange::DestroyConstrainLongRange() { MOZ_RELEASE_ASSERT(IsConstrainLongRange(), "Wrong type!"); mValue.mConstrainLongRange.Destroy(); mType = eUninitialized; } bool OwningLongOrConstrainLongRange::Init(BindingCallContext& cx, JS::Handle value, const char* sourceDescription, bool passedToJSImpl) { MOZ_ASSERT(mType == eUninitialized); bool done = false, failed = false, tryNext; if (!done) { done = (failed = !TrySetToConstrainLongRange(cx, value, tryNext, passedToJSImpl)) || !tryNext; } if (!done) { do { done = (failed = !TrySetToLong(cx, value, tryNext)) || !tryNext; break; } while (false); } if (failed) { return false; } if (!done) { cx.ThrowErrorMessage(sourceDescription, "ConstrainLongRange"); return false; } return true; } bool OwningLongOrConstrainLongRange::Init(JSContext* cx_, JS::Handle value, const char* sourceDescription, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return Init(cx, value, sourceDescription, passedToJSImpl); } void OwningLongOrConstrainLongRange::Uninit() { switch (mType) { case eUninitialized: { break; } case eLong: { DestroyLong(); break; } case eConstrainLongRange: { DestroyConstrainLongRange(); break; } } } bool OwningLongOrConstrainLongRange::ToJSVal(JSContext* cx, JS::Handle scopeObj, JS::MutableHandle rval) const { switch (mType) { case eUninitialized: { return false; } case eLong: { rval.setInt32(int32_t(mValue.mLong.Value())); return true; } case eConstrainLongRange: { if (!mValue.mConstrainLongRange.Value().ToObjectInternal(cx, rval)) { return false; } return true; } default: { return false; } } } OwningLongOrConstrainLongRange& OwningLongOrConstrainLongRange::operator=(OwningLongOrConstrainLongRange&& aOther) { this->~OwningLongOrConstrainLongRange(); new (this) OwningLongOrConstrainLongRange (std::move(aOther)); return *this; } OwningLongOrConstrainLongRange& OwningLongOrConstrainLongRange::operator=(const OwningLongOrConstrainLongRange& aOther) { switch (aOther.mType) { case eUninitialized: { MOZ_ASSERT(mType == eUninitialized, "We need to destroy ourselves?"); break; } case eLong: { SetAsLong() = aOther.GetAsLong(); break; } case eConstrainLongRange: { SetAsConstrainLongRange() = aOther.GetAsConstrainLongRange(); break; } } return *this; } bool StringOrStringSequenceOrConstrainDOMStringParameters::TrySetToString(JSContext* cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot nsAutoString& memberSlot = RawSetAsString(); if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) { return false; } } return true; } bool StringOrStringSequenceOrConstrainDOMStringParameters::TrySetToStringSequence(BindingCallContext& cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot binding_detail::AutoSequence& memberSlot = RawSetAsStringSequence(); JS::ForOfIterator iter(cx); if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) { return false; } if (!iter.valueIsIterable()) { DestroyStringSequence(); tryNext = true; return true; } binding_detail::AutoSequence &arr = memberSlot; 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; } nsString* slotPtr = arr.AppendElement(mozilla::fallible); if (!slotPtr) { JS_ReportOutOfMemory(cx); return false; } nsString& slot = *slotPtr; if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) { return false; } } } return true; } bool StringOrStringSequenceOrConstrainDOMStringParameters::TrySetToStringSequence(JSContext* cx_, JS::Handle value, bool& tryNext, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return TrySetToStringSequence(cx, value, tryNext, passedToJSImpl); } bool StringOrStringSequenceOrConstrainDOMStringParameters::TrySetToConstrainDOMStringParameters(BindingCallContext& cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot binding_detail::FastConstrainDOMStringParameters& memberSlot = RawSetAsConstrainDOMStringParameters(); if (!IsConvertibleToDictionary(value)) { DestroyConstrainDOMStringParameters(); tryNext = true; return true; } if (!memberSlot.Init(cx, value, "ConstrainDOMStringParameters branch of (DOMString or sequence or ConstrainDOMStringParameters)", passedToJSImpl)) { return false; } } return true; } bool StringOrStringSequenceOrConstrainDOMStringParameters::TrySetToConstrainDOMStringParameters(JSContext* cx_, JS::Handle value, bool& tryNext, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return TrySetToConstrainDOMStringParameters(cx, value, tryNext, passedToJSImpl); } bool StringOrStringSequenceOrConstrainDOMStringParameters::Init(BindingCallContext& cx, JS::Handle value, const char* sourceDescription, bool passedToJSImpl) { MOZ_ASSERT(mType == eUninitialized); bool done = false, failed = false, tryNext; if (value.isObject()) { done = (failed = !TrySetToStringSequence(cx, value, tryNext, passedToJSImpl)) || !tryNext; } if (!done) { done = (failed = !TrySetToConstrainDOMStringParameters(cx, value, tryNext, passedToJSImpl)) || !tryNext; } if (!done) { do { done = (failed = !TrySetToString(cx, value, tryNext)) || !tryNext; break; } while (false); } if (failed) { return false; } if (!done) { cx.ThrowErrorMessage(sourceDescription, "sequence, ConstrainDOMStringParameters"); return false; } return true; } bool StringOrStringSequenceOrConstrainDOMStringParameters::Init(JSContext* cx_, JS::Handle value, const char* sourceDescription, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return Init(cx, value, sourceDescription, passedToJSImpl); } bool StringOrStringSequenceOrConstrainDOMStringParameters::ToJSVal(JSContext* cx, JS::Handle scopeObj, JS::MutableHandle rval) const { switch (mType) { case eUninitialized: { return false; } case eString: { if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) { return false; } return true; } case eStringSequence: { uint32_t length = mValue.mStringSequence.Value().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 (!xpc::NonVoidStringToJsval(cx, mValue.mStringSequence.Value()[sequenceIdx0], &tmp)) { return false; } break; } while (false); if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, JSPROP_ENUMERATE)) { return false; } } } rval.setObject(*returnArray); return true; } case eConstrainDOMStringParameters: { if (!mValue.mConstrainDOMStringParameters.Value().ToObjectInternal(cx, rval)) { return false; } return true; } default: { return false; } } } OwningStringOrStringSequenceOrConstrainDOMStringParameters::OwningStringOrStringSequenceOrConstrainDOMStringParameters(OwningStringOrStringSequenceOrConstrainDOMStringParameters&& aOther) : mType(eUninitialized) { switch (aOther.mType) { case eUninitialized: { MOZ_ASSERT(mType == eUninitialized, "We need to destroy ourselves?"); break; } case eString: { mType = eString; mValue.mString.SetValue(std::move(aOther.mValue.mString.Value())); break; } case eStringSequence: { mType = eStringSequence; mValue.mStringSequence.SetValue(std::move(aOther.mValue.mStringSequence.Value())); break; } case eConstrainDOMStringParameters: { mType = eConstrainDOMStringParameters; mValue.mConstrainDOMStringParameters.SetValue(std::move(aOther.mValue.mConstrainDOMStringParameters.Value())); break; } } } bool OwningStringOrStringSequenceOrConstrainDOMStringParameters::TrySetToString(JSContext* cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot nsString& memberSlot = RawSetAsString(); if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) { return false; } } return true; } [[nodiscard]] nsString& OwningStringOrStringSequenceOrConstrainDOMStringParameters::RawSetAsString() { if (mType == eString) { return mValue.mString.Value(); } MOZ_ASSERT(mType == eUninitialized); mType = eString; return mValue.mString.SetValue(); } [[nodiscard]] nsString& OwningStringOrStringSequenceOrConstrainDOMStringParameters::SetAsString() { if (mType == eString) { return mValue.mString.Value(); } Uninit(); mType = eString; return mValue.mString.SetValue(); } void OwningStringOrStringSequenceOrConstrainDOMStringParameters::DestroyString() { MOZ_RELEASE_ASSERT(IsString(), "Wrong type!"); mValue.mString.Destroy(); mType = eUninitialized; } bool OwningStringOrStringSequenceOrConstrainDOMStringParameters::TrySetToStringSequence(BindingCallContext& cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot Sequence& memberSlot = RawSetAsStringSequence(); JS::ForOfIterator iter(cx); if (!iter.init(value, JS::ForOfIterator::AllowNonIterable)) { return false; } if (!iter.valueIsIterable()) { DestroyStringSequence(); tryNext = true; return true; } Sequence &arr = memberSlot; 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; } nsString* slotPtr = arr.AppendElement(mozilla::fallible); if (!slotPtr) { JS_ReportOutOfMemory(cx); return false; } nsString& slot = *slotPtr; if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) { return false; } } } return true; } bool OwningStringOrStringSequenceOrConstrainDOMStringParameters::TrySetToStringSequence(JSContext* cx_, JS::Handle value, bool& tryNext, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return TrySetToStringSequence(cx, value, tryNext, passedToJSImpl); } [[nodiscard]] Sequence& OwningStringOrStringSequenceOrConstrainDOMStringParameters::RawSetAsStringSequence() { if (mType == eStringSequence) { return mValue.mStringSequence.Value(); } MOZ_ASSERT(mType == eUninitialized); mType = eStringSequence; return mValue.mStringSequence.SetValue(); } [[nodiscard]] Sequence& OwningStringOrStringSequenceOrConstrainDOMStringParameters::SetAsStringSequence() { if (mType == eStringSequence) { return mValue.mStringSequence.Value(); } Uninit(); mType = eStringSequence; return mValue.mStringSequence.SetValue(); } void OwningStringOrStringSequenceOrConstrainDOMStringParameters::DestroyStringSequence() { MOZ_RELEASE_ASSERT(IsStringSequence(), "Wrong type!"); mValue.mStringSequence.Destroy(); mType = eUninitialized; } bool OwningStringOrStringSequenceOrConstrainDOMStringParameters::TrySetToConstrainDOMStringParameters(BindingCallContext& cx, JS::Handle value, bool& tryNext, bool passedToJSImpl) { tryNext = false; { // scope for memberSlot ConstrainDOMStringParameters& memberSlot = RawSetAsConstrainDOMStringParameters(); if (!IsConvertibleToDictionary(value)) { DestroyConstrainDOMStringParameters(); tryNext = true; return true; } if (!memberSlot.Init(cx, value, "ConstrainDOMStringParameters branch of (DOMString or sequence or ConstrainDOMStringParameters)", passedToJSImpl)) { return false; } } return true; } bool OwningStringOrStringSequenceOrConstrainDOMStringParameters::TrySetToConstrainDOMStringParameters(JSContext* cx_, JS::Handle value, bool& tryNext, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return TrySetToConstrainDOMStringParameters(cx, value, tryNext, passedToJSImpl); } [[nodiscard]] ConstrainDOMStringParameters& OwningStringOrStringSequenceOrConstrainDOMStringParameters::RawSetAsConstrainDOMStringParameters() { if (mType == eConstrainDOMStringParameters) { return mValue.mConstrainDOMStringParameters.Value(); } MOZ_ASSERT(mType == eUninitialized); mType = eConstrainDOMStringParameters; return mValue.mConstrainDOMStringParameters.SetValue(); } [[nodiscard]] ConstrainDOMStringParameters& OwningStringOrStringSequenceOrConstrainDOMStringParameters::SetAsConstrainDOMStringParameters() { if (mType == eConstrainDOMStringParameters) { return mValue.mConstrainDOMStringParameters.Value(); } Uninit(); mType = eConstrainDOMStringParameters; return mValue.mConstrainDOMStringParameters.SetValue(); } void OwningStringOrStringSequenceOrConstrainDOMStringParameters::DestroyConstrainDOMStringParameters() { MOZ_RELEASE_ASSERT(IsConstrainDOMStringParameters(), "Wrong type!"); mValue.mConstrainDOMStringParameters.Destroy(); mType = eUninitialized; } bool OwningStringOrStringSequenceOrConstrainDOMStringParameters::Init(BindingCallContext& cx, JS::Handle value, const char* sourceDescription, bool passedToJSImpl) { MOZ_ASSERT(mType == eUninitialized); bool done = false, failed = false, tryNext; if (value.isObject()) { done = (failed = !TrySetToStringSequence(cx, value, tryNext, passedToJSImpl)) || !tryNext; } if (!done) { done = (failed = !TrySetToConstrainDOMStringParameters(cx, value, tryNext, passedToJSImpl)) || !tryNext; } if (!done) { do { done = (failed = !TrySetToString(cx, value, tryNext)) || !tryNext; break; } while (false); } if (failed) { return false; } if (!done) { cx.ThrowErrorMessage(sourceDescription, "sequence, ConstrainDOMStringParameters"); return false; } return true; } bool OwningStringOrStringSequenceOrConstrainDOMStringParameters::Init(JSContext* cx_, JS::Handle value, const char* sourceDescription, bool passedToJSImpl) { BindingCallContext cx(cx_, nullptr); return Init(cx, value, sourceDescription, passedToJSImpl); } void OwningStringOrStringSequenceOrConstrainDOMStringParameters::Uninit() { switch (mType) { case eUninitialized: { break; } case eString: { DestroyString(); break; } case eStringSequence: { DestroyStringSequence(); break; } case eConstrainDOMStringParameters: { DestroyConstrainDOMStringParameters(); break; } } } bool OwningStringOrStringSequenceOrConstrainDOMStringParameters::ToJSVal(JSContext* cx, JS::Handle scopeObj, JS::MutableHandle rval) const { switch (mType) { case eUninitialized: { return false; } case eString: { if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) { return false; } return true; } case eStringSequence: { uint32_t length = mValue.mStringSequence.Value().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 (!xpc::NonVoidStringToJsval(cx, mValue.mStringSequence.Value()[sequenceIdx0], &tmp)) { return false; } break; } while (false); if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, JSPROP_ENUMERATE)) { return false; } } } rval.setObject(*returnArray); return true; } case eConstrainDOMStringParameters: { if (!mValue.mConstrainDOMStringParameters.Value().ToObjectInternal(cx, rval)) { return false; } return true; } default: { return false; } } } OwningStringOrStringSequenceOrConstrainDOMStringParameters& OwningStringOrStringSequenceOrConstrainDOMStringParameters::operator=(OwningStringOrStringSequenceOrConstrainDOMStringParameters&& aOther) { this->~OwningStringOrStringSequenceOrConstrainDOMStringParameters(); new (this) OwningStringOrStringSequenceOrConstrainDOMStringParameters (std::move(aOther)); return *this; } OwningStringOrStringSequenceOrConstrainDOMStringParameters& OwningStringOrStringSequenceOrConstrainDOMStringParameters::operator=(const OwningStringOrStringSequenceOrConstrainDOMStringParameters& aOther) { switch (aOther.mType) { case eUninitialized: { MOZ_ASSERT(mType == eUninitialized, "We need to destroy ourselves?"); break; } case eString: { SetAsString() = aOther.GetAsString(); break; } case eStringSequence: { SetAsStringSequence() = aOther.GetAsStringSequence(); break; } case eConstrainDOMStringParameters: { SetAsConstrainDOMStringParameters() = aOther.GetAsConstrainDOMStringParameters(); break; } } return *this; } MediaTrackConstraintSet::MediaTrackConstraintSet() { // Safe to pass a null context if we pass a null value Init(nullptr, JS::NullHandleValue); } bool MediaTrackConstraintSet::InitIds(JSContext* cx, MediaTrackConstraintSetAtoms* atomsCache) { MOZ_ASSERT(reinterpret_cast(atomsCache)->isVoid()); // Initialize these in reverse order so that any failure leaves the first one // uninitialized. if (!atomsCache->width_id.init(cx, "width") || !atomsCache->viewportWidth_id.init(cx, "viewportWidth") || !atomsCache->viewportOffsetY_id.init(cx, "viewportOffsetY") || !atomsCache->viewportOffsetX_id.init(cx, "viewportOffsetX") || !atomsCache->viewportHeight_id.init(cx, "viewportHeight") || !atomsCache->scrollWithPage_id.init(cx, "scrollWithPage") || !atomsCache->resizeMode_id.init(cx, "resizeMode") || !atomsCache->noiseSuppression_id.init(cx, "noiseSuppression") || !atomsCache->mediaSource_id.init(cx, "mediaSource") || !atomsCache->height_id.init(cx, "height") || !atomsCache->groupId_id.init(cx, "groupId") || !atomsCache->frameRate_id.init(cx, "frameRate") || !atomsCache->facingMode_id.init(cx, "facingMode") || !atomsCache->echoCancellation_id.init(cx, "echoCancellation") || !atomsCache->deviceId_id.init(cx, "deviceId") || !atomsCache->channelCount_id.init(cx, "channelCount") || !atomsCache->browserWindow_id.init(cx, "browserWindow") || !atomsCache->autoGainControl_id.init(cx, "autoGainControl")) { return false; } return true; } bool MediaTrackConstraintSet::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()); MediaTrackConstraintSetAtoms* 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->autoGainControl_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mAutoGainControl.Construct(); if (!(mAutoGainControl.Value()).Init(cx, temp.ref(), "'autoGainControl' member of MediaTrackConstraintSet", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->browserWindow_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mBrowserWindow.Construct(); if (!ValueToPrimitive(cx, temp.ref(), "'browserWindow' member of MediaTrackConstraintSet", &(mBrowserWindow.Value()))) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->channelCount_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mChannelCount.Construct(); if (!(mChannelCount.Value()).Init(cx, temp.ref(), "'channelCount' member of MediaTrackConstraintSet", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->deviceId_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mDeviceId.Construct(); if (!(mDeviceId.Value()).Init(cx, temp.ref(), "'deviceId' member of MediaTrackConstraintSet", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->echoCancellation_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mEchoCancellation.Construct(); if (!(mEchoCancellation.Value()).Init(cx, temp.ref(), "'echoCancellation' member of MediaTrackConstraintSet", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->facingMode_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mFacingMode.Construct(); if (!(mFacingMode.Value()).Init(cx, temp.ref(), "'facingMode' member of MediaTrackConstraintSet", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->frameRate_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mFrameRate.Construct(); if (!(mFrameRate.Value()).Init(cx, temp.ref(), "'frameRate' member of MediaTrackConstraintSet", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->groupId_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mGroupId.Construct(); if (!(mGroupId.Value()).Init(cx, temp.ref(), "'groupId' member of MediaTrackConstraintSet", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->height_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mHeight.Construct(); if (!(mHeight.Value()).Init(cx, temp.ref(), "'height' member of MediaTrackConstraintSet", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->mediaSource_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mMediaSource.Construct(); if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mMediaSource.Value()))) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->noiseSuppression_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mNoiseSuppression.Construct(); if (!(mNoiseSuppression.Value()).Init(cx, temp.ref(), "'noiseSuppression' member of MediaTrackConstraintSet", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->resizeMode_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mResizeMode.Construct(); if (!(mResizeMode.Value()).Init(cx, temp.ref(), "'resizeMode' member of MediaTrackConstraintSet", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->scrollWithPage_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mScrollWithPage.Construct(); if (!ValueToPrimitive(cx, temp.ref(), "'scrollWithPage' member of MediaTrackConstraintSet", &(mScrollWithPage.Value()))) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->viewportHeight_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mViewportHeight.Construct(); if (!(mViewportHeight.Value()).Init(cx, temp.ref(), "'viewportHeight' member of MediaTrackConstraintSet", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->viewportOffsetX_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mViewportOffsetX.Construct(); if (!(mViewportOffsetX.Value()).Init(cx, temp.ref(), "'viewportOffsetX' member of MediaTrackConstraintSet", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->viewportOffsetY_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mViewportOffsetY.Construct(); if (!(mViewportOffsetY.Value()).Init(cx, temp.ref(), "'viewportOffsetY' member of MediaTrackConstraintSet", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->viewportWidth_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mViewportWidth.Construct(); if (!(mViewportWidth.Value()).Init(cx, temp.ref(), "'viewportWidth' member of MediaTrackConstraintSet", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } if (!isNull) { if (!JS_GetPropertyById(cx, *object, atomsCache->width_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mWidth.Construct(); if (!(mWidth.Value()).Init(cx, temp.ref(), "'width' member of MediaTrackConstraintSet", passedToJSImpl)) { return false; } mIsAnyMemberPresent = true; } return true; } bool MediaTrackConstraintSet::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); } bool MediaTrackConstraintSet::ToObjectInternal(JSContext* cx, JS::MutableHandle rval) const { MediaTrackConstraintSetAtoms* 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 (mAutoGainControl.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningBooleanOrConstrainBooleanParameters const & currentValue = mAutoGainControl.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->autoGainControl_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mBrowserWindow.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); int64_t const & currentValue = mBrowserWindow.InternalValue(); temp.set(JS::NumberValue(double(currentValue))); if (!JS_DefinePropertyById(cx, obj, atomsCache->browserWindow_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mChannelCount.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningLongOrConstrainLongRange const & currentValue = mChannelCount.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->channelCount_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mDeviceId.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningStringOrStringSequenceOrConstrainDOMStringParameters const & currentValue = mDeviceId.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->deviceId_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mEchoCancellation.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningBooleanOrConstrainBooleanParameters const & currentValue = mEchoCancellation.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->echoCancellation_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mFacingMode.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningStringOrStringSequenceOrConstrainDOMStringParameters const & currentValue = mFacingMode.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->facingMode_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mFrameRate.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningDoubleOrConstrainDoubleRange const & currentValue = mFrameRate.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->frameRate_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mGroupId.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningStringOrStringSequenceOrConstrainDOMStringParameters const & currentValue = mGroupId.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->groupId_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mHeight.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningLongOrConstrainLongRange const & currentValue = mHeight.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->height_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mMediaSource.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); nsString const & currentValue = mMediaSource.InternalValue(); if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->mediaSource_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mNoiseSuppression.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningBooleanOrConstrainBooleanParameters const & currentValue = mNoiseSuppression.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->noiseSuppression_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mResizeMode.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningStringOrStringSequenceOrConstrainDOMStringParameters const & currentValue = mResizeMode.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->resizeMode_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mScrollWithPage.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); bool const & currentValue = mScrollWithPage.InternalValue(); temp.setBoolean(currentValue); if (!JS_DefinePropertyById(cx, obj, atomsCache->scrollWithPage_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mViewportHeight.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningLongOrConstrainLongRange const & currentValue = mViewportHeight.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->viewportHeight_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mViewportOffsetX.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningLongOrConstrainLongRange const & currentValue = mViewportOffsetX.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->viewportOffsetX_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mViewportOffsetY.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningLongOrConstrainLongRange const & currentValue = mViewportOffsetY.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->viewportOffsetY_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mViewportWidth.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningLongOrConstrainLongRange const & currentValue = mViewportWidth.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->viewportWidth_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } if (mWidth.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); OwningLongOrConstrainLongRange const & currentValue = mWidth.InternalValue(); if (!currentValue.ToJSVal(cx, obj, &temp)) { return false; } if (!JS_DefinePropertyById(cx, obj, atomsCache->width_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } return true; } void MediaTrackConstraintSet::TraceDictionary(JSTracer* trc) { } MediaTrackConstraintSet& MediaTrackConstraintSet::operator=(const MediaTrackConstraintSet& aOther) { MaybeEmptyDictionaryBase::operator=(aOther); mAutoGainControl.Reset(); if (aOther.mAutoGainControl.WasPassed()) { mAutoGainControl.Construct(aOther.mAutoGainControl.Value()); } mBrowserWindow.Reset(); if (aOther.mBrowserWindow.WasPassed()) { mBrowserWindow.Construct(aOther.mBrowserWindow.Value()); } mChannelCount.Reset(); if (aOther.mChannelCount.WasPassed()) { mChannelCount.Construct(aOther.mChannelCount.Value()); } mDeviceId.Reset(); if (aOther.mDeviceId.WasPassed()) { mDeviceId.Construct(aOther.mDeviceId.Value()); } mEchoCancellation.Reset(); if (aOther.mEchoCancellation.WasPassed()) { mEchoCancellation.Construct(aOther.mEchoCancellation.Value()); } mFacingMode.Reset(); if (aOther.mFacingMode.WasPassed()) { mFacingMode.Construct(aOther.mFacingMode.Value()); } mFrameRate.Reset(); if (aOther.mFrameRate.WasPassed()) { mFrameRate.Construct(aOther.mFrameRate.Value()); } mGroupId.Reset(); if (aOther.mGroupId.WasPassed()) { mGroupId.Construct(aOther.mGroupId.Value()); } mHeight.Reset(); if (aOther.mHeight.WasPassed()) { mHeight.Construct(aOther.mHeight.Value()); } mMediaSource.Reset(); if (aOther.mMediaSource.WasPassed()) { mMediaSource.Construct(aOther.mMediaSource.Value()); } mNoiseSuppression.Reset(); if (aOther.mNoiseSuppression.WasPassed()) { mNoiseSuppression.Construct(aOther.mNoiseSuppression.Value()); } mResizeMode.Reset(); if (aOther.mResizeMode.WasPassed()) { mResizeMode.Construct(aOther.mResizeMode.Value()); } mScrollWithPage.Reset(); if (aOther.mScrollWithPage.WasPassed()) { mScrollWithPage.Construct(aOther.mScrollWithPage.Value()); } mViewportHeight.Reset(); if (aOther.mViewportHeight.WasPassed()) { mViewportHeight.Construct(aOther.mViewportHeight.Value()); } mViewportOffsetX.Reset(); if (aOther.mViewportOffsetX.WasPassed()) { mViewportOffsetX.Construct(aOther.mViewportOffsetX.Value()); } mViewportOffsetY.Reset(); if (aOther.mViewportOffsetY.WasPassed()) { mViewportOffsetY.Construct(aOther.mViewportOffsetY.Value()); } mViewportWidth.Reset(); if (aOther.mViewportWidth.WasPassed()) { mViewportWidth.Construct(aOther.mViewportWidth.Value()); } mWidth.Reset(); if (aOther.mWidth.WasPassed()) { mWidth.Construct(aOther.mWidth.Value()); } return *this; } MediaTrackConstraints::MediaTrackConstraints() : MediaTrackConstraintSet(FastDictionaryInitializer()) { // Safe to pass a null context if we pass a null value Init(nullptr, JS::NullHandleValue); } bool MediaTrackConstraints::InitIds(JSContext* cx, MediaTrackConstraintsAtoms* atomsCache) { MOZ_ASSERT(reinterpret_cast(atomsCache)->isVoid()); // Initialize these in reverse order so that any failure leaves the first one // uninitialized. if (!atomsCache->advanced_id.init(cx, "advanced")) { return false; } return true; } bool MediaTrackConstraints::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()); MediaTrackConstraintsAtoms* atomsCache = nullptr; if (cx) { atomsCache = GetAtomCache(cx); if (reinterpret_cast(atomsCache)->isVoid() && !InitIds(cx, atomsCache)) { return false; } } // Per spec, we init the parent's members first if (!MediaTrackConstraintSet::Init(cx, val)) { return false; } 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->advanced_id, temp.ptr())) { return false; } } if (!isNull && !temp->isUndefined()) { mAdvanced.Construct(); if (temp.ref().isObject()) { JS::ForOfIterator iter(cx); if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { return false; } if (!iter.valueIsIterable()) { cx.ThrowErrorMessage("'advanced' member of MediaTrackConstraints", "sequence"); return false; } Sequence &arr = (mAdvanced.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; } MediaTrackConstraintSet* slotPtr = arr.AppendElement(mozilla::fallible); if (!slotPtr) { JS_ReportOutOfMemory(cx); return false; } MediaTrackConstraintSet& slot = *slotPtr; if (!slot.Init(cx, temp, "Element of 'advanced' member of MediaTrackConstraints", passedToJSImpl)) { return false; } } } else { cx.ThrowErrorMessage("'advanced' member of MediaTrackConstraints", "sequence"); return false; } mIsAnyMemberPresent = true; } return true; } bool MediaTrackConstraints::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); } bool MediaTrackConstraints::ToObjectInternal(JSContext* cx, JS::MutableHandle rval) const { MediaTrackConstraintsAtoms* atomsCache = GetAtomCache(cx); if (reinterpret_cast(atomsCache)->isVoid() && !InitIds(cx, atomsCache)) { return false; } // Per spec, we define the parent's members first if (!MediaTrackConstraintSet::ToObjectInternal(cx, rval)) { return false; } JS::Rooted obj(cx, &rval.toObject()); if (mAdvanced.WasPassed()) { do { // block for our 'break' successCode and scope for 'temp' and 'currentValue' JS::Rooted temp(cx); Sequence const & currentValue = mAdvanced.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->advanced_id, temp, JSPROP_ENUMERATE)) { return false; } break; } while(false); } return true; } bool MediaTrackConstraints::ToJSON(nsAString& aJSON) const { AutoJSAPI jsapi; jsapi.Init(); JSContext *cx = jsapi.cx(); // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here // because we'll only be creating objects, in ways that have no // side-effects, followed by a call to JS::ToJSONMaybeSafely, // which likewise guarantees no side-effects for the sorts of // things we will pass it. JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible); if (!scope) { JS_ReportOutOfMemory(cx); return false; } JSAutoRealm ar(cx, scope); JS::Rooted val(cx); if (!ToObjectInternal(cx, &val)) { return false; } JS::Rooted obj(cx, &val.toObject()); return StringifyToJSON(cx, obj, aJSON); } bool MediaTrackConstraints::ToJSON(nsACString& aJSON) const { AutoJSAPI jsapi; jsapi.Init(); JSContext *cx = jsapi.cx(); // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here // because we'll only be creating objects, in ways that have no // side-effects, followed by a call to JS::ToJSONMaybeSafely, // which likewise guarantees no side-effects for the sorts of // things we will pass it. JSObject* scope = UnprivilegedJunkScopeOrWorkerGlobal(fallible); if (!scope) { JS_ReportOutOfMemory(cx); return false; } JSAutoRealm ar(cx, scope); JS::Rooted val(cx); if (!ToObjectInternal(cx, &val)) { return false; } JS::Rooted obj(cx, &val.toObject()); return StringifyToJSON(cx, obj, aJSON); } void MediaTrackConstraints::TraceDictionary(JSTracer* trc) { MediaTrackConstraintSet::TraceDictionary(trc); } MediaTrackConstraints& MediaTrackConstraints::operator=(const MediaTrackConstraints& aOther) { MediaTrackConstraintSet::operator=(aOther); mAdvanced.Reset(); if (aOther.mAdvanced.WasPassed()) { mAdvanced.Construct(aOther.mAdvanced.Value()); } return *this; } namespace MediaStreamTrack_Binding { static_assert(IsRefcounted::value == IsRefcounted::value, "Can't inherit from an interface with a different ownership model."); MOZ_CAN_RUN_SCRIPT static bool get_kind(JSContext* cx, JS::Handle obj, void* void_self, JSJitGetterCallArgs args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "kind", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); DOMString result; // NOTE: This assert does NOT call the function. static_assert(std::is_void_vGetKind(result))>, "Should be returning void here"); MOZ_KnownLive(self)->GetKind(result); MOZ_ASSERT(!JS_IsExceptionPending(cx)); if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { return false; } return true; } static const JSJitInfo kind_getterinfo = { { get_kind }, { prototypes::id::MediaStreamTrack }, { PrototypeTraits::Depth }, JSJitInfo::Getter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_STRING, /* 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 get_id(JSContext* cx, JS::Handle obj, void* void_self, JSJitGetterCallArgs args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "id", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); DOMString result; // NOTE: This assert does NOT call the function. static_assert(std::is_void_vGetId(result))>, "Should be returning void here"); MOZ_KnownLive(self)->GetId(result); MOZ_ASSERT(!JS_IsExceptionPending(cx)); if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { return false; } return true; } static const JSJitInfo id_getterinfo = { { get_id }, { prototypes::id::MediaStreamTrack }, { PrototypeTraits::Depth }, JSJitInfo::Getter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_STRING, /* 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 get_label(JSContext* cx, JS::Handle obj, void* void_self, JSJitGetterCallArgs args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "label", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); DOMString result; // NOTE: This assert does NOT call the function. static_assert(std::is_void_vGetLabel(result, nsContentUtils::IsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem))>, "Should be returning void here"); MOZ_KnownLive(self)->GetLabel(result, nsContentUtils::IsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem); MOZ_ASSERT(!JS_IsExceptionPending(cx)); if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { return false; } return true; } static const JSJitInfo label_getterinfo = { { get_label }, { prototypes::id::MediaStreamTrack }, { PrototypeTraits::Depth }, JSJitInfo::Getter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_STRING, /* 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 get_enabled(JSContext* cx, JS::Handle obj, void* void_self, JSJitGetterCallArgs args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "enabled", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); bool result(MOZ_KnownLive(self)->Enabled()); MOZ_ASSERT(!JS_IsExceptionPending(cx)); args.rval().setBoolean(result); return true; } MOZ_CAN_RUN_SCRIPT static bool set_enabled(JSContext* cx, JS::Handle obj, void* void_self, JSJitSetterCallArgs args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "enabled", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_SETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); bool arg0; if (!ValueToPrimitive(cx, args[0], "Value being assigned", &arg0)) { return false; } // NOTE: This assert does NOT call the function. static_assert(std::is_void_vSetEnabled(arg0))>, "Should be returning void here"); MOZ_KnownLive(self)->SetEnabled(arg0); MOZ_ASSERT(!JS_IsExceptionPending(cx)); return true; } static const JSJitInfo enabled_getterinfo = { { get_enabled }, { prototypes::id::MediaStreamTrack }, { PrototypeTraits::Depth }, JSJitInfo::Getter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ true, /* 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 const JSJitInfo enabled_setterinfo = { { (JSJitGetterOp)set_enabled }, { prototypes::id::MediaStreamTrack }, { PrototypeTraits::Depth }, JSJitInfo::Setter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_UNDEFINED, /* 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 get_muted(JSContext* cx, JS::Handle obj, void* void_self, JSJitGetterCallArgs args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "muted", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); bool result(MOZ_KnownLive(self)->Muted()); MOZ_ASSERT(!JS_IsExceptionPending(cx)); args.rval().setBoolean(result); return true; } static const JSJitInfo muted_getterinfo = { { get_muted }, { prototypes::id::MediaStreamTrack }, { PrototypeTraits::Depth }, JSJitInfo::Getter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ true, /* 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 get_onmute(JSContext* cx, JS::Handle obj, void* void_self, JSJitGetterCallArgs args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "onmute", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); RefPtr result(MOZ_KnownLive(self)->GetOnmute()); MOZ_ASSERT(!JS_IsExceptionPending(cx)); if (result) { args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { return false; } return true; } else { args.rval().setNull(); return true; } } MOZ_CAN_RUN_SCRIPT static bool set_onmute(JSContext* cx, JS::Handle obj, void* void_self, JSJitSetterCallArgs args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "onmute", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_SETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); RootedCallback> arg0(cx); if (args[0].isObject()) { { // scope for tempRoot and tempGlobalRoot if needed arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); } } else { arg0 = nullptr; } // NOTE: This assert does NOT call the function. static_assert(std::is_void_vSetOnmute(MOZ_KnownLive(Constify(arg0))))>, "Should be returning void here"); MOZ_KnownLive(self)->SetOnmute(MOZ_KnownLive(Constify(arg0))); MOZ_ASSERT(!JS_IsExceptionPending(cx)); return true; } static const JSJitInfo onmute_getterinfo = { { get_onmute }, { prototypes::id::MediaStreamTrack }, { PrototypeTraits::Depth }, JSJitInfo::Getter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_UNKNOWN, /* 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 const JSJitInfo onmute_setterinfo = { { (JSJitGetterOp)set_onmute }, { prototypes::id::MediaStreamTrack }, { PrototypeTraits::Depth }, JSJitInfo::Setter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_UNDEFINED, /* 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 get_onunmute(JSContext* cx, JS::Handle obj, void* void_self, JSJitGetterCallArgs args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "onunmute", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); RefPtr result(MOZ_KnownLive(self)->GetOnunmute()); MOZ_ASSERT(!JS_IsExceptionPending(cx)); if (result) { args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { return false; } return true; } else { args.rval().setNull(); return true; } } MOZ_CAN_RUN_SCRIPT static bool set_onunmute(JSContext* cx, JS::Handle obj, void* void_self, JSJitSetterCallArgs args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "onunmute", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_SETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); RootedCallback> arg0(cx); if (args[0].isObject()) { { // scope for tempRoot and tempGlobalRoot if needed arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); } } else { arg0 = nullptr; } // NOTE: This assert does NOT call the function. static_assert(std::is_void_vSetOnunmute(MOZ_KnownLive(Constify(arg0))))>, "Should be returning void here"); MOZ_KnownLive(self)->SetOnunmute(MOZ_KnownLive(Constify(arg0))); MOZ_ASSERT(!JS_IsExceptionPending(cx)); return true; } static const JSJitInfo onunmute_getterinfo = { { get_onunmute }, { prototypes::id::MediaStreamTrack }, { PrototypeTraits::Depth }, JSJitInfo::Getter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_UNKNOWN, /* 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 const JSJitInfo onunmute_setterinfo = { { (JSJitGetterOp)set_onunmute }, { prototypes::id::MediaStreamTrack }, { PrototypeTraits::Depth }, JSJitInfo::Setter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_UNDEFINED, /* 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 get_readyState(JSContext* cx, JS::Handle obj, void* void_self, JSJitGetterCallArgs args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "readyState", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); MediaStreamTrackState result(MOZ_KnownLive(self)->ReadyState()); MOZ_ASSERT(!JS_IsExceptionPending(cx)); if (!ToJSValue(cx, result, args.rval())) { return false; } return true; } static const JSJitInfo readyState_getterinfo = { { get_readyState }, { prototypes::id::MediaStreamTrack }, { PrototypeTraits::Depth }, JSJitInfo::Getter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_STRING, /* 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 get_onended(JSContext* cx, JS::Handle obj, void* void_self, JSJitGetterCallArgs args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "onended", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); RefPtr result(MOZ_KnownLive(self)->GetOnended()); MOZ_ASSERT(!JS_IsExceptionPending(cx)); if (result) { args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { return false; } return true; } else { args.rval().setNull(); return true; } } MOZ_CAN_RUN_SCRIPT static bool set_onended(JSContext* cx, JS::Handle obj, void* void_self, JSJitSetterCallArgs args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "onended", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_SETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); RootedCallback> arg0(cx); if (args[0].isObject()) { { // scope for tempRoot and tempGlobalRoot if needed arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); } } else { arg0 = nullptr; } // NOTE: This assert does NOT call the function. static_assert(std::is_void_vSetOnended(MOZ_KnownLive(Constify(arg0))))>, "Should be returning void here"); MOZ_KnownLive(self)->SetOnended(MOZ_KnownLive(Constify(arg0))); MOZ_ASSERT(!JS_IsExceptionPending(cx)); return true; } static const JSJitInfo onended_getterinfo = { { get_onended }, { prototypes::id::MediaStreamTrack }, { PrototypeTraits::Depth }, JSJitInfo::Getter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_UNKNOWN, /* 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 const JSJitInfo onended_setterinfo = { { (JSJitGetterOp)set_onended }, { prototypes::id::MediaStreamTrack }, { PrototypeTraits::Depth }, JSJitInfo::Setter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_UNDEFINED, /* 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 clone(JSContext* cx, JS::Handle obj, void* void_self, const JSJitMethodCallArgs& args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "clone", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); auto result(StrongOrRawPtr(MOZ_KnownLive(self)->Clone())); MOZ_ASSERT(!JS_IsExceptionPending(cx)); if (!GetOrCreateDOMReflector(cx, result, args.rval())) { MOZ_ASSERT(JS_IsExceptionPending(cx)); return false; } return true; } static const JSJitInfo clone_methodinfo = { { (JSJitGetterOp)clone }, { prototypes::id::MediaStreamTrack }, { 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 stop(JSContext* cx, JS::Handle obj, void* void_self, const JSJitMethodCallArgs& args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "stop", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); // NOTE: This assert does NOT call the function. static_assert(std::is_void_vStop())>, "Should be returning void here"); MOZ_KnownLive(self)->Stop(); MOZ_ASSERT(!JS_IsExceptionPending(cx)); args.rval().setUndefined(); return true; } static const JSJitInfo stop_methodinfo = { { (JSJitGetterOp)stop }, { prototypes::id::MediaStreamTrack }, { PrototypeTraits::Depth }, JSJitInfo::Method, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ true, /* 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 getCapabilities(JSContext* cx, JS::Handle obj, void* void_self, const JSJitMethodCallArgs& args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "getCapabilities", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); MediaTrackCapabilities result; // NOTE: This assert does NOT call the function. static_assert(std::is_void_vGetCapabilities(result, nsContentUtils::IsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem))>, "Should be returning void here"); MOZ_KnownLive(self)->GetCapabilities(result, nsContentUtils::IsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem); MOZ_ASSERT(!JS_IsExceptionPending(cx)); if (!result.ToObjectInternal(cx, args.rval())) { return false; } return true; } static const JSJitInfo getCapabilities_methodinfo = { { (JSJitGetterOp)getCapabilities }, { prototypes::id::MediaStreamTrack }, { 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 getConstraints(JSContext* cx, JS::Handle obj, void* void_self, const JSJitMethodCallArgs& args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "getConstraints", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); MediaTrackConstraints result; // NOTE: This assert does NOT call the function. static_assert(std::is_void_vGetConstraints(result))>, "Should be returning void here"); MOZ_KnownLive(self)->GetConstraints(result); MOZ_ASSERT(!JS_IsExceptionPending(cx)); if (!result.ToObjectInternal(cx, args.rval())) { return false; } return true; } static const JSJitInfo getConstraints_methodinfo = { { (JSJitGetterOp)getConstraints }, { prototypes::id::MediaStreamTrack }, { 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 getSettings(JSContext* cx, JS::Handle obj, void* void_self, const JSJitMethodCallArgs& args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "getSettings", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); MediaTrackSettings result; // NOTE: This assert does NOT call the function. static_assert(std::is_void_vGetSettings(result, nsContentUtils::IsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem))>, "Should be returning void here"); MOZ_KnownLive(self)->GetSettings(result, nsContentUtils::IsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem); MOZ_ASSERT(!JS_IsExceptionPending(cx)); if (!result.ToObjectInternal(cx, args.rval())) { return false; } return true; } static const JSJitInfo getSettings_methodinfo = { { (JSJitGetterOp)getSettings }, { prototypes::id::MediaStreamTrack }, { 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 applyConstraints(JSContext* cx_, JS::Handle obj, void* void_self, const JSJitMethodCallArgs& args) { BindingCallContext cx(cx_, "MediaStreamTrack.applyConstraints"); AUTO_PROFILER_LABEL_DYNAMIC_FAST( "MediaStreamTrack", "applyConstraints", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); binding_detail::FastMediaTrackConstraints arg0; if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1", false)) { return false; } FastErrorResult rv; auto result(StrongOrRawPtr(MOZ_KnownLive(self)->ApplyConstraints(Constify(arg0), nsContentUtils::IsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv))); if (rv.MaybeSetPendingException(cx, "MediaStreamTrack.applyConstraints")) [[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 applyConstraints_promiseWrapper(JSContext* cx, JS::Handle obj, void* void_self, const JSJitMethodCallArgs& args) { bool ok = applyConstraints(cx, obj, void_self, args); if (ok) { return true; } return ConvertExceptionToPromise(cx, args.rval()); } static const JSJitInfo applyConstraints_methodinfo = { { (JSJitGetterOp)applyConstraints_promiseWrapper }, { prototypes::id::MediaStreamTrack }, { 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::MediaStreamTrack* 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("clone", (GenericMethod), reinterpret_cast(&clone_methodinfo), 0, JSPROP_ENUMERATE, nullptr), JS_FNSPEC("stop", (GenericMethod), reinterpret_cast(&stop_methodinfo), 0, JSPROP_ENUMERATE, nullptr), JS_FNSPEC("getCapabilities", (GenericMethod), reinterpret_cast(&getCapabilities_methodinfo), 0, JSPROP_ENUMERATE, nullptr), JS_FNSPEC("getConstraints", (GenericMethod), reinterpret_cast(&getConstraints_methodinfo), 0, JSPROP_ENUMERATE, nullptr), JS_FNSPEC("getSettings", (GenericMethod), reinterpret_cast(&getSettings_methodinfo), 0, JSPROP_ENUMERATE, nullptr), JS_FNSPEC("applyConstraints", (GenericMethod), reinterpret_cast(&applyConstraints_methodinfo), 0, JSPROP_ENUMERATE, nullptr), JS_FS_END }; static const Prefable sMethods[] = { { nullptr, &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(6 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); MOZ_GLOBINIT static const JSPropertySpec sAttributes_specs[] = { JSPropertySpec::nativeAccessors("kind", JSPROP_ENUMERATE, GenericGetter, &kind_getterinfo, nullptr, nullptr), JSPropertySpec::nativeAccessors("id", JSPROP_ENUMERATE, GenericGetter, &id_getterinfo, nullptr, nullptr), JSPropertySpec::nativeAccessors("label", JSPROP_ENUMERATE, GenericGetter, &label_getterinfo, nullptr, nullptr), JSPropertySpec::nativeAccessors("enabled", JSPROP_ENUMERATE, GenericGetter, &enabled_getterinfo, GenericSetter, &enabled_setterinfo), JSPropertySpec::nativeAccessors("muted", JSPROP_ENUMERATE, GenericGetter, &muted_getterinfo, nullptr, nullptr), JSPropertySpec::nativeAccessors("onmute", JSPROP_ENUMERATE, GenericGetter, &onmute_getterinfo, GenericSetter, &onmute_setterinfo), JSPropertySpec::nativeAccessors("onunmute", JSPROP_ENUMERATE, GenericGetter, &onunmute_getterinfo, GenericSetter, &onunmute_setterinfo), JSPropertySpec::nativeAccessors("readyState", JSPROP_ENUMERATE, GenericGetter, &readyState_getterinfo, nullptr, nullptr), JSPropertySpec::nativeAccessors("onended", JSPROP_ENUMERATE, GenericGetter, &onended_getterinfo, GenericSetter, &onended_setterinfo), JS_PS_END }; static const Prefable sAttributes[] = { { nullptr, &sAttributes_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(9 <= 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[15]; static PropertyInfo sNativeProperties_propertyInfos[15]; static const NativePropertiesN<2> sNativeProperties = { false, 0, false, 0, true, 0 /* sMethods */, true, 1 /* sAttributes */, false, 0, false, 0, false, 0, -1, 15, sNativeProperties_sortedPropertyIndices, { { sMethods, &sNativeProperties_propertyInfos[0] }, { sAttributes, &sNativeProperties_propertyInfos[6] } } }; static_assert(15 < 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::MediaStreamTrack, constructors::id::MediaStreamTrack, &DefaultXrayExpandoObjectClass }; static const DOMInterfaceInfo sInterfaceObjectInfo = { { ThrowingConstructor, &sNativePropertyHooks }, EventTarget_Binding::GetConstructorObjectHandle, PrototypeTraits::Depth, prototypes::id::MediaStreamTrack, true, 0, "MediaStreamTrack", }; static const DOMIfaceAndProtoJSClass sPrototypeClass = { { "MediaStreamTrackPrototype", 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::MediaStreamTrack, PrototypeTraits::Depth, &sNativePropertyHooks, EventTarget_Binding::GetProtoObject }; 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 = { { "MediaStreamTrack", 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::EventTarget, prototypes::id::MediaStreamTrack, 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::MediaStreamTrack* 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(static_cast(aObject) == reinterpret_cast(aObject), "Multiple inheritance for mozilla::dom::EventTarget is broken."); 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::MediaStreamTrack); JS::Heap* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MediaStreamTrack); JS::Handle parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx)); if (!parentProto) { return; } JS::Handle constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx)); if (!constructorProto) { return; } dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, &sPrototypeClass, protoCache, constructorProto, &sInterfaceObjectInfo, 0, false, Span{}, interfaceCache, sNativeProperties.Upcast(), nullptr, "MediaStreamTrack", aDefineOnGlobal != DefineInterfaceProperty::No, 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::MediaStreamTrack, &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::MediaStreamTrack, &CreateInterfaceObjects, DefineInterfaceProperty::CheckExposure); } } // namespace MediaStreamTrack_Binding } // namespace dom } // namespace mozilla