Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/StyleSheetBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM StyleSheet.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "StyleSheetBinding.h"
4
#include "WrapperFactory.h"
5
#include "mozilla/OwningNonNull.h"
6
#include "mozilla/StyleSheetInlines.h"
7
#include "mozilla/dom/BindingUtils.h"
8
#include "mozilla/dom/DOMJSClass.h"
9
#include "mozilla/dom/MediaList.h"
10
#include "mozilla/dom/NonRefcountedDOMObject.h"
11
#include "mozilla/dom/Nullable.h"
12
#include "mozilla/dom/PrimitiveConversions.h"
13
#include "mozilla/dom/XrayExpandoClass.h"
14
#include "nsContentUtils.h"
15
#include "nsINode.h"
16
17
namespace mozilla {
18
namespace dom {
19
20
namespace binding_detail {}; // Just to make sure it's known as a namespace
21
using namespace mozilla::dom::binding_detail;
22
23
24
namespace StyleSheet_Binding {
25
26
MOZ_CAN_RUN_SCRIPT static bool
27
get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::StyleSheet* self, JSJitGetterCallArgs args)
28
0
{
29
0
  AUTO_PROFILER_LABEL_FAST("get StyleSheet.type", DOM, cx);
30
0
31
0
  DOMString result;
32
0
  self->GetType(result);
33
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
34
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
35
0
    return false;
36
0
  }
37
0
  return true;
38
0
}
39
40
static const JSJitInfo type_getterinfo = {
41
  { (JSJitGetterOp)get_type },
42
  { prototypes::id::StyleSheet },
43
  { PrototypeTraits<prototypes::id::StyleSheet>::Depth },
44
  JSJitInfo::Getter,
45
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
46
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
47
  false,  /* isInfallible. False in setters. */
48
  true,  /* isMovable.  Not relevant for setters. */
49
  true, /* isEliminatable.  Not relevant for setters. */
50
  false, /* isAlwaysInSlot.  Only relevant for getters. */
51
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
52
  false,  /* isTypedMethod.  Only relevant for methods. */
53
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
54
};
55
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
56
static_assert(0 < 1, "There is no slot for us");
57
58
MOZ_CAN_RUN_SCRIPT static bool
59
get_href(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::StyleSheet* self, JSJitGetterCallArgs args)
60
0
{
61
0
  AUTO_PROFILER_LABEL_FAST("get StyleSheet.href", DOM, cx);
62
0
63
0
  FastErrorResult rv;
64
0
  DOMString result;
65
0
  self->GetHref(result, rv);
66
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
67
0
    return false;
68
0
  }
69
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
70
0
  if (!xpc::StringToJsval(cx, result, args.rval())) {
71
0
    return false;
72
0
  }
73
0
  return true;
74
0
}
75
76
static const JSJitInfo href_getterinfo = {
77
  { (JSJitGetterOp)get_href },
78
  { prototypes::id::StyleSheet },
79
  { PrototypeTraits<prototypes::id::StyleSheet>::Depth },
80
  JSJitInfo::Getter,
81
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
82
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
83
  false,  /* isInfallible. False in setters. */
84
  false,  /* isMovable.  Not relevant for setters. */
85
  false, /* isEliminatable.  Not relevant for setters. */
86
  false, /* isAlwaysInSlot.  Only relevant for getters. */
87
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
88
  false,  /* isTypedMethod.  Only relevant for methods. */
89
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
90
};
91
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
92
static_assert(0 < 1, "There is no slot for us");
93
94
MOZ_CAN_RUN_SCRIPT static bool
95
get_ownerNode(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::StyleSheet* self, JSJitGetterCallArgs args)
96
0
{
97
0
  AUTO_PROFILER_LABEL_FAST("get StyleSheet.ownerNode", DOM, cx);
98
0
99
0
  auto result(StrongOrRawPtr<nsINode>(self->GetOwnerNode()));
100
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
101
0
  if (!result) {
102
0
    args.rval().setNull();
103
0
    return true;
104
0
  }
105
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
106
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
107
0
    return false;
108
0
  }
109
0
  return true;
