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