LCOV - code coverage report
Current view: top level - obj-x86_64-pc-linux-gnu/dom/bindings - NativeOSFileInternalsBinding.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 32 105 30.5 %
Date: 2017-07-14 16:53:18 Functions: 3 8 37.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM NativeOSFileInternals.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "AtomList.h"
       4             : #include "NativeOSFileInternalsBinding.h"
       5             : #include "mozilla/OwningNonNull.h"
       6             : #include "mozilla/dom/BindingUtils.h"
       7             : #include "mozilla/dom/NonRefcountedDOMObject.h"
       8             : #include "mozilla/dom/PrimitiveConversions.h"
       9             : #include "mozilla/dom/ScriptSettings.h"
      10             : #include "mozilla/dom/SimpleGlobalObject.h"
      11             : 
      12             : namespace mozilla {
      13             : namespace dom {
      14             : 
      15             : 
      16           3 : NativeOSFileReadOptions::NativeOSFileReadOptions()
      17             : {
      18             :   // Safe to pass a null context if we pass a null value
      19           3 :   Init(nullptr, JS::NullHandleValue);
      20           3 : }
      21             : 
      22             : 
      23             : 
      24             : bool
      25           1 : NativeOSFileReadOptions::InitIds(JSContext* cx, NativeOSFileReadOptionsAtoms* atomsCache)
      26             : {
      27           1 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
      28             : 
      29             :   // Initialize these in reverse order so that any failure leaves the first one
      30             :   // uninitialized.
      31           2 :   if (!atomsCache->encoding_id.init(cx, "encoding") ||
      32           1 :       !atomsCache->bytes_id.init(cx, "bytes")) {
      33           0 :     return false;
      34             :   }
      35           1 :   return true;
      36             : }
      37             : 
      38             : bool
      39           6 : NativeOSFileReadOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
      40             : {
      41             :   // Passing a null JSContext is OK only if we're initing from null,
      42             :   // Since in that case we will not have to do any property gets
      43             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
      44             :   // checkers by static analysis tools
      45           6 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
      46           6 :   NativeOSFileReadOptionsAtoms* atomsCache = nullptr;
      47           6 :   if (cx) {
      48           3 :     atomsCache = GetAtomCache<NativeOSFileReadOptionsAtoms>(cx);
      49           3 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
      50           0 :       return false;
      51             :     }
      52             :   }
      53             : 
      54           6 :   if (!IsConvertibleToDictionary(val)) {
      55           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
      56             :   }
      57             : 
      58           6 :   bool isNull = val.isNullOrUndefined();
      59             :   // We only need these if !isNull, in which case we have |cx|.
      60          12 :   Maybe<JS::Rooted<JSObject *> > object;
      61          12 :   Maybe<JS::Rooted<JS::Value> > temp;
      62           6 :   if (!isNull) {
      63           3 :     MOZ_ASSERT(cx);
      64           3 :     object.emplace(cx, &val.toObject());
      65           3 :     temp.emplace(cx);
      66             :   }
      67           6 :   if (!isNull) {
      68           3 :     if (!JS_GetPropertyById(cx, *object, atomsCache->bytes_id, temp.ptr())) {
      69           0 :       return false;
      70             :     }
      71             :   }
      72           6 :   if (!isNull && !temp->isUndefined()) {
      73           0 :     mBytes.Construct();
      74           0 :     if (temp.ref().isNullOrUndefined()) {
      75           0 :       (mBytes.Value()).SetNull();
      76           0 :     } else if (!ValueToPrimitive<uint64_t, eDefault>(cx, temp.ref(), &(mBytes.Value()).SetValue())) {
      77           0 :       return false;
      78             :     }
      79           0 :     mIsAnyMemberPresent = true;
      80             :   }
      81             : 
      82           6 :   if (!isNull) {
      83           3 :     if (!JS_GetPropertyById(cx, *object, atomsCache->encoding_id, temp.ptr())) {
      84           0 :       return false;
      85             :     }
      86             :   }
      87           6 :   if (!isNull && !temp->isUndefined()) {
      88           2 :     mEncoding.Construct();
      89           2 :     if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, (mEncoding.Value()))) {
      90           0 :       return false;
      91             :     }
      92           2 :     mIsAnyMemberPresent = true;
      93             :   }
      94           6 :   return true;
      95             : }
      96             : 
      97             : bool
      98           0 : NativeOSFileReadOptions::Init(const nsAString& aJSON)
      99             : {
     100           0 :   AutoJSAPI jsapi;
     101           0 :   JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
     102           0 :   if (!cleanGlobal) {
     103           0 :     return false;
     104             :   }
     105           0 :   if (!jsapi.Init(cleanGlobal)) {
     106           0 :     return false;
     107             :   }
     108           0 :   JSContext* cx = jsapi.cx();
     109           0 :   JS::Rooted<JS::Value> json(cx);
     110           0 :   bool ok = ParseJSON(cx, aJSON, &json);
     111           0 :   NS_ENSURE_TRUE(ok, false);
     112           0 :   return Init(cx, json);
     113             : }
     114             : 
     115             : bool
     116           0 : NativeOSFileReadOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     117             : {
     118           0 :   NativeOSFileReadOptionsAtoms* atomsCache = GetAtomCache<NativeOSFileReadOptionsAtoms>(cx);
     119           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     120           0 :     return false;
     121             :   }
     122             : 
     123           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
     124           0 :   if (!obj) {
     125           0 :     return false;
     126             :   }
     127           0 :   rval.set(JS::ObjectValue(*obj));
     128             : 
     129           0 :   if (mBytes.WasPassed()) {
     130             :     do {
     131             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     132           0 :       JS::Rooted<JS::Value> temp(cx);
     133           0 :       Nullable<uint64_t> const & currentValue = mBytes.InternalValue();
     134           0 :       if (currentValue.IsNull()) {
     135           0 :         temp.setNull();
     136           0 :         if (!JS_DefinePropertyById(cx, obj, atomsCache->bytes_id, temp, JSPROP_ENUMERATE)) {
     137           0 :           return false;
     138             :         }
     139           0 :         break;
     140             :       }
     141           0 :       temp.set(JS_NumberValue(double(currentValue.Value())));
     142           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->bytes_id, temp, JSPROP_ENUMERATE)) {
     143           0 :         return false;
     144             :       }
     145           0 :       break;
     146             :     } while(0);
     147             :   }
     148             : 
     149           0 :   if (mEncoding.WasPassed()) {
     150             :     do {
     151             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     152           0 :       JS::Rooted<JS::Value> temp(cx);
     153           0 :       nsString const & currentValue = mEncoding.InternalValue();
     154           0 :       if (!xpc::StringToJsval(cx, currentValue, &temp)) {
     155           0 :         return false;
     156             :       }
     157           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->encoding_id, temp, JSPROP_ENUMERATE)) {
     158           0 :         return false;
     159             :       }
     160           0 :       break;
     161             :     } while(0);
     162             :   }
     163             : 
     164           0 :   return true;
     165             : }
     166             : 
     167             : bool
     168           0 : NativeOSFileReadOptions::ToJSON(nsAString& aJSON) const
     169             : {
     170           0 :   AutoJSAPI jsapi;
     171           0 :   jsapi.Init();
     172           0 :   JSContext *cx = jsapi.cx();
     173             :   // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
     174             :   // because we'll only be creating objects, in ways that have no
     175             :   // side-effects, followed by a call to JS::ToJSONMaybeSafely,
     176             :   // which likewise guarantees no side-effects for the sorts of
     177             :   // things we will pass it.
     178           0 :   JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
     179           0 :   JS::Rooted<JS::Value> val(cx);
     180           0 :   if (!ToObjectInternal(cx, &val)) {
     181           0 :     return false;
     182             :   }
     183           0 :   JS::Rooted<JSObject*> obj(cx, &val.toObject());
     184           0 :   return StringifyToJSON(cx, obj, aJSON);
     185             : }
     186             : 
     187             : void
     188           0 : NativeOSFileReadOptions::TraceDictionary(JSTracer* trc)
     189             : {
     190           0 : }
     191             : 
     192             : NativeOSFileReadOptions&
     193           0 : NativeOSFileReadOptions::operator=(const NativeOSFileReadOptions& aOther)
     194             : {
     195           0 :   mBytes.Reset();
     196           0 :   if (aOther.mBytes.WasPassed()) {
     197           0 :     mBytes.Construct(aOther.mBytes.Value());
     198             :   }
     199           0 :   mEncoding.Reset();
     200           0 :   if (aOther.mEncoding.WasPassed()) {
     201           0 :     mEncoding.Construct(aOther.mEncoding.Value());
     202             :   }
     203           0 :   return *this;
     204             : }
     205             : 
     206             : namespace binding_detail {
     207             : } // namespace binding_detail
     208             : 
     209             : 
     210             : } // namespace dom
     211             : } // namespace mozilla

Generated by: LCOV version 1.13