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