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