Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM FlyWebFetchEvent.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "EventBinding.h"
4 : #include "FlyWebFetchEventBinding.h"
5 : #include "FlyWebServerEvents.h"
6 : #include "WrapperFactory.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/Preferences.h"
9 : #include "mozilla/dom/BindingUtils.h"
10 : #include "mozilla/dom/DOMJSClass.h"
11 : #include "mozilla/dom/NonRefcountedDOMObject.h"
12 : #include "mozilla/dom/PrimitiveConversions.h"
13 : #include "mozilla/dom/Promise.h"
14 : #include "mozilla/dom/Request.h"
15 : #include "mozilla/dom/ToJSValue.h"
16 : #include "mozilla/dom/XrayExpandoClass.h"
17 :
18 : namespace mozilla {
19 : namespace dom {
20 :
21 : namespace FlyWebFetchEventBinding {
22 :
23 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventBinding::NativeType>::value,
24 : "Can't inherit from an interface with a different ownership model.");
25 :
26 : static bool
27 0 : get_request(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FlyWebFetchEvent* self, JSJitGetterCallArgs args)
28 : {
29 0 : auto result(StrongOrRawPtr<mozilla::dom::Request>(self->Request()));
30 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
31 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
32 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
33 0 : return false;
34 : }
35 0 : return true;
36 : }
37 :
38 : static const JSJitInfo request_getterinfo = {
39 : { (JSJitGetterOp)get_request },
40 : { prototypes::id::FlyWebFetchEvent },
41 : { PrototypeTraits<prototypes::id::FlyWebFetchEvent>::Depth },
42 : JSJitInfo::Getter,
43 : JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
44 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
45 : false, /* isInfallible. False in setters. */
46 : true, /* isMovable. Not relevant for setters. */
47 : true, /* isEliminatable. Not relevant for setters. */
48 : false, /* isAlwaysInSlot. Only relevant for getters. */
49 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
50 : false, /* isTypedMethod. Only relevant for methods. */
51 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
52 : };
53 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
54 : static_assert(0 < 1, "There is no slot for us");
55 :
56 : static bool
57 0 : respondWith(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FlyWebFetchEvent* self, const JSJitMethodCallArgs& args)
58 : {
59 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
60 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "FlyWebFetchEvent.respondWith");
61 : }
62 0 : OwningNonNull<Promise> arg0;
63 : { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
64 : // etc.
65 :
66 0 : JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
67 0 : JSAutoCompartment ac(cx, globalObj);
68 0 : GlobalObject promiseGlobal(cx, globalObj);
69 0 : if (promiseGlobal.Failed()) {
70 0 : return false;
71 : }
72 :
73 0 : JS::Rooted<JS::Value> valueToResolve(cx, args[0]);
74 0 : if (!JS_WrapValue(cx, &valueToResolve)) {
75 0 : return false;
76 : }
77 0 : binding_detail::FastErrorResult promiseRv;
78 : nsCOMPtr<nsIGlobalObject> global =
79 0 : do_QueryInterface(promiseGlobal.GetAsSupports());
80 0 : if (!global) {
81 0 : promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
82 0 : MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
83 0 : return false;
84 : }
85 0 : arg0 = Promise::Resolve(global, cx, valueToResolve,
86 0 : promiseRv);
87 0 : if (promiseRv.MaybeSetPendingException(cx)) {
88 0 : return false;
89 : }
90 : }
91 0 : binding_detail::FastErrorResult rv;
92 0 : self->RespondWith(NonNullHelper(arg0), rv);
93 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
94 0 : return false;
95 : }
96 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
97 0 : args.rval().setUndefined();
98 0 : return true;
99 : }
100 :
101 : static const JSJitInfo respondWith_methodinfo = {
102 : { (JSJitGetterOp)respondWith },
103 : { prototypes::id::FlyWebFetchEvent },
104 : { PrototypeTraits<prototypes::id::FlyWebFetchEvent>::Depth },
105 : JSJitInfo::Method,
106 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
107 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
108 : false, /* isInfallible. False in setters. */
109 : false, /* isMovable. Not relevant for setters. */
110 : false, /* isEliminatable. Not relevant for setters. */
111 : false, /* isAlwaysInSlot. Only relevant for getters. */
112 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
113 : false, /* isTypedMethod. Only relevant for methods. */
114 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
115 : };
116 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
117 : static_assert(0 < 1, "There is no slot for us");
118 :
119 : static bool
120 0 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FlyWebFetchEvent* self, JSJitGetterCallArgs args)
121 : {
122 0 : bool result(self->IsTrusted());
123 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
124 0 : args.rval().setBoolean(result);
125 0 : return true;
126 : }
127 :
128 : static const JSJitInfo isTrusted_getterinfo = {
129 : { (JSJitGetterOp)get_isTrusted },
130 : { prototypes::id::FlyWebFetchEvent },
131 : { PrototypeTraits<prototypes::id::FlyWebFetchEvent>::Depth },
132 : JSJitInfo::Getter,
133 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
134 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
135 : true, /* isInfallible. False in setters. */
136 : true, /* isMovable. Not relevant for setters. */
137 : true, /* isEliminatable. Not relevant for setters. */
138 : false, /* isAlwaysInSlot. Only relevant for getters. */
139 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
140 : false, /* isTypedMethod. Only relevant for methods. */
141 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
142 : };
143 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
144 : static_assert(0 < 1, "There is no slot for us");
145 :
146 : static bool
147 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
148 : {
149 0 : mozilla::dom::FlyWebFetchEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FlyWebFetchEvent>(obj);
150 : // We don't want to preserve if we don't have a wrapper, and we
151 : // obviously can't preserve if we're not initialized.
152 0 : if (self && self->GetWrapperPreserveColor()) {
153 0 : PreserveWrapper(self);
154 : }
155 0 : return true;
156 : }
157 :
158 : static void
159 0 : _finalize(js::FreeOp* fop, JSObject* obj)
160 : {
161 0 : mozilla::dom::FlyWebFetchEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FlyWebFetchEvent>(obj);
162 0 : if (self) {
163 0 : ClearWrapper(self, self, obj);
164 0 : AddForDeferredFinalization<mozilla::dom::FlyWebFetchEvent>(self);
165 : }
166 0 : }
167 :
168 : static void
169 0 : _objectMoved(JSObject* obj, const JSObject* old)
170 : {
171 0 : mozilla::dom::FlyWebFetchEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FlyWebFetchEvent>(obj);
172 0 : if (self) {
173 0 : UpdateWrapper(self, self, obj, old);
174 : }
175 0 : }
176 :
177 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
178 : #if defined(__clang__)
179 : #pragma clang diagnostic push
180 : #pragma clang diagnostic ignored "-Wmissing-braces"
181 : #endif
182 : static const JSFunctionSpec sMethods_specs[] = {
183 : JS_FNSPEC("respondWith", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&respondWith_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
184 : JS_FS_END
185 : };
186 : #if defined(__clang__)
187 : #pragma clang diagnostic pop
188 : #endif
189 :
190 :
191 : // Can't be const because the pref-enabled boolean needs to be writable
192 : static Prefable<const JSFunctionSpec> sMethods[] = {
193 : { nullptr, &sMethods_specs[0] },
194 : { nullptr, nullptr }
195 : };
196 :
197 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
198 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
199 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
200 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
201 :
202 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
203 : #if defined(__clang__)
204 : #pragma clang diagnostic push
205 : #pragma clang diagnostic ignored "-Wmissing-braces"
206 : #endif
207 : static const JSPropertySpec sAttributes_specs[] = {
208 : { "request", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &request_getterinfo, nullptr, nullptr },
209 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
210 : };
211 : #if defined(__clang__)
212 : #pragma clang diagnostic pop
213 : #endif
214 :
215 :
216 : // Can't be const because the pref-enabled boolean needs to be writable
217 : static Prefable<const JSPropertySpec> sAttributes[] = {
218 : { nullptr, &sAttributes_specs[0] },
219 : { nullptr, nullptr }
220 : };
221 :
222 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
223 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
224 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
225 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
226 :
227 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
228 : #if defined(__clang__)
229 : #pragma clang diagnostic push
230 : #pragma clang diagnostic ignored "-Wmissing-braces"
231 : #endif
232 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
233 : { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
234 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
235 : };
236 : #if defined(__clang__)
237 : #pragma clang diagnostic pop
238 : #endif
239 :
240 :
241 : // Can't be const because the pref-enabled boolean needs to be writable
242 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
243 : { nullptr, &sUnforgeableAttributes_specs[0] },
244 : { nullptr, nullptr }
245 : };
246 :
247 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
248 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
249 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
250 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
251 :
252 :
253 : static uint16_t sNativeProperties_sortedPropertyIndices[3];
254 : static PropertyInfo sNativeProperties_propertyInfos[3];
255 :
256 : static const NativePropertiesN<3> sNativeProperties = {
257 : false, 0,
258 : false, 0,
259 : true, 0 /* sMethods */,
260 : true, 1 /* sAttributes */,
261 : false, 0,
262 : true, 2 /* sUnforgeableAttributes */,
263 : false, 0,
264 : -1,
265 : 3,
266 : sNativeProperties_sortedPropertyIndices,
267 : {
268 : { sMethods, &sNativeProperties_propertyInfos[0] },
269 : { sAttributes, &sNativeProperties_propertyInfos[1] },
270 : { sUnforgeableAttributes, &sNativeProperties_propertyInfos[2] }
271 : }
272 : };
273 : static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
274 : "We have a property info count that is oversized");
275 :
276 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
277 : {
278 : "Function",
279 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
280 : &sBoringInterfaceObjectClassClassOps,
281 : JS_NULL_CLASS_SPEC,
282 : JS_NULL_CLASS_EXT,
283 : &sInterfaceObjectClassObjectOps
284 : },
285 : eInterface,
286 : true,
287 : prototypes::id::FlyWebFetchEvent,
288 : PrototypeTraits<prototypes::id::FlyWebFetchEvent>::Depth,
289 : sNativePropertyHooks,
290 : "function FlyWebFetchEvent() {\n [native code]\n}",
291 : EventBinding::GetConstructorObject
292 : };
293 :
294 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
295 : {
296 : "FlyWebFetchEventPrototype",
297 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
298 : JS_NULL_CLASS_OPS,
299 : JS_NULL_CLASS_SPEC,
300 : JS_NULL_CLASS_EXT,
301 : JS_NULL_OBJECT_OPS
302 : },
303 : eInterfacePrototype,
304 : false,
305 : prototypes::id::FlyWebFetchEvent,
306 : PrototypeTraits<prototypes::id::FlyWebFetchEvent>::Depth,
307 : sNativePropertyHooks,
308 : "[object FlyWebFetchEventPrototype]",
309 : EventBinding::GetProtoObject
310 : };
311 :
312 : bool
313 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
314 : {
315 : static bool sPrefValue;
316 : static bool sPrefCacheSetUp = false;
317 0 : if (!sPrefCacheSetUp) {
318 0 : sPrefCacheSetUp = true;
319 0 : Preferences::AddBoolVarCache(&sPrefValue, "dom.flyweb.enabled");
320 : }
321 :
322 0 : return sPrefValue;
323 : }
324 :
325 : JSObject*
326 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
327 : {
328 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
329 : }
330 :
331 : static const js::ClassOps sClassOps = {
332 : _addProperty, /* addProperty */
333 : nullptr, /* delProperty */
334 : nullptr, /* getProperty */
335 : nullptr, /* setProperty */
336 : nullptr, /* enumerate */
337 : nullptr, /* newEnumerate */
338 : nullptr, /* resolve */
339 : nullptr, /* mayResolve */
340 : _finalize, /* finalize */
341 : nullptr, /* call */
342 : nullptr, /* hasInstance */
343 : nullptr, /* construct */
344 : nullptr, /* trace */
345 : };
346 :
347 : static const js::ClassExtension sClassExtension = {
348 : nullptr, /* weakmapKeyDelegateOp */
349 : _objectMoved /* objectMovedOp */
350 : };
351 :
352 : static const DOMJSClass sClass = {
353 : { "FlyWebFetchEvent",
354 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
355 : &sClassOps,
356 : JS_NULL_CLASS_SPEC,
357 : &sClassExtension,
358 : JS_NULL_OBJECT_OPS
359 : },
360 : { prototypes::id::Event, prototypes::id::FlyWebFetchEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
361 : IsBaseOf<nsISupports, mozilla::dom::FlyWebFetchEvent >::value,
362 : sNativePropertyHooks,
363 : FindAssociatedGlobalForNative<mozilla::dom::FlyWebFetchEvent>::Get,
364 : GetProtoObjectHandle,
365 : GetCCParticipant<mozilla::dom::FlyWebFetchEvent>::Get()
366 : };
367 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
368 : "Must have the right minimal number of reserved slots.");
369 : static_assert(1 >= 1,
370 : "Must have enough reserved slots.");
371 :
372 : const JSClass*
373 0 : GetJSClass()
374 : {
375 0 : return sClass.ToJSClass();
376 : }
377 :
378 : bool
379 0 : Wrap(JSContext* aCx, mozilla::dom::FlyWebFetchEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
380 : {
381 : MOZ_ASSERT(static_cast<mozilla::dom::FlyWebFetchEvent*>(aObject) ==
382 : reinterpret_cast<mozilla::dom::FlyWebFetchEvent*>(aObject),
383 : "Multiple inheritance for mozilla::dom::FlyWebFetchEvent is broken.");
384 : MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
385 : reinterpret_cast<mozilla::dom::Event*>(aObject),
386 : "Multiple inheritance for mozilla::dom::Event is broken.");
387 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
388 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
389 0 : MOZ_ASSERT(!aCache->GetWrapper(),
390 : "You should probably not be using Wrap() directly; use "
391 : "GetOrCreateDOMReflector instead");
392 :
393 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
394 : "nsISupports must be on our primary inheritance chain");
395 :
396 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
397 0 : if (!global) {
398 0 : return false;
399 : }
400 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
401 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
402 :
403 : // That might have ended up wrapping us already, due to the wonders
404 : // of XBL. Check for that, and bail out as needed.
405 0 : aReflector.set(aCache->GetWrapper());
406 0 : if (aReflector) {
407 : #ifdef DEBUG
408 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
409 : #endif // DEBUG
410 0 : return true;
411 : }
412 :
413 0 : JSAutoCompartment ac(aCx, global);
414 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
415 0 : if (!canonicalProto) {
416 0 : return false;
417 : }
418 0 : JS::Rooted<JSObject*> proto(aCx);
419 0 : if (aGivenProto) {
420 0 : proto = aGivenProto;
421 : // Unfortunately, while aGivenProto was in the compartment of aCx
422 : // coming in, we changed compartments to that of "parent" so may need
423 : // to wrap the proto here.
424 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
425 0 : if (!JS_WrapObject(aCx, &proto)) {
426 0 : return false;
427 : }
428 : }
429 : } else {
430 0 : proto = canonicalProto;
431 : }
432 :
433 0 : BindingJSObjectCreator<mozilla::dom::FlyWebFetchEvent> creator(aCx);
434 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
435 0 : if (!aReflector) {
436 0 : return false;
437 : }
438 :
439 0 : aCache->SetWrapper(aReflector);
440 :
441 : // Important: do unforgeable property setup after we have handed
442 : // over ownership of the C++ object to obj as needed, so that if
443 : // we fail and it ends up GCed it won't have problems in the
444 : // finalizer trying to drop its ownership of the C++ object.
445 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
446 0 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
447 0 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
448 0 : aCache->ReleaseWrapper(aObject);
449 0 : aCache->ClearWrapper();
450 0 : return false;
451 : }
452 0 : creator.InitializationSucceeded();
453 :
454 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
455 : aCache->GetWrapperPreserveColor() == aReflector);
456 : // If proto != canonicalProto, we have to preserve our wrapper;
457 : // otherwise we won't be able to properly recreate it later, since
458 : // we won't know what proto to use. Note that we don't check
459 : // aGivenProto here, since it's entirely possible (and even
460 : // somewhat common) to have a non-null aGivenProto which is the
461 : // same as canonicalProto.
462 0 : if (proto != canonicalProto) {
463 0 : PreserveWrapper(aObject);
464 : }
465 :
466 0 : return true;
467 : }
468 :
469 : const NativePropertyHooks sNativePropertyHooks[] = { {
470 : nullptr,
471 : nullptr,
472 : nullptr,
473 : { sNativeProperties.Upcast(), nullptr },
474 : prototypes::id::FlyWebFetchEvent,
475 : constructors::id::FlyWebFetchEvent,
476 : EventBinding::sNativePropertyHooks,
477 : &DefaultXrayExpandoObjectClass
478 : } };
479 :
480 : void
481 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
482 : {
483 0 : JS::Handle<JSObject*> parentProto(EventBinding::GetProtoObjectHandle(aCx));
484 0 : if (!parentProto) {
485 0 : return;
486 : }
487 :
488 0 : JS::Handle<JSObject*> constructorProto(EventBinding::GetConstructorObjectHandle(aCx));
489 0 : if (!constructorProto) {
490 0 : return;
491 : }
492 :
493 : static bool sIdsInited = false;
494 0 : if (!sIdsInited && NS_IsMainThread()) {
495 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
496 0 : return;
497 : }
498 0 : sIdsInited = true;
499 : }
500 :
501 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::FlyWebFetchEvent);
502 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::FlyWebFetchEvent);
503 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
504 : &sPrototypeClass.mBase, protoCache,
505 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
506 : interfaceCache,
507 : sNativeProperties.Upcast(),
508 : nullptr,
509 : "FlyWebFetchEvent", aDefineOnGlobal,
510 : nullptr,
511 0 : false);
512 :
513 0 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
514 : {
515 0 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
516 0 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
517 0 : if (!unforgeableHolder) {
518 0 : *protoCache = nullptr;
519 0 : if (interfaceCache) {
520 0 : *interfaceCache = nullptr;
521 : }
522 0 : return;
523 : }
524 : }
525 :
526 0 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
527 0 : *protoCache = nullptr;
528 0 : if (interfaceCache) {
529 0 : *interfaceCache = nullptr;
530 : }
531 0 : return;
532 : }
533 :
534 0 : if (*protoCache) {
535 0 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
536 0 : JS::ObjectValue(*unforgeableHolder));
537 : }
538 : }
539 :
540 : JS::Handle<JSObject*>
541 0 : GetProtoObjectHandle(JSContext* aCx)
542 : {
543 : /* Get the interface prototype object for this class. This will create the
544 : object as needed. */
545 0 : bool aDefineOnGlobal = true;
546 :
547 : /* Make sure our global is sane. Hopefully we can remove this sometime */
548 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
549 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
550 0 : return nullptr;
551 : }
552 :
553 : /* Check to see whether the interface objects are already installed */
554 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
555 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::FlyWebFetchEvent)) {
556 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
557 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
558 : }
559 :
560 : /*
561 : * The object might _still_ be null, but that's OK.
562 : *
563 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
564 : * traced by TraceProtoAndIfaceCache() and its contents are never
565 : * changed after they have been set.
566 : *
567 : * Calling address() avoids the read read barrier that does gray
568 : * unmarking, but it's not possible for the object to be gray here.
569 : */
570 :
571 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::FlyWebFetchEvent);
572 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
573 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
574 : }
575 :
576 : JS::Handle<JSObject*>
577 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
578 : {
579 : /* Get the interface object for this class. This will create the object as
580 : needed. */
581 :
582 : /* Make sure our global is sane. Hopefully we can remove this sometime */
583 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
584 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
585 0 : return nullptr;
586 : }
587 :
588 : /* Check to see whether the interface objects are already installed */
589 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
590 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::FlyWebFetchEvent)) {
591 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
592 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
593 : }
594 :
595 : /*
596 : * The object might _still_ be null, but that's OK.
597 : *
598 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
599 : * traced by TraceProtoAndIfaceCache() and its contents are never
600 : * changed after they have been set.
601 : *
602 : * Calling address() avoids the read read barrier that does gray
603 : * unmarking, but it's not possible for the object to be gray here.
604 : */
605 :
606 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::FlyWebFetchEvent);
607 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
608 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
609 : }
610 :
611 : JSObject*
612 0 : GetConstructorObject(JSContext* aCx)
613 : {
614 0 : return GetConstructorObjectHandle(aCx);
615 : }
616 :
617 : } // namespace FlyWebFetchEventBinding
618 :
619 :
620 :
621 : } // namespace dom
622 : } // namespace mozilla
|