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