Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/WebGPUExtrasBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM WebGPUExtras.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "WebGPUExtrasBinding.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
11
namespace mozilla {
12
namespace dom {
13
14
namespace binding_detail {}; // Just to make sure it's known as a namespace
15
using namespace mozilla::dom::binding_detail;
16
17
18
19
WebGPUBufferBinding::WebGPUBufferBinding()
20
0
{
21
0
  // Safe to pass a null context if we pass a null value
22
0
  Init(nullptr, JS::NullHandleValue);
23
0
}
24
25
26
27
bool
28
WebGPUBufferBinding::InitIds(JSContext* cx, WebGPUBufferBindingAtoms* atomsCache)
29
0
{
30
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
31
0
32
0
  // Initialize these in reverse order so that any failure leaves the first one
33
0
  // uninitialized.
34
0
  if (!atomsCache->size_id.init(cx, "size") ||
35
0
      !atomsCache->offset_id.init(cx, "offset") ||
36
0
      !atomsCache->buffer_id.init(cx, "buffer")) {
37
0
    return false;
38
0
  }
39
0
  return true;
40
0
}
41
42
bool
43
WebGPUBufferBinding::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
  WebGPUBufferBindingAtoms* atomsCache = nullptr;
51
0
  if (cx) {
52
0
    atomsCache = GetAtomCache<WebGPUBufferBindingAtoms>(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->buffer_id, temp.ptr())) {
73
0
      return false;
74
0
    }
75
0
  }
76
0
  if (!isNull && !temp->isUndefined()) {
77
0
    mBuffer.Construct();
78
0
    if (temp.ref().isObject()) {
79
0
      static_assert(IsRefcounted<mozilla::webgpu::Buffer>::value, "We can only store refcounted classes.");{
80
0
        nsresult rv = UnwrapObject<prototypes::id::WebGPUBuffer, mozilla::webgpu::Buffer>(temp.ptr(), (mBuffer.Value()));
81
0
        if (NS_FAILED(rv)) {
82
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'buffer' member of WebGPUBufferBinding", "WebGPUBuffer");
83
0
          return false;
84
0
        }
85
0
      }
86
0
    } else {
87
0
      ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'buffer' member of WebGPUBufferBinding");
88
0
      return false;
89
0
    }
90
0
    mIsAnyMemberPresent = true;
91
0
  }
92
0
93
0
  if (!isNull) {
94
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->offset_id, temp.ptr())) {
95
0
      return false;
96
0
    }
97
0
  }
98
0
  if (!isNull && !temp->isUndefined()) {
99
0
    mOffset.Construct();
100
0
    if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mOffset.Value()))) {
101
0
      return false;
102
0
    }
103
0
    mIsAnyMemberPresent = true;
104
0
  }
105
0
106
0
  if (!isNull) {
107
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->size_id, temp.ptr())) {
108
0
      return false;
109
0
    }
110
0
  }
111
0
  if (!isNull && !temp->isUndefined()) {
112
0
    mSize.Construct();
113
0
    if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &(mSize.Value()))) {
114
0
      return false;
115
0
    }
116
0
    mIsAnyMemberPresent = true;
117
0
  }
118
0
  return true;
119
0
}
120
121
bool
122
WebGPUBufferBinding::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
123
0
{
124
0
  WebGPUBufferBindingAtoms* atomsCache = GetAtomCache<WebGPUBufferBindingAtoms>(cx);
125
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
126
0
    return false;
127
0
  }
128
0
129
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
130
0
  if (!obj) {
131
0
    return false;
132
0
  }
133
0
  rval.set(JS::ObjectValue(*obj));
134
0
135
0
  if (mBuffer.WasPassed()) {
136
0
    do {
137
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
138
0
      JS::Rooted<JS::Value> temp(cx);
139
0
      OwningNonNull<mozilla::webgpu::Buffer> const & currentValue = mBuffer.InternalValue();
140
0
      if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) {
141
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
142
0
        return false;
143
0
      }
144
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->buffer_id, temp, JSPROP_ENUMERATE)) {
145
0
        return false;
146
0
      }
147
0
      break;
148
0
    } while(false);
149
0
  }
150
0
151
0
  if (mOffset.WasPassed()) {
152
0
    do {
153
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
154
0
      JS::Rooted<JS::Value> temp(cx);
155
0
      uint32_t const & currentValue = mOffset.InternalValue();
156
0
      temp.setNumber(currentValue);
157
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->offset_id, temp, JSPROP_ENUMERATE)) {
158
0
        return false;
159
0
      }
160
0
      break;
161
0
    } while(false);
162
0
  }
163
0
164
0
  if (mSize.WasPassed()) {
165
0
    do {
166
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
167
0
      JS::Rooted<JS::Value> temp(cx);
168
0
      uint32_t const & currentValue = mSize.InternalValue();
169
0
      temp.setNumber(currentValue);
170
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->size_id, temp, JSPROP_ENUMERATE)) {
171
0
        return false;
172
0
      }
173
0
      break;
174
0
    } while(false);
175
0
  }
176
0
177
0
  return true;
178
0
}
179
180
void
181
WebGPUBufferBinding::TraceDictionary(JSTracer* trc)
182
0
{
183
0
}
184
185
186
187
WebGPUBufferBinding&
188
WebGPUBufferBinding::operator=(const WebGPUBufferBinding& aOther)
189
0
{
190
0
  DictionaryBase::operator=(aOther);
191
0
  mBuffer.Reset();
192
0
  if (aOther.mBuffer.WasPassed()) {
193
0
    mBuffer.Construct(aOther.mBuffer.Value());
194
0
  }
195
0
  mOffset.Reset();
196
0
  if (aOther.mOffset.WasPassed()) {
197
0
    mOffset.Construct(aOther.mOffset.Value());
198
0
  }
199
0
  mSize.Reset();
200
0
  if (aOther.mSize.WasPassed()) {
201
0
    mSize.Construct(aOther.mSize.Value());
202
0
  }
203
0
  return *this;
204
0
}
205
206
namespace binding_detail {
207
} // namespace binding_detail
208
209
210
} // namespace dom
211
} // namespace mozilla