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