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