Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/StructuredCloneHolderBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM StructuredCloneHolder.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "StructuredCloneHolderBinding.h"
4
#include "WrapperFactory.h"
5
#include "mozilla/OwningNonNull.h"
6
#include "mozilla/dom/BindingUtils.h"
7
#include "mozilla/dom/DOMJSClass.h"
8
#include "mozilla/dom/NonRefcountedDOMObject.h"
9
#include "mozilla/dom/Nullable.h"
10
#include "mozilla/dom/StructuredCloneBlob.h"
11
#include "mozilla/dom/XrayExpandoClass.h"
12
#include "nsContentUtils.h"
13
14
namespace mozilla {
15
namespace dom {
16
17
namespace binding_detail {}; // Just to make sure it's known as a namespace
18
using namespace mozilla::dom::binding_detail;
19
20
21
namespace StructuredCloneHolder_Binding {
22
23
MOZ_CAN_RUN_SCRIPT static bool
24
deserialize(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::StructuredCloneBlob* self, const JSJitMethodCallArgs& args)
25
0
{
26
0
  AUTO_PROFILER_LABEL_FAST("StructuredCloneHolder.deserialize", DOM, cx);
27
0
28
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
29
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "StructuredCloneHolder.deserialize");
30
0
  }
31
0
  JS::Rooted<JSObject*> arg0(cx);
32
0
  if (args[0].isObject()) {
33
0
    arg0 = &args[0].toObject();
34
0
  } else {
35
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of StructuredCloneHolder.deserialize");
36
0
    return false;
37
0
  }
38
0
  FastErrorResult rv;
39
0
  JS::Rooted<JS::Value> result(cx);
40
0
  self->Deserialize(cx, arg0, &result, rv);
41
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
42
0
    return false;
43
0
  }
44
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
45
0
  JS::ExposeValueToActiveJS(result);
46
0
  args.rval().set(result);
47
0
  if (!MaybeWrapValue(cx, args.rval())) {
48
0
    return false;
49
0
  }
50
0
  return true;
51
0
}
52
53
static const JSJitInfo deserialize_methodinfo = {
54
  { (JSJitGetterOp)deserialize },
55
  { prototypes::id::StructuredCloneHolder },
56
  { PrototypeTraits<prototypes::id::StructuredCloneHolder>::Depth },
57
  JSJitInfo::Method,
58
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
59
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
60
  false,  /* isInfallible. False in setters. */
61
  false,  /* isMovable.  Not relevant for setters. */
62
  false, /* isEliminatable.  Not relevant for setters. */
63
  false, /* isAlwaysInSlot.  Only relevant for getters. */
64
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
65
  false,  /* isTypedMethod.  Only relevant for methods. */
66
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
67
};
68
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
69
static_assert(0 < 1, "There is no slot for us");
70
71
static void
72
_finalize(js::FreeOp* fop, JSObject* obj)
73
0
{
74
0
  mozilla::dom::StructuredCloneBlob* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::StructuredCloneBlob>(obj);
75
0
  if (self) {
76
0
    AddForDeferredFinalization<mozilla::dom::StructuredCloneBlob>(self);
77
0
  }
78
0
}
79
80
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
81
#if defined(__clang__)
82
#pragma clang diagnostic push
83
#pragma clang diagnostic ignored "-Wmissing-braces"
84
#endif
85
static const JSFunctionSpec sMethods_specs[] = {
86
  JS_FNSPEC("deserialize", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&deserialize_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
87
  JS_FS_END
88
};
89
#if defined(__clang__)
90
#pragma clang diagnostic pop
91
#endif
92
93
94
static const Prefable<const JSFunctionSpec> sMethods[] = {
95
  { nullptr, &sMethods_specs[0] },
96
  { nullptr, nullptr }
97
};
98
99
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
100
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
101
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
102
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
103
104
105
static uint16_t sNativeProperties_sortedPropertyIndices[1];
106
static PropertyInfo sNativeProperties_propertyInfos[1];
107
108
static const NativePropertiesN<1> sNativeProperties = {
109
  false, 0,
110
  false, 0,
111
  true,  0 /* sMethods */,
112
  false, 0,
113
  false, 0,
114
  false, 0,
115
  false, 0,
116
  -1,
117
  1,
118
  sNativeProperties_sortedPropertyIndices,
119
  {
120
    { sMethods, &sNativeProperties_propertyInfos[0] }
121
  }
122
};
123
static_assert(1 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
124
    "We have a property info count that is oversized");
125
126
static bool
127
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
128
0
{
129
0
  AUTO_PROFILER_LABEL_FAST("StructuredCloneHolder constructor", DOM, cx);
130
0
131
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
132
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
133
0
  if (!args.isConstructing()) {
134
0
    // XXXbz wish I could get the name from the callee instead of
135
0
    // Adding more relocations
136
0
    return ThrowConstructorWithoutNew(cx, "StructuredCloneHolder");
137
0
  }
138
0
139
0
  JS::Rooted<JSObject*> desiredProto(cx);
140
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
141
0
    return false;
142
0
  }
143
0
144
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
145
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "StructuredCloneHolder");
146
0
  }
