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