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