/work/obj-fuzz/dom/bindings/EventSourceBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM EventSource.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "EventHandlerBinding.h" |
5 | | #include "EventSourceBinding.h" |
6 | | #include "EventTargetBinding.h" |
7 | | #include "WrapperFactory.h" |
8 | | #include "mozilla/OwningNonNull.h" |
9 | | #include "mozilla/dom/BindingUtils.h" |
10 | | #include "mozilla/dom/DOMJSClass.h" |
11 | | #include "mozilla/dom/EventSource.h" |
12 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
13 | | #include "mozilla/dom/Nullable.h" |
14 | | #include "mozilla/dom/PrimitiveConversions.h" |
15 | | #include "mozilla/dom/ScriptSettings.h" |
16 | | #include "mozilla/dom/SimpleGlobalObject.h" |
17 | | #include "mozilla/dom/XrayExpandoClass.h" |
18 | | #include "nsThreadUtils.h" |
19 | | |
20 | | namespace mozilla { |
21 | | namespace dom { |
22 | | |
23 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
24 | | using namespace mozilla::dom::binding_detail; |
25 | | |
26 | | |
27 | | |
28 | | EventSourceInit::EventSourceInit() |
29 | 0 | { |
30 | 0 | // Safe to pass a null context if we pass a null value |
31 | 0 | Init(nullptr, JS::NullHandleValue); |
32 | 0 | } |
33 | | |
34 | | |
35 | | |
36 | | bool |
37 | | EventSourceInit::InitIds(JSContext* cx, EventSourceInitAtoms* atomsCache) |
38 | 0 | { |
39 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
40 | 0 |
|
41 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
42 | 0 | // uninitialized. |
43 | 0 | if (!atomsCache->withCredentials_id.init(cx, "withCredentials")) { |
44 | 0 | return false; |
45 | 0 | } |
46 | 0 | return true; |
47 | 0 | } |
48 | | |
49 | | bool |
50 | | EventSourceInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
51 | 0 | { |
52 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
53 | 0 | // Since in that case we will not have to do any property gets |
54 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
55 | 0 | // checkers by static analysis tools |
56 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
57 | 0 | EventSourceInitAtoms* atomsCache = nullptr; |
58 | 0 | if (cx) { |
59 | 0 | atomsCache = GetAtomCache<EventSourceInitAtoms>(cx); |
60 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
61 | 0 | return false; |
62 | 0 | } |
63 | 0 | } |
64 | 0 | |
65 | 0 | if (!IsConvertibleToDictionary(val)) { |
66 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
67 | 0 | } |
68 | 0 | |
69 | 0 | bool isNull = val.isNullOrUndefined(); |
70 | 0 | // We only need these if !isNull, in which case we have |cx|. |
71 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
72 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
73 | 0 | if (!isNull) { |
74 | 0 | MOZ_ASSERT(cx); |
75 | 0 | object.emplace(cx, &val.toObject()); |
76 | 0 | temp.emplace(cx); |
77 | 0 | } |
78 | 0 | if (!isNull) { |
79 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->withCredentials_id, temp.ptr())) { |
80 | 0 | return false; |
81 | 0 | } |
82 | 0 | } |
83 | 0 | if (!isNull && !temp->isUndefined()) { |
84 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mWithCredentials)) { |
85 | 0 | return false; |
86 | 0 | } |
87 | 0 | } else { |
88 | 0 | mWithCredentials = false; |
89 | 0 | } |
90 | 0 | mIsAnyMemberPresent = true; |
91 | 0 | return true; |
92 | 0 | } |
93 | | |
94 | | bool |
95 | | EventSourceInit::Init(const nsAString& aJSON) |
96 | 0 | { |
97 | 0 | AutoJSAPI jsapi; |
98 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
99 | 0 | if (!cleanGlobal) { |
100 | 0 | return false; |
101 | 0 | } |
102 | 0 | if (!jsapi.Init(cleanGlobal)) { |
103 | 0 | return false; |
104 | 0 | } |
105 | 0 | JSContext* cx = jsapi.cx(); |
106 | 0 | JS::Rooted<JS::Value> json(cx); |
107 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
108 | 0 | NS_ENSURE_TRUE(ok, false); |
109 | 0 | return Init(cx, json); |
110 | 0 | } |
111 | | |
112 | | bool |
113 | | EventSourceInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
114 | 0 | { |
115 | 0 | EventSourceInitAtoms* atomsCache = GetAtomCache<EventSourceInitAtoms>(cx); |
116 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
117 | 0 | return false; |
118 | 0 | } |
119 | 0 | |
120 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
121 | 0 | if (!obj) { |
122 | 0 | return false; |
123 | 0 | } |
124 | 0 | rval.set(JS::ObjectValue(*obj)); |
125 | 0 |
|
126 | 0 | do { |
127 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
128 | 0 | JS::Rooted<JS::Value> temp(cx); |
129 | 0 | bool const & currentValue = mWithCredentials; |
130 | 0 | temp.setBoolean(currentValue); |
131 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->withCredentials_id, temp, JSPROP_ENUMERATE)) { |
132 | 0 | return false; |
133 | 0 | } |
134 | 0 | break; |
135 | 0 | } while(false); |
136 | 0 |
|
137 | 0 | return true; |
138 | 0 | } |
139 | | |
140 | | bool |
141 | | EventSourceInit::ToJSON(nsAString& aJSON) const |
142 | 0 | { |
143 | 0 | AutoJSAPI jsapi; |
144 | 0 | jsapi.Init(); |
145 | 0 | JSContext *cx = jsapi.cx(); |
146 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
147 | 0 | // because we'll only be creating objects, in ways that have no |
148 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
149 | 0 | // which likewise guarantees no side-effects for the sorts of |
150 | 0 | // things we will pass it. |
151 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
152 | 0 | JS::Rooted<JS::Value> val(cx); |
153 | 0 | if (!ToObjectInternal(cx, &val)) { |
154 | 0 | return false; |
155 | 0 | } |
156 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
157 | 0 | return StringifyToJSON(cx, obj, aJSON); |
158 | 0 | } |
159 | | |
160 | | void |
161 | | EventSourceInit::TraceDictionary(JSTracer* trc) |
162 | 0 | { |
163 | 0 | } |
164 | | |
165 | | EventSourceInit& |
166 | | EventSourceInit::operator=(const EventSourceInit& aOther) |
167 | 0 | { |
168 | 0 | DictionaryBase::operator=(aOther); |
169 | 0 | mWithCredentials = aOther.mWithCredentials; |
170 | 0 | return *this; |
171 | 0 | } |
172 | | |
173 | | namespace binding_detail { |
174 | | } // namespace binding_detail |
175 | | |
176 | | |
177 | | namespace EventSource_Binding { |
178 | | |
179 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value, |
180 | | "Can't inherit from an interface with a different ownership model."); |
181 | | |
182 | | MOZ_CAN_RUN_SCRIPT static bool |
183 | | get_url(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::EventSource* self, JSJitGetterCallArgs args) |
184 | 0 | { |
185 | 0 | AUTO_PROFILER_LABEL_FAST("get EventSource.url", DOM, cx); |
186 | 0 |
|
187 | 0 | DOMString result; |
188 | 0 | self->GetUrl(result); |
189 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
190 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
191 | 0 | return false; |
192 | 0 | } |
193 | 0 | return true; |
194 | 0 | } |
195 | | |
196 | | static const JSJitInfo url_getterinfo = { |
197 | | { (JSJitGetterOp)get_url }, |
198 | | { prototypes::id::EventSource }, |
199 | | { PrototypeTraits<prototypes::id::EventSource>::Depth }, |
200 | | JSJitInfo::Getter, |
201 | | JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */ |
202 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
203 | | false, /* isInfallible. False in setters. */ |
204 | | true, /* isMovable. Not relevant for setters. */ |
205 | | true, /* isEliminatable. Not relevant for setters. */ |
206 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
207 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
208 | | false, /* isTypedMethod. Only relevant for methods. */ |
209 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
210 | | }; |
211 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
212 | | static_assert(0 < 1, "There is no slot for us"); |
213 | | |
214 | | MOZ_CAN_RUN_SCRIPT static bool |
215 | | get_withCredentials(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::EventSource* self, JSJitGetterCallArgs args) |
216 | 0 | { |
217 | 0 | AUTO_PROFILER_LABEL_FAST("get EventSource.withCredentials", DOM, cx); |
218 | 0 |
|
219 | 0 | bool result(self->WithCredentials()); |
220 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
221 | 0 | args.rval().setBoolean(result); |
222 | 0 | return true; |
223 | 0 | } |
224 | | |
225 | | static const JSJitInfo withCredentials_getterinfo = { |
226 | | { (JSJitGetterOp)get_withCredentials }, |
227 | | { prototypes::id::EventSource }, |
228 | | { PrototypeTraits<prototypes::id::EventSource>::Depth }, |
229 | | JSJitInfo::Getter, |
230 | | JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */ |
231 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
232 | | true, /* isInfallible. False in setters. */ |
233 | | true, /* isMovable. Not relevant for setters. */ |
234 | | true, /* isEliminatable. Not relevant for setters. */ |
235 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
236 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
237 | | false, /* isTypedMethod. Only relevant for methods. */ |
238 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
239 | | }; |
240 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
241 | | static_assert(0 < 1, "There is no slot for us"); |
242 | | |
243 | | MOZ_CAN_RUN_SCRIPT static bool |
244 | | get_readyState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::EventSource* self, JSJitGetterCallArgs args) |
245 | 0 | { |
246 | 0 | AUTO_PROFILER_LABEL_FAST("get EventSource.readyState", DOM, cx); |
247 | 0 |
|
248 | 0 | uint16_t result(self->ReadyState()); |
249 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
250 | 0 | args.rval().setInt32(int32_t(result)); |
251 | 0 | return true; |
252 | 0 | } |
253 | | |
254 | | static const JSJitInfo readyState_getterinfo = { |
255 | | { (JSJitGetterOp)get_readyState }, |
256 | | { prototypes::id::EventSource }, |
257 | | { PrototypeTraits<prototypes::id::EventSource>::Depth }, |
258 | | JSJitInfo::Getter, |
259 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
260 | | JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */ |
261 | | true, /* isInfallible. False in setters. */ |
262 | | false, /* isMovable. Not relevant for setters. */ |
263 | | false, /* isEliminatable. Not relevant for setters. */ |
264 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
265 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
266 | | false, /* isTypedMethod. Only relevant for methods. */ |
267 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
268 | | }; |
269 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
270 | | static_assert(0 < 1, "There is no slot for us"); |
271 | | |
272 | | MOZ_CAN_RUN_SCRIPT static bool |
273 | | get_onopen(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::EventSource* self, JSJitGetterCallArgs args) |
274 | 0 | { |
275 | 0 | AUTO_PROFILER_LABEL_FAST("get EventSource.onopen", DOM, cx); |
276 | 0 |
|
277 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnopen()); |
278 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
279 | 0 | if (result) { |
280 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
281 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
282 | 0 | return false; |
283 | 0 | } |
284 | 0 | return true; |
285 | 0 | } else { |
286 | 0 | args.rval().setNull(); |
287 | 0 | return true; |
288 | 0 | } |
289 | 0 | } |
290 | | |
291 | | MOZ_CAN_RUN_SCRIPT static bool |
292 | | set_onopen(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::EventSource* self, JSJitSetterCallArgs args) |
293 | 0 | { |
294 | 0 | AUTO_PROFILER_LABEL_FAST("set EventSource.onopen", DOM, cx); |
295 | 0 |
|
296 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
297 | 0 | if (args[0].isObject()) { |
298 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
299 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
300 | 0 | } |
301 | 0 | } else { |
302 | 0 | arg0 = nullptr; |
303 | 0 | } |
304 | 0 | self->SetOnopen(Constify(arg0)); |
305 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
306 | 0 |
|
307 | 0 | return true; |
308 | 0 | } |
309 | | |
310 | | static const JSJitInfo onopen_getterinfo = { |
311 | | { (JSJitGetterOp)get_onopen }, |
312 | | { prototypes::id::EventSource }, |
313 | | { PrototypeTraits<prototypes::id::EventSource>::Depth }, |
314 | | JSJitInfo::Getter, |
315 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
316 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
317 | | false, /* isInfallible. False in setters. */ |
318 | | false, /* isMovable. Not relevant for setters. */ |
319 | | false, /* isEliminatable. Not relevant for setters. */ |
320 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
321 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
322 | | false, /* isTypedMethod. Only relevant for methods. */ |
323 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
324 | | }; |
325 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
326 | | static_assert(0 < 1, "There is no slot for us"); |
327 | | static const JSJitInfo onopen_setterinfo = { |
328 | | { (JSJitGetterOp)set_onopen }, |
329 | | { prototypes::id::EventSource }, |
330 | | { PrototypeTraits<prototypes::id::EventSource>::Depth }, |
331 | | JSJitInfo::Setter, |
332 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
333 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
334 | | false, /* isInfallible. False in setters. */ |
335 | | false, /* isMovable. Not relevant for setters. */ |
336 | | false, /* isEliminatable. Not relevant for setters. */ |
337 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
338 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
339 | | false, /* isTypedMethod. Only relevant for methods. */ |
340 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
341 | | }; |
342 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
343 | | static_assert(0 < 1, "There is no slot for us"); |
344 | | |
345 | | MOZ_CAN_RUN_SCRIPT static bool |
346 | | get_onmessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::EventSource* self, JSJitGetterCallArgs args) |
347 | 0 | { |
348 | 0 | AUTO_PROFILER_LABEL_FAST("get EventSource.onmessage", DOM, cx); |
349 | 0 |
|
350 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnmessage()); |
351 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
352 | 0 | if (result) { |
353 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
354 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
355 | 0 | return false; |
356 | 0 | } |
357 | 0 | return true; |
358 | 0 | } else { |
359 | 0 | args.rval().setNull(); |
360 | 0 | return true; |
361 | 0 | } |
362 | 0 | } |
363 | | |
364 | | MOZ_CAN_RUN_SCRIPT static bool |
365 | | set_onmessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::EventSource* self, JSJitSetterCallArgs args) |
366 | 0 | { |
367 | 0 | AUTO_PROFILER_LABEL_FAST("set EventSource.onmessage", DOM, cx); |
368 | 0 |
|
369 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
370 | 0 | if (args[0].isObject()) { |
371 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
372 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
373 | 0 | } |
374 | 0 | } else { |
375 | 0 | arg0 = nullptr; |
376 | 0 | } |
377 | 0 | self->SetOnmessage(Constify(arg0)); |
378 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
379 | 0 |
|
380 | 0 | return true; |
381 | 0 | } |
382 | | |
383 | | static const JSJitInfo onmessage_getterinfo = { |
384 | | { (JSJitGetterOp)get_onmessage }, |
385 | | { prototypes::id::EventSource }, |
386 | | { PrototypeTraits<prototypes::id::EventSource>::Depth }, |
387 | | JSJitInfo::Getter, |
388 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
389 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
390 | | false, /* isInfallible. False in setters. */ |
391 | | false, /* isMovable. Not relevant for setters. */ |
392 | | false, /* isEliminatable. Not relevant for setters. */ |
393 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
394 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
395 | | false, /* isTypedMethod. Only relevant for methods. */ |
396 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
397 | | }; |
398 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
399 | | static_assert(0 < 1, "There is no slot for us"); |
400 | | static const JSJitInfo onmessage_setterinfo = { |
401 | | { (JSJitGetterOp)set_onmessage }, |
402 | | { prototypes::id::EventSource }, |
403 | | { PrototypeTraits<prototypes::id::EventSource>::Depth }, |
404 | | JSJitInfo::Setter, |
405 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
406 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
407 | | false, /* isInfallible. False in setters. */ |
408 | | false, /* isMovable. Not relevant for setters. */ |
409 | | false, /* isEliminatable. Not relevant for setters. */ |
410 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
411 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
412 | | false, /* isTypedMethod. Only relevant for methods. */ |
413 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
414 | | }; |
415 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
416 | | static_assert(0 < 1, "There is no slot for us"); |
417 | | |
418 | | MOZ_CAN_RUN_SCRIPT static bool |
419 | | get_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::EventSource* self, JSJitGetterCallArgs args) |
420 | 0 | { |
421 | 0 | AUTO_PROFILER_LABEL_FAST("get EventSource.onerror", DOM, cx); |
422 | 0 |
|
423 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnerror()); |
424 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
425 | 0 | if (result) { |
426 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
427 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
428 | 0 | return false; |
429 | 0 | } |
430 | 0 | return true; |
431 | 0 | } else { |
432 | 0 | args.rval().setNull(); |
433 | 0 | return true; |
434 | 0 | } |
435 | 0 | } |
436 | | |
437 | | MOZ_CAN_RUN_SCRIPT static bool |
438 | | set_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::EventSource* self, JSJitSetterCallArgs args) |
439 | 0 | { |
440 | 0 | AUTO_PROFILER_LABEL_FAST("set EventSource.onerror", DOM, cx); |
441 | 0 |
|
442 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
443 | 0 | if (args[0].isObject()) { |
444 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
445 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
446 | 0 | } |
447 | 0 | } else { |
448 | 0 | arg0 = nullptr; |
449 | 0 | } |
450 | 0 | self->SetOnerror(Constify(arg0)); |
451 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
452 | 0 |
|
453 | 0 | return true; |
454 | 0 | } |
455 | | |
456 | | static const JSJitInfo onerror_getterinfo = { |
457 | | { (JSJitGetterOp)get_onerror }, |
458 | | { prototypes::id::EventSource }, |
459 | | { PrototypeTraits<prototypes::id::EventSource>::Depth }, |
460 | | JSJitInfo::Getter, |
461 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
462 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
463 | | false, /* isInfallible. False in setters. */ |
464 | | false, /* isMovable. Not relevant for setters. */ |
465 | | false, /* isEliminatable. Not relevant for setters. */ |
466 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
467 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
468 | | false, /* isTypedMethod. Only relevant for methods. */ |
469 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
470 | | }; |
471 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
472 | | static_assert(0 < 1, "There is no slot for us"); |
473 | | static const JSJitInfo onerror_setterinfo = { |
474 | | { (JSJitGetterOp)set_onerror }, |
475 | | { prototypes::id::EventSource }, |
476 | | { PrototypeTraits<prototypes::id::EventSource>::Depth }, |
477 | | JSJitInfo::Setter, |
478 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
479 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
480 | | false, /* isInfallible. False in setters. */ |
481 | | false, /* isMovable. Not relevant for setters. */ |
482 | | false, /* isEliminatable. Not relevant for setters. */ |
483 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
484 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
485 | | false, /* isTypedMethod. Only relevant for methods. */ |
486 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
487 | | }; |
488 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
489 | | static_assert(0 < 1, "There is no slot for us"); |
490 | | |
491 | | MOZ_CAN_RUN_SCRIPT static bool |
492 | | close(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::EventSource* self, const JSJitMethodCallArgs& args) |
493 | 0 | { |
494 | 0 | AUTO_PROFILER_LABEL_FAST("EventSource.close", DOM, cx); |
495 | 0 |
|
496 | 0 | self->Close(); |
497 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
498 | 0 | args.rval().setUndefined(); |
499 | 0 | return true; |
500 | 0 | } |
501 | | |
502 | | static const JSJitInfo close_methodinfo = { |
503 | | { (JSJitGetterOp)close }, |
504 | | { prototypes::id::EventSource }, |
505 | | { PrototypeTraits<prototypes::id::EventSource>::Depth }, |
506 | | JSJitInfo::Method, |
507 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
508 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
509 | | true, /* isInfallible. False in setters. */ |
510 | | false, /* isMovable. Not relevant for setters. */ |
511 | | false, /* isEliminatable. Not relevant for setters. */ |
512 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
513 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
514 | | false, /* isTypedMethod. Only relevant for methods. */ |
515 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
516 | | }; |
517 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
518 | | static_assert(0 < 1, "There is no slot for us"); |
519 | | |
520 | | static bool |
521 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
522 | 0 | { |
523 | 0 | mozilla::dom::EventSource* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::EventSource>(obj); |
524 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
525 | 0 | // obviously can't preserve if we're not initialized. |
526 | 0 | if (self && self->GetWrapperPreserveColor()) { |
527 | 0 | PreserveWrapper(self); |
528 | 0 | } |
529 | 0 | return true; |
530 | 0 | } |
531 | | |
532 | | static void |
533 | | _finalize(js::FreeOp* fop, JSObject* obj) |
534 | 0 | { |
535 | 0 | mozilla::dom::EventSource* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::EventSource>(obj); |
536 | 0 | if (self) { |
537 | 0 | ClearWrapper(self, self, obj); |
538 | 0 | AddForDeferredFinalization<mozilla::dom::EventSource>(self); |
539 | 0 | } |
540 | 0 | } |
541 | | |
542 | | static size_t |
543 | | _objectMoved(JSObject* obj, JSObject* old) |
544 | 0 | { |
545 | 0 | mozilla::dom::EventSource* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::EventSource>(obj); |
546 | 0 | if (self) { |
547 | 0 | UpdateWrapper(self, self, obj, old); |
548 | 0 | } |
549 | 0 |
|
550 | 0 | return 0; |
551 | 0 | } |
552 | | |
553 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
554 | | #if defined(__clang__) |
555 | | #pragma clang diagnostic push |
556 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
557 | | #endif |
558 | | static const JSFunctionSpec sMethods_specs[] = { |
559 | | JS_FNSPEC("close", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&close_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
560 | | JS_FS_END |
561 | | }; |
562 | | #if defined(__clang__) |
563 | | #pragma clang diagnostic pop |
564 | | #endif |
565 | | |
566 | | |
567 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
568 | | { nullptr, &sMethods_specs[0] }, |
569 | | { nullptr, nullptr } |
570 | | }; |
571 | | |
572 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
573 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
574 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
575 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
576 | | |
577 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
578 | | #if defined(__clang__) |
579 | | #pragma clang diagnostic push |
580 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
581 | | #endif |
582 | | static const JSPropertySpec sAttributes_specs[] = { |
583 | | { "url", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &url_getterinfo, nullptr, nullptr }, |
584 | | { "withCredentials", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &withCredentials_getterinfo, nullptr, nullptr }, |
585 | | { "readyState", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &readyState_getterinfo, nullptr, nullptr }, |
586 | | { "onopen", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onopen_getterinfo, GenericSetter<NormalThisPolicy>, &onopen_setterinfo }, |
587 | | { "onmessage", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onmessage_getterinfo, GenericSetter<NormalThisPolicy>, &onmessage_setterinfo }, |
588 | | { "onerror", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onerror_getterinfo, GenericSetter<NormalThisPolicy>, &onerror_setterinfo }, |
589 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
590 | | }; |
591 | | #if defined(__clang__) |
592 | | #pragma clang diagnostic pop |
593 | | #endif |
594 | | |
595 | | |
596 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
597 | | { nullptr, &sAttributes_specs[0] }, |
598 | | { nullptr, nullptr } |
599 | | }; |
600 | | |
601 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
602 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
603 | | static_assert(6 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
604 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
605 | | |
606 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
607 | | #if defined(__clang__) |
608 | | #pragma clang diagnostic push |
609 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
610 | | #endif |
611 | | static const ConstantSpec sConstants_specs[] = { |
612 | | { "CONNECTING", JS::Int32Value(0) }, |
613 | | { "OPEN", JS::Int32Value(1) }, |
614 | | { "CLOSED", JS::Int32Value(2) }, |
615 | | { 0, JS::UndefinedValue() } |
616 | | }; |
617 | | #if defined(__clang__) |
618 | | #pragma clang diagnostic pop |
619 | | #endif |
620 | | |
621 | | |
622 | | static const Prefable<const ConstantSpec> sConstants[] = { |
623 | | { nullptr, &sConstants_specs[0] }, |
624 | | { nullptr, nullptr } |
625 | | }; |
626 | | |
627 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
628 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
629 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
630 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
631 | | |
632 | | |
633 | | static uint16_t sNativeProperties_sortedPropertyIndices[10]; |
634 | | static PropertyInfo sNativeProperties_propertyInfos[10]; |
635 | | |
636 | | static const NativePropertiesN<3> sNativeProperties = { |
637 | | false, 0, |
638 | | false, 0, |
639 | | true, 0 /* sMethods */, |
640 | | true, 1 /* sAttributes */, |
641 | | false, 0, |
642 | | false, 0, |
643 | | true, 2 /* sConstants */, |
644 | | -1, |
645 | | 10, |
646 | | sNativeProperties_sortedPropertyIndices, |
647 | | { |
648 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
649 | | { sAttributes, &sNativeProperties_propertyInfos[1] }, |
650 | | { sConstants, &sNativeProperties_propertyInfos[7] } |
651 | | } |
652 | | }; |
653 | | static_assert(10 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
654 | | "We have a property info count that is oversized"); |
655 | | |
656 | | static bool |
657 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
658 | 0 | { |
659 | 0 | AUTO_PROFILER_LABEL_FAST("EventSource constructor", DOM, cx); |
660 | 0 |
|
661 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
662 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
663 | 0 | if (!args.isConstructing()) { |
664 | 0 | // XXXbz wish I could get the name from the callee instead of |
665 | 0 | // Adding more relocations |
666 | 0 | return ThrowConstructorWithoutNew(cx, "EventSource"); |
667 | 0 | } |
668 | 0 | |
669 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
670 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
671 | 0 | return false; |
672 | 0 | } |
673 | 0 | |
674 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
675 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "EventSource"); |
676 | 0 | } |
677 | 0 | GlobalObject global(cx, obj); |
678 | 0 | if (global.Failed()) { |
679 | 0 | return false; |
680 | 0 | } |
681 | 0 | |
682 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
683 | 0 | binding_detail::FakeString arg0; |
684 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
685 | 0 | return false; |
686 | 0 | } |
687 | 0 | NormalizeUSVString(arg0); |
688 | 0 | binding_detail::FastEventSourceInit arg1; |
689 | 0 | if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of EventSource.constructor", false)) { |
690 | 0 | return false; |
691 | 0 | } |
692 | 0 | Maybe<JSAutoRealm> ar; |
693 | 0 | if (objIsXray) { |
694 | 0 | obj = js::CheckedUnwrap(obj); |
695 | 0 | if (!obj) { |
696 | 0 | return false; |
697 | 0 | } |
698 | 0 | ar.emplace(cx, obj); |
699 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
700 | 0 | return false; |
701 | 0 | } |
702 | 0 | } |
703 | 0 | FastErrorResult rv; |
704 | 0 | auto result(StrongOrRawPtr<mozilla::dom::EventSource>(mozilla::dom::EventSource::Constructor(global, Constify(arg0), Constify(arg1), rv))); |
705 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
706 | 0 | return false; |
707 | 0 | } |
708 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
709 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
710 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
711 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
712 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
713 | 0 | return false; |
714 | 0 | } |
715 | 0 | return true; |
716 | 0 | } |
717 | | |
718 | | static const js::ClassOps sInterfaceObjectClassOps = { |
719 | | nullptr, /* addProperty */ |
720 | | nullptr, /* delProperty */ |
721 | | nullptr, /* enumerate */ |
722 | | nullptr, /* newEnumerate */ |
723 | | nullptr, /* resolve */ |
724 | | nullptr, /* mayResolve */ |
725 | | nullptr, /* finalize */ |
726 | | _constructor, /* call */ |
727 | | nullptr, /* hasInstance */ |
728 | | _constructor, /* construct */ |
729 | | nullptr, /* trace */ |
730 | | }; |
731 | | |
732 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
733 | | { |
734 | | "Function", |
735 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
736 | | &sInterfaceObjectClassOps, |
737 | | JS_NULL_CLASS_SPEC, |
738 | | JS_NULL_CLASS_EXT, |
739 | | &sInterfaceObjectClassObjectOps |
740 | | }, |
741 | | eInterface, |
742 | | true, |
743 | | prototypes::id::EventSource, |
744 | | PrototypeTraits<prototypes::id::EventSource>::Depth, |
745 | | sNativePropertyHooks, |
746 | | "function EventSource() {\n [native code]\n}", |
747 | | EventTarget_Binding::GetConstructorObject |
748 | | }; |
749 | | |
750 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
751 | | { |
752 | | "EventSourcePrototype", |
753 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
754 | | JS_NULL_CLASS_OPS, |
755 | | JS_NULL_CLASS_SPEC, |
756 | | JS_NULL_CLASS_EXT, |
757 | | JS_NULL_OBJECT_OPS |
758 | | }, |
759 | | eInterfacePrototype, |
760 | | false, |
761 | | prototypes::id::EventSource, |
762 | | PrototypeTraits<prototypes::id::EventSource>::Depth, |
763 | | sNativePropertyHooks, |
764 | | "[object EventSourcePrototype]", |
765 | | EventTarget_Binding::GetProtoObject |
766 | | }; |
767 | | |
768 | | bool |
769 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
770 | 0 | { |
771 | 0 | if (!NS_IsMainThread()) { |
772 | 0 | const char* name = js::GetObjectClass(aObj)->name; |
773 | 0 | if (strcmp(name, "DedicatedWorkerGlobalScope") && strcmp(name, "SharedWorkerGlobalScope")) { |
774 | 0 | return false; |
775 | 0 | } |
776 | 0 | } |
777 | 0 | |
778 | 0 | return true; |
779 | 0 | } |
780 | | |
781 | | static const js::ClassOps sClassOps = { |
782 | | _addProperty, /* addProperty */ |
783 | | nullptr, /* delProperty */ |
784 | | nullptr, /* enumerate */ |
785 | | nullptr, /* newEnumerate */ |
786 | | nullptr, /* resolve */ |
787 | | nullptr, /* mayResolve */ |
788 | | _finalize, /* finalize */ |
789 | | nullptr, /* call */ |
790 | | nullptr, /* hasInstance */ |
791 | | nullptr, /* construct */ |
792 | | nullptr, /* trace */ |
793 | | }; |
794 | | |
795 | | static const js::ClassExtension sClassExtension = { |
796 | | nullptr, /* weakmapKeyDelegateOp */ |
797 | | _objectMoved /* objectMovedOp */ |
798 | | }; |
799 | | |
800 | | static const DOMJSClass sClass = { |
801 | | { "EventSource", |
802 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
803 | | &sClassOps, |
804 | | JS_NULL_CLASS_SPEC, |
805 | | &sClassExtension, |
806 | | JS_NULL_OBJECT_OPS |
807 | | }, |
808 | | { prototypes::id::EventTarget, prototypes::id::EventSource, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
809 | | IsBaseOf<nsISupports, mozilla::dom::EventSource >::value, |
810 | | sNativePropertyHooks, |
811 | | FindAssociatedGlobalForNative<mozilla::dom::EventSource>::Get, |
812 | | GetProtoObjectHandle, |
813 | | GetCCParticipant<mozilla::dom::EventSource>::Get() |
814 | | }; |
815 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
816 | | "Must have the right minimal number of reserved slots."); |
817 | | static_assert(1 >= 1, |
818 | | "Must have enough reserved slots."); |
819 | | |
820 | | const JSClass* |
821 | | GetJSClass() |
822 | 0 | { |
823 | 0 | return sClass.ToJSClass(); |
824 | 0 | } |
825 | | |
826 | | bool |
827 | | Wrap(JSContext* aCx, mozilla::dom::EventSource* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
828 | 0 | { |
829 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::EventSource>::value, |
830 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
831 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventSource*>(aObject) == |
832 | 0 | reinterpret_cast<mozilla::dom::EventSource*>(aObject), |
833 | 0 | "Multiple inheritance for mozilla::dom::EventSource is broken."); |
834 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
835 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
836 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
837 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
838 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
839 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
840 | 0 | "You should probably not be using Wrap() directly; use " |
841 | 0 | "GetOrCreateDOMReflector instead"); |
842 | 0 |
|
843 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
844 | 0 | "nsISupports must be on our primary inheritance chain"); |
845 | 0 |
|
846 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
847 | 0 | if (!global) { |
848 | 0 | return false; |
849 | 0 | } |
850 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
851 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
852 | 0 |
|
853 | 0 | // That might have ended up wrapping us already, due to the wonders |
854 | 0 | // of XBL. Check for that, and bail out as needed. |
855 | 0 | aReflector.set(aCache->GetWrapper()); |
856 | 0 | if (aReflector) { |
857 | | #ifdef DEBUG |
858 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
859 | | #endif // DEBUG |
860 | | return true; |
861 | 0 | } |
862 | 0 |
|
863 | 0 | JSAutoRealm ar(aCx, global); |
864 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
865 | 0 | if (!canonicalProto) { |
866 | 0 | return false; |
867 | 0 | } |
868 | 0 | JS::Rooted<JSObject*> proto(aCx); |
869 | 0 | if (aGivenProto) { |
870 | 0 | proto = aGivenProto; |
871 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
872 | 0 | // coming in, we changed compartments to that of "parent" so may need |
873 | 0 | // to wrap the proto here. |
874 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
875 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
876 | 0 | return false; |
877 | 0 | } |
878 | 0 | } |
879 | 0 | } else { |
880 | 0 | proto = canonicalProto; |
881 | 0 | } |
882 | 0 |
|
883 | 0 | BindingJSObjectCreator<mozilla::dom::EventSource> creator(aCx); |
884 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
885 | 0 | if (!aReflector) { |
886 | 0 | return false; |
887 | 0 | } |
888 | 0 | |
889 | 0 | aCache->SetWrapper(aReflector); |
890 | 0 | creator.InitializationSucceeded(); |
891 | 0 |
|
892 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
893 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
894 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
895 | 0 | // otherwise we won't be able to properly recreate it later, since |
896 | 0 | // we won't know what proto to use. Note that we don't check |
897 | 0 | // aGivenProto here, since it's entirely possible (and even |
898 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
899 | 0 | // same as canonicalProto. |
900 | 0 | if (proto != canonicalProto) { |
901 | 0 | PreserveWrapper(aObject); |
902 | 0 | } |
903 | 0 |
|
904 | 0 | return true; |
905 | 0 | } |
906 | | |
907 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
908 | | nullptr, |
909 | | nullptr, |
910 | | nullptr, |
911 | | { sNativeProperties.Upcast(), nullptr }, |
912 | | prototypes::id::EventSource, |
913 | | constructors::id::EventSource, |
914 | | EventTarget_Binding::sNativePropertyHooks, |
915 | | &DefaultXrayExpandoObjectClass |
916 | | } }; |
917 | | |
918 | | void |
919 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
920 | 0 | { |
921 | 0 | JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx)); |
922 | 0 | if (!parentProto) { |
923 | 0 | return; |
924 | 0 | } |
925 | 0 | |
926 | 0 | JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx)); |
927 | 0 | if (!constructorProto) { |
928 | 0 | return; |
929 | 0 | } |
930 | 0 | |
931 | 0 | static bool sIdsInited = false; |
932 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
933 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
934 | 0 | return; |
935 | 0 | } |
936 | 0 | sIdsInited = true; |
937 | 0 | } |
938 | 0 |
|
939 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::EventSource); |
940 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::EventSource); |
941 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
942 | 0 | &sPrototypeClass.mBase, protoCache, |
943 | 0 | nullptr, |
944 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr, |
945 | 0 | interfaceCache, |
946 | 0 | sNativeProperties.Upcast(), |
947 | 0 | nullptr, |
948 | 0 | "EventSource", aDefineOnGlobal, |
949 | 0 | nullptr, |
950 | 0 | false); |
951 | 0 | } |
952 | | |
953 | | JSObject* |
954 | | GetConstructorObject(JSContext* aCx) |
955 | 0 | { |
956 | 0 | return GetConstructorObjectHandle(aCx); |
957 | 0 | } |
958 | | |
959 | | } // namespace EventSource_Binding |
960 | | |
961 | | |
962 | | |
963 | | } // namespace dom |
964 | | } // namespace mozilla |