LCOV - code coverage report
Current view: top level - obj-x86_64-pc-linux-gnu/dom/bindings - WidevineCDMManifestBinding.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 80 192 41.7 %
Date: 2017-07-14 16:53:18 Functions: 4 8 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM WidevineCDMManifest.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "AtomList.h"
       4             : #include "WidevineCDMManifestBinding.h"
       5             : #include "mozilla/OwningNonNull.h"
       6             : #include "mozilla/dom/BindingUtils.h"
       7             : #include "mozilla/dom/NonRefcountedDOMObject.h"
       8             : #include "mozilla/dom/ScriptSettings.h"
       9             : #include "mozilla/dom/SimpleGlobalObject.h"
      10             : 
      11             : namespace mozilla {
      12             : namespace dom {
      13             : 
      14             : 
      15           1 : WidevineCDMManifest::WidevineCDMManifest()
      16             : {
      17             :   // Safe to pass a null context if we pass a null value
      18           1 :   Init(nullptr, JS::NullHandleValue);
      19           1 : }
      20             : 
      21             : 
      22             : 
      23             : bool
      24           1 : WidevineCDMManifest::InitIds(JSContext* cx, WidevineCDMManifestAtoms* atomsCache)
      25             : {
      26           1 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
      27             : 
      28             :   // Initialize these in reverse order so that any failure leaves the first one
      29             :   // uninitialized.
      30           3 :   if (!atomsCache->x_cdm_module_versions_id.init(cx, "x-cdm-module-versions") ||
      31           2 :       !atomsCache->x_cdm_interface_versions_id.init(cx, "x-cdm-interface-versions") ||
      32           2 :       !atomsCache->x_cdm_host_versions_id.init(cx, "x-cdm-host-versions") ||
      33           2 :       !atomsCache->x_cdm_codecs_id.init(cx, "x-cdm-codecs") ||
      34           2 :       !atomsCache->version_id.init(cx, "version") ||
      35           3 :       !atomsCache->name_id.init(cx, "name") ||
      36           1 :       !atomsCache->description_id.init(cx, "description")) {
      37           0 :     return false;
      38             :   }
      39           1 :   return true;
      40             : }
      41             : 
      42             : bool
      43           2 : WidevineCDMManifest::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
      44             : {
      45             :   // Passing a null JSContext is OK only if we're initing from null,
      46             :   // Since in that case we will not have to do any property gets
      47             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
      48             :   // checkers by static analysis tools
      49           2 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
      50           2 :   WidevineCDMManifestAtoms* atomsCache = nullptr;
      51           2 :   if (cx) {
      52           1 :     atomsCache = GetAtomCache<WidevineCDMManifestAtoms>(cx);
      53           1 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
      54           0 :       return false;
      55             :     }
      56             :   }
      57             : 
      58           2 :   if (!IsConvertibleToDictionary(val)) {
      59           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
      60             :   }
      61             : 
      62           2 :   bool isNull = val.isNullOrUndefined();
      63             :   // We only need these if !isNull, in which case we have |cx|.
      64           4 :   Maybe<JS::Rooted<JSObject *> > object;
      65           4 :   Maybe<JS::Rooted<JS::Value> > temp;
      66           2 :   if (!isNull) {
      67           1 :     MOZ_ASSERT(cx);
      68           1 :     object.emplace(cx, &val.toObject());
      69           1 :     temp.emplace(cx);
      70             :   }
      71           2 :   if (!isNull) {
      72           1 :     if (!JS_GetPropertyById(cx, *object, atomsCache->description_id, temp.ptr())) {
      73           0 :       return false;
      74             :     }
      75             :   }
      76           2 :   if (!isNull && !temp->isUndefined()) {
      77           1 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mDescription)) {
      78           0 :       return false;
      79             :     }
      80           1 :     mIsAnyMemberPresent = true;
      81           1 :   } else if (cx) {
      82             :     // Don't error out if we have no cx.  In that
      83             :     // situation the caller is default-constructing us and we'll
      84             :     // just assume they know what they're doing.
      85           0 :     return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
      86           0 :                              "'description' member of WidevineCDMManifest");
      87             :   }
      88             : 
      89           2 :   if (!isNull) {
      90           1 :     if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) {
      91           0 :       return false;
      92             :     }
      93             :   }
      94           2 :   if (!isNull && !temp->isUndefined()) {
      95           1 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) {
      96           0 :       return false;
      97             :     }
      98           1 :     mIsAnyMemberPresent = true;
      99           1 :   } else if (cx) {
     100             :     // Don't error out if we have no cx.  In that
     101             :     // situation the caller is default-constructing us and we'll
     102             :     // just assume they know what they're doing.
     103           0 :     return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
     104           0 :                              "'name' member of WidevineCDMManifest");
     105             :   }
     106             : 
     107           2 :   if (!isNull) {
     108           1 :     if (!JS_GetPropertyById(cx, *object, atomsCache->version_id, temp.ptr())) {
     109           0 :       return false;
     110             :     }
     111             :   }
     112           2 :   if (!isNull && !temp->isUndefined()) {
     113           1 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mVersion)) {
     114           0 :       return false;
     115             :     }
     116           1 :     mIsAnyMemberPresent = true;
     117           1 :   } else if (cx) {
     118             :     // Don't error out if we have no cx.  In that
     119             :     // situation the caller is default-constructing us and we'll
     120             :     // just assume they know what they're doing.
     121           0 :     return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
     122           0 :                              "'version' member of WidevineCDMManifest");
     123             :   }
     124             : 
     125           2 :   if (!isNull) {
     126           1 :     if (!JS_GetPropertyById(cx, *object, atomsCache->x_cdm_codecs_id, temp.ptr())) {
     127           0 :       return false;
     128             :     }
     129             :   }
     130           2 :   if (!isNull && !temp->isUndefined()) {
     131           1 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mX_cdm_codecs)) {
     132           0 :       return false;
     133             :     }
     134           1 :     mIsAnyMemberPresent = true;
     135           1 :   } else if (cx) {
     136             :     // Don't error out if we have no cx.  In that
     137             :     // situation the caller is default-constructing us and we'll
     138             :     // just assume they know what they're doing.
     139           0 :     return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
     140           0 :                              "'x-cdm-codecs' member of WidevineCDMManifest");
     141             :   }
     142             : 
     143           2 :   if (!isNull) {
     144           1 :     if (!JS_GetPropertyById(cx, *object, atomsCache->x_cdm_host_versions_id, temp.ptr())) {
     145           0 :       return false;
     146             :     }
     147             :   }
     148           2 :   if (!isNull && !temp->isUndefined()) {
     149           1 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mX_cdm_host_versions)) {
     150           0 :       return false;
     151             :     }
     152           1 :     mIsAnyMemberPresent = true;
     153           1 :   } else if (cx) {
     154             :     // Don't error out if we have no cx.  In that
     155             :     // situation the caller is default-constructing us and we'll
     156             :     // just assume they know what they're doing.
     157           0 :     return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
     158           0 :                              "'x-cdm-host-versions' member of WidevineCDMManifest");
     159             :   }
     160             : 
     161           2 :   if (!isNull) {
     162           1 :     if (!JS_GetPropertyById(cx, *object, atomsCache->x_cdm_interface_versions_id, temp.ptr())) {
     163           0 :       return false;
     164             :     }
     165             :   }
     166           2 :   if (!isNull && !temp->isUndefined()) {
     167           1 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mX_cdm_interface_versions)) {
     168           0 :       return false;
     169             :     }
     170           1 :     mIsAnyMemberPresent = true;
     171           1 :   } else if (cx) {
     172             :     // Don't error out if we have no cx.  In that
     173             :     // situation the caller is default-constructing us and we'll
     174             :     // just assume they know what they're doing.
     175           0 :     return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
     176           0 :                              "'x-cdm-interface-versions' member of WidevineCDMManifest");
     177             :   }
     178             : 
     179           2 :   if (!isNull) {
     180           1 :     if (!JS_GetPropertyById(cx, *object, atomsCache->x_cdm_module_versions_id, temp.ptr())) {
     181           0 :       return false;
     182             :     }
     183             :   }
     184           2 :   if (!isNull && !temp->isUndefined()) {
     185           1 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mX_cdm_module_versions)) {
     186           0 :       return false;
     187             :     }
     188           1 :     mIsAnyMemberPresent = true;
     189           1 :   } else if (cx) {
     190             :     // Don't error out if we have no cx.  In that
     191             :     // situation the caller is default-constructing us and we'll
     192             :     // just assume they know what they're doing.
     193           0 :     return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
     194           0 :                              "'x-cdm-module-versions' member of WidevineCDMManifest");
     195             :   }
     196           2 :   return true;
     197             : }
     198             : 
     199             : bool
     200           1 : WidevineCDMManifest::Init(const nsAString& aJSON)
     201             : {
     202           2 :   AutoJSAPI jsapi;
     203           1 :   JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
     204           1 :   if (!cleanGlobal) {
     205           0 :     return false;
     206             :   }
     207           1 :   if (!jsapi.Init(cleanGlobal)) {
     208           0 :     return false;
     209             :   }
     210           1 :   JSContext* cx = jsapi.cx();
     211           2 :   JS::Rooted<JS::Value> json(cx);
     212           1 :   bool ok = ParseJSON(cx, aJSON, &json);
     213           1 :   NS_ENSURE_TRUE(ok, false);
     214           1 :   return Init(cx, json);
     215             : }
     216             : 
     217             : bool
     218           0 : WidevineCDMManifest::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     219             : {
     220           0 :   WidevineCDMManifestAtoms* atomsCache = GetAtomCache<WidevineCDMManifestAtoms>(cx);
     221           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     222           0 :     return false;
     223             :   }
     224             : 
     225           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
     226           0 :   if (!obj) {
     227           0 :     return false;
     228             :   }
     229           0 :   rval.set(JS::ObjectValue(*obj));
     230             : 
     231             :   do {
     232             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     233           0 :     JS::Rooted<JS::Value> temp(cx);
     234           0 :     nsString const & currentValue = mDescription;
     235           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     236           0 :       return false;
     237             :     }
     238           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->description_id, temp, JSPROP_ENUMERATE)) {
     239           0 :       return false;
     240             :     }
     241           0 :     break;
     242             :   } while(0);
     243             : 
     244             :   do {
     245             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     246           0 :     JS::Rooted<JS::Value> temp(cx);
     247           0 :     nsString const & currentValue = mName;
     248           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     249           0 :       return false;
     250             :     }
     251           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) {
     252           0 :       return false;
     253             :     }
     254           0 :     break;
     255             :   } while(0);
     256             : 
     257             :   do {
     258             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     259           0 :     JS::Rooted<JS::Value> temp(cx);
     260           0 :     nsString const & currentValue = mVersion;
     261           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     262           0 :       return false;
     263             :     }
     264           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->version_id, temp, JSPROP_ENUMERATE)) {
     265           0 :       return false;
     266             :     }
     267           0 :     break;
     268             :   } while(0);
     269             : 
     270             :   do {
     271             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     272           0 :     JS::Rooted<JS::Value> temp(cx);
     273           0 :     nsString const & currentValue = mX_cdm_codecs;
     274           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     275           0 :       return false;
     276             :     }
     277           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->x_cdm_codecs_id, temp, JSPROP_ENUMERATE)) {
     278           0 :       return false;
     279             :     }
     280           0 :     break;
     281             :   } while(0);
     282             : 
     283             :   do {
     284             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     285           0 :     JS::Rooted<JS::Value> temp(cx);
     286           0 :     nsString const & currentValue = mX_cdm_host_versions;
     287           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     288           0 :       return false;
     289             :     }
     290           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->x_cdm_host_versions_id, temp, JSPROP_ENUMERATE)) {
     291           0 :       return false;
     292             :     }
     293           0 :     break;
     294             :   } while(0);
     295             : 
     296             :   do {
     297             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     298           0 :     JS::Rooted<JS::Value> temp(cx);
     299           0 :     nsString const & currentValue = mX_cdm_interface_versions;
     300           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     301           0 :       return false;
     302             :     }
     303           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->x_cdm_interface_versions_id, temp, JSPROP_ENUMERATE)) {
     304           0 :       return false;
     305             :     }
     306           0 :     break;
     307             :   } while(0);
     308             : 
     309             :   do {
     310             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     311           0 :     JS::Rooted<JS::Value> temp(cx);
     312           0 :     nsString const & currentValue = mX_cdm_module_versions;
     313           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     314           0 :       return false;
     315             :     }
     316           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->x_cdm_module_versions_id, temp, JSPROP_ENUMERATE)) {
     317           0 :       return false;
     318             :     }
     319           0 :     break;
     320             :   } while(0);
     321             : 
     322           0 :   return true;
     323             : }
     324             : 
     325             : bool
     326           0 : WidevineCDMManifest::ToJSON(nsAString& aJSON) const
     327             : {
     328           0 :   AutoJSAPI jsapi;
     329           0 :   jsapi.Init();
     330           0 :   JSContext *cx = jsapi.cx();
     331             :   // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
     332             :   // because we'll only be creating objects, in ways that have no
     333             :   // side-effects, followed by a call to JS::ToJSONMaybeSafely,
     334             :   // which likewise guarantees no side-effects for the sorts of
     335             :   // things we will pass it.
     336           0 :   JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
     337           0 :   JS::Rooted<JS::Value> val(cx);
     338           0 :   if (!ToObjectInternal(cx, &val)) {
     339           0 :     return false;
     340             :   }
     341           0 :   JS::Rooted<JSObject*> obj(cx, &val.toObject());
     342           0 :   return StringifyToJSON(cx, obj, aJSON);
     343             : }
     344             : 
     345             : void
     346           0 : WidevineCDMManifest::TraceDictionary(JSTracer* trc)
     347             : {
     348           0 : }
     349             : 
     350             : WidevineCDMManifest&
     351           0 : WidevineCDMManifest::operator=(const WidevineCDMManifest& aOther)
     352             : {
     353           0 :   mDescription = aOther.mDescription;
     354           0 :   mName = aOther.mName;
     355           0 :   mVersion = aOther.mVersion;
     356           0 :   mX_cdm_codecs = aOther.mX_cdm_codecs;
     357           0 :   mX_cdm_host_versions = aOther.mX_cdm_host_versions;
     358           0 :   mX_cdm_interface_versions = aOther.mX_cdm_interface_versions;
     359           0 :   mX_cdm_module_versions = aOther.mX_cdm_module_versions;
     360           0 :   return *this;
     361             : }
     362             : 
     363             : namespace binding_detail {
     364             : } // namespace binding_detail
     365             : 
     366             : 
     367             : } // namespace dom
     368             : } // namespace mozilla

Generated by: LCOV version 1.13