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