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