110
0
}
111
112
static const JSJitInfo ownerNode_getterinfo = {
113
  { (JSJitGetterOp)get_ownerNode },
114
  { prototypes::id::StyleSheet },
115
  { PrototypeTraits<prototypes::id::StyleSheet>::Depth },
116
  JSJitInfo::Getter,
117
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
118
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
119
  false,  /* isInfallible. False in setters. */
120
  true,  /* isMovable.  Not relevant for setters. */
121
  true, /* isEliminatable.  Not relevant for setters. */
122
  false, /* isAlwaysInSlot.  Only relevant for getters. */
123
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
124
  false,  /* isTypedMethod.  Only relevant for methods. */
125
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
126
};
127
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
128
static_assert(0 < 1, "There is no slot for us");
129
130
MOZ_CAN_RUN_SCRIPT static bool
131
get_parentStyleSheet(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::StyleSheet* self, JSJitGetterCallArgs args)
132
0
{
133
0
  AUTO_PROFILER_LABEL_FAST("get StyleSheet.parentStyleSheet", DOM, cx);
134
0
135
0
  auto result(StrongOrRawPtr<mozilla::StyleSheet>(self->GetParentStyleSheet()));
136
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
137
0
  if (!result) {
138
0
    args.rval().setNull();
139
0
    return true;
140
0
  }
141
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
142
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
143
0
    return false;
144
0
  }
145
0
  return true;
146
0
}
147
148
static const JSJitInfo parentStyleSheet_getterinfo = {
149
  { (JSJitGetterOp)get_parentStyleSheet },
150
  { prototypes::id::StyleSheet },
151
  { PrototypeTraits<prototypes::id::StyleSheet>::Depth },
152
  JSJitInfo::Getter,
153
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
154
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
155
  false,  /* isInfallible. False in setters. */
156
  true,  /* isMovable.  Not relevant for setters. */
157
  true, /* isEliminatable.  Not relevant for setters. */
158
  false, /* isAlwaysInSlot.  Only relevant for getters. */
159
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
160
  false,  /* isTypedMethod.  Only relevant for methods. */
161
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
162
};
163
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
164
static_assert(0 < 1, "There is no slot for us");
165
166
MOZ_CAN_RUN_SCRIPT static bool
167
get_title(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::StyleSheet* self, JSJitGetterCallArgs args)
168
0
{
169
0
  AUTO_PROFILER_LABEL_FAST("get StyleSheet.title", DOM, cx);
170
0
171
0
  DOMString result;
172
0
  self->GetTitle(result);
173
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
174
0
  if (!xpc::StringToJsval(cx, result, args.rval())) {
175
0
    return false;
176
0
  }
177
0
  return true;
178
0
}
179
180
static const JSJitInfo title_getterinfo = {
181
  { (JSJitGetterOp)get_title },
182
  { prototypes::id::StyleSheet },
183
  { PrototypeTraits<prototypes::id::StyleSheet>::Depth },
184
  JSJitInfo::Getter,
185
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
186
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
187
  false,  /* isInfallible. False in setters. */
188
  true,  /* isMovable.  Not relevant for setters. */
189
  true, /* isEliminatable.  Not relevant for setters. */
190
  false, /* isAlwaysInSlot.  Only relevant for getters. */
191
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
192
  false,  /* isTypedMethod.  Only relevant for methods. */
193
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
194
};
195
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
196
static_assert(0 < 1, "There is no slot for us");
197
198
MOZ_CAN_RUN_SCRIPT static bool
199
get_media(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::StyleSheet* self, JSJitGetterCallArgs args)
200
0
{
201
0
  AUTO_PROFILER_LABEL_FAST("get StyleSheet.media", DOM, cx);
202
0
203
0
  auto result(StrongOrRawPtr<mozilla::dom::MediaList>(self->Media()));
204
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
205
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
206
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
207
0
    return false;
208
0
  }
209
0
  return true;
210
0
}
211
212
MOZ_CAN_RUN_SCRIPT static bool
213
set_media(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::StyleSheet* self, JSJitSetterCallArgs args)
214
0
{
215
0
  AUTO_PROFILER_LABEL_FAST("set StyleSheet.media", DOM, cx);
216
0
217
0
  JS::Rooted<JS::Value> v(cx);
218
0
  if (!JS_GetProperty(cx, obj, "media", &v)) {
219
0
    return false;
220
0
  }
221
0
222
0
  if (!v.isObject()) {
223
0
    return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "StyleSheet.media");
224
0
  }
225
0
226
0
  JS::Rooted<JSObject*> targetObj(cx, &v.toObject());
227
0
  return JS_SetProperty(cx, targetObj, "mediaText", args[0]);
