/work/obj-fuzz/dom/bindings/TCPSocketBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM TCPSocket.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "EventHandlerBinding.h" |
5 | | #include "EventTargetBinding.h" |
6 | | #include "TCPServerSocketBinding.h" |
7 | | #include "TCPSocket.h" |
8 | | #include "TCPSocketBinding.h" |
9 | | #include "WrapperFactory.h" |
10 | | #include "jsapi.h" |
11 | | #include "jsfriendapi.h" |
12 | | #include "mozilla/OwningNonNull.h" |
13 | | #include "mozilla/dom/BindingUtils.h" |
14 | | #include "mozilla/dom/DOMJSClass.h" |
15 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
16 | | #include "mozilla/dom/Nullable.h" |
17 | | #include "mozilla/dom/PrimitiveConversions.h" |
18 | | #include "mozilla/dom/ScriptSettings.h" |
19 | | #include "mozilla/dom/SimpleGlobalObject.h" |
20 | | #include "mozilla/dom/TCPServerSocket.h" |
21 | | #include "mozilla/dom/TCPSocket.h" |
22 | | #include "mozilla/dom/TypedArray.h" |
23 | | #include "mozilla/dom/XrayExpandoClass.h" |
24 | | #include "nsContentUtils.h" |
25 | | |
26 | | namespace mozilla { |
27 | | namespace dom { |
28 | | |
29 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
30 | | using namespace mozilla::dom::binding_detail; |
31 | | |
32 | | |
33 | | namespace TCPSocketBinaryTypeValues { |
34 | | extern const EnumEntry strings[3] = { |
35 | | {"arraybuffer", 11}, |
36 | | {"string", 6}, |
37 | | { nullptr, 0 } |
38 | | }; |
39 | | } // namespace TCPSocketBinaryTypeValues |
40 | | |
41 | | bool |
42 | | ToJSValue(JSContext* aCx, TCPSocketBinaryType aArgument, JS::MutableHandle<JS::Value> aValue) |
43 | 0 | { |
44 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(TCPSocketBinaryTypeValues::strings)); |
45 | 0 | JSString* resultStr = |
46 | 0 | JS_NewStringCopyN(aCx, TCPSocketBinaryTypeValues::strings[uint32_t(aArgument)].value, |
47 | 0 | TCPSocketBinaryTypeValues::strings[uint32_t(aArgument)].length); |
48 | 0 | if (!resultStr) { |
49 | 0 | return false; |
50 | 0 | } |
51 | 0 | aValue.setString(resultStr); |
52 | 0 | return true; |
53 | 0 | } |
54 | | |
55 | | |
56 | | namespace TCPReadyStateValues { |
57 | | extern const EnumEntry strings[5] = { |
58 | | {"connecting", 10}, |
59 | | {"open", 4}, |
60 | | {"closing", 7}, |
61 | | {"closed", 6}, |
62 | | { nullptr, 0 } |
63 | | }; |
64 | | } // namespace TCPReadyStateValues |
65 | | |
66 | | bool |
67 | | ToJSValue(JSContext* aCx, TCPReadyState aArgument, JS::MutableHandle<JS::Value> aValue) |
68 | 0 | { |
69 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(TCPReadyStateValues::strings)); |
70 | 0 | JSString* resultStr = |
71 | 0 | JS_NewStringCopyN(aCx, TCPReadyStateValues::strings[uint32_t(aArgument)].value, |
72 | 0 | TCPReadyStateValues::strings[uint32_t(aArgument)].length); |
73 | 0 | if (!resultStr) { |
74 | 0 | return false; |
75 | 0 | } |
76 | 0 | aValue.setString(resultStr); |
77 | 0 | return true; |
78 | 0 | } |
79 | | |
80 | | |
81 | | |
82 | | SocketOptions::SocketOptions() |
83 | 0 | { |
84 | 0 | // Safe to pass a null context if we pass a null value |
85 | 0 | Init(nullptr, JS::NullHandleValue); |
86 | 0 | } |
87 | | |
88 | | |
89 | | |
90 | | bool |
91 | | SocketOptions::InitIds(JSContext* cx, SocketOptionsAtoms* atomsCache) |
92 | 0 | { |
93 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
94 | 0 |
|
95 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
96 | 0 | // uninitialized. |
97 | 0 | if (!atomsCache->useSecureTransport_id.init(cx, "useSecureTransport") || |
98 | 0 | !atomsCache->binaryType_id.init(cx, "binaryType")) { |
99 | 0 | return false; |
100 | 0 | } |
101 | 0 | return true; |
102 | 0 | } |
103 | | |
104 | | bool |
105 | | SocketOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
106 | 0 | { |
107 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
108 | 0 | // Since in that case we will not have to do any property gets |
109 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
110 | 0 | // checkers by static analysis tools |
111 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
112 | 0 | SocketOptionsAtoms* atomsCache = nullptr; |
113 | 0 | if (cx) { |
114 | 0 | atomsCache = GetAtomCache<SocketOptionsAtoms>(cx); |
115 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
116 | 0 | return false; |
117 | 0 | } |
118 | 0 | } |
119 | 0 | |
120 | 0 | if (!IsConvertibleToDictionary(val)) { |
121 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
122 | 0 | } |
123 | 0 | |
124 | 0 | bool isNull = val.isNullOrUndefined(); |
125 | 0 | // We only need these if !isNull, in which case we have |cx|. |
126 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
127 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
128 | 0 | if (!isNull) { |
129 | 0 | MOZ_ASSERT(cx); |
130 | 0 | object.emplace(cx, &val.toObject()); |
131 | 0 | temp.emplace(cx); |
132 | 0 | } |
133 | 0 | if (!isNull) { |
134 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->binaryType_id, temp.ptr())) { |
135 | 0 | return false; |
136 | 0 | } |
137 | 0 | } |
138 | 0 | if (!isNull && !temp->isUndefined()) { |
139 | 0 | { |
140 | 0 | int index; |
141 | 0 | if (!FindEnumStringIndex<true>(cx, temp.ref(), TCPSocketBinaryTypeValues::strings, "TCPSocketBinaryType", "'binaryType' member of SocketOptions", &index)) { |
142 | 0 | return false; |
143 | 0 | } |
144 | 0 | MOZ_ASSERT(index >= 0); |
145 | 0 | mBinaryType = static_cast<TCPSocketBinaryType>(index); |
146 | 0 | } |
147 | 0 | } else { |
148 | 0 | mBinaryType = TCPSocketBinaryType::String; |
149 | 0 | } |
150 | 0 | mIsAnyMemberPresent = true; |
151 | 0 |
|
152 | 0 | if (!isNull) { |
153 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->useSecureTransport_id, temp.ptr())) { |
154 | 0 | return false; |
155 | 0 | } |
156 | 0 | } |
157 | 0 | if (!isNull && !temp->isUndefined()) { |
158 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mUseSecureTransport)) { |
159 | 0 | return false; |
160 | 0 | } |
161 | 0 | } else { |
162 | 0 | mUseSecureTransport = false; |
163 | 0 | } |
164 | 0 | mIsAnyMemberPresent = true; |
165 | 0 | return true; |
166 | 0 | } |
167 | | |
168 | | bool |
169 | | SocketOptions::Init(const nsAString& aJSON) |
170 | 0 | { |
171 | 0 | AutoJSAPI jsapi; |
172 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
173 | 0 | if (!cleanGlobal) { |
174 | 0 | return false; |
175 | 0 | } |
176 | 0 | if (!jsapi.Init(cleanGlobal)) { |
177 | 0 | return false; |
178 | 0 | } |
179 | 0 | JSContext* cx = jsapi.cx(); |
180 | 0 | JS::Rooted<JS::Value> json(cx); |
181 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
182 | 0 | NS_ENSURE_TRUE(ok, false); |
183 | 0 | return Init(cx, json); |
184 | 0 | } |
185 | | |
186 | | bool |
187 | | SocketOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
188 | 0 | { |
189 | 0 | SocketOptionsAtoms* atomsCache = GetAtomCache<SocketOptionsAtoms>(cx); |
190 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
191 | 0 | return false; |
192 | 0 | } |
193 | 0 | |
194 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
195 | 0 | if (!obj) { |
196 | 0 | return false; |
197 | 0 | } |
198 | 0 | rval.set(JS::ObjectValue(*obj)); |
199 | 0 |
|
200 | 0 | do { |
201 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
202 | 0 | JS::Rooted<JS::Value> temp(cx); |
203 | 0 | TCPSocketBinaryType const & currentValue = mBinaryType; |
204 | 0 | if (!ToJSValue(cx, currentValue, &temp)) { |
205 | 0 | return false; |
206 | 0 | } |
207 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->binaryType_id, temp, JSPROP_ENUMERATE)) { |
208 | 0 | return false; |
209 | 0 | } |
210 | 0 | break; |
211 | 0 | } while(false); |
212 | 0 |
|
213 | 0 | do { |
214 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
215 | 0 | JS::Rooted<JS::Value> temp(cx); |
216 | 0 | bool const & currentValue = mUseSecureTransport; |
217 | 0 | temp.setBoolean(currentValue); |
218 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->useSecureTransport_id, temp, JSPROP_ENUMERATE)) { |
219 | 0 | return false; |
220 | 0 | } |
221 | 0 | break; |
222 | 0 | } while(false); |
223 | 0 |
|
224 | 0 | return true; |
225 | 0 | } |
226 | | |
227 | | bool |
228 | | SocketOptions::ToJSON(nsAString& aJSON) const |
229 | 0 | { |
230 | 0 | AutoJSAPI jsapi; |
231 | 0 | jsapi.Init(); |
232 | 0 | JSContext *cx = jsapi.cx(); |
233 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
234 | 0 | // because we'll only be creating objects, in ways that have no |
235 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
236 | 0 | // which likewise guarantees no side-effects for the sorts of |
237 | 0 | // things we will pass it. |
238 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
239 | 0 | JS::Rooted<JS::Value> val(cx); |
240 | 0 | if (!ToObjectInternal(cx, &val)) { |
241 | 0 | return false; |
242 | 0 | } |
243 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
244 | 0 | return StringifyToJSON(cx, obj, aJSON); |
245 | 0 | } |
246 | | |
247 | | void |
248 | | SocketOptions::TraceDictionary(JSTracer* trc) |
249 | 0 | { |
250 | 0 | } |
251 | | |
252 | | SocketOptions& |
253 | | SocketOptions::operator=(const SocketOptions& aOther) |
254 | 0 | { |
255 | 0 | DictionaryBase::operator=(aOther); |
256 | 0 | mBinaryType = aOther.mBinaryType; |
257 | 0 | mUseSecureTransport = aOther.mUseSecureTransport; |
258 | 0 | return *this; |
259 | 0 | } |
260 | | |
261 | | namespace binding_detail { |
262 | | } // namespace binding_detail |
263 | | |
264 | | |
265 | | namespace LegacyMozTCPSocket_Binding { |
266 | | |
267 | | MOZ_CAN_RUN_SCRIPT static bool |
268 | | open(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::LegacyMozTCPSocket* self, const JSJitMethodCallArgs& args) |
269 | 0 | { |
270 | 0 | AUTO_PROFILER_LABEL_FAST("LegacyMozTCPSocket.open", DOM, cx); |
271 | 0 |
|
272 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
273 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "LegacyMozTCPSocket.open"); |
274 | 0 | } |
275 | 0 | binding_detail::FakeString arg0; |
276 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
277 | 0 | return false; |
278 | 0 | } |
279 | 0 | uint16_t arg1; |
280 | 0 | if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[1], &arg1)) { |
281 | 0 | return false; |
282 | 0 | } |
283 | 0 | binding_detail::FastSocketOptions arg2; |
284 | 0 | if (!arg2.Init(cx, (args.hasDefined(2)) ? args[2] : JS::NullHandleValue, "Argument 3 of LegacyMozTCPSocket.open", false)) { |
285 | 0 | return false; |
286 | 0 | } |
287 | 0 | FastErrorResult rv; |
288 | 0 | auto result(StrongOrRawPtr<mozilla::dom::TCPSocket>(self->Open(NonNullHelper(Constify(arg0)), arg1, Constify(arg2), rv))); |
289 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
290 | 0 | return false; |
291 | 0 | } |
292 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
293 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
294 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
295 | 0 | return false; |
296 | 0 | } |
297 | 0 | return true; |
298 | 0 | } |
299 | | |
300 | | static const JSJitInfo open_methodinfo = { |
301 | | { (JSJitGetterOp)open }, |
302 | | { prototypes::id::LegacyMozTCPSocket }, |
303 | | { PrototypeTraits<prototypes::id::LegacyMozTCPSocket>::Depth }, |
304 | | JSJitInfo::Method, |
305 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
306 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
307 | | false, /* isInfallible. False in setters. */ |
308 | | false, /* isMovable. Not relevant for setters. */ |
309 | | false, /* isEliminatable. Not relevant for setters. */ |
310 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
311 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
312 | | false, /* isTypedMethod. Only relevant for methods. */ |
313 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
314 | | }; |
315 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
316 | | static_assert(0 < 1, "There is no slot for us"); |
317 | | |
318 | | MOZ_CAN_RUN_SCRIPT static bool |
319 | | listen(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::LegacyMozTCPSocket* self, const JSJitMethodCallArgs& args) |
320 | 0 | { |
321 | 0 | AUTO_PROFILER_LABEL_FAST("LegacyMozTCPSocket.listen", DOM, cx); |
322 | 0 |
|
323 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
324 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "LegacyMozTCPSocket.listen"); |
325 | 0 | } |
326 | 0 | uint16_t arg0; |
327 | 0 | if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[0], &arg0)) { |
328 | 0 | return false; |
329 | 0 | } |
330 | 0 | binding_detail::FastServerSocketOptions arg1; |
331 | 0 | if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of LegacyMozTCPSocket.listen", false)) { |
332 | 0 | return false; |
333 | 0 | } |
334 | 0 | uint16_t arg2; |
335 | 0 | if (args.hasDefined(2)) { |
336 | 0 | if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[2], &arg2)) { |
337 | 0 | return false; |
338 | 0 | } |
339 | 0 | } else { |
340 | 0 | arg2 = 0; |
341 | 0 | } |
342 | 0 | FastErrorResult rv; |
343 | 0 | auto result(StrongOrRawPtr<mozilla::dom::TCPServerSocket>(self->Listen(arg0, Constify(arg1), arg2, rv))); |
344 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
345 | 0 | return false; |
346 | 0 | } |
347 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
348 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
349 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
350 | 0 | return false; |
351 | 0 | } |
352 | 0 | return true; |
353 | 0 | } |
354 | | |
355 | | static const JSJitInfo listen_methodinfo = { |
356 | | { (JSJitGetterOp)listen }, |
357 | | { prototypes::id::LegacyMozTCPSocket }, |
358 | | { PrototypeTraits<prototypes::id::LegacyMozTCPSocket>::Depth }, |
359 | | JSJitInfo::Method, |
360 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
361 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
362 | | false, /* isInfallible. False in setters. */ |
363 | | false, /* isMovable. Not relevant for setters. */ |
364 | | false, /* isEliminatable. Not relevant for setters. */ |
365 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
366 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
367 | | false, /* isTypedMethod. Only relevant for methods. */ |
368 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
369 | | }; |
370 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
371 | | static_assert(0 < 1, "There is no slot for us"); |
372 | | |
373 | | static void |
374 | | _finalize(js::FreeOp* fop, JSObject* obj) |
375 | 0 | { |
376 | 0 | mozilla::dom::LegacyMozTCPSocket* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::LegacyMozTCPSocket>(obj); |
377 | 0 | if (self) { |
378 | 0 | AddForDeferredFinalization<mozilla::dom::LegacyMozTCPSocket>(self); |
379 | 0 | } |
380 | 0 | } |
381 | | |
382 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
383 | | #if defined(__clang__) |
384 | | #pragma clang diagnostic push |
385 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
386 | | #endif |
387 | | static const JSFunctionSpec sMethods_specs[] = { |
388 | | JS_FNSPEC("open", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&open_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
389 | | JS_FNSPEC("listen", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&listen_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
390 | | JS_FS_END |
391 | | }; |
392 | | #if defined(__clang__) |
393 | | #pragma clang diagnostic pop |
394 | | #endif |
395 | | |
396 | | |
397 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
398 | | { nullptr, &sMethods_specs[0] }, |
399 | | { nullptr, nullptr } |
400 | | }; |
401 | | |
402 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
403 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
404 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
405 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
406 | | |
407 | | |
408 | | static uint16_t sNativeProperties_sortedPropertyIndices[2]; |
409 | | static PropertyInfo sNativeProperties_propertyInfos[2]; |
410 | | |
411 | | static const NativePropertiesN<1> sNativeProperties = { |
412 | | false, 0, |
413 | | false, 0, |
414 | | true, 0 /* sMethods */, |
415 | | false, 0, |
416 | | false, 0, |
417 | | false, 0, |
418 | | false, 0, |
419 | | -1, |
420 | | 2, |
421 | | sNativeProperties_sortedPropertyIndices, |
422 | | { |
423 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
424 | | } |
425 | | }; |
426 | | static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
427 | | "We have a property info count that is oversized"); |
428 | | |
429 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
430 | | { |
431 | | "LegacyMozTCPSocketPrototype", |
432 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
433 | | JS_NULL_CLASS_OPS, |
434 | | JS_NULL_CLASS_SPEC, |
435 | | JS_NULL_CLASS_EXT, |
436 | | JS_NULL_OBJECT_OPS |
437 | | }, |
438 | | eInterfacePrototype, |
439 | | false, |
440 | | prototypes::id::LegacyMozTCPSocket, |
441 | | PrototypeTraits<prototypes::id::LegacyMozTCPSocket>::Depth, |
442 | | sNativePropertyHooks, |
443 | | "[object LegacyMozTCPSocketPrototype]", |
444 | | JS::GetRealmObjectPrototype |
445 | | }; |
446 | | |
447 | | static const js::ClassOps sClassOps = { |
448 | | nullptr, /* addProperty */ |
449 | | nullptr, /* delProperty */ |
450 | | nullptr, /* enumerate */ |
451 | | nullptr, /* newEnumerate */ |
452 | | nullptr, /* resolve */ |
453 | | nullptr, /* mayResolve */ |
454 | | _finalize, /* finalize */ |
455 | | nullptr, /* call */ |
456 | | nullptr, /* hasInstance */ |
457 | | nullptr, /* construct */ |
458 | | nullptr, /* trace */ |
459 | | }; |
460 | | |
461 | | static const js::ClassExtension sClassExtension = { |
462 | | nullptr, /* weakmapKeyDelegateOp */ |
463 | | nullptr /* objectMovedOp */ |
464 | | }; |
465 | | |
466 | | static const DOMJSClass sClass = { |
467 | | { "LegacyMozTCPSocket", |
468 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
469 | | &sClassOps, |
470 | | JS_NULL_CLASS_SPEC, |
471 | | &sClassExtension, |
472 | | JS_NULL_OBJECT_OPS |
473 | | }, |
474 | | { prototypes::id::LegacyMozTCPSocket, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
475 | | IsBaseOf<nsISupports, mozilla::dom::LegacyMozTCPSocket >::value, |
476 | | sNativePropertyHooks, |
477 | | FindAssociatedGlobalForNative<mozilla::dom::LegacyMozTCPSocket>::Get, |
478 | | GetProtoObjectHandle, |
479 | | GetCCParticipant<mozilla::dom::LegacyMozTCPSocket>::Get() |
480 | | }; |
481 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
482 | | "Must have the right minimal number of reserved slots."); |
483 | | static_assert(1 >= 1, |
484 | | "Must have enough reserved slots."); |
485 | | |
486 | | const JSClass* |
487 | | GetJSClass() |
488 | 0 | { |
489 | 0 | return sClass.ToJSClass(); |
490 | 0 | } |
491 | | |
492 | | bool |
493 | | Wrap(JSContext* aCx, mozilla::dom::LegacyMozTCPSocket* aObject, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
494 | 0 | { |
495 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::LegacyMozTCPSocket*>(aObject) == |
496 | 0 | reinterpret_cast<mozilla::dom::LegacyMozTCPSocket*>(aObject), |
497 | 0 | "Multiple inheritance for mozilla::dom::LegacyMozTCPSocket is broken."); |
498 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
499 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
500 | 0 |
|
501 | 0 | JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx)); |
502 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
503 | 0 | if (!canonicalProto) { |
504 | 0 | return false; |
505 | 0 | } |
506 | 0 | JS::Rooted<JSObject*> proto(aCx); |
507 | 0 | if (aGivenProto) { |
508 | 0 | proto = aGivenProto; |
509 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
510 | 0 | // coming in, we changed compartments to that of "parent" so may need |
511 | 0 | // to wrap the proto here. |
512 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
513 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
514 | 0 | return false; |
515 | 0 | } |
516 | 0 | } |
517 | 0 | } else { |
518 | 0 | proto = canonicalProto; |
519 | 0 | } |
520 | 0 |
|
521 | 0 | BindingJSObjectCreator<mozilla::dom::LegacyMozTCPSocket> creator(aCx); |
522 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
523 | 0 | if (!aReflector) { |
524 | 0 | return false; |
525 | 0 | } |
526 | 0 | |
527 | 0 | |
528 | 0 | |
529 | 0 | creator.InitializationSucceeded(); |
530 | 0 | return true; |
531 | 0 | } |
532 | | |
533 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
534 | | nullptr, |
535 | | nullptr, |
536 | | nullptr, |
537 | | { sNativeProperties.Upcast(), nullptr }, |
538 | | prototypes::id::LegacyMozTCPSocket, |
539 | | constructors::id::_ID_Count, |
540 | | nullptr, |
541 | | &DefaultXrayExpandoObjectClass |
542 | | } }; |
543 | | |
544 | | void |
545 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
546 | 0 | { |
547 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
548 | 0 | if (!parentProto) { |
549 | 0 | return; |
550 | 0 | } |
551 | 0 | |
552 | 0 | static bool sIdsInited = false; |
553 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
554 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
555 | 0 | return; |
556 | 0 | } |
557 | 0 | sIdsInited = true; |
558 | 0 | } |
559 | 0 |
|
560 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::LegacyMozTCPSocket); |
561 | 0 | JS::Heap<JSObject*>* interfaceCache = nullptr; |
562 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
563 | 0 | &sPrototypeClass.mBase, protoCache, |
564 | 0 | nullptr, |
565 | 0 | nullptr, nullptr, 0, nullptr, |
566 | 0 | interfaceCache, |
567 | 0 | sNativeProperties.Upcast(), |
568 | 0 | nullptr, |
569 | 0 | nullptr, aDefineOnGlobal, |
570 | 0 | nullptr, |
571 | 0 | false); |
572 | 0 | } |
573 | | |
574 | | } // namespace LegacyMozTCPSocket_Binding |
575 | | |
576 | | |
577 | | |
578 | | namespace TCPSocket_Binding { |
579 | | |
580 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value, |
581 | | "Can't inherit from an interface with a different ownership model."); |
582 | | |
583 | | MOZ_CAN_RUN_SCRIPT static bool |
584 | | upgradeToSecure(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, const JSJitMethodCallArgs& args) |
585 | 0 | { |
586 | 0 | AUTO_PROFILER_LABEL_FAST("TCPSocket.upgradeToSecure", DOM, cx); |
587 | 0 |
|
588 | 0 | FastErrorResult rv; |
589 | 0 | self->UpgradeToSecure(rv); |
590 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
591 | 0 | return false; |
592 | 0 | } |
593 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
594 | 0 | args.rval().setUndefined(); |
595 | 0 | return true; |
596 | 0 | } |
597 | | |
598 | | static const JSJitInfo upgradeToSecure_methodinfo = { |
599 | | { (JSJitGetterOp)upgradeToSecure }, |
600 | | { prototypes::id::TCPSocket }, |
601 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
602 | | JSJitInfo::Method, |
603 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
604 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
605 | | false, /* isInfallible. False in setters. */ |
606 | | false, /* isMovable. Not relevant for setters. */ |
607 | | false, /* isEliminatable. Not relevant for setters. */ |
608 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
609 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
610 | | false, /* isTypedMethod. Only relevant for methods. */ |
611 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
612 | | }; |
613 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
614 | | static_assert(0 < 1, "There is no slot for us"); |
615 | | |
616 | | MOZ_CAN_RUN_SCRIPT static bool |
617 | | get_host(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args) |
618 | 0 | { |
619 | 0 | AUTO_PROFILER_LABEL_FAST("get TCPSocket.host", DOM, cx); |
620 | 0 |
|
621 | 0 | DOMString result; |
622 | 0 | self->GetHost(result); |
623 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
624 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
625 | 0 | return false; |
626 | 0 | } |
627 | 0 | return true; |
628 | 0 | } |
629 | | |
630 | | static const JSJitInfo host_getterinfo = { |
631 | | { (JSJitGetterOp)get_host }, |
632 | | { prototypes::id::TCPSocket }, |
633 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
634 | | JSJitInfo::Getter, |
635 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
636 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
637 | | false, /* isInfallible. False in setters. */ |
638 | | false, /* isMovable. Not relevant for setters. */ |
639 | | false, /* isEliminatable. Not relevant for setters. */ |
640 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
641 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
642 | | false, /* isTypedMethod. Only relevant for methods. */ |
643 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
644 | | }; |
645 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
646 | | static_assert(0 < 1, "There is no slot for us"); |
647 | | |
648 | | MOZ_CAN_RUN_SCRIPT static bool |
649 | | get_port(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args) |
650 | 0 | { |
651 | 0 | AUTO_PROFILER_LABEL_FAST("get TCPSocket.port", DOM, cx); |
652 | 0 |
|
653 | 0 | uint16_t result(self->Port()); |
654 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
655 | 0 | args.rval().setInt32(int32_t(result)); |
656 | 0 | return true; |
657 | 0 | } |
658 | | |
659 | | static const JSJitInfo port_getterinfo = { |
660 | | { (JSJitGetterOp)get_port }, |
661 | | { prototypes::id::TCPSocket }, |
662 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
663 | | JSJitInfo::Getter, |
664 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
665 | | JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */ |
666 | | true, /* isInfallible. False in setters. */ |
667 | | false, /* isMovable. Not relevant for setters. */ |
668 | | false, /* isEliminatable. Not relevant for setters. */ |
669 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
670 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
671 | | false, /* isTypedMethod. Only relevant for methods. */ |
672 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
673 | | }; |
674 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
675 | | static_assert(0 < 1, "There is no slot for us"); |
676 | | |
677 | | MOZ_CAN_RUN_SCRIPT static bool |
678 | | get_ssl(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args) |
679 | 0 | { |
680 | 0 | AUTO_PROFILER_LABEL_FAST("get TCPSocket.ssl", DOM, cx); |
681 | 0 |
|
682 | 0 | bool result(self->Ssl()); |
683 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
684 | 0 | args.rval().setBoolean(result); |
685 | 0 | return true; |
686 | 0 | } |
687 | | |
688 | | static const JSJitInfo ssl_getterinfo = { |
689 | | { (JSJitGetterOp)get_ssl }, |
690 | | { prototypes::id::TCPSocket }, |
691 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
692 | | JSJitInfo::Getter, |
693 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
694 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
695 | | true, /* isInfallible. False in setters. */ |
696 | | false, /* isMovable. Not relevant for setters. */ |
697 | | false, /* isEliminatable. Not relevant for setters. */ |
698 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
699 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
700 | | false, /* isTypedMethod. Only relevant for methods. */ |
701 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
702 | | }; |
703 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
704 | | static_assert(0 < 1, "There is no slot for us"); |
705 | | |
706 | | MOZ_CAN_RUN_SCRIPT static bool |
707 | | get_bufferedAmount(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args) |
708 | 0 | { |
709 | 0 | AUTO_PROFILER_LABEL_FAST("get TCPSocket.bufferedAmount", DOM, cx); |
710 | 0 |
|
711 | 0 | uint64_t result(self->BufferedAmount()); |
712 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
713 | 0 | args.rval().set(JS_NumberValue(double(result))); |
714 | 0 | return true; |
715 | 0 | } |
716 | | |
717 | | static const JSJitInfo bufferedAmount_getterinfo = { |
718 | | { (JSJitGetterOp)get_bufferedAmount }, |
719 | | { prototypes::id::TCPSocket }, |
720 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
721 | | JSJitInfo::Getter, |
722 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
723 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
724 | | true, /* isInfallible. False in setters. */ |
725 | | false, /* isMovable. Not relevant for setters. */ |
726 | | false, /* isEliminatable. Not relevant for setters. */ |
727 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
728 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
729 | | false, /* isTypedMethod. Only relevant for methods. */ |
730 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
731 | | }; |
732 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
733 | | static_assert(0 < 1, "There is no slot for us"); |
734 | | |
735 | | MOZ_CAN_RUN_SCRIPT static bool |
736 | | suspend(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, const JSJitMethodCallArgs& args) |
737 | 0 | { |
738 | 0 | AUTO_PROFILER_LABEL_FAST("TCPSocket.suspend", DOM, cx); |
739 | 0 |
|
740 | 0 | self->Suspend(); |
741 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
742 | 0 | args.rval().setUndefined(); |
743 | 0 | return true; |
744 | 0 | } |
745 | | |
746 | | static const JSJitInfo suspend_methodinfo = { |
747 | | { (JSJitGetterOp)suspend }, |
748 | | { prototypes::id::TCPSocket }, |
749 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
750 | | JSJitInfo::Method, |
751 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
752 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
753 | | true, /* isInfallible. False in setters. */ |
754 | | false, /* isMovable. Not relevant for setters. */ |
755 | | false, /* isEliminatable. Not relevant for setters. */ |
756 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
757 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
758 | | false, /* isTypedMethod. Only relevant for methods. */ |
759 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
760 | | }; |
761 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
762 | | static_assert(0 < 1, "There is no slot for us"); |
763 | | |
764 | | MOZ_CAN_RUN_SCRIPT static bool |
765 | | resume(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, const JSJitMethodCallArgs& args) |
766 | 0 | { |
767 | 0 | AUTO_PROFILER_LABEL_FAST("TCPSocket.resume", DOM, cx); |
768 | 0 |
|
769 | 0 | FastErrorResult rv; |
770 | 0 | self->Resume(rv); |
771 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
772 | 0 | return false; |
773 | 0 | } |
774 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
775 | 0 | args.rval().setUndefined(); |
776 | 0 | return true; |
777 | 0 | } |
778 | | |
779 | | static const JSJitInfo resume_methodinfo = { |
780 | | { (JSJitGetterOp)resume }, |
781 | | { prototypes::id::TCPSocket }, |
782 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
783 | | JSJitInfo::Method, |
784 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
785 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
786 | | false, /* isInfallible. False in setters. */ |
787 | | false, /* isMovable. Not relevant for setters. */ |
788 | | false, /* isEliminatable. Not relevant for setters. */ |
789 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
790 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
791 | | false, /* isTypedMethod. Only relevant for methods. */ |
792 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
793 | | }; |
794 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
795 | | static_assert(0 < 1, "There is no slot for us"); |
796 | | |
797 | | MOZ_CAN_RUN_SCRIPT static bool |
798 | | close(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, const JSJitMethodCallArgs& args) |
799 | 0 | { |
800 | 0 | AUTO_PROFILER_LABEL_FAST("TCPSocket.close", DOM, cx); |
801 | 0 |
|
802 | 0 | self->Close(); |
803 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
804 | 0 | args.rval().setUndefined(); |
805 | 0 | return true; |
806 | 0 | } |
807 | | |
808 | | static const JSJitInfo close_methodinfo = { |
809 | | { (JSJitGetterOp)close }, |
810 | | { prototypes::id::TCPSocket }, |
811 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
812 | | JSJitInfo::Method, |
813 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
814 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
815 | | true, /* isInfallible. False in setters. */ |
816 | | false, /* isMovable. Not relevant for setters. */ |
817 | | false, /* isEliminatable. Not relevant for setters. */ |
818 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
819 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
820 | | false, /* isTypedMethod. Only relevant for methods. */ |
821 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
822 | | }; |
823 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
824 | | static_assert(0 < 1, "There is no slot for us"); |
825 | | |
826 | | MOZ_CAN_RUN_SCRIPT static bool |
827 | | closeImmediately(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, const JSJitMethodCallArgs& args) |
828 | 0 | { |
829 | 0 | AUTO_PROFILER_LABEL_FAST("TCPSocket.closeImmediately", DOM, cx); |
830 | 0 |
|
831 | 0 | self->CloseImmediately(); |
832 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
833 | 0 | args.rval().setUndefined(); |
834 | 0 | return true; |
835 | 0 | } |
836 | | |
837 | | static const JSJitInfo closeImmediately_methodinfo = { |
838 | | { (JSJitGetterOp)closeImmediately }, |
839 | | { prototypes::id::TCPSocket }, |
840 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
841 | | JSJitInfo::Method, |
842 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
843 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
844 | | true, /* isInfallible. False in setters. */ |
845 | | false, /* isMovable. Not relevant for setters. */ |
846 | | false, /* isEliminatable. Not relevant for setters. */ |
847 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
848 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
849 | | false, /* isTypedMethod. Only relevant for methods. */ |
850 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
851 | | }; |
852 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
853 | | static_assert(0 < 1, "There is no slot for us"); |
854 | | |
855 | | MOZ_CAN_RUN_SCRIPT static bool |
856 | | send(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, const JSJitMethodCallArgs& args) |
857 | 0 | { |
858 | 0 | AUTO_PROFILER_LABEL_FAST("TCPSocket.send", DOM, cx); |
859 | 0 |
|
860 | 0 | unsigned argcount = std::min(args.length(), 3u); |
861 | 0 | switch (argcount) { |
862 | 0 | case 1: { |
863 | 0 | if (args[0].isObject()) { |
864 | 0 | do { |
865 | 0 | RootedSpiderMonkeyInterface<ArrayBuffer> arg0(cx); |
866 | 0 | if (!arg0.Init(&args[0].toObject())) { |
867 | 0 | break; |
868 | 0 | } |
869 | 0 | uint32_t arg1; |
870 | 0 | if (args.hasDefined(1)) { |
871 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) { |
872 | 0 | return false; |
873 | 0 | } |
874 | 0 | } else { |
875 | 0 | arg1 = 0U; |
876 | 0 | } |
877 | 0 | Optional<uint32_t> arg2; |
878 | 0 | if (args.hasDefined(2)) { |
879 | 0 | arg2.Construct(); |
880 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[2], &arg2.Value())) { |
881 | 0 | return false; |
882 | 0 | } |
883 | 0 | } |
884 | 0 | FastErrorResult rv; |
885 | 0 | bool result(self->Send(cx, Constify(arg0), arg1, Constify(arg2), rv)); |
886 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
887 | 0 | return false; |
888 | 0 | } |
889 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
890 | 0 | args.rval().setBoolean(result); |
891 | 0 | return true; |
892 | 0 | } while (false); |
893 | 0 | } |
894 | 0 | nsCString arg0; |
895 | 0 | if (!ConvertJSValueToByteString(cx, args[0], false, arg0)) { |
896 | 0 | return false; |
897 | 0 | } |
898 | 0 | FastErrorResult rv; |
899 | 0 | bool result(self->Send(cx, Constify(arg0), rv)); |
900 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
901 | 0 | return false; |
902 | 0 | } |
903 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
904 | 0 | args.rval().setBoolean(result); |
905 | 0 | return true; |
906 | 0 | break; |
907 | 0 | } |
908 | 0 | case 2: { |
909 | 0 | MOZ_FALLTHROUGH; |
910 | 0 | } |
911 | 0 | case 3: { |
912 | 0 | RootedSpiderMonkeyInterface<ArrayBuffer> arg0(cx); |
913 | 0 | if (args[0].isObject()) { |
914 | 0 | if (!arg0.Init(&args[0].toObject())) { |
915 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of TCPSocket.send", "ArrayBuffer"); |
916 | 0 | return false; |
917 | 0 | } |
918 | 0 | } else { |
919 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of TCPSocket.send"); |
920 | 0 | return false; |
921 | 0 | } |
922 | 0 | uint32_t arg1; |
923 | 0 | if (args.hasDefined(1)) { |
924 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) { |
925 | 0 | return false; |
926 | 0 | } |
927 | 0 | } else { |
928 | 0 | arg1 = 0U; |
929 | 0 | } |
930 | 0 | Optional<uint32_t> arg2; |
931 | 0 | if (args.hasDefined(2)) { |
932 | 0 | arg2.Construct(); |
933 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[2], &arg2.Value())) { |
934 | 0 | return false; |
935 | 0 | } |
936 | 0 | } |
937 | 0 | FastErrorResult rv; |
938 | 0 | bool result(self->Send(cx, Constify(arg0), arg1, Constify(arg2), rv)); |
939 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
940 | 0 | return false; |
941 | 0 | } |
942 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
943 | 0 | args.rval().setBoolean(result); |
944 | 0 | return true; |
945 | 0 | break; |
946 | 0 | } |
947 | 0 | default: { |
948 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "TCPSocket.send"); |
949 | 0 | break; |
950 | 0 | } |
951 | 0 | } |
952 | 0 | MOZ_CRASH("We have an always-returning default case"); |
953 | 0 | return false; |
954 | 0 | } |
955 | | |
956 | | static const JSJitInfo send_methodinfo = { |
957 | | { (JSJitGetterOp)send }, |
958 | | { prototypes::id::TCPSocket }, |
959 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
960 | | JSJitInfo::Method, |
961 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
962 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
963 | | false, /* isInfallible. False in setters. */ |
964 | | false, /* isMovable. Not relevant for setters. */ |
965 | | false, /* isEliminatable. Not relevant for setters. */ |
966 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
967 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
968 | | false, /* isTypedMethod. Only relevant for methods. */ |
969 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
970 | | }; |
971 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
972 | | static_assert(0 < 1, "There is no slot for us"); |
973 | | |
974 | | MOZ_CAN_RUN_SCRIPT static bool |
975 | | get_readyState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args) |
976 | 0 | { |
977 | 0 | AUTO_PROFILER_LABEL_FAST("get TCPSocket.readyState", DOM, cx); |
978 | 0 |
|
979 | 0 | TCPReadyState result(self->ReadyState()); |
980 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
981 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
982 | 0 | return false; |
983 | 0 | } |
984 | 0 | return true; |
985 | 0 | } |
986 | | |
987 | | static const JSJitInfo readyState_getterinfo = { |
988 | | { (JSJitGetterOp)get_readyState }, |
989 | | { prototypes::id::TCPSocket }, |
990 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
991 | | JSJitInfo::Getter, |
992 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
993 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
994 | | false, /* isInfallible. False in setters. */ |
995 | | false, /* isMovable. Not relevant for setters. */ |
996 | | false, /* isEliminatable. Not relevant for setters. */ |
997 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
998 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
999 | | false, /* isTypedMethod. Only relevant for methods. */ |
1000 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1001 | | }; |
1002 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1003 | | static_assert(0 < 1, "There is no slot for us"); |
1004 | | |
1005 | | MOZ_CAN_RUN_SCRIPT static bool |
1006 | | get_binaryType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args) |
1007 | 0 | { |
1008 | 0 | AUTO_PROFILER_LABEL_FAST("get TCPSocket.binaryType", DOM, cx); |
1009 | 0 |
|
1010 | 0 | TCPSocketBinaryType result(self->BinaryType()); |
1011 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1012 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
1013 | 0 | return false; |
1014 | 0 | } |
1015 | 0 | return true; |
1016 | 0 | } |
1017 | | |
1018 | | static const JSJitInfo binaryType_getterinfo = { |
1019 | | { (JSJitGetterOp)get_binaryType }, |
1020 | | { prototypes::id::TCPSocket }, |
1021 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
1022 | | JSJitInfo::Getter, |
1023 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1024 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
1025 | | false, /* isInfallible. False in setters. */ |
1026 | | false, /* isMovable. Not relevant for setters. */ |
1027 | | false, /* isEliminatable. Not relevant for setters. */ |
1028 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1029 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1030 | | false, /* isTypedMethod. Only relevant for methods. */ |
1031 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1032 | | }; |
1033 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1034 | | static_assert(0 < 1, "There is no slot for us"); |
1035 | | |
1036 | | MOZ_CAN_RUN_SCRIPT static bool |
1037 | | get_onopen(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args) |
1038 | 0 | { |
1039 | 0 | AUTO_PROFILER_LABEL_FAST("get TCPSocket.onopen", DOM, cx); |
1040 | 0 |
|
1041 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnopen()); |
1042 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1043 | 0 | if (result) { |
1044 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
1045 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
1046 | 0 | return false; |
1047 | 0 | } |
1048 | 0 | return true; |
1049 | 0 | } else { |
1050 | 0 | args.rval().setNull(); |
1051 | 0 | return true; |
1052 | 0 | } |
1053 | 0 | } |
1054 | | |
1055 | | MOZ_CAN_RUN_SCRIPT static bool |
1056 | | set_onopen(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitSetterCallArgs args) |
1057 | 0 | { |
1058 | 0 | AUTO_PROFILER_LABEL_FAST("set TCPSocket.onopen", DOM, cx); |
1059 | 0 |
|
1060 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
1061 | 0 | if (args[0].isObject()) { |
1062 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
1063 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
1064 | 0 | } |
1065 | 0 | } else { |
1066 | 0 | arg0 = nullptr; |
1067 | 0 | } |
1068 | 0 | self->SetOnopen(Constify(arg0)); |
1069 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1070 | 0 |
|
1071 | 0 | return true; |
1072 | 0 | } |
1073 | | |
1074 | | static const JSJitInfo onopen_getterinfo = { |
1075 | | { (JSJitGetterOp)get_onopen }, |
1076 | | { prototypes::id::TCPSocket }, |
1077 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
1078 | | JSJitInfo::Getter, |
1079 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1080 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
1081 | | false, /* isInfallible. False in setters. */ |
1082 | | false, /* isMovable. Not relevant for setters. */ |
1083 | | false, /* isEliminatable. Not relevant for setters. */ |
1084 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1085 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1086 | | false, /* isTypedMethod. Only relevant for methods. */ |
1087 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1088 | | }; |
1089 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1090 | | static_assert(0 < 1, "There is no slot for us"); |
1091 | | static const JSJitInfo onopen_setterinfo = { |
1092 | | { (JSJitGetterOp)set_onopen }, |
1093 | | { prototypes::id::TCPSocket }, |
1094 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
1095 | | JSJitInfo::Setter, |
1096 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1097 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
1098 | | false, /* isInfallible. False in setters. */ |
1099 | | false, /* isMovable. Not relevant for setters. */ |
1100 | | false, /* isEliminatable. Not relevant for setters. */ |
1101 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1102 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1103 | | false, /* isTypedMethod. Only relevant for methods. */ |
1104 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1105 | | }; |
1106 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1107 | | static_assert(0 < 1, "There is no slot for us"); |
1108 | | |
1109 | | MOZ_CAN_RUN_SCRIPT static bool |
1110 | | get_ondrain(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args) |
1111 | 0 | { |
1112 | 0 | AUTO_PROFILER_LABEL_FAST("get TCPSocket.ondrain", DOM, cx); |
1113 | 0 |
|
1114 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOndrain()); |
1115 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1116 | 0 | if (result) { |
1117 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
1118 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
1119 | 0 | return false; |
1120 | 0 | } |
1121 | 0 | return true; |
1122 | 0 | } else { |
1123 | 0 | args.rval().setNull(); |
1124 | 0 | return true; |
1125 | 0 | } |
1126 | 0 | } |
1127 | | |
1128 | | MOZ_CAN_RUN_SCRIPT static bool |
1129 | | set_ondrain(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitSetterCallArgs args) |
1130 | 0 | { |
1131 | 0 | AUTO_PROFILER_LABEL_FAST("set TCPSocket.ondrain", DOM, cx); |
1132 | 0 |
|
1133 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
1134 | 0 | if (args[0].isObject()) { |
1135 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
1136 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
1137 | 0 | } |
1138 | 0 | } else { |
1139 | 0 | arg0 = nullptr; |
1140 | 0 | } |
1141 | 0 | self->SetOndrain(Constify(arg0)); |
1142 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1143 | 0 |
|
1144 | 0 | return true; |
1145 | 0 | } |
1146 | | |
1147 | | static const JSJitInfo ondrain_getterinfo = { |
1148 | | { (JSJitGetterOp)get_ondrain }, |
1149 | | { prototypes::id::TCPSocket }, |
1150 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
1151 | | JSJitInfo::Getter, |
1152 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1153 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
1154 | | false, /* isInfallible. False in setters. */ |
1155 | | false, /* isMovable. Not relevant for setters. */ |
1156 | | false, /* isEliminatable. Not relevant for setters. */ |
1157 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1158 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1159 | | false, /* isTypedMethod. Only relevant for methods. */ |
1160 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1161 | | }; |
1162 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1163 | | static_assert(0 < 1, "There is no slot for us"); |
1164 | | static const JSJitInfo ondrain_setterinfo = { |
1165 | | { (JSJitGetterOp)set_ondrain }, |
1166 | | { prototypes::id::TCPSocket }, |
1167 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
1168 | | JSJitInfo::Setter, |
1169 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1170 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
1171 | | false, /* isInfallible. False in setters. */ |
1172 | | false, /* isMovable. Not relevant for setters. */ |
1173 | | false, /* isEliminatable. Not relevant for setters. */ |
1174 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1175 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1176 | | false, /* isTypedMethod. Only relevant for methods. */ |
1177 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1178 | | }; |
1179 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1180 | | static_assert(0 < 1, "There is no slot for us"); |
1181 | | |
1182 | | MOZ_CAN_RUN_SCRIPT static bool |
1183 | | get_ondata(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args) |
1184 | 0 | { |
1185 | 0 | AUTO_PROFILER_LABEL_FAST("get TCPSocket.ondata", DOM, cx); |
1186 | 0 |
|
1187 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOndata()); |
1188 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1189 | 0 | if (result) { |
1190 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
1191 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
1192 | 0 | return false; |
1193 | 0 | } |
1194 | 0 | return true; |
1195 | 0 | } else { |
1196 | 0 | args.rval().setNull(); |
1197 | 0 | return true; |
1198 | 0 | } |
1199 | 0 | } |
1200 | | |
1201 | | MOZ_CAN_RUN_SCRIPT static bool |
1202 | | set_ondata(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitSetterCallArgs args) |
1203 | 0 | { |
1204 | 0 | AUTO_PROFILER_LABEL_FAST("set TCPSocket.ondata", DOM, cx); |
1205 | 0 |
|
1206 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
1207 | 0 | if (args[0].isObject()) { |
1208 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
1209 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
1210 | 0 | } |
1211 | 0 | } else { |
1212 | 0 | arg0 = nullptr; |
1213 | 0 | } |
1214 | 0 | self->SetOndata(Constify(arg0)); |
1215 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1216 | 0 |
|
1217 | 0 | return true; |
1218 | 0 | } |
1219 | | |
1220 | | static const JSJitInfo ondata_getterinfo = { |
1221 | | { (JSJitGetterOp)get_ondata }, |
1222 | | { prototypes::id::TCPSocket }, |
1223 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
1224 | | JSJitInfo::Getter, |
1225 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1226 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
1227 | | false, /* isInfallible. False in setters. */ |
1228 | | false, /* isMovable. Not relevant for setters. */ |
1229 | | false, /* isEliminatable. Not relevant for setters. */ |
1230 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1231 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1232 | | false, /* isTypedMethod. Only relevant for methods. */ |
1233 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1234 | | }; |
1235 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1236 | | static_assert(0 < 1, "There is no slot for us"); |
1237 | | static const JSJitInfo ondata_setterinfo = { |
1238 | | { (JSJitGetterOp)set_ondata }, |
1239 | | { prototypes::id::TCPSocket }, |
1240 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
1241 | | JSJitInfo::Setter, |
1242 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1243 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
1244 | | false, /* isInfallible. False in setters. */ |
1245 | | false, /* isMovable. Not relevant for setters. */ |
1246 | | false, /* isEliminatable. Not relevant for setters. */ |
1247 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1248 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1249 | | false, /* isTypedMethod. Only relevant for methods. */ |
1250 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1251 | | }; |
1252 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1253 | | static_assert(0 < 1, "There is no slot for us"); |
1254 | | |
1255 | | MOZ_CAN_RUN_SCRIPT static bool |
1256 | | get_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args) |
1257 | 0 | { |
1258 | 0 | AUTO_PROFILER_LABEL_FAST("get TCPSocket.onerror", DOM, cx); |
1259 | 0 |
|
1260 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnerror()); |
1261 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1262 | 0 | if (result) { |
1263 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
1264 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
1265 | 0 | return false; |
1266 | 0 | } |
1267 | 0 | return true; |
1268 | 0 | } else { |
1269 | 0 | args.rval().setNull(); |
1270 | 0 | return true; |
1271 | 0 | } |
1272 | 0 | } |
1273 | | |
1274 | | MOZ_CAN_RUN_SCRIPT static bool |
1275 | | set_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitSetterCallArgs args) |
1276 | 0 | { |
1277 | 0 | AUTO_PROFILER_LABEL_FAST("set TCPSocket.onerror", DOM, cx); |
1278 | 0 |
|
1279 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
1280 | 0 | if (args[0].isObject()) { |
1281 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
1282 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
1283 | 0 | } |
1284 | 0 | } else { |
1285 | 0 | arg0 = nullptr; |
1286 | 0 | } |
1287 | 0 | self->SetOnerror(Constify(arg0)); |
1288 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1289 | 0 |
|
1290 | 0 | return true; |
1291 | 0 | } |
1292 | | |
1293 | | static const JSJitInfo onerror_getterinfo = { |
1294 | | { (JSJitGetterOp)get_onerror }, |
1295 | | { prototypes::id::TCPSocket }, |
1296 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
1297 | | JSJitInfo::Getter, |
1298 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1299 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
1300 | | false, /* isInfallible. False in setters. */ |
1301 | | false, /* isMovable. Not relevant for setters. */ |
1302 | | false, /* isEliminatable. Not relevant for setters. */ |
1303 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1304 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1305 | | false, /* isTypedMethod. Only relevant for methods. */ |
1306 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1307 | | }; |
1308 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1309 | | static_assert(0 < 1, "There is no slot for us"); |
1310 | | static const JSJitInfo onerror_setterinfo = { |
1311 | | { (JSJitGetterOp)set_onerror }, |
1312 | | { prototypes::id::TCPSocket }, |
1313 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
1314 | | JSJitInfo::Setter, |
1315 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1316 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
1317 | | false, /* isInfallible. False in setters. */ |
1318 | | false, /* isMovable. Not relevant for setters. */ |
1319 | | false, /* isEliminatable. Not relevant for setters. */ |
1320 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1321 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1322 | | false, /* isTypedMethod. Only relevant for methods. */ |
1323 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1324 | | }; |
1325 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1326 | | static_assert(0 < 1, "There is no slot for us"); |
1327 | | |
1328 | | MOZ_CAN_RUN_SCRIPT static bool |
1329 | | get_onclose(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitGetterCallArgs args) |
1330 | 0 | { |
1331 | 0 | AUTO_PROFILER_LABEL_FAST("get TCPSocket.onclose", DOM, cx); |
1332 | 0 |
|
1333 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnclose()); |
1334 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1335 | 0 | if (result) { |
1336 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
1337 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
1338 | 0 | return false; |
1339 | 0 | } |
1340 | 0 | return true; |
1341 | 0 | } else { |
1342 | 0 | args.rval().setNull(); |
1343 | 0 | return true; |
1344 | 0 | } |
1345 | 0 | } |
1346 | | |
1347 | | MOZ_CAN_RUN_SCRIPT static bool |
1348 | | set_onclose(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TCPSocket* self, JSJitSetterCallArgs args) |
1349 | 0 | { |
1350 | 0 | AUTO_PROFILER_LABEL_FAST("set TCPSocket.onclose", DOM, cx); |
1351 | 0 |
|
1352 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
1353 | 0 | if (args[0].isObject()) { |
1354 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
1355 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
1356 | 0 | } |
1357 | 0 | } else { |
1358 | 0 | arg0 = nullptr; |
1359 | 0 | } |
1360 | 0 | self->SetOnclose(Constify(arg0)); |
1361 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1362 | 0 |
|
1363 | 0 | return true; |
1364 | 0 | } |
1365 | | |
1366 | | static const JSJitInfo onclose_getterinfo = { |
1367 | | { (JSJitGetterOp)get_onclose }, |
1368 | | { prototypes::id::TCPSocket }, |
1369 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
1370 | | JSJitInfo::Getter, |
1371 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1372 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
1373 | | false, /* isInfallible. False in setters. */ |
1374 | | false, /* isMovable. Not relevant for setters. */ |
1375 | | false, /* isEliminatable. Not relevant for setters. */ |
1376 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1377 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1378 | | false, /* isTypedMethod. Only relevant for methods. */ |
1379 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1380 | | }; |
1381 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1382 | | static_assert(0 < 1, "There is no slot for us"); |
1383 | | static const JSJitInfo onclose_setterinfo = { |
1384 | | { (JSJitGetterOp)set_onclose }, |
1385 | | { prototypes::id::TCPSocket }, |
1386 | | { PrototypeTraits<prototypes::id::TCPSocket>::Depth }, |
1387 | | JSJitInfo::Setter, |
1388 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1389 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
1390 | | false, /* isInfallible. False in setters. */ |
1391 | | false, /* isMovable. Not relevant for setters. */ |
1392 | | false, /* isEliminatable. Not relevant for setters. */ |
1393 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1394 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1395 | | false, /* isTypedMethod. Only relevant for methods. */ |
1396 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1397 | | }; |
1398 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1399 | | static_assert(0 < 1, "There is no slot for us"); |
1400 | | |
1401 | | static bool |
1402 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
1403 | 0 | { |
1404 | 0 | mozilla::dom::TCPSocket* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TCPSocket>(obj); |
1405 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
1406 | 0 | // obviously can't preserve if we're not initialized. |
1407 | 0 | if (self && self->GetWrapperPreserveColor()) { |
1408 | 0 | PreserveWrapper(self); |
1409 | 0 | } |
1410 | 0 | return true; |
1411 | 0 | } |
1412 | | |
1413 | | static void |
1414 | | _finalize(js::FreeOp* fop, JSObject* obj) |
1415 | 0 | { |
1416 | 0 | mozilla::dom::TCPSocket* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TCPSocket>(obj); |
1417 | 0 | if (self) { |
1418 | 0 | ClearWrapper(self, self, obj); |
1419 | 0 | AddForDeferredFinalization<mozilla::dom::TCPSocket>(self); |
1420 | 0 | } |
1421 | 0 | } |
1422 | | |
1423 | | static size_t |
1424 | | _objectMoved(JSObject* obj, JSObject* old) |
1425 | 0 | { |
1426 | 0 | mozilla::dom::TCPSocket* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TCPSocket>(obj); |
1427 | 0 | if (self) { |
1428 | 0 | UpdateWrapper(self, self, obj, old); |
1429 | 0 | } |
1430 | 0 |
|
1431 | 0 | return 0; |
1432 | 0 | } |
1433 | | |
1434 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
1435 | | #if defined(__clang__) |
1436 | | #pragma clang diagnostic push |
1437 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
1438 | | #endif |
1439 | | static const JSFunctionSpec sMethods_specs[] = { |
1440 | | JS_FNSPEC("upgradeToSecure", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&upgradeToSecure_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
1441 | | JS_FNSPEC("suspend", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&suspend_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
1442 | | JS_FNSPEC("resume", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&resume_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
1443 | | JS_FNSPEC("close", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&close_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
1444 | | JS_FNSPEC("send", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&send_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
1445 | | JS_FS_END |
1446 | | }; |
1447 | | #if defined(__clang__) |
1448 | | #pragma clang diagnostic pop |
1449 | | #endif |
1450 | | |
1451 | | |
1452 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
1453 | | { nullptr, &sMethods_specs[0] }, |
1454 | | { nullptr, nullptr } |
1455 | | }; |
1456 | | |
1457 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1458 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1459 | | static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1460 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1461 | | |
1462 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
1463 | | #if defined(__clang__) |
1464 | | #pragma clang diagnostic push |
1465 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
1466 | | #endif |
1467 | | static const JSFunctionSpec sChromeMethods_specs[] = { |
1468 | | JS_FNSPEC("closeImmediately", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&closeImmediately_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
1469 | | JS_FS_END |
1470 | | }; |
1471 | | #if defined(__clang__) |
1472 | | #pragma clang diagnostic pop |
1473 | | #endif |
1474 | | |
1475 | | |
1476 | | static const Prefable<const JSFunctionSpec> sChromeMethods[] = { |
1477 | | { nullptr, &sChromeMethods_specs[0] }, |
1478 | | { nullptr, nullptr } |
1479 | | }; |
1480 | | |
1481 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1482 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1483 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1484 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1485 | | |
1486 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
1487 | | #if defined(__clang__) |
1488 | | #pragma clang diagnostic push |
1489 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
1490 | | #endif |
1491 | | static const JSPropertySpec sAttributes_specs[] = { |
1492 | | { "host", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &host_getterinfo, nullptr, nullptr }, |
1493 | | { "port", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &port_getterinfo, nullptr, nullptr }, |
1494 | | { "ssl", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &ssl_getterinfo, nullptr, nullptr }, |
1495 | | { "bufferedAmount", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &bufferedAmount_getterinfo, nullptr, nullptr }, |
1496 | | { "readyState", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &readyState_getterinfo, nullptr, nullptr }, |
1497 | | { "binaryType", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &binaryType_getterinfo, nullptr, nullptr }, |
1498 | | { "onopen", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onopen_getterinfo, GenericSetter<NormalThisPolicy>, &onopen_setterinfo }, |
1499 | | { "ondrain", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &ondrain_getterinfo, GenericSetter<NormalThisPolicy>, &ondrain_setterinfo }, |
1500 | | { "ondata", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &ondata_getterinfo, GenericSetter<NormalThisPolicy>, &ondata_setterinfo }, |
1501 | | { "onerror", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onerror_getterinfo, GenericSetter<NormalThisPolicy>, &onerror_setterinfo }, |
1502 | | { "onclose", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onclose_getterinfo, GenericSetter<NormalThisPolicy>, &onclose_setterinfo }, |
1503 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
1504 | | }; |
1505 | | #if defined(__clang__) |
1506 | | #pragma clang diagnostic pop |
1507 | | #endif |
1508 | | |
1509 | | |
1510 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
1511 | | { nullptr, &sAttributes_specs[0] }, |
1512 | | { nullptr, nullptr } |
1513 | | }; |
1514 | | |
1515 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1516 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1517 | | static_assert(11 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1518 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1519 | | |
1520 | | |
1521 | | static uint16_t sNativeProperties_sortedPropertyIndices[16]; |
1522 | | static PropertyInfo sNativeProperties_propertyInfos[16]; |
1523 | | |
1524 | | static const NativePropertiesN<2> sNativeProperties = { |
1525 | | false, 0, |
1526 | | false, 0, |
1527 | | true, 0 /* sMethods */, |
1528 | | true, 1 /* sAttributes */, |
1529 | | false, 0, |
1530 | | false, 0, |
1531 | | false, 0, |
1532 | | -1, |
1533 | | 16, |
1534 | | sNativeProperties_sortedPropertyIndices, |
1535 | | { |
1536 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
1537 | | { sAttributes, &sNativeProperties_propertyInfos[5] } |
1538 | | } |
1539 | | }; |
1540 | | static_assert(16 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
1541 | | "We have a property info count that is oversized"); |
1542 | | |
1543 | | static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1]; |
1544 | | static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1]; |
1545 | | |
1546 | | static const NativePropertiesN<1> sChromeOnlyNativeProperties = { |
1547 | | false, 0, |
1548 | | false, 0, |
1549 | | true, 0 /* sChromeMethods */, |
1550 | | false, 0, |
1551 | | false, 0, |
1552 | | false, 0, |
1553 | | false, 0, |
1554 | | -1, |
1555 | | 1, |
1556 | | sChromeOnlyNativeProperties_sortedPropertyIndices, |
1557 | | { |
1558 | | { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[0] } |
1559 | | } |
1560 | | }; |
1561 | | static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount), |
1562 | | "We have a property info count that is oversized"); |
1563 | | |
1564 | | static bool |
1565 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
1566 | 0 | { |
1567 | 0 | AUTO_PROFILER_LABEL_FAST("TCPSocket constructor", DOM, cx); |
1568 | 0 |
|
1569 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
1570 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
1571 | 0 | if (!args.isConstructing()) { |
1572 | 0 | // XXXbz wish I could get the name from the callee instead of |
1573 | 0 | // Adding more relocations |
1574 | 0 | return ThrowConstructorWithoutNew(cx, "TCPSocket"); |
1575 | 0 | } |
1576 | 0 | |
1577 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
1578 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
1579 | 0 | return false; |
1580 | 0 | } |
1581 | 0 | |
1582 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
1583 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "TCPSocket"); |
1584 | 0 | } |
1585 | 0 | GlobalObject global(cx, obj); |
1586 | 0 | if (global.Failed()) { |
1587 | 0 | return false; |
1588 | 0 | } |
1589 | 0 | |
1590 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
1591 | 0 | binding_detail::FakeString arg0; |
1592 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
1593 | 0 | return false; |
1594 | 0 | } |
1595 | 0 | uint16_t arg1; |
1596 | 0 | if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[1], &arg1)) { |
1597 | 0 | return false; |
1598 | 0 | } |
1599 | 0 | binding_detail::FastSocketOptions arg2; |
1600 | 0 | if (!arg2.Init(cx, (args.hasDefined(2)) ? args[2] : JS::NullHandleValue, "Argument 3 of TCPSocket.constructor", false)) { |
1601 | 0 | return false; |
1602 | 0 | } |
1603 | 0 | Maybe<JSAutoRealm> ar; |
1604 | 0 | if (objIsXray) { |
1605 | 0 | obj = js::CheckedUnwrap(obj); |
1606 | 0 | if (!obj) { |
1607 | 0 | return false; |
1608 | 0 | } |
1609 | 0 | ar.emplace(cx, obj); |
1610 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
1611 | 0 | return false; |
1612 | 0 | } |
1613 | 0 | } |
1614 | 0 | FastErrorResult rv; |
1615 | 0 | auto result(StrongOrRawPtr<mozilla::dom::TCPSocket>(mozilla::dom::TCPSocket::Constructor(global, NonNullHelper(Constify(arg0)), arg1, Constify(arg2), rv))); |
1616 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
1617 | 0 | return false; |
1618 | 0 | } |
1619 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1620 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
1621 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
1622 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
1623 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
1624 | 0 | return false; |
1625 | 0 | } |
1626 | 0 | return true; |
1627 | 0 | } |
1628 | | |
1629 | | static const js::ClassOps sInterfaceObjectClassOps = { |
1630 | | nullptr, /* addProperty */ |
1631 | | nullptr, /* delProperty */ |
1632 | | nullptr, /* enumerate */ |
1633 | | nullptr, /* newEnumerate */ |
1634 | | nullptr, /* resolve */ |
1635 | | nullptr, /* mayResolve */ |
1636 | | nullptr, /* finalize */ |
1637 | | _constructor, /* call */ |
1638 | | nullptr, /* hasInstance */ |
1639 | | _constructor, /* construct */ |
1640 | | nullptr, /* trace */ |
1641 | | }; |
1642 | | |
1643 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
1644 | | { |
1645 | | "Function", |
1646 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
1647 | | &sInterfaceObjectClassOps, |
1648 | | JS_NULL_CLASS_SPEC, |
1649 | | JS_NULL_CLASS_EXT, |
1650 | | &sInterfaceObjectClassObjectOps |
1651 | | }, |
1652 | | eInterface, |
1653 | | true, |
1654 | | prototypes::id::TCPSocket, |
1655 | | PrototypeTraits<prototypes::id::TCPSocket>::Depth, |
1656 | | sNativePropertyHooks, |
1657 | | "function TCPSocket() {\n [native code]\n}", |
1658 | | EventTarget_Binding::GetConstructorObject |
1659 | | }; |
1660 | | |
1661 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
1662 | | { |
1663 | | "TCPSocketPrototype", |
1664 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
1665 | | JS_NULL_CLASS_OPS, |
1666 | | JS_NULL_CLASS_SPEC, |
1667 | | JS_NULL_CLASS_EXT, |
1668 | | JS_NULL_OBJECT_OPS |
1669 | | }, |
1670 | | eInterfacePrototype, |
1671 | | false, |
1672 | | prototypes::id::TCPSocket, |
1673 | | PrototypeTraits<prototypes::id::TCPSocket>::Depth, |
1674 | | sNativePropertyHooks, |
1675 | | "[object TCPSocketPrototype]", |
1676 | | EventTarget_Binding::GetProtoObject |
1677 | | }; |
1678 | | |
1679 | | bool |
1680 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
1681 | 0 | { |
1682 | 0 | return mozilla::dom::TCPSocket::ShouldTCPSocketExist(aCx, aObj); |
1683 | 0 | } |
1684 | | |
1685 | | static const js::ClassOps sClassOps = { |
1686 | | _addProperty, /* addProperty */ |
1687 | | nullptr, /* delProperty */ |
1688 | | nullptr, /* enumerate */ |
1689 | | nullptr, /* newEnumerate */ |
1690 | | nullptr, /* resolve */ |
1691 | | nullptr, /* mayResolve */ |
1692 | | _finalize, /* finalize */ |
1693 | | nullptr, /* call */ |
1694 | | nullptr, /* hasInstance */ |
1695 | | nullptr, /* construct */ |
1696 | | nullptr, /* trace */ |
1697 | | }; |
1698 | | |
1699 | | static const js::ClassExtension sClassExtension = { |
1700 | | nullptr, /* weakmapKeyDelegateOp */ |
1701 | | _objectMoved /* objectMovedOp */ |
1702 | | }; |
1703 | | |
1704 | | static const DOMJSClass sClass = { |
1705 | | { "TCPSocket", |
1706 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
1707 | | &sClassOps, |
1708 | | JS_NULL_CLASS_SPEC, |
1709 | | &sClassExtension, |
1710 | | JS_NULL_OBJECT_OPS |
1711 | | }, |
1712 | | { prototypes::id::EventTarget, prototypes::id::TCPSocket, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
1713 | | IsBaseOf<nsISupports, mozilla::dom::TCPSocket >::value, |
1714 | | sNativePropertyHooks, |
1715 | | FindAssociatedGlobalForNative<mozilla::dom::TCPSocket>::Get, |
1716 | | GetProtoObjectHandle, |
1717 | | GetCCParticipant<mozilla::dom::TCPSocket>::Get() |
1718 | | }; |
1719 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
1720 | | "Must have the right minimal number of reserved slots."); |
1721 | | static_assert(1 >= 1, |
1722 | | "Must have enough reserved slots."); |
1723 | | |
1724 | | const JSClass* |
1725 | | GetJSClass() |
1726 | 0 | { |
1727 | 0 | return sClass.ToJSClass(); |
1728 | 0 | } |
1729 | | |
1730 | | bool |
1731 | | Wrap(JSContext* aCx, mozilla::dom::TCPSocket* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
1732 | 0 | { |
1733 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::TCPSocket>::value, |
1734 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
1735 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::TCPSocket*>(aObject) == |
1736 | 0 | reinterpret_cast<mozilla::dom::TCPSocket*>(aObject), |
1737 | 0 | "Multiple inheritance for mozilla::dom::TCPSocket is broken."); |
1738 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
1739 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
1740 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
1741 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
1742 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
1743 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
1744 | 0 | "You should probably not be using Wrap() directly; use " |
1745 | 0 | "GetOrCreateDOMReflector instead"); |
1746 | 0 |
|
1747 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
1748 | 0 | "nsISupports must be on our primary inheritance chain"); |
1749 | 0 |
|
1750 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
1751 | 0 | if (!global) { |
1752 | 0 | return false; |
1753 | 0 | } |
1754 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
1755 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
1756 | 0 |
|
1757 | 0 | // That might have ended up wrapping us already, due to the wonders |
1758 | 0 | // of XBL. Check for that, and bail out as needed. |
1759 | 0 | aReflector.set(aCache->GetWrapper()); |
1760 | 0 | if (aReflector) { |
1761 | | #ifdef DEBUG |
1762 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
1763 | | #endif // DEBUG |
1764 | | return true; |
1765 | 0 | } |
1766 | 0 |
|
1767 | 0 | JSAutoRealm ar(aCx, global); |
1768 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
1769 | 0 | if (!canonicalProto) { |
1770 | 0 | return false; |
1771 | 0 | } |
1772 | 0 | JS::Rooted<JSObject*> proto(aCx); |
1773 | 0 | if (aGivenProto) { |
1774 | 0 | proto = aGivenProto; |
1775 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
1776 | 0 | // coming in, we changed compartments to that of "parent" so may need |
1777 | 0 | // to wrap the proto here. |
1778 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
1779 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
1780 | 0 | return false; |
1781 | 0 | } |
1782 | 0 | } |
1783 | 0 | } else { |
1784 | 0 | proto = canonicalProto; |
1785 | 0 | } |
1786 | 0 |
|
1787 | 0 | BindingJSObjectCreator<mozilla::dom::TCPSocket> creator(aCx); |
1788 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
1789 | 0 | if (!aReflector) { |
1790 | 0 | return false; |
1791 | 0 | } |
1792 | 0 | |
1793 | 0 | aCache->SetWrapper(aReflector); |
1794 | 0 | creator.InitializationSucceeded(); |
1795 | 0 |
|
1796 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
1797 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
1798 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
1799 | 0 | // otherwise we won't be able to properly recreate it later, since |
1800 | 0 | // we won't know what proto to use. Note that we don't check |
1801 | 0 | // aGivenProto here, since it's entirely possible (and even |
1802 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
1803 | 0 | // same as canonicalProto. |
1804 | 0 | if (proto != canonicalProto) { |
1805 | 0 | PreserveWrapper(aObject); |
1806 | 0 | } |
1807 | 0 |
|
1808 | 0 | return true; |
1809 | 0 | } |
1810 | | |
1811 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
1812 | | nullptr, |
1813 | | nullptr, |
1814 | | nullptr, |
1815 | | { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() }, |
1816 | | prototypes::id::TCPSocket, |
1817 | | constructors::id::TCPSocket, |
1818 | | EventTarget_Binding::sNativePropertyHooks, |
1819 | | &DefaultXrayExpandoObjectClass |
1820 | | } }; |
1821 | | |
1822 | | void |
1823 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
1824 | 0 | { |
1825 | 0 | JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx)); |
1826 | 0 | if (!parentProto) { |
1827 | 0 | return; |
1828 | 0 | } |
1829 | 0 | |
1830 | 0 | JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx)); |
1831 | 0 | if (!constructorProto) { |
1832 | 0 | return; |
1833 | 0 | } |
1834 | 0 | |
1835 | 0 | static bool sIdsInited = false; |
1836 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
1837 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
1838 | 0 | return; |
1839 | 0 | } |
1840 | 0 | if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) { |
1841 | 0 | return; |
1842 | 0 | } |
1843 | 0 | sIdsInited = true; |
1844 | 0 | } |
1845 | 0 |
|
1846 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::TCPSocket); |
1847 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::TCPSocket); |
1848 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
1849 | 0 | &sPrototypeClass.mBase, protoCache, |
1850 | 0 | nullptr, |
1851 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 2, nullptr, |
1852 | 0 | interfaceCache, |
1853 | 0 | sNativeProperties.Upcast(), |
1854 | 0 | sChromeOnlyNativeProperties.Upcast(), |
1855 | 0 | "TCPSocket", aDefineOnGlobal, |
1856 | 0 | nullptr, |
1857 | 0 | false); |
1858 | 0 | } |
1859 | | |
1860 | | JSObject* |
1861 | | GetConstructorObject(JSContext* aCx) |
1862 | 0 | { |
1863 | 0 | return GetConstructorObjectHandle(aCx); |
1864 | 0 | } |
1865 | | |
1866 | | } // namespace TCPSocket_Binding |
1867 | | |
1868 | | |
1869 | | |
1870 | | } // namespace dom |
1871 | | } // namespace mozilla |