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