228
0
}
229
230
static const JSJitInfo media_getterinfo = {
231
  { (JSJitGetterOp)get_media },
232
  { prototypes::id::StyleSheet },
233
  { PrototypeTraits<prototypes::id::StyleSheet>::Depth },
234
  JSJitInfo::Getter,
235
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
236
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
237
  false,  /* isInfallible. False in setters. */
238
  true,  /* isMovable.  Not relevant for setters. */
239
  true, /* isEliminatable.  Not relevant for setters. */
240
  false, /* isAlwaysInSlot.  Only relevant for getters. */
241
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
242
  false,  /* isTypedMethod.  Only relevant for methods. */
243
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
244
};
245
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
246
static_assert(0 < 1, "There is no slot for us");
247
static const JSJitInfo media_setterinfo = {
248
  { (JSJitGetterOp)set_media },
249
  { prototypes::id::StyleSheet },
250
  { PrototypeTraits<prototypes::id::StyleSheet>::Depth },
251
  JSJitInfo::Setter,
252
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
253
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
254
  false,  /* isInfallible. False in setters. */
255
  false,  /* isMovable.  Not relevant for setters. */
256
  false, /* isEliminatable.  Not relevant for setters. */
257
  false, /* isAlwaysInSlot.  Only relevant for getters. */
258
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
259
  false,  /* isTypedMethod.  Only relevant for methods. */
260
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
261
};
262
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
263
static_assert(0 < 1, "There is no slot for us");
264
265
MOZ_CAN_RUN_SCRIPT static bool
266
get_disabled(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::StyleSheet* self, JSJitGetterCallArgs args)
267
0
{
268
0
  AUTO_PROFILER_LABEL_FAST("get StyleSheet.disabled", DOM, cx);
269
0
270
0
  bool result(self->Disabled());
271
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
272
0
  args.rval().setBoolean(result);
273
0
  return true;
274
0
}
275
276
MOZ_CAN_RUN_SCRIPT static bool
277
set_disabled(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::StyleSheet* self, JSJitSetterCallArgs args)
278
0
{
279
0
  AUTO_PROFILER_LABEL_FAST("set StyleSheet.disabled", DOM, cx);
280
0
281
0
  bool arg0;
282
0
  if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
283
0
    return false;
284
0
  }
285
0
  self->SetDisabled(arg0);
286
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
287
0
288
0
  return true;
289
0
}
290
291
static const JSJitInfo disabled_getterinfo = {
292
  { (JSJitGetterOp)get_disabled },
293
  { prototypes::id::StyleSheet },
294
  { PrototypeTraits<prototypes::id::StyleSheet>::Depth },
295
  JSJitInfo::Getter,
296
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
297
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
298
  true,  /* isInfallible. False in setters. */
299
  true,  /* isMovable.  Not relevant for setters. */
300
  true, /* isEliminatable.  Not relevant for setters. */
301
  false, /* isAlwaysInSlot.  Only relevant for getters. */
302
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
303
  false,  /* isTypedMethod.  Only relevant for methods. */
304
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
305
};
306
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
307
static_assert(0 < 1, "There is no slot for us");
308
static const JSJitInfo disabled_setterinfo = {
309
  { (JSJitGetterOp)set_disabled },
310
  { prototypes::id::StyleSheet },
311
  { PrototypeTraits<prototypes::id::StyleSheet>::Depth },
312
  JSJitInfo::Setter,
313
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
314
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
315
  false,  /* isInfallible. False in setters. */
316
  false,  /* isMovable.  Not relevant for setters. */
317
  false, /* isEliminatable.  Not relevant for setters. */
318
  false, /* isAlwaysInSlot.  Only relevant for getters. */
319
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
320
  false,  /* isTypedMethod.  Only relevant for methods. */
321
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
322
};
323
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
324
static_assert(0 < 1, "There is no slot for us");
325
326
MOZ_CAN_RUN_SCRIPT static bool
327
get_sourceMapURL(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::StyleSheet* self, JSJitGetterCallArgs args)
328
0
{
329
0
  AUTO_PROFILER_LABEL_FAST("get StyleSheet.sourceMapURL", DOM, cx);
330
0
331
0
  DOMString result;
332
0
  self->GetSourceMapURL(result);
333
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
334
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
335
0
    return false;
336
0
  }
337
0
  return true;
