Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/NativeOSFileInternalsBinding.cpp
Line
Count
Source (jump to first uncovered line)
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
namespace binding_detail {}; // Just to make sure it's known as a namespace
16
using namespace mozilla::dom::binding_detail;
17
18
19
20
NativeOSFileReadOptions::NativeOSFileReadOptions()
21
0
{
22
0
  // Safe to pass a null context if we pass a null value
23
0
  Init(nullptr, JS::NullHandleValue);
24
0
}
25
26
27
28
bool
29
NativeOSFileReadOptions::InitIds(JSContext* cx, NativeOSFileReadOptionsAtoms* atomsCache)
30
0
{
31
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
32
0
33
0
  // Initialize these in reverse order so that any failure leaves the first one
34
0
  // uninitialized.
35
0
  if (!atomsCache->encoding_id.init(cx, "encoding") ||
36
0
      !atomsCache->bytes_id.init(cx, "bytes")) {
37
0
    return false;
38
0
  }
39
0
  return true;
40
0
}
41
42
bool
43
NativeOSFileReadOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
44
0
{
45
0
  // Passing a null JSContext is OK only if we're initing from null,
46
0
  // Since in that case we will not have to do any property gets
47
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
48
0
  // checkers by static analysis tools
49
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
50
0
  NativeOSFileReadOptionsAtoms* atomsCache = nullptr;
51
0
  if (cx) {
52
0
    atomsCache = GetAtomCache<NativeOSFileReadOptionsAtoms>(cx);
53
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
54
0
      return false;
55
0
    }
56
0
  }
57
0
58
0
  if (!IsConvertibleToDictionary(val)) {
59
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
60
0
  }
61
0
62
0
  bool isNull = val.isNullOrUndefined();
63
0
  // We only need these if !isNull, in which case we have |cx|.
64
0
  Maybe<JS::Rooted<JSObject *> > object;
65
0
  Maybe<JS::Rooted<JS::Value> > temp;
66
0
  if (!isNull) {
67
0
    MOZ_ASSERT(cx);
68
0
    object.emplace(cx, &val.toObject());
69
0
    temp.emplace(cx);
70
0
  }
71
0
  if (!isNull) {
72
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->bytes_id, temp.ptr())) {
73
0
      return false;
74
0
    }
75
0
  }
76
0
  if (!isNull && !temp->isUndefined()) {
77
0
    mBytes.Construct();
78
0
    if (temp.ref().isNullOrUndefined()) {
79
0
      (mBytes.Value()).SetNull();
80
0
    } else if (!ValueToPrimitive<uint64_t, eDefault>(cx, temp.ref(), &(mBytes.Value()).SetValue())) {
81
0
      return false;
82
0
    }
83
0
    mIsAnyMemberPresent = true;
84
0
  }
85
0
86
0
  if (!isNull) {
87
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->encoding_id, temp.ptr())) {
88
0
      return false;
89
0
    }
90
0
  }
91
0
  if (!isNull && !temp->isUndefined()) {
92
0
    mEncoding.Construct();
93
0
    if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, (mEncoding.Value()))) {
94
0
      return false;
95
0
    }
96
0
    mIsAnyMemberPresent = true;
97
0
  }
98
0
  return true;
99
0
}
100
101
bool
102
NativeOSFileReadOptions::Init(const nsAString& aJSON)
103
0
{
104
0
  AutoJSAPI jsapi;
105
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
106
0
  if (!cleanGlobal) {
107
0
    return false;
108
0
  }
109
0
  if (!jsapi.Init(cleanGlobal)) {
110
0
    return false;
111
0
  }
112
0
  JSContext* cx = jsapi.cx();
113
0
  JS::Rooted<JS::Value> json(cx);
114
0
  bool ok = ParseJSON(cx, aJSON, &json);
115
0
  NS_ENSURE_TRUE(ok, false);
116
0
  return Init(cx, json);
117
0
}
118
119
bool
120
NativeOSFileReadOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
121
0
{
122
0
  NativeOSFileReadOptionsAtoms* atomsCache = GetAtomCache<NativeOSFileReadOptionsAtoms>(cx);
123
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
124
0
    return false;
125
0
  }
126
0
127
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
128
0
  if (!obj) {
129
0
    return false;
130
0
  }
131
0
  rval.set(JS::ObjectValue(*obj));
