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