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