132
0
133
0
  if (mBytes.WasPassed()) {
134
0
    do {
135
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
136
0
      JS::Rooted<JS::Value> temp(cx);
137
0
      Nullable<uint64_t> const & currentValue = mBytes.InternalValue();
138
0
      if (currentValue.IsNull()) {
139
0
        temp.setNull();
140
0
        if (!JS_DefinePropertyById(cx, obj, atomsCache->bytes_id, temp, JSPROP_ENUMERATE)) {
141
0
          return false;
142
0
        }
143
0
        break;
144
0
      }
145
0
      temp.set(JS_NumberValue(double(currentValue.Value())));
146
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->bytes_id, temp, JSPROP_ENUMERATE)) {
147
0
        return false;
148
0
      }
149
0
      break;
150
0
    } while(false);
151
0
  }
152
0
153
0
  if (mEncoding.WasPassed()) {
154
0
    do {
155
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
156
0
      JS::Rooted<JS::Value> temp(cx);
157
0
      nsString const & currentValue = mEncoding.InternalValue();
158
0
      if (!xpc::StringToJsval(cx, currentValue, &temp)) {
159
0
        return false;
160
0
      }
161
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->encoding_id, temp, JSPROP_ENUMERATE)) {
162
0
        return false;
163
0
      }
164
0
      break;
165
0
    } while(false);
166
0
  }
167
0
168
0
  return true;
169
0
}
170
171
bool
172
NativeOSFileReadOptions::ToJSON(nsAString& aJSON) const
173
0
{
174
0
  AutoJSAPI jsapi;
175
0
  jsapi.Init();
176
0
  JSContext *cx = jsapi.cx();
177
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
178
0
  // because we'll only be creating objects, in ways that have no
179
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
180
0
  // which likewise guarantees no side-effects for the sorts of
181
0
  // things we will pass it.
182
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
183
0
  JS::Rooted<JS::Value> val(cx);
184
0
  if (!ToObjectInternal(cx, &val)) {
185
0
    return false;
186
0
  }
187
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
188
0
  return StringifyToJSON(cx, obj, aJSON);
189
0
}
190
191
void
192
NativeOSFileReadOptions::TraceDictionary(JSTracer* trc)
193
0
{
194
0
}
195
196
NativeOSFileReadOptions&
197
NativeOSFileReadOptions::operator=(const NativeOSFileReadOptions& aOther)
198
0
{
199
0
  DictionaryBase::operator=(aOther);
200
0
  mBytes.Reset();
201
0
  if (aOther.mBytes.WasPassed()) {
202
0
    mBytes.Construct(aOther.mBytes.Value());
203
0
  }
204
0
  mEncoding.Reset();
205
0
  if (aOther.mEncoding.WasPassed()) {
206
0
    mEncoding.Construct(aOther.mEncoding.Value());
207
0
  }
208
0
  return *this;
209
0
}
210
211
namespace binding_detail {
212
} // namespace binding_detail
213
214
215
216
NativeOSFileWriteAtomicOptions::NativeOSFileWriteAtomicOptions()
217
0
{
218
0
  // Safe to pass a null context if we pass a null value
219
0
  Init(nullptr, JS::NullHandleValue);
220
0
}
221
222
223
224
bool
225
NativeOSFileWriteAtomicOptions::InitIds(JSContext* cx, NativeOSFileWriteAtomicOptionsAtoms* atomsCache)
226
0
{
227
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
228
0
229
0
  // Initialize these in reverse order so that any failure leaves the first one
230
0
  // uninitialized.
231
0
  if (!atomsCache->tmpPath_id.init(cx, "tmpPath") ||
232
0
      !atomsCache->noOverwrite_id.init(cx, "noOverwrite") ||
233
0
      !atomsCache->flush_id.init(cx, "flush") ||
234
0
      !atomsCache->bytes_id.init(cx, "bytes") ||
235
0
      !atomsCache->backupTo_id.init(cx, "backupTo")) {
236
0
    return false;
237
0
  }
238
0
  return true;
239
0
}
240
241
bool
242
NativeOSFileWriteAtomicOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
243
0
{
244
0
  // Passing a null JSContext is OK only if we're initing from null,
245
0
  // Since in that case we will not have to do any property gets
246
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
247
0
  // checkers by static analysis tools
248
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
249
0
  NativeOSFileWriteAtomicOptionsAtoms* atomsCache = nullptr;
250
0
  if (cx) {
251
0
    atomsCache = GetAtomCache<NativeOSFileWriteAtomicOptionsAtoms>(cx);
252
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
253
0
      return false;
254
0
    }
255
0
  }