147
0
  GlobalObject global(cx, obj);
148
0
  if (global.Failed()) {
149
0
    return false;
150
0
  }
151
0
152
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
153
0
  JS::Rooted<JS::Value> arg0(cx);
154
0
  arg0 = args[0];
155
0
  JS::Rooted<JSObject*> arg1(cx);
156
0
  if (args.hasDefined(1)) {
157
0
    if (args[1].isObject()) {
158
0
      arg1 = &args[1].toObject();
159
0
    } else if (args[1].isNullOrUndefined()) {
160
0
      arg1 = nullptr;
161
0
    } else {
162
0
      ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of StructuredCloneHolder.constructor");
163
0
      return false;
164
0
    }
165
0
  } else {
166
0
    arg1 = nullptr;
167
0
  }
168
0
  Maybe<JSAutoRealm> ar;
169
0
  if (objIsXray) {
170
0
    obj = js::CheckedUnwrap(obj);
171
0
    if (!obj) {
172
0
      return false;
173
0
    }
174
0
    ar.emplace(cx, obj);
175
0
    if (!JS_WrapObject(cx, &desiredProto)) {
176
0
      return false;
177
0
    }
178
0
    if (!JS_WrapValue(cx, &arg0)) {
179
0
      return false;
180
0
    }
181
0
    if (!JS_WrapObject(cx, &arg1)) {
182
0
      return false;
183
0
    }
184
0
  }
185
0
  FastErrorResult rv;
186
0
  auto result(StrongOrRawPtr<mozilla::dom::StructuredCloneBlob>(mozilla::dom::StructuredCloneBlob::Constructor(global, arg0, arg1, rv)));
187
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
188
0
    return false;
189
0
  }
190
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
191
0
  static_assert(!IsPointer<decltype(result)>::value,
192
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
193
0
  if (!WrapNewBindingNonWrapperCachedObject(cx, obj, result, args.rval(), desiredProto)) {
194
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
195
0
    return false;
196
0
  }
197
0
  return true;
198
0
}
199
200
static const js::ClassOps sInterfaceObjectClassOps = {
201
    nullptr,               /* addProperty */
202
    nullptr,               /* delProperty */
203
    nullptr,               /* enumerate */
204
    nullptr,               /* newEnumerate */
205
    nullptr,               /* resolve */
206
    nullptr,               /* mayResolve */
207
    nullptr,               /* finalize */
208
    _constructor, /* call */
209
    nullptr,               /* hasInstance */
210
    _constructor, /* construct */
211
    nullptr,               /* trace */
212
};
213
214
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
215
  {
216
    "Function",
217
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
218
    &sInterfaceObjectClassOps,
219
    JS_NULL_CLASS_SPEC,
220
    JS_NULL_CLASS_EXT,
221
    &sInterfaceObjectClassObjectOps
222
  },
223
  eInterface,
224
  true,
225
  prototypes::id::StructuredCloneHolder,
226
  PrototypeTraits<prototypes::id::StructuredCloneHolder>::Depth,
227
  sNativePropertyHooks,
228
  "function StructuredCloneHolder() {\n    [native code]\n}",
229
  JS::GetRealmFunctionPrototype
230
};
231
232
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
233
  {
234
    "StructuredCloneHolderPrototype",
235
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
236
    JS_NULL_CLASS_OPS,
237
    JS_NULL_CLASS_SPEC,
238
    JS_NULL_CLASS_EXT,
239
    JS_NULL_OBJECT_OPS
240
  },
241
  eInterfacePrototype,
242
  false,
243
  prototypes::id::StructuredCloneHolder,
244
  PrototypeTraits<prototypes::id::StructuredCloneHolder>::Depth,
245
  sNativePropertyHooks,
246
  "[object StructuredCloneHolderPrototype]",
247
  JS::GetRealmObjectPrototype
