/work/obj-fuzz/dom/bindings/CompositionEventBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM CompositionEvent.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "CompositionEventBinding.h" |
5 | | #include "UIEventBinding.h" |
6 | | #include "WrapperFactory.h" |
7 | | #include "XrayWrapper.h" |
8 | | #include "mozilla/OwningNonNull.h" |
9 | | #include "mozilla/dom/BindingUtils.h" |
10 | | #include "mozilla/dom/CompositionEvent.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/SimpleGlobalObject.h" |
17 | | #include "mozilla/dom/TextClause.h" |
18 | | #include "mozilla/dom/XrayExpandoClass.h" |
19 | | #include "nsContentUtils.h" |
20 | | #include "nsGlobalWindow.h" |
21 | | |
22 | | namespace mozilla { |
23 | | namespace dom { |
24 | | |
25 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
26 | | using namespace mozilla::dom::binding_detail; |
27 | | |
28 | | |
29 | | |
30 | | CompositionEventInit::CompositionEventInit() |
31 | | : UIEventInit(FastDictionaryInitializer()) |
32 | 0 | { |
33 | 0 | // Safe to pass a null context if we pass a null value |
34 | 0 | Init(nullptr, JS::NullHandleValue); |
35 | 0 | } |
36 | | |
37 | | |
38 | | |
39 | | bool |
40 | | CompositionEventInit::InitIds(JSContext* cx, CompositionEventInitAtoms* atomsCache) |
41 | 0 | { |
42 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
43 | 0 |
|
44 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
45 | 0 | // uninitialized. |
46 | 0 | if (!atomsCache->data_id.init(cx, "data")) { |
47 | 0 | return false; |
48 | 0 | } |
49 | 0 | return true; |
50 | 0 | } |
51 | | |
52 | | bool |
53 | | CompositionEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
54 | 0 | { |
55 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
56 | 0 | // Since in that case we will not have to do any property gets |
57 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
58 | 0 | // checkers by static analysis tools |
59 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
60 | 0 | CompositionEventInitAtoms* atomsCache = nullptr; |
61 | 0 | if (cx) { |
62 | 0 | atomsCache = GetAtomCache<CompositionEventInitAtoms>(cx); |
63 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
64 | 0 | return false; |
65 | 0 | } |
66 | 0 | } |
67 | 0 | |
68 | 0 | // Per spec, we init the parent's members first |
69 | 0 | if (!UIEventInit::Init(cx, val)) { |
70 | 0 | return false; |
71 | 0 | } |
72 | 0 | |
73 | 0 | bool isNull = val.isNullOrUndefined(); |
74 | 0 | // We only need these if !isNull, in which case we have |cx|. |
75 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
76 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
77 | 0 | if (!isNull) { |
78 | 0 | MOZ_ASSERT(cx); |
79 | 0 | object.emplace(cx, &val.toObject()); |
80 | 0 | temp.emplace(cx); |
81 | 0 | } |
82 | 0 | if (!isNull) { |
83 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->data_id, temp.ptr())) { |
84 | 0 | return false; |
85 | 0 | } |
86 | 0 | } |
87 | 0 | if (!isNull && !temp->isUndefined()) { |
88 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mData)) { |
89 | 0 | return false; |
90 | 0 | } |
91 | 0 | } else { |
92 | 0 | static const char16_t data[] = { 0 }; |
93 | 0 | mData.Rebind(data, ArrayLength(data) - 1); |
94 | 0 | } |
95 | 0 | mIsAnyMemberPresent = true; |
96 | 0 | return true; |
97 | 0 | } |
98 | | |
99 | | bool |
100 | | CompositionEventInit::Init(const nsAString& aJSON) |
101 | 0 | { |
102 | 0 | AutoJSAPI jsapi; |
103 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
104 | 0 | if (!cleanGlobal) { |
105 | 0 | return false; |
106 | 0 | } |
107 | 0 | if (!jsapi.Init(cleanGlobal)) { |
108 | 0 | return false; |
109 | 0 | } |
110 | 0 | JSContext* cx = jsapi.cx(); |
111 | 0 | JS::Rooted<JS::Value> json(cx); |
112 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
113 | 0 | NS_ENSURE_TRUE(ok, false); |
114 | 0 | return Init(cx, json); |
115 | 0 | } |
116 | | |
117 | | bool |
118 | | CompositionEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
119 | 0 | { |
120 | 0 | CompositionEventInitAtoms* atomsCache = GetAtomCache<CompositionEventInitAtoms>(cx); |
121 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
122 | 0 | return false; |
123 | 0 | } |
124 | 0 | |
125 | 0 | // Per spec, we define the parent's members first |
126 | 0 | if (!UIEventInit::ToObjectInternal(cx, rval)) { |
127 | 0 | return false; |
128 | 0 | } |
129 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
130 | 0 |
|
131 | 0 | do { |
132 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
133 | 0 | JS::Rooted<JS::Value> temp(cx); |
134 | 0 | nsString const & currentValue = mData; |
135 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
136 | 0 | return false; |
137 | 0 | } |
138 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->data_id, temp, JSPROP_ENUMERATE)) { |
139 | 0 | return false; |
140 | 0 | } |
141 | 0 | break; |
142 | 0 | } while(false); |
143 | 0 |
|
144 | 0 | return true; |
145 | 0 | } |
146 | | |
147 | | bool |
148 | | CompositionEventInit::ToJSON(nsAString& aJSON) const |
149 | 0 | { |
150 | 0 | AutoJSAPI jsapi; |
151 | 0 | jsapi.Init(); |
152 | 0 | JSContext *cx = jsapi.cx(); |
153 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
154 | 0 | // because we'll only be creating objects, in ways that have no |
155 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
156 | 0 | // which likewise guarantees no side-effects for the sorts of |
157 | 0 | // things we will pass it. |
158 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
159 | 0 | JS::Rooted<JS::Value> val(cx); |
160 | 0 | if (!ToObjectInternal(cx, &val)) { |
161 | 0 | return false; |
162 | 0 | } |
163 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
164 | 0 | return StringifyToJSON(cx, obj, aJSON); |
165 | 0 | } |
166 | | |
167 | | void |
168 | | CompositionEventInit::TraceDictionary(JSTracer* trc) |
169 | 0 | { |
170 | 0 | UIEventInit::TraceDictionary(trc); |
171 | 0 | } |
172 | | |
173 | | |
174 | | |
175 | | CompositionEventInit& |
176 | | CompositionEventInit::operator=(const CompositionEventInit& aOther) |
177 | 0 | { |
178 | 0 | UIEventInit::operator=(aOther); |
179 | 0 | mData = aOther.mData; |
180 | 0 | return *this; |
181 | 0 | } |
182 | | |
183 | | namespace binding_detail { |
184 | | } // namespace binding_detail |
185 | | |
186 | | |
187 | | namespace CompositionEvent_Binding { |
188 | | |
189 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<UIEvent_Binding::NativeType>::value, |
190 | | "Can't inherit from an interface with a different ownership model."); |
191 | | |
192 | | MOZ_CAN_RUN_SCRIPT static bool |
193 | | get_data(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CompositionEvent* self, JSJitGetterCallArgs args) |
194 | 0 | { |
195 | 0 | AUTO_PROFILER_LABEL_FAST("get CompositionEvent.data", DOM, cx); |
196 | 0 |
|
197 | 0 | DOMString result; |
198 | 0 | self->GetData(result); |
199 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
200 | 0 | if (!xpc::StringToJsval(cx, result, args.rval())) { |
201 | 0 | return false; |
202 | 0 | } |
203 | 0 | return true; |
204 | 0 | } |
205 | | |
206 | | static const JSJitInfo data_getterinfo = { |
207 | | { (JSJitGetterOp)get_data }, |
208 | | { prototypes::id::CompositionEvent }, |
209 | | { PrototypeTraits<prototypes::id::CompositionEvent>::Depth }, |
210 | | JSJitInfo::Getter, |
211 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
212 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
213 | | false, /* isInfallible. False in setters. */ |
214 | | false, /* isMovable. Not relevant for setters. */ |
215 | | false, /* isEliminatable. Not relevant for setters. */ |
216 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
217 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
218 | | false, /* isTypedMethod. Only relevant for methods. */ |
219 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
220 | | }; |
221 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
222 | | static_assert(0 < 2, "There is no slot for us"); |
223 | | |
224 | | MOZ_CAN_RUN_SCRIPT static bool |
225 | | get_locale(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CompositionEvent* self, JSJitGetterCallArgs args) |
226 | 0 | { |
227 | 0 | AUTO_PROFILER_LABEL_FAST("get CompositionEvent.locale", DOM, cx); |
228 | 0 |
|
229 | 0 | DOMString result; |
230 | 0 | self->GetLocale(result); |
231 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
232 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
233 | 0 | return false; |
234 | 0 | } |
235 | 0 | return true; |
236 | 0 | } |
237 | | |
238 | | static const JSJitInfo locale_getterinfo = { |
239 | | { (JSJitGetterOp)get_locale }, |
240 | | { prototypes::id::CompositionEvent }, |
241 | | { PrototypeTraits<prototypes::id::CompositionEvent>::Depth }, |
242 | | JSJitInfo::Getter, |
243 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
244 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
245 | | false, /* isInfallible. False in setters. */ |
246 | | false, /* isMovable. Not relevant for setters. */ |
247 | | false, /* isEliminatable. Not relevant for setters. */ |
248 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
249 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
250 | | false, /* isTypedMethod. Only relevant for methods. */ |
251 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
252 | | }; |
253 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
254 | | static_assert(0 < 2, "There is no slot for us"); |
255 | | |
256 | | MOZ_CAN_RUN_SCRIPT static bool |
257 | | get_ranges(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CompositionEvent* self, JSJitGetterCallArgs args) |
258 | 0 | { |
259 | 0 | AUTO_PROFILER_LABEL_FAST("get CompositionEvent.ranges", DOM, cx); |
260 | 0 |
|
261 | 0 | // Have to either root across the getter call or reget after. |
262 | 0 | bool isXray; |
263 | 0 | JS::Rooted<JSObject*> slotStorage(cx, GetCachedSlotStorageObject(cx, obj, &isXray)); |
264 | 0 | if (!slotStorage) { |
265 | 0 | return false; |
266 | 0 | } |
267 | 0 | const size_t slotIndex = isXray ? (xpc::JSSLOT_EXPANDO_COUNT + 0) : (DOM_INSTANCE_RESERVED_SLOTS + 0); |
268 | 0 | MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex); |
269 | 0 | { |
270 | 0 | // Scope for cachedVal |
271 | 0 | JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex); |
272 | 0 | if (!cachedVal.isUndefined()) { |
273 | 0 | args.rval().set(cachedVal); |
274 | 0 | // The cached value is in the compartment of slotStorage, |
275 | 0 | // so wrap into the caller compartment as needed. |
276 | 0 | if (MaybeWrapNonDOMObjectValue(cx, args.rval())) { |
277 | 0 | return true; |
278 | 0 | } |
279 | 0 | return false; |
280 | 0 | } |
281 | 0 | } |
282 | 0 | |
283 | 0 | nsTArray<StrongPtrForMember<mozilla::dom::TextClause>::Type> result; |
284 | 0 | self->GetRanges(result); |
285 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
286 | 0 | { |
287 | 0 | JS::Rooted<JSObject*> conversionScope(cx, isXray ? JS::CurrentGlobalOrNull(cx) : slotStorage); |
288 | 0 | JSAutoRealm ar(cx, conversionScope); |
289 | 0 | do { // block we break out of when done wrapping |
290 | 0 |
|
291 | 0 | uint32_t length = result.Length(); |
292 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
293 | 0 | if (!returnArray) { |
294 | 0 | return false; |
295 | 0 | } |
296 | 0 | // Scope for 'tmp' |
297 | 0 | { |
298 | 0 | JS::Rooted<JS::Value> tmp(cx); |
299 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
300 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
301 | 0 | // are different ways to succeed at wrapping the object. |
302 | 0 | do { |
303 | 0 | if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) { |
304 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
305 | 0 | return false; |
306 | 0 | } |
307 | 0 | break; |
308 | 0 | } while (false); |
309 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
310 | 0 | JSPROP_ENUMERATE)) { |
311 | 0 | return false; |
312 | 0 | } |
313 | 0 | } |
314 | 0 | } |
315 | 0 | args.rval().setObject(*returnArray); |
316 | 0 | break; |
317 | 0 | } while (false); |
318 | 0 | } |
319 | 0 | { // And now store things in the realm of our slotStorage. |
320 | 0 | JSAutoRealm ar(cx, slotStorage); |
321 | 0 | // Make a copy so that we don't do unnecessary wrapping on args.rval(). |
322 | 0 | JS::Rooted<JS::Value> storedVal(cx, args.rval()); |
323 | 0 | if (!MaybeWrapNonDOMObjectValue(cx, &storedVal)) { |
324 | 0 | return false; |
325 | 0 | } |
326 | 0 | js::SetReservedSlot(slotStorage, slotIndex, storedVal); |
327 | 0 | if (!isXray) { |
328 | 0 | // In the Xray case we don't need to do this, because getting the |
329 | 0 | // expando object already preserved our wrapper. |
330 | 0 | PreserveWrapper(self); |
331 | 0 | } |
332 | 0 | } |
333 | 0 | // And now make sure args.rval() is in the caller realm. |
334 | 0 | if (MaybeWrapNonDOMObjectValue(cx, args.rval())) { |
335 | 0 | return true; |
336 | 0 | } |
337 | 0 | return false; |
338 | 0 | } |
339 | | |
340 | | static const JSJitInfo ranges_getterinfo = { |
341 | | { (JSJitGetterOp)get_ranges }, |
342 | | { prototypes::id::CompositionEvent }, |
343 | | { PrototypeTraits<prototypes::id::CompositionEvent>::Depth }, |
344 | | JSJitInfo::Getter, |
345 | | JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */ |
346 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
347 | | false, /* 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 | | true, /* isLazilyCachedInSlot. Only relevant for getters. */ |
352 | | false, /* isTypedMethod. Only relevant for methods. */ |
353 | | (DOM_INSTANCE_RESERVED_SLOTS + 0) /* Reserved slot index, if we're stored in a slot, else 0. */ |
354 | | }; |
355 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) <= JSJitInfo::maxSlotIndex, "We won't fit"); |
356 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) < 2, "There is no slot for us"); |
357 | | |
358 | | MOZ_CAN_RUN_SCRIPT static bool |
359 | | initCompositionEvent(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CompositionEvent* self, const JSJitMethodCallArgs& args) |
360 | 0 | { |
361 | 0 | AUTO_PROFILER_LABEL_FAST("CompositionEvent.initCompositionEvent", DOM, cx); |
362 | 0 |
|
363 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
364 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CompositionEvent.initCompositionEvent"); |
365 | 0 | } |
366 | 0 | binding_detail::FakeString arg0; |
367 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
368 | 0 | return false; |
369 | 0 | } |
370 | 0 | bool arg1; |
371 | 0 | if (args.hasDefined(1)) { |
372 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, args[1], &arg1)) { |
373 | 0 | return false; |
374 | 0 | } |
375 | 0 | } else { |
376 | 0 | arg1 = false; |
377 | 0 | } |
378 | 0 | bool arg2; |
379 | 0 | if (args.hasDefined(2)) { |
380 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, args[2], &arg2)) { |
381 | 0 | return false; |
382 | 0 | } |
383 | 0 | } else { |
384 | 0 | arg2 = false; |
385 | 0 | } |
386 | 0 | nsGlobalWindowInner* arg3; |
387 | 0 | if (args.hasDefined(3)) { |
388 | 0 | if (args[3].isObject()) { |
389 | 0 | { |
390 | 0 | nsresult rv = UnwrapObject<prototypes::id::Window, nsGlobalWindowInner>(args[3], arg3); |
391 | 0 | if (NS_FAILED(rv)) { |
392 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 4 of CompositionEvent.initCompositionEvent", "Window"); |
393 | 0 | return false; |
394 | 0 | } |
395 | 0 | } |
396 | 0 | } else if (args[3].isNullOrUndefined()) { |
397 | 0 | arg3 = nullptr; |
398 | 0 | } else { |
399 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 4 of CompositionEvent.initCompositionEvent"); |
400 | 0 | return false; |
401 | 0 | } |
402 | 0 | } else { |
403 | 0 | arg3 = nullptr; |
404 | 0 | } |
405 | 0 | binding_detail::FakeString arg4; |
406 | 0 | if (args.hasDefined(4)) { |
407 | 0 | if (!ConvertJSValueToString(cx, args[4], eNull, eNull, arg4)) { |
408 | 0 | return false; |
409 | 0 | } |
410 | 0 | } else { |
411 | 0 | arg4.SetIsVoid(true); |
412 | 0 | } |
413 | 0 | binding_detail::FakeString arg5; |
414 | 0 | if (args.hasDefined(5)) { |
415 | 0 | if (!ConvertJSValueToString(cx, args[5], eStringify, eStringify, arg5)) { |
416 | 0 | return false; |
417 | 0 | } |
418 | 0 | } else { |
419 | 0 | static const char16_t data[] = { 0 }; |
420 | 0 | arg5.Rebind(data, ArrayLength(data) - 1); |
421 | 0 | } |
422 | 0 | self->InitCompositionEvent(NonNullHelper(Constify(arg0)), arg1, arg2, MOZ_KnownLive(Constify(arg3)), NonNullHelper(Constify(arg4)), NonNullHelper(Constify(arg5))); |
423 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
424 | 0 | args.rval().setUndefined(); |
425 | 0 | return true; |
426 | 0 | } |
427 | | |
428 | | static const JSJitInfo initCompositionEvent_methodinfo = { |
429 | | { (JSJitGetterOp)initCompositionEvent }, |
430 | | { prototypes::id::CompositionEvent }, |
431 | | { PrototypeTraits<prototypes::id::CompositionEvent>::Depth }, |
432 | | JSJitInfo::Method, |
433 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
434 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
435 | | false, /* isInfallible. False in setters. */ |
436 | | false, /* isMovable. Not relevant for setters. */ |
437 | | false, /* isEliminatable. Not relevant for setters. */ |
438 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
439 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
440 | | false, /* isTypedMethod. Only relevant for methods. */ |
441 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
442 | | }; |
443 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
444 | | static_assert(0 < 2, "There is no slot for us"); |
445 | | |
446 | | MOZ_CAN_RUN_SCRIPT static bool |
447 | | get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CompositionEvent* self, JSJitGetterCallArgs args) |
448 | 0 | { |
449 | 0 | AUTO_PROFILER_LABEL_FAST("get CompositionEvent.isTrusted", DOM, cx); |
450 | 0 |
|
451 | 0 | bool result(self->IsTrusted()); |
452 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
453 | 0 | args.rval().setBoolean(result); |
454 | 0 | return true; |
455 | 0 | } |
456 | | |
457 | | static const JSJitInfo isTrusted_getterinfo = { |
458 | | { (JSJitGetterOp)get_isTrusted }, |
459 | | { prototypes::id::CompositionEvent }, |
460 | | { PrototypeTraits<prototypes::id::CompositionEvent>::Depth }, |
461 | | JSJitInfo::Getter, |
462 | | JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */ |
463 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
464 | | true, /* isInfallible. False in setters. */ |
465 | | true, /* isMovable. Not relevant for setters. */ |
466 | | true, /* isEliminatable. Not relevant for setters. */ |
467 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
468 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
469 | | false, /* isTypedMethod. Only relevant for methods. */ |
470 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
471 | | }; |
472 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
473 | | static_assert(0 < 2, "There is no slot for us"); |
474 | | |
475 | | static bool |
476 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
477 | 0 | { |
478 | 0 | mozilla::dom::CompositionEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CompositionEvent>(obj); |
479 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
480 | 0 | // obviously can't preserve if we're not initialized. |
481 | 0 | if (self && self->GetWrapperPreserveColor()) { |
482 | 0 | PreserveWrapper(self); |
483 | 0 | } |
484 | 0 | return true; |
485 | 0 | } |
486 | | |
487 | | static void |
488 | | _finalize(js::FreeOp* fop, JSObject* obj) |
489 | 0 | { |
490 | 0 | mozilla::dom::CompositionEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CompositionEvent>(obj); |
491 | 0 | if (self) { |
492 | 0 | ClearWrapper(self, self, obj); |
493 | 0 | AddForDeferredFinalization<mozilla::dom::CompositionEvent>(self); |
494 | 0 | } |
495 | 0 | } |
496 | | |
497 | | static size_t |
498 | | _objectMoved(JSObject* obj, JSObject* old) |
499 | 0 | { |
500 | 0 | mozilla::dom::CompositionEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CompositionEvent>(obj); |
501 | 0 | if (self) { |
502 | 0 | UpdateWrapper(self, self, obj, old); |
503 | 0 | } |
504 | 0 |
|
505 | 0 | return 0; |
506 | 0 | } |
507 | | |
508 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
509 | | #if defined(__clang__) |
510 | | #pragma clang diagnostic push |
511 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
512 | | #endif |
513 | | static const JSFunctionSpec sMethods_specs[] = { |
514 | | JS_FNSPEC("initCompositionEvent", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&initCompositionEvent_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
515 | | JS_FS_END |
516 | | }; |
517 | | #if defined(__clang__) |
518 | | #pragma clang diagnostic pop |
519 | | #endif |
520 | | |
521 | | |
522 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
523 | | { nullptr, &sMethods_specs[0] }, |
524 | | { nullptr, nullptr } |
525 | | }; |
526 | | |
527 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
528 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
529 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
530 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
531 | | |
532 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
533 | | #if defined(__clang__) |
534 | | #pragma clang diagnostic push |
535 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
536 | | #endif |
537 | | static const JSPropertySpec sAttributes_specs[] = { |
538 | | { "data", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &data_getterinfo, nullptr, nullptr }, |
539 | | { "locale", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &locale_getterinfo, nullptr, nullptr }, |
540 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
541 | | }; |
542 | | #if defined(__clang__) |
543 | | #pragma clang diagnostic pop |
544 | | #endif |
545 | | |
546 | | |
547 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
548 | | { nullptr, &sAttributes_specs[0] }, |
549 | | { nullptr, nullptr } |
550 | | }; |
551 | | |
552 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
553 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
554 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
555 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
556 | | |
557 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
558 | | #if defined(__clang__) |
559 | | #pragma clang diagnostic push |
560 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
561 | | #endif |
562 | | static const JSPropertySpec sChromeAttributes_specs[] = { |
563 | | { "ranges", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &ranges_getterinfo, nullptr, nullptr }, |
564 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
565 | | }; |
566 | | #if defined(__clang__) |
567 | | #pragma clang diagnostic pop |
568 | | #endif |
569 | | |
570 | | |
571 | | static const Prefable<const JSPropertySpec> sChromeAttributes[] = { |
572 | | { nullptr, &sChromeAttributes_specs[0] }, |
573 | | { nullptr, nullptr } |
574 | | }; |
575 | | |
576 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
577 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
578 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
579 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
580 | | |
581 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
582 | | #if defined(__clang__) |
583 | | #pragma clang diagnostic push |
584 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
585 | | #endif |
586 | | static const JSPropertySpec sUnforgeableAttributes_specs[] = { |
587 | | { "isTrusted", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isTrusted_getterinfo, nullptr, nullptr }, |
588 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
589 | | }; |
590 | | #if defined(__clang__) |
591 | | #pragma clang diagnostic pop |
592 | | #endif |
593 | | |
594 | | |
595 | | static const Prefable<const JSPropertySpec> sUnforgeableAttributes[] = { |
596 | | { nullptr, &sUnforgeableAttributes_specs[0] }, |
597 | | { nullptr, nullptr } |
598 | | }; |
599 | | |
600 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
601 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
602 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
603 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
604 | | |
605 | | |
606 | | static uint16_t sNativeProperties_sortedPropertyIndices[4]; |
607 | | static PropertyInfo sNativeProperties_propertyInfos[4]; |
608 | | |
609 | | static const NativePropertiesN<3> sNativeProperties = { |
610 | | false, 0, |
611 | | false, 0, |
612 | | true, 0 /* sMethods */, |
613 | | true, 1 /* sAttributes */, |
614 | | false, 0, |
615 | | true, 2 /* sUnforgeableAttributes */, |
616 | | false, 0, |
617 | | -1, |
618 | | 4, |
619 | | sNativeProperties_sortedPropertyIndices, |
620 | | { |
621 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
622 | | { sAttributes, &sNativeProperties_propertyInfos[1] }, |
623 | | { sUnforgeableAttributes, &sNativeProperties_propertyInfos[3] } |
624 | | } |
625 | | }; |
626 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
627 | | "We have a property info count that is oversized"); |
628 | | |
629 | | static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1]; |
630 | | static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1]; |
631 | | |
632 | | static const NativePropertiesN<1> sChromeOnlyNativeProperties = { |
633 | | false, 0, |
634 | | false, 0, |
635 | | false, 0, |
636 | | true, 0 /* sChromeAttributes */, |
637 | | false, 0, |
638 | | false, 0, |
639 | | false, 0, |
640 | | -1, |
641 | | 1, |
642 | | sChromeOnlyNativeProperties_sortedPropertyIndices, |
643 | | { |
644 | | { sChromeAttributes, &sChromeOnlyNativeProperties_propertyInfos[0] } |
645 | | } |
646 | | }; |
647 | | static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount), |
648 | | "We have a property info count that is oversized"); |
649 | | |
650 | | static bool |
651 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
652 | 0 | { |
653 | 0 | AUTO_PROFILER_LABEL_FAST("CompositionEvent constructor", DOM, cx); |
654 | 0 |
|
655 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
656 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
657 | 0 | if (!args.isConstructing()) { |
658 | 0 | // XXXbz wish I could get the name from the callee instead of |
659 | 0 | // Adding more relocations |
660 | 0 | return ThrowConstructorWithoutNew(cx, "CompositionEvent"); |
661 | 0 | } |
662 | 0 | |
663 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
664 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
665 | 0 | return false; |
666 | 0 | } |
667 | 0 | |
668 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
669 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "CompositionEvent"); |
670 | 0 | } |
671 | 0 | GlobalObject global(cx, obj); |
672 | 0 | if (global.Failed()) { |
673 | 0 | return false; |
674 | 0 | } |
675 | 0 | |
676 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
677 | 0 | binding_detail::FakeString arg0; |
678 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
679 | 0 | return false; |
680 | 0 | } |
681 | 0 | binding_detail::FastCompositionEventInit arg1; |
682 | 0 | if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of CompositionEvent.constructor", false)) { |
683 | 0 | return false; |
684 | 0 | } |
685 | 0 | Maybe<JSAutoRealm> ar; |
686 | 0 | if (objIsXray) { |
687 | 0 | obj = js::CheckedUnwrap(obj); |
688 | 0 | if (!obj) { |
689 | 0 | return false; |
690 | 0 | } |
691 | 0 | ar.emplace(cx, obj); |
692 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
693 | 0 | return false; |
694 | 0 | } |
695 | 0 | } |
696 | 0 | FastErrorResult rv; |
697 | 0 | auto result(StrongOrRawPtr<mozilla::dom::CompositionEvent>(mozilla::dom::CompositionEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv))); |
698 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
699 | 0 | return false; |
700 | 0 | } |
701 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
702 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
703 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
704 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
705 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
706 | 0 | return false; |
707 | 0 | } |
708 | 0 | return true; |
709 | 0 | } |
710 | | |
711 | | static const js::ClassOps sInterfaceObjectClassOps = { |
712 | | nullptr, /* addProperty */ |
713 | | nullptr, /* delProperty */ |
714 | | nullptr, /* enumerate */ |
715 | | nullptr, /* newEnumerate */ |
716 | | nullptr, /* resolve */ |
717 | | nullptr, /* mayResolve */ |
718 | | nullptr, /* finalize */ |
719 | | _constructor, /* call */ |
720 | | nullptr, /* hasInstance */ |
721 | | _constructor, /* construct */ |
722 | | nullptr, /* trace */ |
723 | | }; |
724 | | |
725 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
726 | | { |
727 | | "Function", |
728 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
729 | | &sInterfaceObjectClassOps, |
730 | | JS_NULL_CLASS_SPEC, |
731 | | JS_NULL_CLASS_EXT, |
732 | | &sInterfaceObjectClassObjectOps |
733 | | }, |
734 | | eInterface, |
735 | | true, |
736 | | prototypes::id::CompositionEvent, |
737 | | PrototypeTraits<prototypes::id::CompositionEvent>::Depth, |
738 | | sNativePropertyHooks, |
739 | | "function CompositionEvent() {\n [native code]\n}", |
740 | | UIEvent_Binding::GetConstructorObject |
741 | | }; |
742 | | |
743 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
744 | | { |
745 | | "CompositionEventPrototype", |
746 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */), |
747 | | JS_NULL_CLASS_OPS, |
748 | | JS_NULL_CLASS_SPEC, |
749 | | JS_NULL_CLASS_EXT, |
750 | | JS_NULL_OBJECT_OPS |
751 | | }, |
752 | | eInterfacePrototype, |
753 | | false, |
754 | | prototypes::id::CompositionEvent, |
755 | | PrototypeTraits<prototypes::id::CompositionEvent>::Depth, |
756 | | sNativePropertyHooks, |
757 | | "[object CompositionEventPrototype]", |
758 | | UIEvent_Binding::GetProtoObject |
759 | | }; |
760 | | |
761 | | static const js::ClassOps sClassOps = { |
762 | | _addProperty, /* addProperty */ |
763 | | nullptr, /* delProperty */ |
764 | | nullptr, /* enumerate */ |
765 | | nullptr, /* newEnumerate */ |
766 | | nullptr, /* resolve */ |
767 | | nullptr, /* mayResolve */ |
768 | | _finalize, /* finalize */ |
769 | | nullptr, /* call */ |
770 | | nullptr, /* hasInstance */ |
771 | | nullptr, /* construct */ |
772 | | nullptr, /* trace */ |
773 | | }; |
774 | | |
775 | | static const js::ClassExtension sClassExtension = { |
776 | | nullptr, /* weakmapKeyDelegateOp */ |
777 | | _objectMoved /* objectMovedOp */ |
778 | | }; |
779 | | |
780 | | static const DOMJSClass sClass = { |
781 | | { "CompositionEvent", |
782 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(2) | JSCLASS_SKIP_NURSERY_FINALIZE, |
783 | | &sClassOps, |
784 | | JS_NULL_CLASS_SPEC, |
785 | | &sClassExtension, |
786 | | JS_NULL_OBJECT_OPS |
787 | | }, |
788 | | { prototypes::id::Event, prototypes::id::UIEvent, prototypes::id::CompositionEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
789 | | IsBaseOf<nsISupports, mozilla::dom::CompositionEvent >::value, |
790 | | sNativePropertyHooks, |
791 | | FindAssociatedGlobalForNative<mozilla::dom::CompositionEvent>::Get, |
792 | | GetProtoObjectHandle, |
793 | | GetCCParticipant<mozilla::dom::CompositionEvent>::Get() |
794 | | }; |
795 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
796 | | "Must have the right minimal number of reserved slots."); |
797 | | static_assert(2 >= 2, |
798 | | "Must have enough reserved slots."); |
799 | | |
800 | | const JSClass* |
801 | | GetJSClass() |
802 | 0 | { |
803 | 0 | return sClass.ToJSClass(); |
804 | 0 | } |
805 | | |
806 | | bool |
807 | | Wrap(JSContext* aCx, mozilla::dom::CompositionEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
808 | 0 | { |
809 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::CompositionEvent>::value, |
810 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
811 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::CompositionEvent*>(aObject) == |
812 | 0 | reinterpret_cast<mozilla::dom::CompositionEvent*>(aObject), |
813 | 0 | "Multiple inheritance for mozilla::dom::CompositionEvent is broken."); |
814 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::UIEvent*>(aObject) == |
815 | 0 | reinterpret_cast<mozilla::dom::UIEvent*>(aObject), |
816 | 0 | "Multiple inheritance for mozilla::dom::UIEvent is broken."); |
817 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) == |
818 | 0 | reinterpret_cast<mozilla::dom::Event*>(aObject), |
819 | 0 | "Multiple inheritance for mozilla::dom::Event is broken."); |
820 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
821 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
822 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
823 | 0 | "You should probably not be using Wrap() directly; use " |
824 | 0 | "GetOrCreateDOMReflector instead"); |
825 | 0 |
|
826 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
827 | 0 | "nsISupports must be on our primary inheritance chain"); |
828 | 0 |
|
829 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
830 | 0 | if (!global) { |
831 | 0 | return false; |
832 | 0 | } |
833 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
834 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
835 | 0 |
|
836 | 0 | // That might have ended up wrapping us already, due to the wonders |
837 | 0 | // of XBL. Check for that, and bail out as needed. |
838 | 0 | aReflector.set(aCache->GetWrapper()); |
839 | 0 | if (aReflector) { |
840 | | #ifdef DEBUG |
841 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
842 | | #endif // DEBUG |
843 | | return true; |
844 | 0 | } |
845 | 0 |
|
846 | 0 | JSAutoRealm ar(aCx, global); |
847 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
848 | 0 | if (!canonicalProto) { |
849 | 0 | return false; |
850 | 0 | } |
851 | 0 | JS::Rooted<JSObject*> proto(aCx); |
852 | 0 | if (aGivenProto) { |
853 | 0 | proto = aGivenProto; |
854 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
855 | 0 | // coming in, we changed compartments to that of "parent" so may need |
856 | 0 | // to wrap the proto here. |
857 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
858 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
859 | 0 | return false; |
860 | 0 | } |
861 | 0 | } |
862 | 0 | } else { |
863 | 0 | proto = canonicalProto; |
864 | 0 | } |
865 | 0 |
|
866 | 0 | BindingJSObjectCreator<mozilla::dom::CompositionEvent> creator(aCx); |
867 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
868 | 0 | if (!aReflector) { |
869 | 0 | return false; |
870 | 0 | } |
871 | 0 | |
872 | 0 | aCache->SetWrapper(aReflector); |
873 | 0 |
|
874 | 0 | // Important: do unforgeable property setup after we have handed |
875 | 0 | // over ownership of the C++ object to obj as needed, so that if |
876 | 0 | // we fail and it ends up GCed it won't have problems in the |
877 | 0 | // finalizer trying to drop its ownership of the C++ object. |
878 | 0 | JS::Rooted<JSObject*> unforgeableHolder(aCx, |
879 | 0 | &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject()); |
880 | 0 | if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) { |
881 | 0 | aCache->ReleaseWrapper(aObject); |
882 | 0 | aCache->ClearWrapper(); |
883 | 0 | return false; |
884 | 0 | } |
885 | 0 | creator.InitializationSucceeded(); |
886 | 0 |
|
887 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
888 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
889 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
890 | 0 | // otherwise we won't be able to properly recreate it later, since |
891 | 0 | // we won't know what proto to use. Note that we don't check |
892 | 0 | // aGivenProto here, since it's entirely possible (and even |
893 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
894 | 0 | // same as canonicalProto. |
895 | 0 | if (proto != canonicalProto) { |
896 | 0 | PreserveWrapper(aObject); |
897 | 0 | } |
898 | 0 |
|
899 | 0 | return true; |
900 | 0 | } |
901 | | |
902 | | // This may allocate too many slots, because we only really need |
903 | | // slots for our non-interface-typed members that we cache. But |
904 | | // allocating slots only for those would make the slot index |
905 | | // computations much more complicated, so let's do this the simple |
906 | | // way for now. |
907 | | DEFINE_XRAY_EXPANDO_CLASS(static, sXrayExpandoObjectClass, 1); |
908 | | |
909 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
910 | | nullptr, |
911 | | nullptr, |
912 | | nullptr, |
913 | | { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() }, |
914 | | prototypes::id::CompositionEvent, |
915 | | constructors::id::CompositionEvent, |
916 | | UIEvent_Binding::sNativePropertyHooks, |
917 | | &sXrayExpandoObjectClass |
918 | | } }; |
919 | | |
920 | | void |
921 | | ClearCachedRangesValue(mozilla::dom::CompositionEvent* aObject) |
922 | 0 | { |
923 | 0 | JSObject* obj; |
924 | 0 | obj = aObject->GetWrapper(); |
925 | 0 | if (!obj) { |
926 | 0 | return; |
927 | 0 | } |
928 | 0 | js::SetReservedSlot(obj, (DOM_INSTANCE_RESERVED_SLOTS + 0), JS::UndefinedValue()); |
929 | 0 | xpc::ClearXrayExpandoSlots(obj, (xpc::JSSLOT_EXPANDO_COUNT + 0)); |
930 | 0 | } |
931 | | |
932 | | void |
933 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
934 | 0 | { |
935 | 0 | JS::Handle<JSObject*> parentProto(UIEvent_Binding::GetProtoObjectHandle(aCx)); |
936 | 0 | if (!parentProto) { |
937 | 0 | return; |
938 | 0 | } |
939 | 0 | |
940 | 0 | JS::Handle<JSObject*> constructorProto(UIEvent_Binding::GetConstructorObjectHandle(aCx)); |
941 | 0 | if (!constructorProto) { |
942 | 0 | return; |
943 | 0 | } |
944 | 0 | |
945 | 0 | static bool sIdsInited = false; |
946 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
947 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
948 | 0 | return; |
949 | 0 | } |
950 | 0 | if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) { |
951 | 0 | return; |
952 | 0 | } |
953 | 0 | sIdsInited = true; |
954 | 0 | } |
955 | 0 |
|
956 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::CompositionEvent); |
957 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::CompositionEvent); |
958 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
959 | 0 | &sPrototypeClass.mBase, protoCache, |
960 | 0 | nullptr, |
961 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr, |
962 | 0 | interfaceCache, |
963 | 0 | sNativeProperties.Upcast(), |
964 | 0 | sChromeOnlyNativeProperties.Upcast(), |
965 | 0 | "CompositionEvent", aDefineOnGlobal, |
966 | 0 | nullptr, |
967 | 0 | false); |
968 | 0 |
|
969 | 0 | JS::Rooted<JSObject*> unforgeableHolder(aCx); |
970 | 0 | { |
971 | 0 | JS::Rooted<JSObject*> holderProto(aCx, *protoCache); |
972 | 0 | unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto); |
973 | 0 | if (!unforgeableHolder) { |
974 | 0 | *protoCache = nullptr; |
975 | 0 | if (interfaceCache) { |
976 | 0 | *interfaceCache = nullptr; |
977 | 0 | } |
978 | 0 | return; |
979 | 0 | } |
980 | 0 | } |
981 | 0 |
|
982 | 0 | if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) { |
983 | 0 | *protoCache = nullptr; |
984 | 0 | if (interfaceCache) { |
985 | 0 | *interfaceCache = nullptr; |
986 | 0 | } |
987 | 0 | return; |
988 | 0 | } |
989 | 0 |
|
990 | 0 | if (*protoCache) { |
991 | 0 | js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE, |
992 | 0 | JS::ObjectValue(*unforgeableHolder)); |
993 | 0 | } |
994 | 0 | } |
995 | | |
996 | | JSObject* |
997 | | GetConstructorObject(JSContext* aCx) |
998 | 0 | { |
999 | 0 | return GetConstructorObjectHandle(aCx); |
1000 | 0 | } |
1001 | | |
1002 | | } // namespace CompositionEvent_Binding |
1003 | | |
1004 | | |
1005 | | |
1006 | | } // namespace dom |
1007 | | } // namespace mozilla |