338
0
}
339
340
static const JSJitInfo sourceMapURL_getterinfo = {
341
  { (JSJitGetterOp)get_sourceMapURL },
342
  { prototypes::id::StyleSheet },
343
  { PrototypeTraits<prototypes::id::StyleSheet>::Depth },
344
  JSJitInfo::Getter,
345
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
346
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
347
  false,  /* isInfallible. False in setters. */
348
  true,  /* isMovable.  Not relevant for setters. */
349
  true, /* isEliminatable.  Not relevant for setters. */
350
  false, /* isAlwaysInSlot.  Only relevant for getters. */
351
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
352
  false,  /* isTypedMethod.  Only relevant for methods. */
353
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
354
};
355
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
356
static_assert(0 < 1, "There is no slot for us");
357
358
MOZ_CAN_RUN_SCRIPT static bool
359
get_sourceURL(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::StyleSheet* self, JSJitGetterCallArgs args)
360
0
{
361
0
  AUTO_PROFILER_LABEL_FAST("get StyleSheet.sourceURL", DOM, cx);
362
0
363
0
  DOMString result;
364
0
  self->GetSourceURL(result);
365
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
366
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
367
0
    return false;
368
0
  }
369
0
  return true;
370
0
}
371
372
static const JSJitInfo sourceURL_getterinfo = {
373
  { (JSJitGetterOp)get_sourceURL },
374
  { prototypes::id::StyleSheet },
375
  { PrototypeTraits<prototypes::id::StyleSheet>::Depth },
376
  JSJitInfo::Getter,
377
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
378
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
379
  false,  /* isInfallible. False in setters. */
380
  true,  /* isMovable.  Not relevant for setters. */
381
  true, /* isEliminatable.  Not relevant for setters. */
382
  false, /* isAlwaysInSlot.  Only relevant for getters. */
383
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
384
  false,  /* isTypedMethod.  Only relevant for methods. */
385
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
386
};
387
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
388
static_assert(0 < 1, "There is no slot for us");
389
390
static bool
391
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
392
0
{
393
0
  mozilla::StyleSheet* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::StyleSheet>(obj);
394
0
  // We don't want to preserve if we don't have a wrapper, and we
395
0
  // obviously can't preserve if we're not initialized.
396
0
  if (self && self->GetWrapperPreserveColor()) {
397
0
    PreserveWrapper(self);
398
0
  }
399
0
  return true;
400
0
}
401
402
static void
403
_finalize(js::FreeOp* fop, JSObject* obj)
404
0
{
405
0
  mozilla::StyleSheet* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::StyleSheet>(obj);
406
0
  if (self) {
407
0
    ClearWrapper(self, self, obj);
408
0
    AddForDeferredFinalization<mozilla::StyleSheet>(self);
409
0
  }
410
0
}
411
412
static size_t
413
_objectMoved(JSObject* obj, JSObject* old)
414
0
{
415
0
  mozilla::StyleSheet* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::StyleSheet>(obj);
416
0
  if (self) {
417
0
    UpdateWrapper(self, self, obj, old);
418
0
  }
419
0
420
0
  return 0;
421
0
}
422
423
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
424
#if defined(__clang__)
425
#pragma clang diagnostic push
426
#pragma clang diagnostic ignored "-Wmissing-braces"
427
#endif
428
static const JSPropertySpec sAttributes_specs[] = {
429
  { "type", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &type_getterinfo, nullptr, nullptr },
430
  { "href", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &href_getterinfo, nullptr, nullptr },
431
  { "ownerNode", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &ownerNode_getterinfo, nullptr, nullptr },
432
  { "parentStyleSheet", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &parentStyleSheet_getterinfo, nullptr, nullptr },
433
  { "title", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &title_getterinfo, nullptr, nullptr },
434
  { "media", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &media_getterinfo, GenericSetter<NormalThisPolicy>, &media_setterinfo },
435
  { "disabled", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &disabled_getterinfo, GenericSetter<NormalThisPolicy>, &disabled_setterinfo },
436
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
437
};
438
#if defined(__clang__)
439
#pragma clang diagnostic pop
440
#endif
441
442
443
static const Prefable<const JSPropertySpec> sAttributes[] = {
444
  { nullptr, &sAttributes_specs[0] },
445
  { nullptr, nullptr }
446
};
447
448
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
449
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
450
static_assert(7 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
451
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
452
453
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
454
#if defined(__clang__)
455
#pragma clang diagnostic push
456
#pragma clang diagnostic ignored "-Wmissing-braces"
457
#endif
458
static const JSPropertySpec sChromeAttributes_specs[] = {
459
  { "sourceMapURL", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &sourceMapURL_getterinfo, nullptr, nullptr },
460
  { "sourceURL", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &sourceURL_getterinfo, nullptr, nullptr },
461
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
462
};
463
#if defined(__clang__)
464
#pragma clang diagnostic pop
465
#endif
466
467
468
static const Prefable<const JSPropertySpec> sChromeAttributes[] = {
469
  { nullptr, &sChromeAttributes_specs[0] },
470
  { nullptr, nullptr }
471
};
472
473
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
474
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
475
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
476
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
477
478
479
static uint16_t sNativeProperties_sortedPropertyIndices[7];
480
static PropertyInfo sNativeProperties_propertyInfos[7];
481
482
static const NativePropertiesN<1> sNativeProperties = {
483
  false, 0,
484
  false, 0,
485
  false, 0,
486
  true,  0 /* sAttributes */,
487
  false, 0,
488
  false, 0,
489
  false, 0,
490
  -1,
491
  7,
492
  sNativeProperties_sortedPropertyIndices,
493
  {
494
    { sAttributes, &sNativeProperties_propertyInfos[0] }
495
  }
496
};
497
static_assert(7 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
498
    "We have a property info count that is oversized");
499
500
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[2];
501
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[2];
502
503
static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
504
  false, 0,
505
  false, 0,
506
  false, 0,
507
  true,  0 /* sChromeAttributes */,
508
  false, 0,
509
  false, 0,
510
  false, 0,
511
  -1,
512
  2,
513
  sChromeOnlyNativeProperties_sortedPropertyIndices,
514
  {
515
    { sChromeAttributes, &sChromeOnlyNativeProperties_propertyInfos[0] }
516
  }
517
};
518
static_assert(2 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
519
    "We have a property info count that is oversized");
