Copy as Markdown

Other Tools

/* THIS FILE IS AUTOGENERATED FROM WidevineCDMManifest.webidl BY Codegen.py - DO NOT EDIT */
#include <type_traits>
#include "AtomList.h"
#include "MainThreadUtils.h"
#include "WidevineCDMManifestBinding.h"
#include "js/Array.h"
#include "js/CallAndConstruct.h"
#include "js/Exception.h"
#include "js/ForOfIterator.h"
#include "js/MapAndSet.h"
#include "js/Object.h"
#include "js/PropertyAndElement.h"
#include "js/PropertyDescriptor.h"
#include "js/experimental/JitInfo.h"
#include "mozilla/OwningNonNull.h"
#include "mozilla/dom/BindingCallContext.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/NonRefcountedDOMObject.h"
#include "mozilla/dom/PrimitiveConversions.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/SimpleGlobalObject.h"
namespace mozilla::dom {
namespace binding_detail {}; // Just to make sure it's known as a namespace
using namespace mozilla::dom::binding_detail;
WidevineCDMManifest::WidevineCDMManifest()
{
// Safe to pass a null context if we pass a null value
Init(nullptr, JS::NullHandleValue);
}
bool
WidevineCDMManifest::InitIds(JSContext* cx, WidevineCDMManifestAtoms* atomsCache)
{
MOZ_ASSERT(reinterpret_cast<jsid*>(atomsCache)->isVoid());
// Initialize these in reverse order so that any failure leaves the first one
// uninitialized.
if (!atomsCache->x_cdm_module_versions_id.init(cx, "x-cdm-module-versions") ||
!atomsCache->x_cdm_interface_versions_id.init(cx, "x-cdm-interface-versions") ||
!atomsCache->x_cdm_host_versions_id.init(cx, "x-cdm-host-versions") ||
!atomsCache->x_cdm_codecs_id.init(cx, "x-cdm-codecs") ||
!atomsCache->version_id.init(cx, "version") ||
!atomsCache->name_id.init(cx, "name") ||
!atomsCache->manifest_version_id.init(cx, "manifest_version") ||
!atomsCache->description_id.init(cx, "description") ||
!atomsCache->accept_arch_id.init(cx, "accept_arch")) {
return false;
}
return true;
}
bool
WidevineCDMManifest::Init(BindingCallContext& cx, JS::Handle<JS::Value> 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());
WidevineCDMManifestAtoms* atomsCache = nullptr;
if (cx) {
atomsCache = GetAtomCache<WidevineCDMManifestAtoms>(cx);
if (reinterpret_cast<jsid*>(atomsCache)->isVoid() &&
!InitIds(cx, atomsCache)) {
return false;
}
}
if (!IsConvertibleToDictionary(val)) {
return cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>(sourceDescription, "dictionary");
}
bool isNull = val.isNullOrUndefined();
// We only need these if !isNull, in which case we have |cx|.
Maybe<JS::Rooted<JSObject *> > object;
Maybe<JS::Rooted<JS::Value> > temp;
if (!isNull) {
MOZ_ASSERT(cx);
object.emplace(cx, &val.toObject());
temp.emplace(cx);
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->accept_arch_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mAccept_arch.Construct();
if (temp.ref().isObject()) {
JS::ForOfIterator iter(cx);
if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
return false;
}
if (!iter.valueIsIterable()) {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'accept_arch' member of WidevineCDMManifest", "sequence");
return false;
}
Sequence<nsString> &arr = (mAccept_arch.Value());
JS::Rooted<JS::Value> 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;
}
}
} else {
cx.ThrowErrorMessage<MSG_CONVERSION_ERROR>("'accept_arch' member of WidevineCDMManifest", "sequence");
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->description_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mDescription.Construct();
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mDescription.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->manifest_version_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mManifest_version.Construct();
if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), "'manifest_version' member of WidevineCDMManifest", &(mManifest_version.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) {
return false;
}
mIsAnyMemberPresent = true;
} else if (cx) {
// Don't error out if we have no cx. In that
// situation the caller is default-constructing us and we'll
// just assume they know what they're doing.
return cx.ThrowErrorMessage<MSG_MISSING_REQUIRED_DICTIONARY_MEMBER>("'name' member of WidevineCDMManifest");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->version_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mVersion)) {
return false;
}
mIsAnyMemberPresent = true;
} else if (cx) {
// Don't error out if we have no cx. In that
// situation the caller is default-constructing us and we'll
// just assume they know what they're doing.
return cx.ThrowErrorMessage<MSG_MISSING_REQUIRED_DICTIONARY_MEMBER>("'version' member of WidevineCDMManifest");
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->x_cdm_codecs_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mX_cdm_codecs.Construct();
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mX_cdm_codecs.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->x_cdm_host_versions_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mX_cdm_host_versions.Construct();
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mX_cdm_host_versions.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->x_cdm_interface_versions_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mX_cdm_interface_versions.Construct();
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mX_cdm_interface_versions.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
if (!isNull) {
if (!JS_GetPropertyById(cx, *object, atomsCache->x_cdm_module_versions_id, temp.ptr())) {
return false;
}
}
if (!isNull && !temp->isUndefined()) {
mX_cdm_module_versions.Construct();
if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mX_cdm_module_versions.Value()))) {
return false;
}
mIsAnyMemberPresent = true;
}
return true;
}
bool
WidevineCDMManifest::Init(JSContext* cx_, JS::Handle<JS::Value> 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
WidevineCDMManifest::Init(const nsAString& aJSON)
{
AutoJSAPI jsapi;
JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
if (!cleanGlobal) {
return false;
}
if (!jsapi.Init(cleanGlobal)) {
return false;
}
JSContext* cx = jsapi.cx();
JS::Rooted<JS::Value> json(cx);
bool ok = ParseJSON(cx, aJSON, &json);
NS_ENSURE_TRUE(ok, false);
return Init(cx, json);
}
void
WidevineCDMManifest::TraceDictionary(JSTracer* trc)
{
}
WidevineCDMManifest&
WidevineCDMManifest::operator=(const WidevineCDMManifest& aOther)
{
DictionaryBase::operator=(aOther);
mAccept_arch.Reset();
if (aOther.mAccept_arch.WasPassed()) {
mAccept_arch.Construct(aOther.mAccept_arch.Value());
}
mDescription.Reset();
if (aOther.mDescription.WasPassed()) {
mDescription.Construct(aOther.mDescription.Value());
}
mManifest_version.Reset();
if (aOther.mManifest_version.WasPassed()) {
mManifest_version.Construct(aOther.mManifest_version.Value());
}
mName = aOther.mName;
mVersion = aOther.mVersion;
mX_cdm_codecs.Reset();
if (aOther.mX_cdm_codecs.WasPassed()) {
mX_cdm_codecs.Construct(aOther.mX_cdm_codecs.Value());
}
mX_cdm_host_versions.Reset();
if (aOther.mX_cdm_host_versions.WasPassed()) {
mX_cdm_host_versions.Construct(aOther.mX_cdm_host_versions.Value());
}
mX_cdm_interface_versions.Reset();
if (aOther.mX_cdm_interface_versions.WasPassed()) {
mX_cdm_interface_versions.Construct(aOther.mX_cdm_interface_versions.Value());
}
mX_cdm_module_versions.Reset();
if (aOther.mX_cdm_module_versions.WasPassed()) {
mX_cdm_module_versions.Construct(aOther.mX_cdm_module_versions.Value());
}
return *this;
}
} // namespace mozilla::dom