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