520
521
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
522
  {
523
    "Function",
524
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
525
    &sBoringInterfaceObjectClassClassOps,
526
    JS_NULL_CLASS_SPEC,
527
    JS_NULL_CLASS_EXT,
528
    &sInterfaceObjectClassObjectOps
529
  },
530
  eInterface,
531
  true,
532
  prototypes::id::StyleSheet,
533
  PrototypeTraits<prototypes::id::StyleSheet>::Depth,
534
  sNativePropertyHooks,
535
  "function StyleSheet() {\n    [native code]\n}",
536
  JS::GetRealmFunctionPrototype
537
};
538
539
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
540
  {
541
    "StyleSheetPrototype",
542
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
543
    JS_NULL_CLASS_OPS,
544
    JS_NULL_CLASS_SPEC,
545
    JS_NULL_CLASS_EXT,
546
    JS_NULL_OBJECT_OPS
547
  },
548
  eInterfacePrototype,
549
  false,
550
  prototypes::id::StyleSheet,
551
  PrototypeTraits<prototypes::id::StyleSheet>::Depth,
552
  sNativePropertyHooks,
553
  "[object StyleSheetPrototype]",
554
  JS::GetRealmObjectPrototype
555
};
556
557
static const js::ClassOps sClassOps = {
558
  _addProperty, /* addProperty */
559
  nullptr,               /* delProperty */
560
  nullptr,               /* enumerate */
561
  nullptr, /* newEnumerate */
562
  nullptr, /* resolve */
563
  nullptr, /* mayResolve */
564
  _finalize, /* finalize */
565
  nullptr, /* call */
566
  nullptr,               /* hasInstance */
567
  nullptr,               /* construct */
568
  nullptr, /* trace */
569
};
570
571
static const js::ClassExtension sClassExtension = {
572
  nullptr, /* weakmapKeyDelegateOp */
573
  _objectMoved /* objectMovedOp */
574
};
575
576
static const DOMJSClass sClass = {
577
  { "StyleSheet",
578
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
579
    &sClassOps,
580
    JS_NULL_CLASS_SPEC,
581
    &sClassExtension,
582
    JS_NULL_OBJECT_OPS
583
  },
584
  { prototypes::id::StyleSheet, 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 },
585
  IsBaseOf<nsISupports, mozilla::StyleSheet >::value,
586
  sNativePropertyHooks,
587
  FindAssociatedGlobalForNative<mozilla::StyleSheet>::Get,
588
  GetProtoObjectHandle,
589
  GetCCParticipant<mozilla::StyleSheet>::Get()
590
};
591
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
592
              "Must have the right minimal number of reserved slots.");
593
static_assert(1 >= 1,
594
              "Must have enough reserved slots.");
