/work/obj-fuzz/dom/bindings/DedicatedWorkerGlobalScopeBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM DedicatedWorkerGlobalScope.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "DedicatedWorkerGlobalScopeBinding.h" |
4 | | #include "EventHandlerBinding.h" |
5 | | #include "WorkerGlobalScopeBinding.h" |
6 | | #include "WrapperFactory.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/dom/BindingUtils.h" |
9 | | #include "mozilla/dom/DOMJSClass.h" |
10 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
11 | | #include "mozilla/dom/Nullable.h" |
12 | | #include "mozilla/dom/WorkerScope.h" |
13 | | #include "nsThreadUtils.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 DedicatedWorkerGlobalScope_Binding { |
23 | | |
24 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<WorkerGlobalScope_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::DedicatedWorkerGlobalScope* self, JSJitGetterCallArgs args) |
29 | 0 | { |
30 | 0 | AUTO_PROFILER_LABEL_FAST("get DedicatedWorkerGlobalScope.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 | | MOZ_CAN_RUN_SCRIPT static bool |
42 | | set_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DedicatedWorkerGlobalScope* self, JSJitSetterCallArgs args) |
43 | 0 | { |
44 | 0 | AUTO_PROFILER_LABEL_FAST("set DedicatedWorkerGlobalScope.name", DOM, cx); |
45 | 0 |
|
46 | 0 | return JS_DefineProperty(cx, obj, "name", args[0], JSPROP_ENUMERATE); |
47 | 0 | } |
48 | | |
49 | | static const JSJitInfo name_getterinfo = { |
50 | | { (JSJitGetterOp)get_name }, |
51 | | { prototypes::id::DedicatedWorkerGlobalScope }, |
52 | | { PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth }, |
53 | | JSJitInfo::Getter, |
54 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
55 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
56 | | false, /* isInfallible. False in setters. */ |
57 | | false, /* isMovable. Not relevant for setters. */ |
58 | | false, /* isEliminatable. Not relevant for setters. */ |
59 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
60 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
61 | | false, /* isTypedMethod. Only relevant for methods. */ |
62 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
63 | | }; |
64 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
65 | | static_assert(0 < 3, "There is no slot for us"); |
66 | | static const JSJitInfo name_setterinfo = { |
67 | | { (JSJitGetterOp)set_name }, |
68 | | { prototypes::id::DedicatedWorkerGlobalScope }, |
69 | | { PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth }, |
70 | | JSJitInfo::Setter, |
71 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
72 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
73 | | false, /* isInfallible. False in setters. */ |
74 | | false, /* isMovable. Not relevant for setters. */ |
75 | | false, /* isEliminatable. Not relevant for setters. */ |
76 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
77 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
78 | | false, /* isTypedMethod. Only relevant for methods. */ |
79 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
80 | | }; |
81 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
82 | | static_assert(0 < 3, "There is no slot for us"); |
83 | | |
84 | | MOZ_CAN_RUN_SCRIPT static bool |
85 | | postMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DedicatedWorkerGlobalScope* self, const JSJitMethodCallArgs& args) |
86 | 0 | { |
87 | 0 | AUTO_PROFILER_LABEL_FAST("DedicatedWorkerGlobalScope.postMessage", DOM, cx); |
88 | 0 |
|
89 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
90 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "DedicatedWorkerGlobalScope.postMessage"); |
91 | 0 | } |
92 | 0 | JS::Rooted<JS::Value> arg0(cx); |
93 | 0 | arg0 = args[0]; |
94 | 0 | binding_detail::AutoSequence<JSObject*> arg1; |
95 | 0 | SequenceRooter<JSObject*> arg1_holder(cx, &arg1); |
96 | 0 | if (args.hasDefined(1)) { |
97 | 0 | if (args[1].isObject()) { |
98 | 0 | JS::ForOfIterator iter(cx); |
99 | 0 | if (!iter.init(args[1], JS::ForOfIterator::AllowNonIterable)) { |
100 | 0 | return false; |
101 | 0 | } |
102 | 0 | if (!iter.valueIsIterable()) { |
103 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 2 of DedicatedWorkerGlobalScope.postMessage"); |
104 | 0 | return false; |
105 | 0 | } |
106 | 0 | binding_detail::AutoSequence<JSObject*> &arr = arg1; |
107 | 0 | JS::Rooted<JS::Value> temp(cx); |
108 | 0 | while (true) { |
109 | 0 | bool done; |
110 | 0 | if (!iter.next(&temp, &done)) { |
111 | 0 | return false; |
112 | 0 | } |
113 | 0 | if (done) { |
114 | 0 | break; |
115 | 0 | } |
116 | 0 | JSObject** slotPtr = arr.AppendElement(mozilla::fallible); |
117 | 0 | if (!slotPtr) { |
118 | 0 | JS_ReportOutOfMemory(cx); |
119 | 0 | return false; |
120 | 0 | } |
121 | 0 | JSObject*& slot = *slotPtr; |
122 | 0 | if (temp.isObject()) { |
123 | 0 | slot = &temp.toObject(); |
124 | 0 | } else { |
125 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of argument 2 of DedicatedWorkerGlobalScope.postMessage"); |
126 | 0 | return false; |
127 | 0 | } |
128 | 0 | } |
129 | 0 | } else { |
130 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 2 of DedicatedWorkerGlobalScope.postMessage"); |
131 | 0 | return false; |
132 | 0 | } |
133 | 0 | } else { |
134 | 0 | /* Array is already empty; nothing to do */ |
135 | 0 | } |
136 | 0 | FastErrorResult rv; |
137 | 0 | self->PostMessage(cx, arg0, Constify(arg1), rv); |
138 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
139 | 0 | return false; |
140 | 0 | } |
141 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
142 | 0 | args.rval().setUndefined(); |
143 | 0 | return true; |
144 | 0 | } |
145 | | |
146 | | static const JSJitInfo postMessage_methodinfo = { |
147 | | { (JSJitGetterOp)postMessage }, |
148 | | { prototypes::id::DedicatedWorkerGlobalScope }, |
149 | | { PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth }, |
150 | | JSJitInfo::Method, |
151 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
152 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
153 | | false, /* isInfallible. False in setters. */ |
154 | | false, /* isMovable. Not relevant for setters. */ |
155 | | false, /* isEliminatable. Not relevant for setters. */ |
156 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
157 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
158 | | false, /* isTypedMethod. Only relevant for methods. */ |
159 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
160 | | }; |
161 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
162 | | static_assert(0 < 3, "There is no slot for us"); |
163 | | |
164 | | MOZ_CAN_RUN_SCRIPT static bool |
165 | | close(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DedicatedWorkerGlobalScope* self, const JSJitMethodCallArgs& args) |
166 | 0 | { |
167 | 0 | AUTO_PROFILER_LABEL_FAST("DedicatedWorkerGlobalScope.close", DOM, cx); |
168 | 0 |
|
169 | 0 | self->Close(); |
170 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
171 | 0 | args.rval().setUndefined(); |
172 | 0 | return true; |
173 | 0 | } |
174 | | |
175 | | static const JSJitInfo close_methodinfo = { |
176 | | { (JSJitGetterOp)close }, |
177 | | { prototypes::id::DedicatedWorkerGlobalScope }, |
178 | | { PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth }, |
179 | | JSJitInfo::Method, |
180 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
181 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
182 | | true, /* isInfallible. False in setters. */ |
183 | | false, /* isMovable. Not relevant for setters. */ |
184 | | false, /* isEliminatable. Not relevant for setters. */ |
185 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
186 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
187 | | false, /* isTypedMethod. Only relevant for methods. */ |
188 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
189 | | }; |
190 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
191 | | static_assert(0 < 3, "There is no slot for us"); |
192 | | |
193 | | MOZ_CAN_RUN_SCRIPT static bool |
194 | | get_onmessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DedicatedWorkerGlobalScope* self, JSJitGetterCallArgs args) |
195 | 0 | { |
196 | 0 | AUTO_PROFILER_LABEL_FAST("get DedicatedWorkerGlobalScope.onmessage", DOM, cx); |
197 | 0 |
|
198 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnmessage()); |
199 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
200 | 0 | if (result) { |
201 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
202 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
203 | 0 | return false; |
204 | 0 | } |
205 | 0 | return true; |
206 | 0 | } else { |
207 | 0 | args.rval().setNull(); |
208 | 0 | return true; |
209 | 0 | } |
210 | 0 | } |
211 | | |
212 | | MOZ_CAN_RUN_SCRIPT static bool |
213 | | set_onmessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DedicatedWorkerGlobalScope* self, JSJitSetterCallArgs args) |
214 | 0 | { |
215 | 0 | AUTO_PROFILER_LABEL_FAST("set DedicatedWorkerGlobalScope.onmessage", DOM, cx); |
216 | 0 |
|
217 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
218 | 0 | if (args[0].isObject()) { |
219 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
220 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
221 | 0 | } |
222 | 0 | } else { |
223 | 0 | arg0 = nullptr; |
224 | 0 | } |
225 | 0 | self->SetOnmessage(Constify(arg0)); |
226 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
227 | 0 |
|
228 | 0 | return true; |
229 | 0 | } |
230 | | |
231 | | static const JSJitInfo onmessage_getterinfo = { |
232 | | { (JSJitGetterOp)get_onmessage }, |
233 | | { prototypes::id::DedicatedWorkerGlobalScope }, |
234 | | { PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth }, |
235 | | JSJitInfo::Getter, |
236 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
237 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
238 | | false, /* isInfallible. False in setters. */ |
239 | | false, /* isMovable. Not relevant for setters. */ |
240 | | false, /* isEliminatable. Not relevant for setters. */ |
241 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
242 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
243 | | false, /* isTypedMethod. Only relevant for methods. */ |
244 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
245 | | }; |
246 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
247 | | static_assert(0 < 3, "There is no slot for us"); |
248 | | static const JSJitInfo onmessage_setterinfo = { |
249 | | { (JSJitGetterOp)set_onmessage }, |
250 | | { prototypes::id::DedicatedWorkerGlobalScope }, |
251 | | { PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth }, |
252 | | JSJitInfo::Setter, |
253 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
254 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
255 | | false, /* isInfallible. False in setters. */ |
256 | | false, /* isMovable. Not relevant for setters. */ |
257 | | false, /* isEliminatable. Not relevant for setters. */ |
258 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
259 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
260 | | false, /* isTypedMethod. Only relevant for methods. */ |
261 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
262 | | }; |
263 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
264 | | static_assert(0 < 3, "There is no slot for us"); |
265 | | |
266 | | MOZ_CAN_RUN_SCRIPT static bool |
267 | | get_onmessageerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DedicatedWorkerGlobalScope* self, JSJitGetterCallArgs args) |
268 | 0 | { |
269 | 0 | AUTO_PROFILER_LABEL_FAST("get DedicatedWorkerGlobalScope.onmessageerror", DOM, cx); |
270 | 0 |
|
271 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnmessageerror()); |
272 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
273 | 0 | if (result) { |
274 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
275 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
276 | 0 | return false; |
277 | 0 | } |
278 | 0 | return true; |
279 | 0 | } else { |
280 | 0 | args.rval().setNull(); |
281 | 0 | return true; |
282 | 0 | } |
283 | 0 | } |
284 | | |
285 | | MOZ_CAN_RUN_SCRIPT static bool |
286 | | set_onmessageerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DedicatedWorkerGlobalScope* self, JSJitSetterCallArgs args) |
287 | 0 | { |
288 | 0 | AUTO_PROFILER_LABEL_FAST("set DedicatedWorkerGlobalScope.onmessageerror", DOM, cx); |
289 | 0 |
|
290 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
291 | 0 | if (args[0].isObject()) { |
292 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
293 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
294 | 0 | } |
295 | 0 | } else { |
296 | 0 | arg0 = nullptr; |
297 | 0 | } |
298 | 0 | self->SetOnmessageerror(Constify(arg0)); |
299 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
300 | 0 |
|
301 | 0 | return true; |
302 | 0 | } |
303 | | |
304 | | static const JSJitInfo onmessageerror_getterinfo = { |
305 | | { (JSJitGetterOp)get_onmessageerror }, |
306 | | { prototypes::id::DedicatedWorkerGlobalScope }, |
307 | | { PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth }, |
308 | | JSJitInfo::Getter, |
309 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
310 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
311 | | false, /* isInfallible. False in setters. */ |
312 | | false, /* isMovable. Not relevant for setters. */ |
313 | | false, /* isEliminatable. Not relevant for setters. */ |
314 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
315 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
316 | | false, /* isTypedMethod. Only relevant for methods. */ |
317 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
318 | | }; |
319 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
320 | | static_assert(0 < 3, "There is no slot for us"); |
321 | | static const JSJitInfo onmessageerror_setterinfo = { |
322 | | { (JSJitGetterOp)set_onmessageerror }, |
323 | | { prototypes::id::DedicatedWorkerGlobalScope }, |
324 | | { PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth }, |
325 | | JSJitInfo::Setter, |
326 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
327 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
328 | | false, /* isInfallible. False in setters. */ |
329 | | false, /* isMovable. Not relevant for setters. */ |
330 | | false, /* isEliminatable. Not relevant for setters. */ |
331 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
332 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
333 | | false, /* isTypedMethod. Only relevant for methods. */ |
334 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
335 | | }; |
336 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
337 | | static_assert(0 < 3, "There is no slot for us"); |
338 | | |
339 | | static void |
340 | | _finalize(js::FreeOp* fop, JSObject* obj) |
341 | 0 | { |
342 | 0 | mozilla::dom::DedicatedWorkerGlobalScope* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DedicatedWorkerGlobalScope>(obj); |
343 | 0 | if (self) { |
344 | 0 | ClearWrapper(self, self, obj); |
345 | 0 | mozilla::dom::FinalizeGlobal(CastToJSFreeOp(fop), obj); |
346 | 0 | AddForDeferredFinalization<mozilla::dom::DedicatedWorkerGlobalScope>(self); |
347 | 0 | } |
348 | 0 | } |
349 | | |
350 | | static size_t |
351 | | _objectMoved(JSObject* obj, JSObject* old) |
352 | 0 | { |
353 | 0 | mozilla::dom::DedicatedWorkerGlobalScope* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DedicatedWorkerGlobalScope>(obj); |
354 | 0 | if (self) { |
355 | 0 | UpdateWrapper(self, self, obj, old); |
356 | 0 | } |
357 | 0 |
|
358 | 0 | return 0; |
359 | 0 | } |
360 | | |
361 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
362 | | #if defined(__clang__) |
363 | | #pragma clang diagnostic push |
364 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
365 | | #endif |
366 | | static const JSFunctionSpec sMethods_specs[] = { |
367 | | JS_FNSPEC("postMessage", (GenericMethod<MaybeGlobalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&postMessage_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
368 | | JS_FNSPEC("close", (GenericMethod<MaybeGlobalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&close_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
369 | | JS_FS_END |
370 | | }; |
371 | | #if defined(__clang__) |
372 | | #pragma clang diagnostic pop |
373 | | #endif |
374 | | |
375 | | |
376 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
377 | | { nullptr, &sMethods_specs[0] }, |
378 | | { nullptr, nullptr } |
379 | | }; |
380 | | |
381 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
382 | | #if defined(__clang__) |
383 | | #pragma clang diagnostic push |
384 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
385 | | #endif |
386 | | static const JSPropertySpec sAttributes_specs[] = { |
387 | | { "name", JSPROP_ENUMERATE, GenericGetter<MaybeGlobalThisPolicy, ThrowExceptions>, &name_getterinfo, GenericSetter<MaybeGlobalThisPolicy>, &name_setterinfo }, |
388 | | { "onmessage", JSPROP_ENUMERATE, GenericGetter<MaybeGlobalThisPolicy, ThrowExceptions>, &onmessage_getterinfo, GenericSetter<MaybeGlobalThisPolicy>, &onmessage_setterinfo }, |
389 | | { "onmessageerror", JSPROP_ENUMERATE, GenericGetter<MaybeGlobalThisPolicy, ThrowExceptions>, &onmessageerror_getterinfo, GenericSetter<MaybeGlobalThisPolicy>, &onmessageerror_setterinfo }, |
390 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
391 | | }; |
392 | | #if defined(__clang__) |
393 | | #pragma clang diagnostic pop |
394 | | #endif |
395 | | |
396 | | |
397 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
398 | | { nullptr, &sAttributes_specs[0] }, |
399 | | { nullptr, nullptr } |
400 | | }; |
401 | | |
402 | | |
403 | | static const NativePropertiesN<2> sNativeProperties = { |
404 | | false, 0, |
405 | | false, 0, |
406 | | true, 0 /* sMethods */, |
407 | | true, 1 /* sAttributes */, |
408 | | false, 0, |
409 | | false, 0, |
410 | | false, 0, |
411 | | -1, |
412 | | 0, |
413 | | nullptr, |
414 | | { |
415 | | { sMethods, nullptr }, |
416 | | { sAttributes, nullptr } |
417 | | } |
418 | | }; |
419 | | |
420 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
421 | | { |
422 | | "Function", |
423 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
424 | | &sBoringInterfaceObjectClassClassOps, |
425 | | JS_NULL_CLASS_SPEC, |
426 | | JS_NULL_CLASS_EXT, |
427 | | &sInterfaceObjectClassObjectOps |
428 | | }, |
429 | | eInterface, |
430 | | true, |
431 | | prototypes::id::DedicatedWorkerGlobalScope, |
432 | | PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth, |
433 | | &sEmptyNativePropertyHooks, |
434 | | "function DedicatedWorkerGlobalScope() {\n [native code]\n}", |
435 | | WorkerGlobalScope_Binding::GetConstructorObject |
436 | | }; |
437 | | |
438 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
439 | | { |
440 | | "DedicatedWorkerGlobalScopePrototype", |
441 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
442 | | JS_NULL_CLASS_OPS, |
443 | | JS_NULL_CLASS_SPEC, |
444 | | JS_NULL_CLASS_EXT, |
445 | | JS_NULL_OBJECT_OPS |
446 | | }, |
447 | | eGlobalInterfacePrototype, |
448 | | false, |
449 | | prototypes::id::DedicatedWorkerGlobalScope, |
450 | | PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth, |
451 | | &sEmptyNativePropertyHooks, |
452 | | "[object DedicatedWorkerGlobalScopePrototype]", |
453 | | WorkerGlobalScope_Binding::GetProtoObject |
454 | | }; |
455 | | |
456 | | bool |
457 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
458 | 0 | { |
459 | 0 | MOZ_ASSERT(!NS_IsMainThread(), "Why did we even get called?"); |
460 | 0 |
|
461 | 0 | const char* name = js::GetObjectClass(aObj)->name; |
462 | 0 | if (strcmp(name, "DedicatedWorkerGlobalScope")) { |
463 | 0 | return false; |
464 | 0 | } |
465 | 0 | |
466 | 0 | return true; |
467 | 0 | } |
468 | | |
469 | | static const js::ClassOps sClassOps = { |
470 | | nullptr, /* addProperty */ |
471 | | nullptr, /* delProperty */ |
472 | | nullptr, /* enumerate */ |
473 | | mozilla::dom::EnumerateGlobal, /* newEnumerate */ |
474 | | mozilla::dom::ResolveGlobal, /* resolve */ |
475 | | mozilla::dom::MayResolveGlobal, /* mayResolve */ |
476 | | _finalize, /* finalize */ |
477 | | nullptr, /* call */ |
478 | | nullptr, /* hasInstance */ |
479 | | nullptr, /* construct */ |
480 | | JS_GlobalObjectTraceHook, /* trace */ |
481 | | }; |
482 | | |
483 | | static const js::ClassExtension sClassExtension = { |
484 | | nullptr, /* weakmapKeyDelegateOp */ |
485 | | _objectMoved /* objectMovedOp */ |
486 | | }; |
487 | | |
488 | | static const DOMJSClass sClass = { |
489 | | { "DedicatedWorkerGlobalScope", |
490 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_DOM_GLOBAL | JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(DOM_GLOBAL_SLOTS), |
491 | | &sClassOps, |
492 | | JS_NULL_CLASS_SPEC, |
493 | | &sClassExtension, |
494 | | JS_NULL_OBJECT_OPS |
495 | | }, |
496 | | { prototypes::id::EventTarget, prototypes::id::WorkerGlobalScope, prototypes::id::DedicatedWorkerGlobalScope, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
497 | | IsBaseOf<nsISupports, mozilla::dom::DedicatedWorkerGlobalScope >::value, |
498 | | &sEmptyNativePropertyHooks, |
499 | | FindAssociatedGlobalForNative<mozilla::dom::DedicatedWorkerGlobalScope>::Get, |
500 | | GetProtoObjectHandle, |
501 | | GetCCParticipant<mozilla::dom::DedicatedWorkerGlobalScope>::Get() |
502 | | }; |
503 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
504 | | "Must have the right minimal number of reserved slots."); |
505 | | static_assert(JSCLASS_GLOBAL_APPLICATION_SLOTS >= 3, |
506 | | "Must have enough reserved slots."); |
507 | | |
508 | | const JSClass* |
509 | | GetJSClass() |
510 | 0 | { |
511 | 0 | return sClass.ToJSClass(); |
512 | 0 | } |
513 | | |
514 | | bool |
515 | | Wrap(JSContext* aCx, mozilla::dom::DedicatedWorkerGlobalScope* aObject, nsWrapperCache* aCache, JS::RealmOptions& aOptions, JSPrincipals* aPrincipal, bool aInitStandardClasses, JS::MutableHandle<JSObject*> aReflector) |
516 | 0 | { |
517 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::DedicatedWorkerGlobalScope*>(aObject) == |
518 | 0 | reinterpret_cast<mozilla::dom::DedicatedWorkerGlobalScope*>(aObject), |
519 | 0 | "Multiple inheritance for mozilla::dom::DedicatedWorkerGlobalScope is broken."); |
520 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::WorkerGlobalScope*>(aObject) == |
521 | 0 | reinterpret_cast<mozilla::dom::WorkerGlobalScope*>(aObject), |
522 | 0 | "Multiple inheritance for mozilla::dom::WorkerGlobalScope is broken."); |
523 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
524 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
525 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
526 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
527 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
528 | 0 | "nsISupports must be on our primary inheritance chain"); |
529 | 0 |
|
530 | 0 | if (!CreateGlobal<mozilla::dom::DedicatedWorkerGlobalScope, GetProtoObjectHandle>(aCx, |
531 | 0 | aObject, |
532 | 0 | aCache, |
533 | 0 | sClass.ToJSClass(), |
534 | 0 | aOptions, |
535 | 0 | aPrincipal, |
536 | 0 | aInitStandardClasses, |
537 | 0 | aReflector)) { |
538 | 0 | aCache->ReleaseWrapper(aObject); |
539 | 0 | aCache->ClearWrapper(); |
540 | 0 | return false; |
541 | 0 | } |
542 | 0 | |
543 | 0 | // aReflector is a new global, so has a new realm. Enter it |
544 | 0 | // before doing anything with it. |
545 | 0 | JSAutoRealm ar(aCx, aReflector); |
546 | 0 |
|
547 | 0 | if (!DefineProperties(aCx, aReflector, sNativeProperties.Upcast(), nullptr)) { |
548 | 0 | aCache->ReleaseWrapper(aObject); |
549 | 0 | aCache->ClearWrapper(); |
550 | 0 | return false; |
551 | 0 | } |
552 | 0 | |
553 | 0 | |
554 | 0 | return true; |
555 | 0 | } |
556 | | |
557 | | void |
558 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
559 | 0 | { |
560 | 0 | JS::Handle<JSObject*> parentProto(WorkerGlobalScope_Binding::GetProtoObjectHandle(aCx)); |
561 | 0 | if (!parentProto) { |
562 | 0 | return; |
563 | 0 | } |
564 | 0 | |
565 | 0 | JS::Handle<JSObject*> constructorProto(WorkerGlobalScope_Binding::GetConstructorObjectHandle(aCx)); |
566 | 0 | if (!constructorProto) { |
567 | 0 | return; |
568 | 0 | } |
569 | 0 | |
570 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DedicatedWorkerGlobalScope); |
571 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::DedicatedWorkerGlobalScope); |
572 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
573 | 0 | &sPrototypeClass.mBase, protoCache, |
574 | 0 | nullptr, |
575 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
576 | 0 | interfaceCache, |
577 | 0 | sNativeProperties.Upcast(), |
578 | 0 | nullptr, |
579 | 0 | "DedicatedWorkerGlobalScope", aDefineOnGlobal, |
580 | 0 | nullptr, |
581 | 0 | true); |
582 | 0 |
|
583 | 0 | if (*&aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DedicatedWorkerGlobalScope)) { |
584 | 0 | bool succeeded; |
585 | 0 | JS::Handle<JSObject*> prot = GetProtoObjectHandle(aCx); |
586 | 0 | if (!JS_SetImmutablePrototype(aCx, prot, &succeeded)) { |
587 | 0 | *protoCache = nullptr; |
588 | 0 | if (interfaceCache) { |
589 | 0 | *interfaceCache = nullptr; |
590 | 0 | } |
591 | 0 | return; |
592 | 0 | } |
593 | 0 |
|
594 | 0 | MOZ_ASSERT(succeeded, |
595 | 0 | "making a fresh prototype object's [[Prototype]] " |
596 | 0 | "immutable can internally fail, but it should " |
597 | 0 | "never be unsuccessful"); |
598 | 0 | } |
599 | 0 | } |
600 | | |
601 | | JSObject* |
602 | | GetConstructorObject(JSContext* aCx) |
603 | 0 | { |
604 | 0 | return GetConstructorObjectHandle(aCx); |
605 | 0 | } |
606 | | |
607 | | } // namespace DedicatedWorkerGlobalScope_Binding |
608 | | |
609 | | |
610 | | |
611 | | } // namespace dom |
612 | | } // namespace mozilla |