256
0
257
0
  if (!IsConvertibleToDictionary(val)) {
258
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
259
0
  }
260
0
261
0
  bool isNull = val.isNullOrUndefined();
262
0
  // We only need these if !isNull, in which case we have |cx|.
263
0
  Maybe<JS::Rooted<JSObject *> > object;
264
0
  Maybe<JS::Rooted<JS::Value> > temp;
265
0
  if (!isNull) {
266
0
    MOZ_ASSERT(cx);
267
0
    object.emplace(cx, &val.toObject());
268
0
    temp.emplace(cx);
269
0
  }
270
0
  if (!isNull) {
271
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->backupTo_id, temp.ptr())) {
272
0
      return false;
273
0
    }
274
0
  }
275
0
  if (!isNull && !temp->isUndefined()) {
276
0
    if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, mBackupTo)) {
277
0
      return false;
278
0
    }
279
0
  } else {
280
0
    mBackupTo.SetIsVoid(true);
281
0
  }
282
0
  mIsAnyMemberPresent = true;
283
0
284
0
  if (!isNull) {
285
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->bytes_id, temp.ptr())) {
286
0
      return false;
287
0
    }
288
0
  }
289
0
  if (!isNull && !temp->isUndefined()) {
290
0
    mBytes.Construct();
291
0
    if (temp.ref().isNullOrUndefined()) {
292
0
      (mBytes.Value()).SetNull();
293
0
    } else if (!ValueToPrimitive<uint64_t, eDefault>(cx, temp.ref(), &(mBytes.Value()).SetValue())) {
294
0
      return false;
295
0
    }
296
0
    mIsAnyMemberPresent = true;
297
0
  }
298
0
299
0
  if (!isNull) {
300
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->flush_id, temp.ptr())) {
301
0
      return false;
302
0
    }
303
0
  }
304
0
  if (!isNull && !temp->isUndefined()) {
305
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mFlush)) {
306
0
      return false;
307
0
    }
308
0
  } else {
309
0
    mFlush = false;
310
0
  }
311
0
  mIsAnyMemberPresent = true;
312
0
313
0
  if (!isNull) {
314
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->noOverwrite_id, temp.ptr())) {
315
0
      return false;
316
0
    }
317
0
  }
318
0
  if (!isNull && !temp->isUndefined()) {
319
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mNoOverwrite)) {
320
0
      return false;
321
0
    }
322
0
  } else {
323
0
    mNoOverwrite = false;
324
0
  }
325
0
  mIsAnyMemberPresent = true;
326
0
327
0
  if (!isNull) {
328
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->tmpPath_id, temp.ptr())) {
329
0
      return false;
330
0
    }
331
0
  }
332
0
  if (!isNull && !temp->isUndefined()) {
333
0
    if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, mTmpPath)) {
334
0
      return false;
335
0
    }
336
0
  } else {
337
0
    mTmpPath.SetIsVoid(true);
338
0
  }
339
0
  mIsAnyMemberPresent = true;
340
0
  return true;
341
0
}
342
343
bool
344
NativeOSFileWriteAtomicOptions::Init(const nsAString& aJSON)
345
0
{
346
0
  AutoJSAPI jsapi;
347
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
348
0
  if (!cleanGlobal) {
349
0
    return false;
350
0
  }
351
0
  if (!jsapi.Init(cleanGlobal)) {
352
0
    return false;
353
0
  }
354
0
  JSContext* cx = jsapi.cx();
355
0
  JS::Rooted<JS::Value> json(cx);
356
0
  bool ok = ParseJSON(cx, aJSON, &json);
357
0
  NS_ENSURE_TRUE(ok, false);
358
0
  return Init(cx, json);
359
0
}
360
361
bool
362
NativeOSFileWriteAtomicOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
363
0
{
364
0
  NativeOSFileWriteAtomicOptionsAtoms* atomsCache = GetAtomCache<NativeOSFileWriteAtomicOptionsAtoms>(cx);
365
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
366
0
    return false;
367
0
  }
368
0
369
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
370
0
  if (!obj) {
371
0
    return false;
372
0
  }
