Coverage Report

Created: 2018-09-25 14:53

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