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