373
0
  rval.set(JS::ObjectValue(*obj));
374
0
375
0
  do {
376
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
377
0
    JS::Rooted<JS::Value> temp(cx);
378
0
    nsString const & currentValue = mBackupTo;
379
0
    if (!xpc::StringToJsval(cx, currentValue, &temp)) {
380
0
      return false;
381
0
    }
382
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->backupTo_id, temp, JSPROP_ENUMERATE)) {
383
0
      return false;
384
0
    }
385
0
    break;
386
0
  } while(false);
387
0
388
0
  if (mBytes.WasPassed()) {
389
0
    do {
390
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
391
0
      JS::Rooted<JS::Value> temp(cx);
392
0
      Nullable<uint64_t> const & currentValue = mBytes.InternalValue();
393
0
      if (currentValue.IsNull()) {
394
0
        temp.setNull();
395
0
        if (!JS_DefinePropertyById(cx, obj, atomsCache->bytes_id, temp, JSPROP_ENUMERATE)) {
396
0
          return false;
397
0
        }
398
0
        break;
399
0
      }
400
0
      temp.set(JS_NumberValue(double(currentValue.Value())));
401
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->bytes_id, temp, JSPROP_ENUMERATE)) {
402
0
        return false;
403
0
      }
404
0
      break;
405
0
    } while(false);
406
0
  }
407
0
408
0
  do {
409
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
410
0
    JS::Rooted<JS::Value> temp(cx);
411
0
    bool const & currentValue = mFlush;
412
0
    temp.setBoolean(currentValue);
413
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->flush_id, temp, JSPROP_ENUMERATE)) {
414
0
      return false;
415
0
    }
416
0
    break;
417
0
  } while(false);
418
0
419
0
  do {
420
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
421
0
    JS::Rooted<JS::Value> temp(cx);
422
0
    bool const & currentValue = mNoOverwrite;
423
0
    temp.setBoolean(currentValue);
424
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->noOverwrite_id, temp, JSPROP_ENUMERATE)) {
425
0
      return false;
426
0
    }
427
0
    break;
428
0
  } while(false);
429
0
430
0
  do {
431
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
432
0
    JS::Rooted<JS::Value> temp(cx);
433
0
    nsString const & currentValue = mTmpPath;
434
0
    if (!xpc::StringToJsval(cx, currentValue, &temp)) {
435
0
      return false;
436
0
    }
437
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->tmpPath_id, temp, JSPROP_ENUMERATE)) {
438
0
      return false;
439
0
    }
440
0
    break;
441
0
  } while(false);
442
0
443
0
  return true;
444
0
}
445
446
bool
447
NativeOSFileWriteAtomicOptions::ToJSON(nsAString& aJSON) const
448
0
{
449
0
  AutoJSAPI jsapi;
450
0
  jsapi.Init();
451
0
  JSContext *cx = jsapi.cx();
452
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
453
0
  // because we'll only be creating objects, in ways that have no
454
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
455
0
  // which likewise guarantees no side-effects for the sorts of
456
0
  // things we will pass it.
457
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
458
0
  JS::Rooted<JS::Value> val(cx);
459
0
  if (!ToObjectInternal(cx, &val)) {
460
0
    return false;
461
0
  }
462
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
463
0
  return StringifyToJSON(cx, obj, aJSON);
464
0
}
465
466
void
467
NativeOSFileWriteAtomicOptions::TraceDictionary(JSTracer* trc)
468
0
{
469
0
}
470
471
NativeOSFileWriteAtomicOptions&
472
NativeOSFileWriteAtomicOptions::operator=(const NativeOSFileWriteAtomicOptions& aOther)
473
0
{
474
0
  DictionaryBase::operator=(aOther);
475
0
  mBackupTo = aOther.mBackupTo;
476
0
  mBytes.Reset();
477
0
  if (aOther.mBytes.WasPassed()) {
478
0
    mBytes.Construct(aOther.mBytes.Value());
479
0
  }
480
0
  mFlush = aOther.mFlush;
481
0
  mNoOverwrite = aOther.mNoOverwrite;
482
0
  mTmpPath = aOther.mTmpPath;
483
0
  return *this;
484
0
}
485
486
namespace binding_detail {
487
} // namespace binding_detail
488
489
490
} // namespace dom
491
} // namespace mozilla