Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM FontFaceSetLoadEvent.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "EventBinding.h"
5 : #include "FontFaceSetLoadEventBinding.h"
6 : #include "WrapperFactory.h"
7 : #include "XrayWrapper.h"
8 : #include "mozilla/OwningNonNull.h"
9 : #include "mozilla/Preferences.h"
10 : #include "mozilla/dom/BindingUtils.h"
11 : #include "mozilla/dom/DOMJSClass.h"
12 : #include "mozilla/dom/FontFace.h"
13 : #include "mozilla/dom/FontFaceSetLoadEvent.h"
14 : #include "mozilla/dom/NonRefcountedDOMObject.h"
15 : #include "mozilla/dom/PrimitiveConversions.h"
16 : #include "mozilla/dom/ScriptSettings.h"
17 : #include "mozilla/dom/XrayExpandoClass.h"
18 :
19 : namespace mozilla {
20 : namespace dom {
21 :
22 :
23 0 : FontFaceSetLoadEventInit::FontFaceSetLoadEventInit()
24 0 : : EventInit(FastDictionaryInitializer())
25 : {
26 : // Safe to pass a null context if we pass a null value
27 0 : Init(nullptr, JS::NullHandleValue);
28 0 : }
29 :
30 :
31 :
32 : bool
33 0 : FontFaceSetLoadEventInit::InitIds(JSContext* cx, FontFaceSetLoadEventInitAtoms* atomsCache)
34 : {
35 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
36 :
37 : // Initialize these in reverse order so that any failure leaves the first one
38 : // uninitialized.
39 0 : if (!atomsCache->fontfaces_id.init(cx, "fontfaces")) {
40 0 : return false;
41 : }
42 0 : return true;
43 : }
44 :
45 : bool
46 0 : FontFaceSetLoadEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
47 : {
48 : // Passing a null JSContext is OK only if we're initing from null,
49 : // Since in that case we will not have to do any property gets
50 : // Also evaluate isNullOrUndefined in order to avoid false-positive
51 : // checkers by static analysis tools
52 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
53 0 : FontFaceSetLoadEventInitAtoms* atomsCache = nullptr;
54 0 : if (cx) {
55 0 : atomsCache = GetAtomCache<FontFaceSetLoadEventInitAtoms>(cx);
56 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
57 0 : return false;
58 : }
59 : }
60 :
61 : // Per spec, we init the parent's members first
62 0 : if (!EventInit::Init(cx, val)) {
63 0 : return false;
64 : }
65 :
66 0 : bool isNull = val.isNullOrUndefined();
67 : // We only need these if !isNull, in which case we have |cx|.
68 0 : Maybe<JS::Rooted<JSObject *> > object;
69 0 : Maybe<JS::Rooted<JS::Value> > temp;
70 0 : if (!isNull) {
71 0 : MOZ_ASSERT(cx);
72 0 : object.emplace(cx, &val.toObject());
73 0 : temp.emplace(cx);
74 : }
75 0 : if (!isNull) {
76 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->fontfaces_id, temp.ptr())) {
77 0 : return false;
78 : }
79 : }
80 0 : if (!isNull && !temp->isUndefined()) {
81 0 : if (temp.ref().isObject()) {
82 0 : JS::ForOfIterator iter(cx);
83 0 : if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
84 0 : return false;
85 : }
86 0 : if (!iter.valueIsIterable()) {
87 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'fontfaces' member of FontFaceSetLoadEventInit");
88 0 : return false;
89 : }
90 0 : Sequence<OwningNonNull<mozilla::dom::FontFace>> &arr = mFontfaces;
91 0 : JS::Rooted<JS::Value> temp(cx);
92 : while (true) {
93 : bool done;
94 0 : if (!iter.next(&temp, &done)) {
95 0 : return false;
96 : }
97 0 : if (done) {
98 0 : break;
99 : }
100 0 : OwningNonNull<mozilla::dom::FontFace>* slotPtr = arr.AppendElement(mozilla::fallible);
101 0 : if (!slotPtr) {
102 0 : JS_ReportOutOfMemory(cx);
103 0 : return false;
104 : }
105 0 : OwningNonNull<mozilla::dom::FontFace>& slot = *slotPtr;
106 0 : if (temp.isObject()) {
107 : static_assert(IsRefcounted<mozilla::dom::FontFace>::value, "We can only store refcounted classes.");{
108 0 : nsresult rv = UnwrapObject<prototypes::id::FontFace, mozilla::dom::FontFace>(&temp, slot);
109 0 : if (NS_FAILED(rv)) {
110 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of 'fontfaces' member of FontFaceSetLoadEventInit", "FontFace");
111 0 : return false;
112 : }
113 : }
114 : } else {
115 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of 'fontfaces' member of FontFaceSetLoadEventInit");
116 0 : return false;
117 : }
118 0 : }
119 : } else {
120 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'fontfaces' member of FontFaceSetLoadEventInit");
121 0 : return false;
122 : }
123 : } else {
124 : /* Array is already empty; nothing to do */
125 : }
126 0 : mIsAnyMemberPresent = true;
127 0 : return true;
128 : }
129 :
130 : bool
131 0 : FontFaceSetLoadEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
132 : {
133 0 : FontFaceSetLoadEventInitAtoms* atomsCache = GetAtomCache<FontFaceSetLoadEventInitAtoms>(cx);
134 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
135 0 : return false;
136 : }
137 :
138 : // Per spec, we define the parent's members first
139 0 : if (!EventInit::ToObjectInternal(cx, rval)) {
140 0 : return false;
141 : }
142 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
143 :
144 : do {
145 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
146 0 : JS::Rooted<JS::Value> temp(cx);
147 0 : Sequence<OwningNonNull<mozilla::dom::FontFace>> const & currentValue = mFontfaces;
148 :
149 0 : uint32_t length = currentValue.Length();
150 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
151 0 : if (!returnArray) {
152 0 : return false;
153 : }
154 : // Scope for 'tmp'
155 : {
156 0 : JS::Rooted<JS::Value> tmp(cx);
157 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
158 : // Control block to let us common up the JS_DefineElement calls when there
159 : // are different ways to succeed at wrapping the object.
160 : do {
161 0 : if (!GetOrCreateDOMReflector(cx, currentValue[sequenceIdx0], &tmp)) {
162 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
163 0 : return false;
164 : }
165 0 : break;
166 : } while (0);
167 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
168 : JSPROP_ENUMERATE)) {
169 0 : return false;
170 : }
171 : }
172 : }
173 0 : temp.setObject(*returnArray);
174 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->fontfaces_id, temp, JSPROP_ENUMERATE)) {
175 0 : return false;
176 : }
177 0 : break;
178 : } while(0);
179 :
180 0 : return true;
181 : }
182 :
183 : void
184 0 : FontFaceSetLoadEventInit::TraceDictionary(JSTracer* trc)
185 : {
186 0 : EventInit::TraceDictionary(trc);
187 0 : }
188 :
189 : FontFaceSetLoadEventInit&
190 0 : FontFaceSetLoadEventInit::operator=(const FontFaceSetLoadEventInit& aOther)
191 : {
192 0 : EventInit::operator=(aOther);
193 0 : mFontfaces = aOther.mFontfaces;
194 0 : return *this;
195 : }
196 :
197 : namespace binding_detail {
198 : } // namespace binding_detail
199 :
200 :
201 : namespace FontFaceSetLoadEventBinding {
202 :
203 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventBinding::NativeType>::value,
204 : "Can't inherit from an interface with a different ownership model.");
205 :
206 : static bool
207 0 : get_fontfaces(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FontFaceSetLoadEvent* self, JSJitGetterCallArgs args)
208 : {
209 : // Have to either root across the getter call or reget after.
210 : bool isXray;
211 0 : JS::Rooted<JSObject*> slotStorage(cx, GetCachedSlotStorageObject(cx, obj, &isXray));
212 0 : if (!slotStorage) {
213 0 : return false;
214 : }
215 0 : const size_t slotIndex = isXray ? (xpc::JSSLOT_EXPANDO_COUNT + 0) : (DOM_INSTANCE_RESERVED_SLOTS + 0);
216 0 : MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex);
217 : {
218 : // Scope for cachedVal
219 0 : JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex);
220 0 : if (!cachedVal.isUndefined()) {
221 0 : args.rval().set(cachedVal);
222 : // The cached value is in the compartment of slotStorage,
223 : // so wrap into the caller compartment as needed.
224 0 : return MaybeWrapNonDOMObjectValue(cx, args.rval());
225 : }
226 : }
227 :
228 0 : nsTArray<StrongPtrForMember<mozilla::dom::FontFace>::Type> result;
229 0 : self->GetFontfaces(result);
230 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
231 : {
232 0 : JS::Rooted<JSObject*> conversionScope(cx, isXray ? obj : slotStorage);
233 0 : JSAutoCompartment ac(cx, conversionScope);
234 : do { // block we break out of when done wrapping
235 :
236 0 : uint32_t length = result.Length();
237 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
238 0 : if (!returnArray) {
239 0 : return false;
240 : }
241 : // Scope for 'tmp'
242 : {
243 0 : JS::Rooted<JS::Value> tmp(cx);
244 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
245 : // Control block to let us common up the JS_DefineElement calls when there
246 : // are different ways to succeed at wrapping the object.
247 : do {
248 0 : if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
249 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
250 0 : return false;
251 : }
252 0 : break;
253 : } while (0);
254 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
255 : JSPROP_ENUMERATE)) {
256 0 : return false;
257 : }
258 : }
259 : }
260 0 : args.rval().setObject(*returnArray);
261 0 : break;
262 : } while (0);
263 0 : JS::Rooted<JSObject*> rvalObj(cx, &args.rval().toObject());
264 0 : if (!JS_FreezeObject(cx, rvalObj)) {
265 0 : return false;
266 : }
267 : }
268 : { // And now store things in the compartment of our slotStorage.
269 0 : JSAutoCompartment ac(cx, slotStorage);
270 : // Make a copy so that we don't do unnecessary wrapping on args.rval().
271 0 : JS::Rooted<JS::Value> storedVal(cx, args.rval());
272 0 : if (!MaybeWrapNonDOMObjectValue(cx, &storedVal)) {
273 0 : return false;
274 : }
275 0 : js::SetReservedSlot(slotStorage, slotIndex, storedVal);
276 0 : if (!isXray) {
277 : // In the Xray case we don't need to do this, because getting the
278 : // expando object already preserved our wrapper.
279 0 : PreserveWrapper(self);
280 : }
281 : }
282 : // And now make sure args.rval() is in the caller compartment
283 0 : return MaybeWrapNonDOMObjectValue(cx, args.rval());
284 : }
285 :
286 : static const JSJitInfo fontfaces_getterinfo = {
287 : { (JSJitGetterOp)get_fontfaces },
288 : { prototypes::id::FontFaceSetLoadEvent },
289 : { PrototypeTraits<prototypes::id::FontFaceSetLoadEvent>::Depth },
290 : JSJitInfo::Getter,
291 : JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
292 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
293 : false, /* isInfallible. False in setters. */
294 : true, /* isMovable. Not relevant for setters. */
295 : true, /* isEliminatable. Not relevant for setters. */
296 : false, /* isAlwaysInSlot. Only relevant for getters. */
297 : true, /* isLazilyCachedInSlot. Only relevant for getters. */
298 : false, /* isTypedMethod. Only relevant for methods. */
299 : (DOM_INSTANCE_RESERVED_SLOTS + 0) /* Reserved slot index, if we're stored in a slot, else 0. */
300 : };
301 : static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) <= JSJitInfo::maxSlotIndex, "We won't fit");
302 : static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) < 2, "There is no slot for us");
303 :
304 : static bool
305 0 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FontFaceSetLoadEvent* self, JSJitGetterCallArgs args)
306 : {
307 0 : bool result(self->IsTrusted());
308 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
309 0 : args.rval().setBoolean(result);
310 0 : return true;
311 : }
312 :
313 : static const JSJitInfo isTrusted_getterinfo = {
314 : { (JSJitGetterOp)get_isTrusted },
315 : { prototypes::id::FontFaceSetLoadEvent },
316 : { PrototypeTraits<prototypes::id::FontFaceSetLoadEvent>::Depth },
317 : JSJitInfo::Getter,
318 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
319 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
320 : true, /* isInfallible. False in setters. */
321 : true, /* isMovable. Not relevant for setters. */
322 : true, /* isEliminatable. Not relevant for setters. */
323 : false, /* isAlwaysInSlot. Only relevant for getters. */
324 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
325 : false, /* isTypedMethod. Only relevant for methods. */
326 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
327 : };
328 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
329 : static_assert(0 < 2, "There is no slot for us");
330 :
331 : static bool
332 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
333 : {
334 0 : mozilla::dom::FontFaceSetLoadEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FontFaceSetLoadEvent>(obj);
335 : // We don't want to preserve if we don't have a wrapper, and we
336 : // obviously can't preserve if we're not initialized.
337 0 : if (self && self->GetWrapperPreserveColor()) {
338 0 : PreserveWrapper(self);
339 : }
340 0 : return true;
341 : }
342 :
343 : static void
344 0 : _finalize(js::FreeOp* fop, JSObject* obj)
345 : {
346 0 : mozilla::dom::FontFaceSetLoadEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FontFaceSetLoadEvent>(obj);
347 0 : if (self) {
348 0 : ClearWrapper(self, self, obj);
349 0 : AddForDeferredFinalization<mozilla::dom::FontFaceSetLoadEvent>(self);
350 : }
351 0 : }
352 :
353 : static void
354 0 : _objectMoved(JSObject* obj, const JSObject* old)
355 : {
356 0 : mozilla::dom::FontFaceSetLoadEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FontFaceSetLoadEvent>(obj);
357 0 : if (self) {
358 0 : UpdateWrapper(self, self, obj, old);
359 : }
360 0 : }
361 :
362 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
363 : #if defined(__clang__)
364 : #pragma clang diagnostic push
365 : #pragma clang diagnostic ignored "-Wmissing-braces"
366 : #endif
367 : static const JSPropertySpec sAttributes_specs[] = {
368 : { "fontfaces", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &fontfaces_getterinfo, nullptr, nullptr },
369 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
370 : };
371 : #if defined(__clang__)
372 : #pragma clang diagnostic pop
373 : #endif
374 :
375 :
376 : // Can't be const because the pref-enabled boolean needs to be writable
377 : static Prefable<const JSPropertySpec> sAttributes[] = {
378 : { nullptr, &sAttributes_specs[0] },
379 : { nullptr, nullptr }
380 : };
381 :
382 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
383 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
384 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
385 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
386 :
387 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
388 : #if defined(__clang__)
389 : #pragma clang diagnostic push
390 : #pragma clang diagnostic ignored "-Wmissing-braces"
391 : #endif
392 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
393 : { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
394 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
395 : };
396 : #if defined(__clang__)
397 : #pragma clang diagnostic pop
398 : #endif
399 :
400 :
401 : // Can't be const because the pref-enabled boolean needs to be writable
402 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
403 : { nullptr, &sUnforgeableAttributes_specs[0] },
404 : { nullptr, nullptr }
405 : };
406 :
407 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
408 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
409 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
410 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
411 :
412 :
413 : static uint16_t sNativeProperties_sortedPropertyIndices[2];
414 : static PropertyInfo sNativeProperties_propertyInfos[2];
415 :
416 : static const NativePropertiesN<2> sNativeProperties = {
417 : false, 0,
418 : false, 0,
419 : false, 0,
420 : true, 0 /* sAttributes */,
421 : false, 0,
422 : true, 1 /* sUnforgeableAttributes */,
423 : false, 0,
424 : -1,
425 : 2,
426 : sNativeProperties_sortedPropertyIndices,
427 : {
428 : { sAttributes, &sNativeProperties_propertyInfos[0] },
429 : { sUnforgeableAttributes, &sNativeProperties_propertyInfos[1] }
430 : }
431 : };
432 : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
433 : "We have a property info count that is oversized");
434 :
435 : static bool
436 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
437 : {
438 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
439 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
440 0 : if (!args.isConstructing()) {
441 : // XXXbz wish I could get the name from the callee instead of
442 : // Adding more relocations
443 0 : return ThrowConstructorWithoutNew(cx, "FontFaceSetLoadEvent");
444 : }
445 :
446 0 : GlobalObject global(cx, obj);
447 0 : if (global.Failed()) {
448 0 : return false;
449 : }
450 :
451 0 : JS::Rooted<JSObject*> desiredProto(cx);
452 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
453 0 : return false;
454 : }
455 :
456 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
457 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "FontFaceSetLoadEvent");
458 : }
459 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
460 0 : binding_detail::FakeString arg0;
461 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
462 0 : return false;
463 : }
464 0 : binding_detail::FastFontFaceSetLoadEventInit arg1;
465 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of FontFaceSetLoadEvent.constructor", false)) {
466 0 : return false;
467 : }
468 0 : Maybe<JSAutoCompartment> ac;
469 0 : if (objIsXray) {
470 0 : obj = js::CheckedUnwrap(obj);
471 0 : if (!obj) {
472 0 : return false;
473 : }
474 0 : ac.emplace(cx, obj);
475 0 : if (!JS_WrapObject(cx, &desiredProto)) {
476 0 : return false;
477 : }
478 : }
479 0 : binding_detail::FastErrorResult rv;
480 0 : auto result(StrongOrRawPtr<mozilla::dom::FontFaceSetLoadEvent>(mozilla::dom::FontFaceSetLoadEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
481 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
482 0 : return false;
483 : }
484 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
485 : static_assert(!IsPointer<decltype(result)>::value,
486 : "NewObject implies that we need to keep the object alive with a strong reference.");
487 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
488 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
489 0 : return false;
490 : }
491 0 : return true;
492 : }
493 :
494 : static const js::ClassOps sInterfaceObjectClassOps = {
495 : nullptr, /* addProperty */
496 : nullptr, /* delProperty */
497 : nullptr, /* getProperty */
498 : nullptr, /* setProperty */
499 : nullptr, /* enumerate */
500 : nullptr, /* newEnumerate */
501 : nullptr, /* resolve */
502 : nullptr, /* mayResolve */
503 : nullptr, /* finalize */
504 : _constructor, /* call */
505 : nullptr, /* hasInstance */
506 : _constructor, /* construct */
507 : nullptr, /* trace */
508 : };
509 :
510 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
511 : {
512 : "Function",
513 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
514 : &sInterfaceObjectClassOps,
515 : JS_NULL_CLASS_SPEC,
516 : JS_NULL_CLASS_EXT,
517 : &sInterfaceObjectClassObjectOps
518 : },
519 : eInterface,
520 : true,
521 : prototypes::id::FontFaceSetLoadEvent,
522 : PrototypeTraits<prototypes::id::FontFaceSetLoadEvent>::Depth,
523 : sNativePropertyHooks,
524 : "function FontFaceSetLoadEvent() {\n [native code]\n}",
525 : EventBinding::GetConstructorObject
526 : };
527 :
528 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
529 : {
530 : "FontFaceSetLoadEventPrototype",
531 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
532 : JS_NULL_CLASS_OPS,
533 : JS_NULL_CLASS_SPEC,
534 : JS_NULL_CLASS_EXT,
535 : JS_NULL_OBJECT_OPS
536 : },
537 : eInterfacePrototype,
538 : false,
539 : prototypes::id::FontFaceSetLoadEvent,
540 : PrototypeTraits<prototypes::id::FontFaceSetLoadEvent>::Depth,
541 : sNativePropertyHooks,
542 : "[object FontFaceSetLoadEventPrototype]",
543 : EventBinding::GetProtoObject
544 : };
545 :
546 : bool
547 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
548 : {
549 : static bool sPrefValue;
550 : static bool sPrefCacheSetUp = false;
551 0 : if (!sPrefCacheSetUp) {
552 0 : sPrefCacheSetUp = true;
553 0 : Preferences::AddBoolVarCache(&sPrefValue, "layout.css.font-loading-api.enabled");
554 : }
555 :
556 0 : return sPrefValue;
557 : }
558 :
559 : JSObject*
560 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
561 : {
562 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
563 : }
564 :
565 : static const js::ClassOps sClassOps = {
566 : _addProperty, /* addProperty */
567 : nullptr, /* delProperty */
568 : nullptr, /* getProperty */
569 : nullptr, /* setProperty */
570 : nullptr, /* enumerate */
571 : nullptr, /* newEnumerate */
572 : nullptr, /* resolve */
573 : nullptr, /* mayResolve */
574 : _finalize, /* finalize */
575 : nullptr, /* call */
576 : nullptr, /* hasInstance */
577 : nullptr, /* construct */
578 : nullptr, /* trace */
579 : };
580 :
581 : static const js::ClassExtension sClassExtension = {
582 : nullptr, /* weakmapKeyDelegateOp */
583 : _objectMoved /* objectMovedOp */
584 : };
585 :
586 : static const DOMJSClass sClass = {
587 : { "FontFaceSetLoadEvent",
588 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(2) | JSCLASS_SKIP_NURSERY_FINALIZE,
589 : &sClassOps,
590 : JS_NULL_CLASS_SPEC,
591 : &sClassExtension,
592 : JS_NULL_OBJECT_OPS
593 : },
594 : { prototypes::id::Event, prototypes::id::FontFaceSetLoadEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
595 : IsBaseOf<nsISupports, mozilla::dom::FontFaceSetLoadEvent >::value,
596 : sNativePropertyHooks,
597 : FindAssociatedGlobalForNative<mozilla::dom::FontFaceSetLoadEvent>::Get,
598 : GetProtoObjectHandle,
599 : GetCCParticipant<mozilla::dom::FontFaceSetLoadEvent>::Get()
600 : };
601 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
602 : "Must have the right minimal number of reserved slots.");
603 : static_assert(2 >= 2,
604 : "Must have enough reserved slots.");
605 :
606 : const JSClass*
607 0 : GetJSClass()
608 : {
609 0 : return sClass.ToJSClass();
610 : }
611 :
612 : bool
613 0 : Wrap(JSContext* aCx, mozilla::dom::FontFaceSetLoadEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
614 : {
615 : MOZ_ASSERT(static_cast<mozilla::dom::FontFaceSetLoadEvent*>(aObject) ==
616 : reinterpret_cast<mozilla::dom::FontFaceSetLoadEvent*>(aObject),
617 : "Multiple inheritance for mozilla::dom::FontFaceSetLoadEvent is broken.");
618 : MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
619 : reinterpret_cast<mozilla::dom::Event*>(aObject),
620 : "Multiple inheritance for mozilla::dom::Event is broken.");
621 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
622 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
623 0 : MOZ_ASSERT(!aCache->GetWrapper(),
624 : "You should probably not be using Wrap() directly; use "
625 : "GetOrCreateDOMReflector instead");
626 :
627 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
628 : "nsISupports must be on our primary inheritance chain");
629 :
630 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
631 0 : if (!global) {
632 0 : return false;
633 : }
634 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
635 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
636 :
637 : // That might have ended up wrapping us already, due to the wonders
638 : // of XBL. Check for that, and bail out as needed.
639 0 : aReflector.set(aCache->GetWrapper());
640 0 : if (aReflector) {
641 : #ifdef DEBUG
642 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
643 : #endif // DEBUG
644 0 : return true;
645 : }
646 :
647 0 : JSAutoCompartment ac(aCx, global);
648 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
649 0 : if (!canonicalProto) {
650 0 : return false;
651 : }
652 0 : JS::Rooted<JSObject*> proto(aCx);
653 0 : if (aGivenProto) {
654 0 : proto = aGivenProto;
655 : // Unfortunately, while aGivenProto was in the compartment of aCx
656 : // coming in, we changed compartments to that of "parent" so may need
657 : // to wrap the proto here.
658 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
659 0 : if (!JS_WrapObject(aCx, &proto)) {
660 0 : return false;
661 : }
662 : }
663 : } else {
664 0 : proto = canonicalProto;
665 : }
666 :
667 0 : BindingJSObjectCreator<mozilla::dom::FontFaceSetLoadEvent> creator(aCx);
668 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
669 0 : if (!aReflector) {
670 0 : return false;
671 : }
672 :
673 0 : aCache->SetWrapper(aReflector);
674 :
675 : // Important: do unforgeable property setup after we have handed
676 : // over ownership of the C++ object to obj as needed, so that if
677 : // we fail and it ends up GCed it won't have problems in the
678 : // finalizer trying to drop its ownership of the C++ object.
679 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
680 0 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
681 0 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
682 0 : aCache->ReleaseWrapper(aObject);
683 0 : aCache->ClearWrapper();
684 0 : return false;
685 : }
686 0 : creator.InitializationSucceeded();
687 :
688 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
689 : aCache->GetWrapperPreserveColor() == aReflector);
690 : // If proto != canonicalProto, we have to preserve our wrapper;
691 : // otherwise we won't be able to properly recreate it later, since
692 : // we won't know what proto to use. Note that we don't check
693 : // aGivenProto here, since it's entirely possible (and even
694 : // somewhat common) to have a non-null aGivenProto which is the
695 : // same as canonicalProto.
696 0 : if (proto != canonicalProto) {
697 0 : PreserveWrapper(aObject);
698 : }
699 :
700 0 : return true;
701 : }
702 :
703 : // This may allocate too many slots, because we only really need
704 : // slots for our non-interface-typed members that we cache. But
705 : // allocating slots only for those would make the slot index
706 : // computations much more complicated, so let's do this the simple
707 : // way for now.
708 : DEFINE_XRAY_EXPANDO_CLASS(static, sXrayExpandoObjectClass, 1);
709 :
710 : const NativePropertyHooks sNativePropertyHooks[] = { {
711 : nullptr,
712 : nullptr,
713 : nullptr,
714 : { sNativeProperties.Upcast(), nullptr },
715 : prototypes::id::FontFaceSetLoadEvent,
716 : constructors::id::FontFaceSetLoadEvent,
717 : EventBinding::sNativePropertyHooks,
718 : &sXrayExpandoObjectClass
719 : } };
720 :
721 : void
722 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
723 : {
724 0 : JS::Handle<JSObject*> parentProto(EventBinding::GetProtoObjectHandle(aCx));
725 0 : if (!parentProto) {
726 0 : return;
727 : }
728 :
729 0 : JS::Handle<JSObject*> constructorProto(EventBinding::GetConstructorObjectHandle(aCx));
730 0 : if (!constructorProto) {
731 0 : return;
732 : }
733 :
734 : static bool sIdsInited = false;
735 0 : if (!sIdsInited && NS_IsMainThread()) {
736 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
737 0 : return;
738 : }
739 0 : sIdsInited = true;
740 : }
741 :
742 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::FontFaceSetLoadEvent);
743 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::FontFaceSetLoadEvent);
744 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
745 : &sPrototypeClass.mBase, protoCache,
746 : constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
747 : interfaceCache,
748 : sNativeProperties.Upcast(),
749 : nullptr,
750 : "FontFaceSetLoadEvent", aDefineOnGlobal,
751 : nullptr,
752 0 : false);
753 :
754 0 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
755 : {
756 0 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
757 0 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
758 0 : if (!unforgeableHolder) {
759 0 : *protoCache = nullptr;
760 0 : if (interfaceCache) {
761 0 : *interfaceCache = nullptr;
762 : }
763 0 : return;
764 : }
765 : }
766 :
767 0 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
768 0 : *protoCache = nullptr;
769 0 : if (interfaceCache) {
770 0 : *interfaceCache = nullptr;
771 : }
772 0 : return;
773 : }
774 :
775 0 : if (*protoCache) {
776 0 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
777 0 : JS::ObjectValue(*unforgeableHolder));
778 : }
779 : }
780 :
781 : JS::Handle<JSObject*>
782 0 : GetProtoObjectHandle(JSContext* aCx)
783 : {
784 : /* Get the interface prototype object for this class. This will create the
785 : object as needed. */
786 0 : bool aDefineOnGlobal = true;
787 :
788 : /* Make sure our global is sane. Hopefully we can remove this sometime */
789 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
790 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
791 0 : return nullptr;
792 : }
793 :
794 : /* Check to see whether the interface objects are already installed */
795 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
796 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::FontFaceSetLoadEvent)) {
797 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
798 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
799 : }
800 :
801 : /*
802 : * The object might _still_ be null, but that's OK.
803 : *
804 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
805 : * traced by TraceProtoAndIfaceCache() and its contents are never
806 : * changed after they have been set.
807 : *
808 : * Calling address() avoids the read read barrier that does gray
809 : * unmarking, but it's not possible for the object to be gray here.
810 : */
811 :
812 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::FontFaceSetLoadEvent);
813 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
814 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
815 : }
816 :
817 : JS::Handle<JSObject*>
818 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
819 : {
820 : /* Get the interface object for this class. This will create the object as
821 : needed. */
822 :
823 : /* Make sure our global is sane. Hopefully we can remove this sometime */
824 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
825 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
826 0 : return nullptr;
827 : }
828 :
829 : /* Check to see whether the interface objects are already installed */
830 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
831 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::FontFaceSetLoadEvent)) {
832 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
833 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
834 : }
835 :
836 : /*
837 : * The object might _still_ be null, but that's OK.
838 : *
839 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
840 : * traced by TraceProtoAndIfaceCache() and its contents are never
841 : * changed after they have been set.
842 : *
843 : * Calling address() avoids the read read barrier that does gray
844 : * unmarking, but it's not possible for the object to be gray here.
845 : */
846 :
847 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::FontFaceSetLoadEvent);
848 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
849 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
850 : }
851 :
852 : JSObject*
853 0 : GetConstructorObject(JSContext* aCx)
854 : {
855 0 : return GetConstructorObjectHandle(aCx);
856 : }
857 :
858 : } // namespace FontFaceSetLoadEventBinding
859 :
860 :
861 :
862 : } // namespace dom
863 : } // namespace mozilla
|