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