248
};
249
250
bool
251
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
252
0
{
253
0
  return nsContentUtils::ThreadsafeIsSystemCaller(aCx);
254
0
}
255
256
static const js::ClassOps sClassOps = {
257
  nullptr, /* addProperty */
258
  nullptr,               /* delProperty */
259
  nullptr,               /* enumerate */
260
  nullptr, /* newEnumerate */
261
  nullptr, /* resolve */
262
  nullptr, /* mayResolve */
263
  _finalize, /* finalize */
264
  nullptr, /* call */
265
  nullptr,               /* hasInstance */
266
  nullptr,               /* construct */
267
  nullptr, /* trace */
268
};
269
270
static const js::ClassExtension sClassExtension = {
271
  nullptr, /* weakmapKeyDelegateOp */
272
  nullptr /* objectMovedOp */
273
};
274
275
static const DOMJSClass sClass = {
276
  { "StructuredCloneHolder",
277
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
278
    &sClassOps,
279
    JS_NULL_CLASS_SPEC,
280
    &sClassExtension,
281
    JS_NULL_OBJECT_OPS
282
  },
283
  { prototypes::id::StructuredCloneHolder, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
284
  IsBaseOf<nsISupports, mozilla::dom::StructuredCloneBlob >::value,
285
  sNativePropertyHooks,
286
  FindAssociatedGlobalForNative<mozilla::dom::StructuredCloneBlob>::Get,
287
  GetProtoObjectHandle,
288
  GetCCParticipant<mozilla::dom::StructuredCloneBlob>::Get()
289
};
290
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
291
              "Must have the right minimal number of reserved slots.");
292
static_assert(1 >= 1,
293
              "Must have enough reserved slots.");
294
295
const JSClass*
296
GetJSClass()
297
0
{
298
0
  return sClass.ToJSClass();
299
0
}
300
301
bool
302
Wrap(JSContext* aCx, mozilla::dom::StructuredCloneBlob* aObject, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
303
0
{
304
0
  MOZ_ASSERT(static_cast<mozilla::dom::StructuredCloneBlob*>(aObject) ==
305
0
             reinterpret_cast<mozilla::dom::StructuredCloneBlob*>(aObject),
306
0
             "Multiple inheritance for mozilla::dom::StructuredCloneBlob is broken.");
307
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
308
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
309
0
310
0
  JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
311
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
312
0
  if (!canonicalProto) {
313
0
    return false;
314
0
  }
315
0
  JS::Rooted<JSObject*> proto(aCx);
316
0
  if (aGivenProto) {
317
0
    proto = aGivenProto;
318
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
319
0
    // coming in, we changed compartments to that of "parent" so may need
320
0
    // to wrap the proto here.
321
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
322
0
      if (!JS_WrapObject(aCx, &proto)) {
323
0
        return false;
324
0
      }
325
0
    }
326
0
  } else {
327
0
    proto = canonicalProto;
328
0
  }
329
0
330
0
  BindingJSObjectCreator<mozilla::dom::StructuredCloneBlob> creator(aCx);
331
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
332
0
  if (!aReflector) {
333
0
    return false;
334
0
  }
335
0
336
0
337
0
338
0
  creator.InitializationSucceeded();
339
0
  return true;
340
0
}
341
342
const NativePropertyHooks sNativePropertyHooks[] = { {
343
  nullptr,
344
  nullptr,
345
  nullptr,
346
  { sNativeProperties.Upcast(), nullptr },
347
  prototypes::id::StructuredCloneHolder,
348
  constructors::id::StructuredCloneHolder,
349
  nullptr,
350
  &DefaultXrayExpandoObjectClass
351
} };
352
353
void
354
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
355
0
{
356
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
357
0
  if (!parentProto) {
358
0
    return;
359
0
  }
360
0
361
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
362
0
  if (!constructorProto) {
363
0
    return;
364
0
  }
365
0
366
0
  static bool sIdsInited = false;
367
0
  if (!sIdsInited && NS_IsMainThread()) {
368
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
369
0
      return;
370
0
    }
371
0
    sIdsInited = true;
372
0
  }
373
0
374
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::StructuredCloneHolder);
375
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::StructuredCloneHolder);
376
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
377
0
                              &sPrototypeClass.mBase, protoCache,
378
0
                              nullptr,
379
0
                              constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
380
0
                              interfaceCache,
381
0
                              sNativeProperties.Upcast(),
382
0
                              nullptr,
383
0
                              "StructuredCloneHolder", aDefineOnGlobal,
384
0
                              nullptr,
385
0
                              false);
386
0
}
387
388
JSObject*
389
GetConstructorObject(JSContext* aCx)
390
0
{
391
0
  return GetConstructorObjectHandle(aCx);
392
0
}
393
394
} // namespace StructuredCloneHolder_Binding
395
396
397
398
} // namespace dom
399
} // namespace mozilla