Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM WebGLContextEvent.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "EventBinding.h"
5 : #include "WebGLContextEventBinding.h"
6 : #include "WrapperFactory.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/dom/BindingUtils.h"
9 : #include "mozilla/dom/DOMJSClass.h"
10 : #include "mozilla/dom/NonRefcountedDOMObject.h"
11 : #include "mozilla/dom/OffscreenCanvas.h"
12 : #include "mozilla/dom/PrimitiveConversions.h"
13 : #include "mozilla/dom/ScriptSettings.h"
14 : #include "mozilla/dom/SimpleGlobalObject.h"
15 : #include "mozilla/dom/WebGLContextEvent.h"
16 : #include "mozilla/dom/XrayExpandoClass.h"
17 :
18 : namespace mozilla {
19 : namespace dom {
20 :
21 :
22 0 : WebGLContextEventInit::WebGLContextEventInit()
23 0 : : EventInit(FastDictionaryInitializer())
24 : {
25 : // Safe to pass a null context if we pass a null value
26 0 : Init(nullptr, JS::NullHandleValue);
27 0 : }
28 :
29 :
30 :
31 : bool
32 0 : WebGLContextEventInit::InitIds(JSContext* cx, WebGLContextEventInitAtoms* atomsCache)
33 : {
34 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
35 :
36 : // Initialize these in reverse order so that any failure leaves the first one
37 : // uninitialized.
38 0 : if (!atomsCache->statusMessage_id.init(cx, "statusMessage")) {
39 0 : return false;
40 : }
41 0 : return true;
42 : }
43 :
44 : bool
45 0 : WebGLContextEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
46 : {
47 : // Passing a null JSContext is OK only if we're initing from null,
48 : // Since in that case we will not have to do any property gets
49 : // Also evaluate isNullOrUndefined in order to avoid false-positive
50 : // checkers by static analysis tools
51 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
52 0 : WebGLContextEventInitAtoms* atomsCache = nullptr;
53 0 : if (cx) {
54 0 : atomsCache = GetAtomCache<WebGLContextEventInitAtoms>(cx);
55 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
56 0 : return false;
57 : }
58 : }
59 :
60 : // Per spec, we init the parent's members first
61 0 : if (!EventInit::Init(cx, val)) {
62 0 : return false;
63 : }
64 :
65 0 : bool isNull = val.isNullOrUndefined();
66 : // We only need these if !isNull, in which case we have |cx|.
67 0 : Maybe<JS::Rooted<JSObject *> > object;
68 0 : Maybe<JS::Rooted<JS::Value> > temp;
69 0 : if (!isNull) {
70 0 : MOZ_ASSERT(cx);
71 0 : object.emplace(cx, &val.toObject());
72 0 : temp.emplace(cx);
73 : }
74 0 : if (!isNull) {
75 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->statusMessage_id, temp.ptr())) {
76 0 : return false;
77 : }
78 : }
79 0 : if (!isNull && !temp->isUndefined()) {
80 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mStatusMessage)) {
81 0 : return false;
82 : }
83 : } else {
84 : static const char16_t data[] = { 0 };
85 0 : mStatusMessage.Rebind(data, ArrayLength(data) - 1);
86 : }
87 0 : mIsAnyMemberPresent = true;
88 0 : return true;
89 : }
90 :
91 : bool
92 0 : WebGLContextEventInit::Init(const nsAString& aJSON)
93 : {
94 0 : AutoJSAPI jsapi;
95 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
96 0 : if (!cleanGlobal) {
97 0 : return false;
98 : }
99 0 : if (!jsapi.Init(cleanGlobal)) {
100 0 : return false;
101 : }
102 0 : JSContext* cx = jsapi.cx();
103 0 : JS::Rooted<JS::Value> json(cx);
104 0 : bool ok = ParseJSON(cx, aJSON, &json);
105 0 : NS_ENSURE_TRUE(ok, false);
106 0 : return Init(cx, json);
107 : }
108 :
109 : bool
110 0 : WebGLContextEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
111 : {
112 0 : WebGLContextEventInitAtoms* atomsCache = GetAtomCache<WebGLContextEventInitAtoms>(cx);
113 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
114 0 : return false;
115 : }
116 :
117 : // Per spec, we define the parent's members first
118 0 : if (!EventInit::ToObjectInternal(cx, rval)) {
119 0 : return false;
120 : }
121 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
122 :
123 : do {
124 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
125 0 : JS::Rooted<JS::Value> temp(cx);
126 0 : nsString const & currentValue = mStatusMessage;
127 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
128 0 : return false;
129 : }
130 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->statusMessage_id, temp, JSPROP_ENUMERATE)) {
131 0 : return false;
132 : }
133 0 : break;
134 : } while(0);
135 :
136 0 : return true;
137 : }
138 :
139 : bool
140 0 : WebGLContextEventInit::ToJSON(nsAString& aJSON) const
141 : {
142 0 : AutoJSAPI jsapi;
143 0 : jsapi.Init();
144 0 : JSContext *cx = jsapi.cx();
145 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
146 : // because we'll only be creating objects, in ways that have no
147 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
148 : // which likewise guarantees no side-effects for the sorts of
149 : // things we will pass it.
150 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
151 0 : JS::Rooted<JS::Value> val(cx);
152 0 : if (!ToObjectInternal(cx, &val)) {
153 0 : return false;
154 : }
155 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
156 0 : return StringifyToJSON(cx, obj, aJSON);
157 : }
158 :
159 : void
160 0 : WebGLContextEventInit::TraceDictionary(JSTracer* trc)
161 : {
162 0 : EventInit::TraceDictionary(trc);
163 0 : }
164 :
165 : WebGLContextEventInit&
166 0 : WebGLContextEventInit::operator=(const WebGLContextEventInit& aOther)
167 : {
168 0 : EventInit::operator=(aOther);
169 0 : mStatusMessage = aOther.mStatusMessage;
170 0 : return *this;
171 : }
172 :
173 : namespace binding_detail {
174 : } // namespace binding_detail
175 :
176 :
177 : namespace WebGLContextEventBinding {
178 :
179 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventBinding::NativeType>::value,
180 : "Can't inherit from an interface with a different ownership model.");
181 :
182 : static bool
183 0 : get_statusMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebGLContextEvent* self, JSJitGetterCallArgs args)
184 : {
185 0 : DOMString result;
186 0 : self->GetStatusMessage(result);
187 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
188 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
189 0 : return false;
190 : }
191 0 : return true;
192 : }
193 :
194 : static const JSJitInfo statusMessage_getterinfo = {
195 : { (JSJitGetterOp)get_statusMessage },
196 : { prototypes::id::WebGLContextEvent },
197 : { PrototypeTraits<prototypes::id::WebGLContextEvent>::Depth },
198 : JSJitInfo::Getter,
199 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
200 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
201 : false, /* isInfallible. False in setters. */
202 : false, /* isMovable. Not relevant for setters. */
203 : false, /* isEliminatable. Not relevant for setters. */
204 : false, /* isAlwaysInSlot. Only relevant for getters. */
205 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
206 : false, /* isTypedMethod. Only relevant for methods. */
207 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
208 : };
209 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
210 : static_assert(0 < 1, "There is no slot for us");
211 :
212 : static bool
213 0 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WebGLContextEvent* self, JSJitGetterCallArgs args)
214 : {
215 0 : bool result(self->IsTrusted());
216 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
217 0 : args.rval().setBoolean(result);
218 0 : return true;
219 : }
220 :
221 : static const JSJitInfo isTrusted_getterinfo = {
222 : { (JSJitGetterOp)get_isTrusted },
223 : { prototypes::id::WebGLContextEvent },
224 : { PrototypeTraits<prototypes::id::WebGLContextEvent>::Depth },
225 : JSJitInfo::Getter,
226 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
227 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
228 : true, /* isInfallible. False in setters. */
229 : true, /* isMovable. Not relevant for setters. */
230 : true, /* isEliminatable. Not relevant for setters. */
231 : false, /* isAlwaysInSlot. Only relevant for getters. */
232 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
233 : false, /* isTypedMethod. Only relevant for methods. */
234 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
235 : };
236 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
237 : static_assert(0 < 1, "There is no slot for us");
238 :
239 : static bool
240 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
241 : {
242 0 : mozilla::dom::WebGLContextEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WebGLContextEvent>(obj);
243 : // We don't want to preserve if we don't have a wrapper, and we
244 : // obviously can't preserve if we're not initialized.
245 0 : if (self && self->GetWrapperPreserveColor()) {
246 0 : PreserveWrapper(self);
247 : }
248 0 : return true;
249 : }
250 :
251 : static void
252 0 : _finalize(js::FreeOp* fop, JSObject* obj)
253 : {
254 0 : mozilla::dom::WebGLContextEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WebGLContextEvent>(obj);
255 0 : if (self) {
256 0 : ClearWrapper(self, self, obj);
257 0 : AddForDeferredFinalization<mozilla::dom::WebGLContextEvent>(self);
258 : }
259 0 : }
260 :
261 : static void
262 0 : _objectMoved(JSObject* obj, const JSObject* old)
263 : {
264 0 : mozilla::dom::WebGLContextEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WebGLContextEvent>(obj);
265 0 : if (self) {
266 0 : UpdateWrapper(self, self, obj, old);
267 : }
268 0 : }
269 :
270 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
271 : #if defined(__clang__)
272 : #pragma clang diagnostic push
273 : #pragma clang diagnostic ignored "-Wmissing-braces"
274 : #endif
275 : static const JSPropertySpec sAttributes_specs[] = {
276 : { "statusMessage", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &statusMessage_getterinfo, nullptr, nullptr },
277 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
278 : };
279 : #if defined(__clang__)
280 : #pragma clang diagnostic pop
281 : #endif
282 :
283 :
284 : // Can't be const because the pref-enabled boolean needs to be writable
285 : static Prefable<const JSPropertySpec> sAttributes[] = {
286 : { nullptr, &sAttributes_specs[0] },
287 : { nullptr, nullptr }
288 : };
289 :
290 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
291 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
292 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
293 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
294 :
295 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
296 : #if defined(__clang__)
297 : #pragma clang diagnostic push
298 : #pragma clang diagnostic ignored "-Wmissing-braces"
299 : #endif
300 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
301 : { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
302 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
303 : };
304 : #if defined(__clang__)
305 : #pragma clang diagnostic pop
306 : #endif
307 :
308 :
309 : // Can't be const because the pref-enabled boolean needs to be writable
310 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
311 : { nullptr, &sUnforgeableAttributes_specs[0] },
312 : { nullptr, nullptr }
313 : };
314 :
315 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
316 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
317 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
318 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
319 :
320 :
321 : static uint16_t sNativeProperties_sortedPropertyIndices[2];
322 : static PropertyInfo sNativeProperties_propertyInfos[2];
323 :
324 : static const NativePropertiesN<2> sNativeProperties = {
325 : false, 0,
326 : false, 0,
327 : false, 0,
328 : true, 0 /* sAttributes */,
329 : false, 0,
330 : true, 1 /* sUnforgeableAttributes */,
331 : false, 0,
332 : -1,
333 : 2,
334 : sNativeProperties_sortedPropertyIndices,
335 : {
336 : { sAttributes, &sNativeProperties_propertyInfos[0] },
337 : { sUnforgeableAttributes, &sNativeProperties_propertyInfos[1] }
338 : }
339 : };
340 : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
341 : "We have a property info count that is oversized");
342 :
343 : static bool
344 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
345 : {
346 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
347 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
348 0 : if (!args.isConstructing()) {
349 : // XXXbz wish I could get the name from the callee instead of
350 : // Adding more relocations
351 0 : return ThrowConstructorWithoutNew(cx, "WebGLContextEvent");
352 : }
353 :
354 0 : GlobalObject global(cx, obj);
355 0 : if (global.Failed()) {
356 0 : return false;
357 : }
358 :
359 0 : JS::Rooted<JSObject*> desiredProto(cx);
360 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
361 0 : return false;
362 : }
363 :
364 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
365 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WebGLContextEvent");
366 : }
367 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
368 0 : binding_detail::FakeString arg0;
369 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
370 0 : return false;
371 : }
372 0 : binding_detail::FastWebGLContextEventInit arg1;
373 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of WebGLContextEvent.constructor", false)) {
374 0 : return false;
375 : }
376 0 : Maybe<JSAutoCompartment> ac;
377 0 : if (objIsXray) {
378 0 : obj = js::CheckedUnwrap(obj);
379 0 : if (!obj) {
380 0 : return false;
381 : }
382 0 : ac.emplace(cx, obj);
383 0 : if (!JS_WrapObject(cx, &desiredProto)) {
384 0 : return false;
385 : }
386 : }
387 0 : binding_detail::FastErrorResult rv;
388 0 : auto result(StrongOrRawPtr<mozilla::dom::WebGLContextEvent>(mozilla::dom::WebGLContextEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
389 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
390 0 : return false;
391 : }
392 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
393 : static_assert(!IsPointer<decltype(result)>::value,
394 : "NewObject implies that we need to keep the object alive with a strong reference.");
395 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
396 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
397 0 : return false;
398 : }
399 0 : return true;
400 : }
401 :
402 : static const js::ClassOps sInterfaceObjectClassOps = {
403 : nullptr, /* addProperty */
404 : nullptr, /* delProperty */
405 : nullptr, /* getProperty */
406 : nullptr, /* setProperty */
407 : nullptr, /* enumerate */
408 : nullptr, /* newEnumerate */
409 : nullptr, /* resolve */
410 : nullptr, /* mayResolve */
411 : nullptr, /* finalize */
412 : _constructor, /* call */
413 : nullptr, /* hasInstance */
414 : _constructor, /* construct */
415 : nullptr, /* trace */
416 : };
417 :
418 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
419 : {
420 : "Function",
421 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
422 : &sInterfaceObjectClassOps,
423 : JS_NULL_CLASS_SPEC,
424 : JS_NULL_CLASS_EXT,
425 : &sInterfaceObjectClassObjectOps
426 : },
427 : eInterface,
428 : true,
429 : prototypes::id::WebGLContextEvent,
430 : PrototypeTraits<prototypes::id::WebGLContextEvent>::Depth,
431 : sNativePropertyHooks,
432 : "function WebGLContextEvent() {\n [native code]\n}",
433 : EventBinding::GetConstructorObject
434 : };
435 :
436 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
437 : {
438 : "WebGLContextEventPrototype",
439 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
440 : JS_NULL_CLASS_OPS,
441 : JS_NULL_CLASS_SPEC,
442 : JS_NULL_CLASS_EXT,
443 : JS_NULL_OBJECT_OPS
444 : },
445 : eInterfacePrototype,
446 : false,
447 : prototypes::id::WebGLContextEvent,
448 : PrototypeTraits<prototypes::id::WebGLContextEvent>::Depth,
449 : sNativePropertyHooks,
450 : "[object WebGLContextEventPrototype]",
451 : EventBinding::GetProtoObject
452 : };
453 :
454 : bool
455 1 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
456 : {
457 1 : return mozilla::dom::OffscreenCanvas::PrefEnabledOnWorkerThread(aCx, aObj);
458 : }
459 :
460 : JSObject*
461 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
462 : {
463 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
464 : }
465 :
466 : static const js::ClassOps sClassOps = {
467 : _addProperty, /* addProperty */
468 : nullptr, /* delProperty */
469 : nullptr, /* getProperty */
470 : nullptr, /* setProperty */
471 : nullptr, /* enumerate */
472 : nullptr, /* newEnumerate */
473 : nullptr, /* resolve */
474 : nullptr, /* mayResolve */
475 : _finalize, /* finalize */
476 : nullptr, /* call */
477 : nullptr, /* hasInstance */
478 : nullptr, /* construct */
479 : nullptr, /* trace */
480 : };
481 :
482 : static const js::ClassExtension sClassExtension = {
483 : nullptr, /* weakmapKeyDelegateOp */
484 : _objectMoved /* objectMovedOp */
485 : };
486 :
487 : static const DOMJSClass sClass = {
488 : { "WebGLContextEvent",
489 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
490 : &sClassOps,
491 : JS_NULL_CLASS_SPEC,
492 : &sClassExtension,
493 : JS_NULL_OBJECT_OPS
494 : },
495 : { prototypes::id::Event, prototypes::id::WebGLContextEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
496 : IsBaseOf<nsISupports, mozilla::dom::WebGLContextEvent >::value,
497 : sNativePropertyHooks,
498 : FindAssociatedGlobalForNative<mozilla::dom::WebGLContextEvent>::Get,
499 : GetProtoObjectHandle,
500 : GetCCParticipant<mozilla::dom::WebGLContextEvent>::Get()
501 : };
502 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
503 : "Must have the right minimal number of reserved slots.");
504 : static_assert(1 >= 1,
505 : "Must have enough reserved slots.");
506 :
507 : const JSClass*
508 0 : GetJSClass()
509 : {
510 0 : return sClass.ToJSClass();
511 : }
512 :
513 : bool
514 0 : Wrap(JSContext* aCx, mozilla::dom::WebGLContextEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
515 : {
516 : MOZ_ASSERT(static_cast<mozilla::dom::WebGLContextEvent*>(aObject) ==
517 : reinterpret_cast<mozilla::dom::WebGLContextEvent*>(aObject),
518 : "Multiple inheritance for mozilla::dom::WebGLContextEvent is broken.");
519 : MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
520 : reinterpret_cast<mozilla::dom::Event*>(aObject),
521 : "Multiple inheritance for mozilla::dom::Event is broken.");
522 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
523 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
524 0 : MOZ_ASSERT(!aCache->GetWrapper(),
525 : "You should probably not be using Wrap() directly; use "
526 : "GetOrCreateDOMReflector instead");
527 :
528 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
529 : "nsISupports must be on our primary inheritance chain");
530 :
531 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
532 0 : if (!global) {
533 0 : return false;
534 : }
535 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
536 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
537 :
538 : // That might have ended up wrapping us already, due to the wonders
539 : // of XBL. Check for that, and bail out as needed.
540 0 : aReflector.set(aCache->GetWrapper());
541 0 : if (aReflector) {
542 : #ifdef DEBUG
543 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
544 : #endif // DEBUG
545 0 : return true;
546 : }
547 :
548 0 : JSAutoCompartment ac(aCx, global);
549 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
550 0 : if (!canonicalProto) {
551 0 : return false;
552 : }
553 0 : JS::Rooted<JSObject*> proto(aCx);
554 0 : if (aGivenProto) {
555 0 : proto = aGivenProto;
556 : // Unfortunately, while aGivenProto was in the compartment of aCx
557 : // coming in, we changed compartments to that of "parent" so may need
558 : // to wrap the proto here.
559 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
560 0 : if (!JS_WrapObject(aCx, &proto)) {
561 0 : return false;
562 : }
563 : }
564 : } else {
565 0 : proto = canonicalProto;
566 : }
567 :
568 0 : BindingJSObjectCreator<mozilla::dom::WebGLContextEvent> creator(aCx);
569 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
570 0 : if (!aReflector) {
571 0 : return false;
572 : }
573 :
574 0 : aCache->SetWrapper(aReflector);
575 :
576 : // Important: do unforgeable property setup after we have handed
577 : // over ownership of the C++ object to obj as needed, so that if
578 : // we fail and it ends up GCed it won't have problems in the
579 : // finalizer trying to drop its ownership of the C++ object.
580 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
581 0 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
582 0 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
583 0 : aCache->ReleaseWrapper(aObject);
584 0 : aCache->ClearWrapper();
585 0 : return false;
586 : }
587 0 : creator.InitializationSucceeded();
588 :
589 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
590 : aCache->GetWrapperPreserveColor() == aReflector);
591 : // If proto != canonicalProto, we have to preserve our wrapper;
592 : // otherwise we won't be able to properly recreate it later, since
593 : // we won't know what proto to use. Note that we don't check
594 : // aGivenProto here, since it's entirely possible (and even
595 : // somewhat common) to have a non-null aGivenProto which is the
596 : // same as canonicalProto.
597 0 : if (proto != canonicalProto) {
598 0 : PreserveWrapper(aObject);
599 : }
600 :
601 0 : return true;
602 : }
603 :
604 : const NativePropertyHooks sNativePropertyHooks[] = { {
605 : nullptr,
606 : nullptr,
607 : nullptr,
608 : { sNativeProperties.Upcast(), nullptr },
609 : prototypes::id::WebGLContextEvent,
610 : constructors::id::WebGLContextEvent,
611 : EventBinding::sNativePropertyHooks,
612 : &DefaultXrayExpandoObjectClass
613 : } };
614 :
615 : void
616 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
617 : {
618 0 : JS::Handle<JSObject*> parentProto(EventBinding::GetProtoObjectHandle(aCx));
619 0 : if (!parentProto) {
620 0 : return;
621 : }
622 :
623 0 : JS::Handle<JSObject*> constructorProto(EventBinding::GetConstructorObjectHandle(aCx));
624 0 : if (!constructorProto) {
625 0 : return;
626 : }
627 :
628 : static bool sIdsInited = false;
629 0 : if (!sIdsInited && NS_IsMainThread()) {
630 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
631 0 : return;
632 : }
633 0 : sIdsInited = true;
634 : }
635 :
636 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WebGLContextEvent);
637 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WebGLContextEvent);
638 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
639 : &sPrototypeClass.mBase, protoCache,
640 : constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
641 : interfaceCache,
642 : sNativeProperties.Upcast(),
643 : nullptr,
644 : "WebGLContextEvent", aDefineOnGlobal,
645 : nullptr,
646 0 : false);
647 :
648 0 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
649 : {
650 0 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
651 0 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
652 0 : if (!unforgeableHolder) {
653 0 : *protoCache = nullptr;
654 0 : if (interfaceCache) {
655 0 : *interfaceCache = nullptr;
656 : }
657 0 : return;
658 : }
659 : }
660 :
661 0 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
662 0 : *protoCache = nullptr;
663 0 : if (interfaceCache) {
664 0 : *interfaceCache = nullptr;
665 : }
666 0 : return;
667 : }
668 :
669 0 : if (*protoCache) {
670 0 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
671 0 : JS::ObjectValue(*unforgeableHolder));
672 : }
673 : }
674 :
675 : JS::Handle<JSObject*>
676 0 : GetProtoObjectHandle(JSContext* aCx)
677 : {
678 : /* Get the interface prototype object for this class. This will create the
679 : object as needed. */
680 0 : bool aDefineOnGlobal = true;
681 :
682 : /* Make sure our global is sane. Hopefully we can remove this sometime */
683 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
684 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
685 0 : return nullptr;
686 : }
687 :
688 : /* Check to see whether the interface objects are already installed */
689 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
690 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::WebGLContextEvent)) {
691 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
692 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
693 : }
694 :
695 : /*
696 : * The object might _still_ be null, but that's OK.
697 : *
698 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
699 : * traced by TraceProtoAndIfaceCache() and its contents are never
700 : * changed after they have been set.
701 : *
702 : * Calling address() avoids the read read barrier that does gray
703 : * unmarking, but it's not possible for the object to be gray here.
704 : */
705 :
706 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::WebGLContextEvent);
707 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
708 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
709 : }
710 :
711 : JS::Handle<JSObject*>
712 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
713 : {
714 : /* Get the interface object for this class. This will create the object as
715 : needed. */
716 :
717 : /* Make sure our global is sane. Hopefully we can remove this sometime */
718 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
719 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
720 0 : return nullptr;
721 : }
722 :
723 : /* Check to see whether the interface objects are already installed */
724 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
725 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::WebGLContextEvent)) {
726 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
727 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
728 : }
729 :
730 : /*
731 : * The object might _still_ be null, but that's OK.
732 : *
733 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
734 : * traced by TraceProtoAndIfaceCache() and its contents are never
735 : * changed after they have been set.
736 : *
737 : * Calling address() avoids the read read barrier that does gray
738 : * unmarking, but it's not possible for the object to be gray here.
739 : */
740 :
741 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::WebGLContextEvent);
742 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
743 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
744 : }
745 :
746 : JSObject*
747 0 : GetConstructorObject(JSContext* aCx)
748 : {
749 0 : return GetConstructorObjectHandle(aCx);
750 : }
751 :
752 : } // namespace WebGLContextEventBinding
753 :
754 :
755 :
756 : } // namespace dom
757 : } // namespace mozilla
|