Line data Source code
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 DedicatedWorkerGlobalScopeBinding {
19 :
20 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<WorkerGlobalScopeBinding::NativeType>::value,
21 : "Can't inherit from an interface with a different ownership model.");
22 :
23 : static bool
24 0 : get_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DedicatedWorkerGlobalScope* self, JSJitGetterCallArgs args)
25 : {
26 0 : DOMString result;
27 0 : self->GetName(result);
28 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
29 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
30 0 : return false;
31 : }
32 0 : return true;
33 : }
34 :
35 : static bool
36 0 : set_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DedicatedWorkerGlobalScope* self, JSJitSetterCallArgs args)
37 : {
38 0 : return JS_DefineProperty(cx, obj, "name", args[0], JSPROP_ENUMERATE);
39 : }
40 :
41 : static const JSJitInfo name_getterinfo = {
42 : { (JSJitGetterOp)get_name },
43 : { prototypes::id::DedicatedWorkerGlobalScope },
44 : { PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::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 < 3, "There is no slot for us");
58 : static const JSJitInfo name_setterinfo = {
59 : { (JSJitGetterOp)set_name },
60 : { prototypes::id::DedicatedWorkerGlobalScope },
61 : { PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth },
62 : JSJitInfo::Setter,
63 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
64 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
65 : false, /* isInfallible. False in setters. */
66 : false, /* isMovable. Not relevant for setters. */
67 : false, /* isEliminatable. Not relevant for setters. */
68 : false, /* isAlwaysInSlot. Only relevant for getters. */
69 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
70 : false, /* isTypedMethod. Only relevant for methods. */
71 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
72 : };
73 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
74 : static_assert(0 < 3, "There is no slot for us");
75 :
76 : static bool
77 0 : postMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DedicatedWorkerGlobalScope* self, const JSJitMethodCallArgs& args)
78 : {
79 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
80 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "DedicatedWorkerGlobalScope.postMessage");
81 : }
82 0 : JS::Rooted<JS::Value> arg0(cx);
83 0 : arg0 = args[0];
84 0 : binding_detail::AutoSequence<JSObject*> arg1;
85 0 : SequenceRooter<JSObject*> arg1_holder(cx, &arg1);
86 0 : if (args.hasDefined(1)) {
87 0 : if (args[1].isObject()) {
88 0 : JS::ForOfIterator iter(cx);
89 0 : if (!iter.init(args[1], JS::ForOfIterator::AllowNonIterable)) {
90 0 : return false;
91 : }
92 0 : if (!iter.valueIsIterable()) {
93 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 2 of DedicatedWorkerGlobalScope.postMessage");
94 0 : return false;
95 : }
96 0 : binding_detail::AutoSequence<JSObject*> &arr = arg1;
97 0 : JS::Rooted<JS::Value> temp(cx);
98 : while (true) {
99 : bool done;
100 0 : if (!iter.next(&temp, &done)) {
101 0 : return false;
102 : }
103 0 : if (done) {
104 0 : break;
105 : }
106 0 : JSObject** slotPtr = arr.AppendElement(mozilla::fallible);
107 0 : if (!slotPtr) {
108 0 : JS_ReportOutOfMemory(cx);
109 0 : return false;
110 : }
111 0 : JSObject*& slot = *slotPtr;
112 0 : if (temp.isObject()) {
113 0 : slot = &temp.toObject();
114 : } else {
115 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of argument 2 of DedicatedWorkerGlobalScope.postMessage");
116 0 : return false;
117 : }
118 0 : }
119 : } else {
120 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 2 of DedicatedWorkerGlobalScope.postMessage");
121 0 : return false;
122 : }
123 : } else {
124 : /* Array is already empty; nothing to do */
125 : }
126 0 : binding_detail::FastErrorResult rv;
127 0 : self->PostMessage(cx, arg0, Constify(arg1), rv);
128 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
129 0 : return false;
130 : }
131 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
132 0 : args.rval().setUndefined();
133 0 : return true;
134 : }
135 :
136 : static const JSJitInfo postMessage_methodinfo = {
137 : { (JSJitGetterOp)postMessage },
138 : { prototypes::id::DedicatedWorkerGlobalScope },
139 : { PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth },
140 : JSJitInfo::Method,
141 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
142 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
143 : false, /* isInfallible. False in setters. */
144 : false, /* isMovable. Not relevant for setters. */
145 : false, /* isEliminatable. Not relevant for setters. */
146 : false, /* isAlwaysInSlot. Only relevant for getters. */
147 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
148 : false, /* isTypedMethod. Only relevant for methods. */
149 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
150 : };
151 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
152 : static_assert(0 < 3, "There is no slot for us");
153 :
154 : static bool
155 0 : close(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DedicatedWorkerGlobalScope* self, const JSJitMethodCallArgs& args)
156 : {
157 0 : self->Close(cx);
158 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
159 0 : args.rval().setUndefined();
160 0 : return true;
161 : }
162 :
163 : static const JSJitInfo close_methodinfo = {
164 : { (JSJitGetterOp)close },
165 : { prototypes::id::DedicatedWorkerGlobalScope },
166 : { PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth },
167 : JSJitInfo::Method,
168 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
169 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
170 : true, /* isInfallible. False in setters. */
171 : false, /* isMovable. Not relevant for setters. */
172 : false, /* isEliminatable. Not relevant for setters. */
173 : false, /* isAlwaysInSlot. Only relevant for getters. */
174 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
175 : false, /* isTypedMethod. Only relevant for methods. */
176 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
177 : };
178 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
179 : static_assert(0 < 3, "There is no slot for us");
180 :
181 : static bool
182 0 : get_onmessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DedicatedWorkerGlobalScope* self, JSJitGetterCallArgs args)
183 : {
184 0 : RefPtr<EventHandlerNonNull> result(self->GetOnmessage());
185 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
186 0 : if (result) {
187 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
188 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
189 0 : return false;
190 : }
191 0 : return true;
192 : } else {
193 0 : args.rval().setNull();
194 0 : return true;
195 : }
196 : }
197 :
198 : static bool
199 0 : set_onmessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DedicatedWorkerGlobalScope* self, JSJitSetterCallArgs args)
200 : {
201 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
202 0 : if (args[0].isObject()) {
203 : { // scope for tempRoot
204 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
205 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
206 : }
207 : } else {
208 0 : arg0 = nullptr;
209 : }
210 0 : self->SetOnmessage(Constify(arg0));
211 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
212 :
213 0 : return true;
214 : }
215 :
216 : static const JSJitInfo onmessage_getterinfo = {
217 : { (JSJitGetterOp)get_onmessage },
218 : { prototypes::id::DedicatedWorkerGlobalScope },
219 : { PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth },
220 : JSJitInfo::Getter,
221 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
222 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
223 : false, /* isInfallible. False in setters. */
224 : false, /* isMovable. Not relevant for setters. */
225 : false, /* isEliminatable. Not relevant for setters. */
226 : false, /* isAlwaysInSlot. Only relevant for getters. */
227 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
228 : false, /* isTypedMethod. Only relevant for methods. */
229 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
230 : };
231 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
232 : static_assert(0 < 3, "There is no slot for us");
233 : static const JSJitInfo onmessage_setterinfo = {
234 : { (JSJitGetterOp)set_onmessage },
235 : { prototypes::id::DedicatedWorkerGlobalScope },
236 : { PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth },
237 : JSJitInfo::Setter,
238 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
239 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
240 : false, /* isInfallible. False in setters. */
241 : false, /* isMovable. Not relevant for setters. */
242 : false, /* isEliminatable. Not relevant for setters. */
243 : false, /* isAlwaysInSlot. Only relevant for getters. */
244 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
245 : false, /* isTypedMethod. Only relevant for methods. */
246 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
247 : };
248 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
249 : static_assert(0 < 3, "There is no slot for us");
250 :
251 : static bool
252 0 : genericMethod(JSContext* cx, unsigned argc, JS::Value* vp)
253 : {
254 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
255 0 : if (!args.thisv().isNullOrUndefined() && !args.thisv().isObject()) {
256 0 : return ThrowInvalidThis(cx, args, false, "DedicatedWorkerGlobalScope");
257 : }
258 0 : JS::Rooted<JSObject*> obj(cx, args.thisv().isObject() ? &args.thisv().toObject() : js::GetGlobalForObjectCrossCompartment(&args.callee()));
259 :
260 : mozilla::dom::DedicatedWorkerGlobalScope* self;
261 0 : JS::Rooted<JS::Value> rootSelf(cx, JS::ObjectValue(*obj));
262 : {
263 0 : nsresult rv = UnwrapObject<prototypes::id::DedicatedWorkerGlobalScope, mozilla::dom::DedicatedWorkerGlobalScope>(&rootSelf, self);
264 0 : if (NS_FAILED(rv)) {
265 0 : return ThrowInvalidThis(cx, args, rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO, "DedicatedWorkerGlobalScope");
266 : }
267 : }
268 0 : const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(args.calleev());
269 0 : MOZ_ASSERT(info->type() == JSJitInfo::Method);
270 0 : JSJitMethodOp method = info->method;
271 0 : bool ok = method(cx, obj, self, JSJitMethodCallArgs(args));
272 : #ifdef DEBUG
273 0 : if (ok) {
274 0 : AssertReturnTypeMatchesJitinfo(info, args.rval());
275 : }
276 : #endif
277 0 : return ok;
278 : }
279 :
280 : static bool
281 0 : genericGetter(JSContext* cx, unsigned argc, JS::Value* vp)
282 : {
283 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
284 0 : if (!args.thisv().isNullOrUndefined() && !args.thisv().isObject()) {
285 0 : return ThrowInvalidThis(cx, args, false, "DedicatedWorkerGlobalScope");
286 : }
287 0 : JS::Rooted<JSObject*> obj(cx, args.thisv().isObject() ? &args.thisv().toObject() : js::GetGlobalForObjectCrossCompartment(&args.callee()));
288 :
289 : mozilla::dom::DedicatedWorkerGlobalScope* self;
290 0 : JS::Rooted<JS::Value> rootSelf(cx, JS::ObjectValue(*obj));
291 : {
292 0 : nsresult rv = UnwrapObject<prototypes::id::DedicatedWorkerGlobalScope, mozilla::dom::DedicatedWorkerGlobalScope>(&rootSelf, self);
293 0 : if (NS_FAILED(rv)) {
294 0 : return ThrowInvalidThis(cx, args, rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO, "DedicatedWorkerGlobalScope");
295 : }
296 : }
297 0 : const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(args.calleev());
298 0 : MOZ_ASSERT(info->type() == JSJitInfo::Getter);
299 0 : JSJitGetterOp getter = info->getter;
300 0 : bool ok = getter(cx, obj, self, JSJitGetterCallArgs(args));
301 : #ifdef DEBUG
302 0 : if (ok) {
303 0 : AssertReturnTypeMatchesJitinfo(info, args.rval());
304 : }
305 : #endif
306 0 : return ok;
307 : }
308 :
309 : static bool
310 0 : genericSetter(JSContext* cx, unsigned argc, JS::Value* vp)
311 : {
312 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
313 0 : if (!args.thisv().isNullOrUndefined() && !args.thisv().isObject()) {
314 0 : return ThrowInvalidThis(cx, args, false, "DedicatedWorkerGlobalScope");
315 : }
316 0 : JS::Rooted<JSObject*> obj(cx, args.thisv().isObject() ? &args.thisv().toObject() : js::GetGlobalForObjectCrossCompartment(&args.callee()));
317 :
318 : mozilla::dom::DedicatedWorkerGlobalScope* self;
319 0 : JS::Rooted<JS::Value> rootSelf(cx, JS::ObjectValue(*obj));
320 : {
321 0 : nsresult rv = UnwrapObject<prototypes::id::DedicatedWorkerGlobalScope, mozilla::dom::DedicatedWorkerGlobalScope>(&rootSelf, self);
322 0 : if (NS_FAILED(rv)) {
323 0 : return ThrowInvalidThis(cx, args, rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO, "DedicatedWorkerGlobalScope");
324 : }
325 : }
326 0 : if (args.length() == 0) {
327 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "DedicatedWorkerGlobalScope attribute setter");
328 : }
329 0 : const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(args.calleev());
330 0 : MOZ_ASSERT(info->type() == JSJitInfo::Setter);
331 0 : JSJitSetterOp setter = info->setter;
332 0 : if (!setter(cx, obj, self, JSJitSetterCallArgs(args))) {
333 0 : return false;
334 : }
335 0 : args.rval().setUndefined();
336 : #ifdef DEBUG
337 0 : AssertReturnTypeMatchesJitinfo(info, args.rval());
338 : #endif
339 0 : return true;
340 : }
341 :
342 : static void
343 0 : _finalize(js::FreeOp* fop, JSObject* obj)
344 : {
345 0 : mozilla::dom::DedicatedWorkerGlobalScope* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DedicatedWorkerGlobalScope>(obj);
346 0 : if (self) {
347 0 : ClearWrapper(self, self, obj);
348 0 : mozilla::dom::FinalizeGlobal(CastToJSFreeOp(fop), obj);
349 0 : AddForDeferredFinalization<mozilla::dom::DedicatedWorkerGlobalScope>(self);
350 : }
351 0 : }
352 :
353 : static void
354 0 : _objectMoved(JSObject* obj, const JSObject* old)
355 : {
356 0 : mozilla::dom::DedicatedWorkerGlobalScope* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DedicatedWorkerGlobalScope>(obj);
357 0 : if (self) {
358 0 : UpdateWrapper(self, self, obj, old);
359 : }
360 0 : }
361 :
362 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
363 : #if defined(__clang__)
364 : #pragma clang diagnostic push
365 : #pragma clang diagnostic ignored "-Wmissing-braces"
366 : #endif
367 : static const JSFunctionSpec sMethods_specs[] = {
368 : JS_FNSPEC("postMessage", genericMethod, reinterpret_cast<const JSJitInfo*>(&postMessage_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
369 : JS_FNSPEC("close", genericMethod, reinterpret_cast<const JSJitInfo*>(&close_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
370 : JS_FS_END
371 : };
372 : #if defined(__clang__)
373 : #pragma clang diagnostic pop
374 : #endif
375 :
376 :
377 : // Can't be const because the pref-enabled boolean needs to be writable
378 : static Prefable<const JSFunctionSpec> sMethods[] = {
379 : { nullptr, &sMethods_specs[0] },
380 : { nullptr, nullptr }
381 : };
382 :
383 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
384 : #if defined(__clang__)
385 : #pragma clang diagnostic push
386 : #pragma clang diagnostic ignored "-Wmissing-braces"
387 : #endif
388 : static const JSPropertySpec sAttributes_specs[] = {
389 : { "name", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &name_getterinfo, genericSetter, &name_setterinfo },
390 : { "onmessage", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &onmessage_getterinfo, genericSetter, &onmessage_setterinfo },
391 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
392 : };
393 : #if defined(__clang__)
394 : #pragma clang diagnostic pop
395 : #endif
396 :
397 :
398 : // Can't be const because the pref-enabled boolean needs to be writable
399 : static Prefable<const JSPropertySpec> sAttributes[] = {
400 : { nullptr, &sAttributes_specs[0] },
401 : { nullptr, nullptr }
402 : };
403 :
404 :
405 : static const NativePropertiesN<2> sNativeProperties = {
406 : false, 0,
407 : false, 0,
408 : true, 0 /* sMethods */,
409 : true, 1 /* sAttributes */,
410 : false, 0,
411 : false, 0,
412 : false, 0,
413 : -1,
414 : 0,
415 : nullptr,
416 : {
417 : { sMethods, nullptr },
418 : { sAttributes, nullptr }
419 : }
420 : };
421 :
422 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
423 : {
424 : "Function",
425 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
426 : &sBoringInterfaceObjectClassClassOps,
427 : JS_NULL_CLASS_SPEC,
428 : JS_NULL_CLASS_EXT,
429 : &sInterfaceObjectClassObjectOps
430 : },
431 : eInterface,
432 : true,
433 : prototypes::id::DedicatedWorkerGlobalScope,
434 : PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth,
435 : &sEmptyNativePropertyHooks,
436 : "function DedicatedWorkerGlobalScope() {\n [native code]\n}",
437 : WorkerGlobalScopeBinding::GetConstructorObject
438 : };
439 :
440 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
441 : {
442 : "DedicatedWorkerGlobalScopePrototype",
443 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
444 : JS_NULL_CLASS_OPS,
445 : JS_NULL_CLASS_SPEC,
446 : JS_NULL_CLASS_EXT,
447 : JS_NULL_OBJECT_OPS
448 : },
449 : eGlobalInterfacePrototype,
450 : false,
451 : prototypes::id::DedicatedWorkerGlobalScope,
452 : PrototypeTraits<prototypes::id::DedicatedWorkerGlobalScope>::Depth,
453 : &sEmptyNativePropertyHooks,
454 : "[object DedicatedWorkerGlobalScopePrototype]",
455 : WorkerGlobalScopeBinding::GetProtoObject
456 : };
457 :
458 : bool
459 1 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
460 : {
461 1 : MOZ_ASSERT(!NS_IsMainThread(), "Why did we even get called?");
462 :
463 1 : const char* name = js::GetObjectClass(aObj)->name;
464 1 : if (strcmp(name, "DedicatedWorkerGlobalScope")) {
465 0 : return false;
466 : }
467 :
468 1 : return true;
469 : }
470 :
471 : static const js::ClassOps sClassOps = {
472 : nullptr, /* addProperty */
473 : nullptr, /* delProperty */
474 : nullptr, /* getProperty */
475 : nullptr, /* setProperty */
476 : nullptr, /* enumerate */
477 : mozilla::dom::EnumerateGlobal, /* newEnumerate */
478 : mozilla::dom::ResolveGlobal, /* resolve */
479 : mozilla::dom::MayResolveGlobal, /* mayResolve */
480 : _finalize, /* finalize */
481 : nullptr, /* call */
482 : nullptr, /* hasInstance */
483 : nullptr, /* construct */
484 : JS_GlobalObjectTraceHook, /* trace */
485 : };
486 :
487 : static const js::ClassExtension sClassExtension = {
488 : nullptr, /* weakmapKeyDelegateOp */
489 : _objectMoved /* objectMovedOp */
490 : };
491 :
492 : static const DOMJSClass sClass = {
493 : { "DedicatedWorkerGlobalScope",
494 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_DOM_GLOBAL | JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(DOM_GLOBAL_SLOTS),
495 : &sClassOps,
496 : JS_NULL_CLASS_SPEC,
497 : &sClassExtension,
498 : JS_NULL_OBJECT_OPS
499 : },
500 : { 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 },
501 : IsBaseOf<nsISupports, mozilla::dom::DedicatedWorkerGlobalScope >::value,
502 : &sEmptyNativePropertyHooks,
503 : FindAssociatedGlobalForNative<mozilla::dom::DedicatedWorkerGlobalScope>::Get,
504 : GetProtoObjectHandle,
505 : GetCCParticipant<mozilla::dom::DedicatedWorkerGlobalScope>::Get()
506 : };
507 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
508 : "Must have the right minimal number of reserved slots.");
509 : static_assert(JSCLASS_GLOBAL_APPLICATION_SLOTS >= 3,
510 : "Must have enough reserved slots.");
511 :
512 : const JSClass*
513 0 : GetJSClass()
514 : {
515 0 : return sClass.ToJSClass();
516 : }
517 :
518 : bool
519 1 : Wrap(JSContext* aCx, mozilla::dom::DedicatedWorkerGlobalScope* aObject, nsWrapperCache* aCache, JS::CompartmentOptions& aOptions, JSPrincipals* aPrincipal, bool aInitStandardClasses, JS::MutableHandle<JSObject*> aReflector)
520 : {
521 : MOZ_ASSERT(static_cast<mozilla::dom::DedicatedWorkerGlobalScope*>(aObject) ==
522 : reinterpret_cast<mozilla::dom::DedicatedWorkerGlobalScope*>(aObject),
523 : "Multiple inheritance for mozilla::dom::DedicatedWorkerGlobalScope is broken.");
524 : MOZ_ASSERT(static_cast<mozilla::dom::WorkerGlobalScope*>(aObject) ==
525 : reinterpret_cast<mozilla::dom::WorkerGlobalScope*>(aObject),
526 : "Multiple inheritance for mozilla::dom::WorkerGlobalScope is broken.");
527 : MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
528 : reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
529 : "Multiple inheritance for mozilla::dom::EventTarget is broken.");
530 1 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
531 1 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
532 : "nsISupports must be on our primary inheritance chain");
533 :
534 1 : if (!CreateGlobal<mozilla::dom::DedicatedWorkerGlobalScope, GetProtoObjectHandle>(aCx,
535 : aObject,
536 : aCache,
537 : sClass.ToJSClass(),
538 : aOptions,
539 : aPrincipal,
540 : aInitStandardClasses,
541 : aReflector)) {
542 0 : aCache->ReleaseWrapper(aObject);
543 0 : aCache->ClearWrapper();
544 0 : return false;
545 : }
546 :
547 : // aReflector is a new global, so has a new compartment. Enter it
548 : // before doing anything with it.
549 2 : JSAutoCompartment ac(aCx, aReflector);
550 :
551 1 : if (!DefineProperties(aCx, aReflector, sNativeProperties.Upcast(), nullptr)) {
552 0 : aCache->ReleaseWrapper(aObject);
553 0 : aCache->ClearWrapper();
554 0 : return false;
555 : }
556 :
557 :
558 1 : return true;
559 : }
560 :
561 : void
562 1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
563 : {
564 1 : JS::Handle<JSObject*> parentProto(WorkerGlobalScopeBinding::GetProtoObjectHandle(aCx));
565 1 : if (!parentProto) {
566 0 : return;
567 : }
568 :
569 1 : JS::Handle<JSObject*> constructorProto(WorkerGlobalScopeBinding::GetConstructorObjectHandle(aCx));
570 1 : if (!constructorProto) {
571 0 : return;
572 : }
573 :
574 1 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DedicatedWorkerGlobalScope);
575 1 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::DedicatedWorkerGlobalScope);
576 1 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
577 : &sPrototypeClass.mBase, protoCache,
578 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
579 : interfaceCache,
580 : sNativeProperties.Upcast(),
581 : nullptr,
582 : "DedicatedWorkerGlobalScope", aDefineOnGlobal,
583 : nullptr,
584 1 : true);
585 :
586 1 : if (*&aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DedicatedWorkerGlobalScope)) {
587 : bool succeeded;
588 1 : JS::Handle<JSObject*> prot = GetProtoObjectHandle(aCx);
589 1 : if (!JS_SetImmutablePrototype(aCx, prot, &succeeded)) {
590 0 : *protoCache = nullptr;
591 0 : if (interfaceCache) {
592 0 : *interfaceCache = nullptr;
593 : }
594 0 : return;
595 : }
596 :
597 1 : MOZ_ASSERT(succeeded,
598 : "making a fresh prototype object's [[Prototype]] "
599 : "immutable can internally fail, but it should "
600 : "never be unsuccessful");
601 : }
602 : }
603 :
604 : JS::Handle<JSObject*>
605 2 : GetProtoObjectHandle(JSContext* aCx)
606 : {
607 : /* Get the interface prototype object for this class. This will create the
608 : object as needed. */
609 2 : bool aDefineOnGlobal = true;
610 :
611 : /* Make sure our global is sane. Hopefully we can remove this sometime */
612 2 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
613 2 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
614 0 : return nullptr;
615 : }
616 :
617 : /* Check to see whether the interface objects are already installed */
618 2 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
619 2 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::DedicatedWorkerGlobalScope)) {
620 2 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
621 1 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
622 : }
623 :
624 : /*
625 : * The object might _still_ be null, but that's OK.
626 : *
627 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
628 : * traced by TraceProtoAndIfaceCache() and its contents are never
629 : * changed after they have been set.
630 : *
631 : * Calling address() avoids the read read barrier that does gray
632 : * unmarking, but it's not possible for the object to be gray here.
633 : */
634 :
635 2 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::DedicatedWorkerGlobalScope);
636 2 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
637 2 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
638 : }
639 :
640 : JS::Handle<JSObject*>
641 1 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
642 : {
643 : /* Get the interface object for this class. This will create the object as
644 : needed. */
645 :
646 : /* Make sure our global is sane. Hopefully we can remove this sometime */
647 1 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
648 1 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
649 0 : return nullptr;
650 : }
651 :
652 : /* Check to see whether the interface objects are already installed */
653 1 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
654 1 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::DedicatedWorkerGlobalScope)) {
655 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
656 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
657 : }
658 :
659 : /*
660 : * The object might _still_ be null, but that's OK.
661 : *
662 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
663 : * traced by TraceProtoAndIfaceCache() and its contents are never
664 : * changed after they have been set.
665 : *
666 : * Calling address() avoids the read read barrier that does gray
667 : * unmarking, but it's not possible for the object to be gray here.
668 : */
669 :
670 1 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::DedicatedWorkerGlobalScope);
671 1 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
672 1 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
673 : }
674 :
675 : JSObject*
676 1 : GetConstructorObject(JSContext* aCx)
677 : {
678 1 : return GetConstructorObjectHandle(aCx);
679 : }
680 :
681 : } // namespace DedicatedWorkerGlobalScopeBinding
682 :
683 :
684 :
685 : } // namespace dom
686 : } // namespace mozilla
|