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