/work/obj-fuzz/dom/bindings/WorkletGlobalScopeBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM WorkletGlobalScope.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "WorkletGlobalScopeBinding.h" |
4 | | #include "WrapperFactory.h" |
5 | | #include "mozilla/OwningNonNull.h" |
6 | | #include "mozilla/dom/BindingUtils.h" |
7 | | #include "mozilla/dom/DOMJSClass.h" |
8 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
9 | | #include "mozilla/dom/WorkletGlobalScope.h" |
10 | | |
11 | | namespace mozilla { |
12 | | namespace dom { |
13 | | |
14 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
15 | | using namespace mozilla::dom::binding_detail; |
16 | | |
17 | | |
18 | | namespace WorkletGlobalScope_Binding { |
19 | | |
20 | | MOZ_CAN_RUN_SCRIPT static bool |
21 | | dump(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkletGlobalScope* self, const JSJitMethodCallArgs& args) |
22 | 0 | { |
23 | 0 | AUTO_PROFILER_LABEL_FAST("WorkletGlobalScope.dump", DOM, cx); |
24 | 0 |
|
25 | 0 | Optional<nsAString> arg0; |
26 | 0 | binding_detail::FakeString arg0_holder; |
27 | 0 | if (args.hasDefined(0)) { |
28 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0_holder)) { |
29 | 0 | return false; |
30 | 0 | } |
31 | 0 | arg0 = &arg0_holder; |
32 | 0 | } |
33 | 0 | self->Dump(NonNullHelper(Constify(arg0))); |
34 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
35 | 0 | args.rval().setUndefined(); |
36 | 0 | return true; |
37 | 0 | } |
38 | | |
39 | | static const JSJitInfo dump_methodinfo = { |
40 | | { (JSJitGetterOp)dump }, |
41 | | { prototypes::id::WorkletGlobalScope }, |
42 | | { PrototypeTraits<prototypes::id::WorkletGlobalScope>::Depth }, |
43 | | JSJitInfo::Method, |
44 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
45 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
46 | | false, /* isInfallible. False in setters. */ |
47 | | false, /* isMovable. Not relevant for setters. */ |
48 | | false, /* isEliminatable. Not relevant for setters. */ |
49 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
50 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
51 | | false, /* isTypedMethod. Only relevant for methods. */ |
52 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
53 | | }; |
54 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
55 | | static_assert(0 < 1, "There is no slot for us"); |
56 | | |
57 | | static bool |
58 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
59 | 0 | { |
60 | 0 | mozilla::dom::WorkletGlobalScope* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WorkletGlobalScope>(obj); |
61 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
62 | 0 | // obviously can't preserve if we're not initialized. |
63 | 0 | if (self && self->GetWrapperPreserveColor()) { |
64 | 0 | PreserveWrapper(self); |
65 | 0 | } |
66 | 0 | return true; |
67 | 0 | } |
68 | | |
69 | | static void |
70 | | _finalize(js::FreeOp* fop, JSObject* obj) |
71 | 0 | { |
72 | 0 | mozilla::dom::WorkletGlobalScope* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WorkletGlobalScope>(obj); |
73 | 0 | if (self) { |
74 | 0 | ClearWrapper(self, self, obj); |
75 | 0 | AddForDeferredFinalization<mozilla::dom::WorkletGlobalScope>(self); |
76 | 0 | } |
77 | 0 | } |
78 | | |
79 | | static size_t |
80 | | _objectMoved(JSObject* obj, JSObject* old) |
81 | 0 | { |
82 | 0 | mozilla::dom::WorkletGlobalScope* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WorkletGlobalScope>(obj); |
83 | 0 | if (self) { |
84 | 0 | UpdateWrapper(self, self, obj, old); |
85 | 0 | } |
86 | 0 |
|
87 | 0 | return 0; |
88 | 0 | } |
89 | | |
90 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
91 | | #if defined(__clang__) |
92 | | #pragma clang diagnostic push |
93 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
94 | | #endif |
95 | | static const JSFunctionSpec sMethods_specs[] = { |
96 | | JS_FNSPEC("dump", (GenericMethod<MaybeGlobalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&dump_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
97 | | JS_FS_END |
98 | | }; |
99 | | #if defined(__clang__) |
100 | | #pragma clang diagnostic pop |
101 | | #endif |
102 | | |
103 | | |
104 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
105 | | { nullptr, &sMethods_specs[0] }, |
106 | | { nullptr, nullptr } |
107 | | }; |
108 | | |
109 | | |
110 | | static const NativePropertiesN<1> sNativeProperties = { |
111 | | false, 0, |
112 | | false, 0, |
113 | | true, 0 /* sMethods */, |
114 | | false, 0, |
115 | | false, 0, |
116 | | false, 0, |
117 | | false, 0, |
118 | | -1, |
119 | | 0, |
120 | | nullptr, |
121 | | { |
122 | | { sMethods, nullptr } |
123 | | } |
124 | | }; |
125 | | |
126 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
127 | | { |
128 | | "Function", |
129 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
130 | | &sBoringInterfaceObjectClassClassOps, |
131 | | JS_NULL_CLASS_SPEC, |
132 | | JS_NULL_CLASS_EXT, |
133 | | &sInterfaceObjectClassObjectOps |
134 | | }, |
135 | | eInterface, |
136 | | true, |
137 | | prototypes::id::WorkletGlobalScope, |
138 | | PrototypeTraits<prototypes::id::WorkletGlobalScope>::Depth, |
139 | | &sEmptyNativePropertyHooks, |
140 | | "function WorkletGlobalScope() {\n [native code]\n}", |
141 | | JS::GetRealmFunctionPrototype |
142 | | }; |
143 | | |
144 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
145 | | { |
146 | | "WorkletGlobalScopePrototype", |
147 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
148 | | JS_NULL_CLASS_OPS, |
149 | | JS_NULL_CLASS_SPEC, |
150 | | JS_NULL_CLASS_EXT, |
151 | | JS_NULL_OBJECT_OPS |
152 | | }, |
153 | | eInterfacePrototype, |
154 | | false, |
155 | | prototypes::id::WorkletGlobalScope, |
156 | | PrototypeTraits<prototypes::id::WorkletGlobalScope>::Depth, |
157 | | &sEmptyNativePropertyHooks, |
158 | | "[object WorkletGlobalScopePrototype]", |
159 | | JS::GetRealmObjectPrototype |
160 | | }; |
161 | | |
162 | | static const js::ClassOps sClassOps = { |
163 | | _addProperty, /* addProperty */ |
164 | | nullptr, /* delProperty */ |
165 | | nullptr, /* enumerate */ |
166 | | nullptr, /* newEnumerate */ |
167 | | nullptr, /* resolve */ |
168 | | nullptr, /* mayResolve */ |
169 | | _finalize, /* finalize */ |
170 | | nullptr, /* call */ |
171 | | nullptr, /* hasInstance */ |
172 | | nullptr, /* construct */ |
173 | | nullptr, /* trace */ |
174 | | }; |
175 | | |
176 | | static const js::ClassExtension sClassExtension = { |
177 | | nullptr, /* weakmapKeyDelegateOp */ |
178 | | _objectMoved /* objectMovedOp */ |
179 | | }; |
180 | | |
181 | | static const DOMJSClass sClass = { |
182 | | { "WorkletGlobalScope", |
183 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
184 | | &sClassOps, |
185 | | JS_NULL_CLASS_SPEC, |
186 | | &sClassExtension, |
187 | | JS_NULL_OBJECT_OPS |
188 | | }, |
189 | | { prototypes::id::WorkletGlobalScope, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
190 | | IsBaseOf<nsISupports, mozilla::dom::WorkletGlobalScope >::value, |
191 | | &sEmptyNativePropertyHooks, |
192 | | FindAssociatedGlobalForNative<mozilla::dom::WorkletGlobalScope>::Get, |
193 | | GetProtoObjectHandle, |
194 | | GetCCParticipant<mozilla::dom::WorkletGlobalScope>::Get() |
195 | | }; |
196 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
197 | | "Must have the right minimal number of reserved slots."); |
198 | | static_assert(1 >= 1, |
199 | | "Must have enough reserved slots."); |
200 | | |
201 | | const JSClass* |
202 | | GetJSClass() |
203 | 0 | { |
204 | 0 | return sClass.ToJSClass(); |
205 | 0 | } |
206 | | |
207 | | bool |
208 | | Wrap(JSContext* aCx, mozilla::dom::WorkletGlobalScope* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
209 | 0 | { |
210 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::WorkletGlobalScope>::value, |
211 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
212 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::WorkletGlobalScope*>(aObject) == |
213 | 0 | reinterpret_cast<mozilla::dom::WorkletGlobalScope*>(aObject), |
214 | 0 | "Multiple inheritance for mozilla::dom::WorkletGlobalScope is broken."); |
215 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
216 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
217 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
218 | 0 | "You should probably not be using Wrap() directly; use " |
219 | 0 | "GetOrCreateDOMReflector instead"); |
220 | 0 |
|
221 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
222 | 0 | "nsISupports must be on our primary inheritance chain"); |
223 | 0 |
|
224 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
225 | 0 | if (!global) { |
226 | 0 | return false; |
227 | 0 | } |
228 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
229 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
230 | 0 |
|
231 | 0 | // That might have ended up wrapping us already, due to the wonders |
232 | 0 | // of XBL. Check for that, and bail out as needed. |
233 | 0 | aReflector.set(aCache->GetWrapper()); |
234 | 0 | if (aReflector) { |
235 | | #ifdef DEBUG |
236 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
237 | | #endif // DEBUG |
238 | | return true; |
239 | 0 | } |
240 | 0 |
|
241 | 0 | JSAutoRealm ar(aCx, global); |
242 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
243 | 0 | if (!canonicalProto) { |
244 | 0 | return false; |
245 | 0 | } |
246 | 0 | JS::Rooted<JSObject*> proto(aCx); |
247 | 0 | if (aGivenProto) { |
248 | 0 | proto = aGivenProto; |
249 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
250 | 0 | // coming in, we changed compartments to that of "parent" so may need |
251 | 0 | // to wrap the proto here. |
252 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
253 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
254 | 0 | return false; |
255 | 0 | } |
256 | 0 | } |
257 | 0 | } else { |
258 | 0 | proto = canonicalProto; |
259 | 0 | } |
260 | 0 |
|
261 | 0 | BindingJSObjectCreator<mozilla::dom::WorkletGlobalScope> creator(aCx); |
262 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
263 | 0 | if (!aReflector) { |
264 | 0 | return false; |
265 | 0 | } |
266 | 0 | |
267 | 0 | aCache->SetWrapper(aReflector); |
268 | 0 | creator.InitializationSucceeded(); |
269 | 0 |
|
270 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
271 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
272 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
273 | 0 | // otherwise we won't be able to properly recreate it later, since |
274 | 0 | // we won't know what proto to use. Note that we don't check |
275 | 0 | // aGivenProto here, since it's entirely possible (and even |
276 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
277 | 0 | // same as canonicalProto. |
278 | 0 | if (proto != canonicalProto) { |
279 | 0 | PreserveWrapper(aObject); |
280 | 0 | } |
281 | 0 |
|
282 | 0 | return true; |
283 | 0 | } |
284 | | |
285 | | void |
286 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
287 | 0 | { |
288 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
289 | 0 | if (!parentProto) { |
290 | 0 | return; |
291 | 0 | } |
292 | 0 | |
293 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
294 | 0 | if (!constructorProto) { |
295 | 0 | return; |
296 | 0 | } |
297 | 0 | |
298 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WorkletGlobalScope); |
299 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WorkletGlobalScope); |
300 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
301 | 0 | &sPrototypeClass.mBase, protoCache, |
302 | 0 | nullptr, |
303 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
304 | 0 | interfaceCache, |
305 | 0 | sNativeProperties.Upcast(), |
306 | 0 | nullptr, |
307 | 0 | "WorkletGlobalScope", aDefineOnGlobal, |
308 | 0 | nullptr, |
309 | 0 | false); |
310 | 0 |
|
311 | 0 | if (*&aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WorkletGlobalScope)) { |
312 | 0 | bool succeeded; |
313 | 0 | JS::Handle<JSObject*> prot = GetProtoObjectHandle(aCx); |
314 | 0 | if (!JS_SetImmutablePrototype(aCx, prot, &succeeded)) { |
315 | 0 | *protoCache = nullptr; |
316 | 0 | if (interfaceCache) { |
317 | 0 | *interfaceCache = nullptr; |
318 | 0 | } |
319 | 0 | return; |
320 | 0 | } |
321 | 0 |
|
322 | 0 | MOZ_ASSERT(succeeded, |
323 | 0 | "making a fresh prototype object's [[Prototype]] " |
324 | 0 | "immutable can internally fail, but it should " |
325 | 0 | "never be unsuccessful"); |
326 | 0 | } |
327 | 0 | } |
328 | | |
329 | | JSObject* |
330 | | GetProtoObject(JSContext* aCx) |
331 | 0 | { |
332 | 0 | return GetProtoObjectHandle(aCx); |
333 | 0 | } |
334 | | |
335 | | JSObject* |
336 | | GetConstructorObject(JSContext* aCx) |
337 | 0 | { |
338 | 0 | return GetConstructorObjectHandle(aCx); |
339 | 0 | } |
340 | | |
341 | | } // namespace WorkletGlobalScope_Binding |
342 | | |
343 | | |
344 | | |
345 | | } // namespace dom |
346 | | } // namespace mozilla |