595
596
const JSClass*
597
GetJSClass()
598
0
{
599
0
  return sClass.ToJSClass();
600
0
}
601
602
bool
603
Wrap(JSContext* aCx, mozilla::StyleSheet* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
604
0
{
605
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::StyleSheet>::value,
606
0
                "Shouldn't have wrappercached things that are not refcounted.");
607
0
  MOZ_ASSERT(static_cast<mozilla::StyleSheet*>(aObject) ==
608
0
             reinterpret_cast<mozilla::StyleSheet*>(aObject),
609
0
             "Multiple inheritance for mozilla::StyleSheet is broken.");
610
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
611
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
612
0
  MOZ_ASSERT(!aCache->GetWrapper(),
613
0
             "You should probably not be using Wrap() directly; use "
614
0
             "GetOrCreateDOMReflector instead");
615
0
616
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
617
0
             "nsISupports must be on our primary inheritance chain");
618
0
619
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
620
0
  if (!global) {
621
0
    return false;
622
0
  }
623
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
624
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
625
0
626
0
  // That might have ended up wrapping us already, due to the wonders
627
0
  // of XBL.  Check for that, and bail out as needed.
628
0
  aReflector.set(aCache->GetWrapper());
629
0
  if (aReflector) {
630
#ifdef DEBUG
631
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
632
#endif // DEBUG
633
    return true;
634
0
  }
635
0
636
0
  JSAutoRealm ar(aCx, global);
637
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
638
0
  if (!canonicalProto) {
639
0
    return false;
640
0
  }
641
0
  JS::Rooted<JSObject*> proto(aCx);
642
0
  if (aGivenProto) {
643
0
    proto = aGivenProto;
644
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
645
0
    // coming in, we changed compartments to that of "parent" so may need
646
0
    // to wrap the proto here.
647
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
648
0
      if (!JS_WrapObject(aCx, &proto)) {
649
0
        return false;
650
0
      }
651
0
    }
652
0
  } else {
653
0
    proto = canonicalProto;
654
0
  }
655
0
656
0
  BindingJSObjectCreator<mozilla::StyleSheet> creator(aCx);
657
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
658
0
  if (!aReflector) {
659
0
    return false;
660
0
  }
661
0
662
0
  aCache->SetWrapper(aReflector);
663
0
  creator.InitializationSucceeded();
664
0
665
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
666
0
             aCache->GetWrapperPreserveColor() == aReflector);
667
0
  // If proto != canonicalProto, we have to preserve our wrapper;
668
0
  // otherwise we won't be able to properly recreate it later, since
669
0
  // we won't know what proto to use.  Note that we don't check
670
0
  // aGivenProto here, since it's entirely possible (and even
671
0
  // somewhat common) to have a non-null aGivenProto which is the
672
0
  // same as canonicalProto.
673
0
  if (proto != canonicalProto) {
674
0
    PreserveWrapper(aObject);
675
0
  }
676
0
677
0
  return true;
678
0
}
679
680
const NativePropertyHooks sNativePropertyHooks[] = { {
681
  nullptr,
682
  nullptr,
683
  nullptr,
684
  { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
685
  prototypes::id::StyleSheet,
686
  constructors::id::StyleSheet,
687
  nullptr,
688
  &DefaultXrayExpandoObjectClass
689
} };
690
691
void
692
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
693
0
{
694
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
695
0
  if (!parentProto) {
696
0
    return;
697
0
  }
698
0
699
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
700
0
  if (!constructorProto) {
701
0
    return;
702
0
  }
703
0
704
0
  static bool sIdsInited = false;
705
0
  if (!sIdsInited && NS_IsMainThread()) {
706
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
707
0
      return;
708
0
    }
709
0
    if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
710
0
      return;
711
0
    }
712
0
    sIdsInited = true;
713
0
  }
714
0
715
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::StyleSheet);
716
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::StyleSheet);
717
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
718
0
                              &sPrototypeClass.mBase, protoCache,
719
0
                              nullptr,
720
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
721
0
                              interfaceCache,
722
0
                              sNativeProperties.Upcast(),
723
0
                              sChromeOnlyNativeProperties.Upcast(),
724
0
                              "StyleSheet", aDefineOnGlobal,
725
0
                              nullptr,
726
0
                              false);
727
0
}
728
729
JSObject*
730
GetProtoObject(JSContext* aCx)
731
0
{
732
0
  return GetProtoObjectHandle(aCx);
733
0
}
734
735
JSObject*
736
GetConstructorObject(JSContext* aCx)
737
0
{
738
0
  return GetConstructorObjectHandle(aCx);
739
0
}
740
741
} // namespace StyleSheet_Binding
742
743
744
745
} // namespace dom
746
} // namespace mozilla