/work/obj-fuzz/dom/bindings/ClientBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM Client.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "ClientBinding.h" |
4 | | #include "WrapperFactory.h" |
5 | | #include "jsapi.h" |
6 | | #include "mozilla/OwningNonNull.h" |
7 | | #include "mozilla/dom/BindingUtils.h" |
8 | | #include "mozilla/dom/Client.h" |
9 | | #include "mozilla/dom/DOMJSClass.h" |
10 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
11 | | #include "mozilla/dom/PrimitiveConversions.h" |
12 | | #include "mozilla/dom/Promise.h" |
13 | | #include "mozilla/dom/ToJSValue.h" |
14 | | #include "nsThreadUtils.h" |
15 | | |
16 | | namespace mozilla { |
17 | | namespace dom { |
18 | | |
19 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
20 | | using namespace mozilla::dom::binding_detail; |
21 | | |
22 | | |
23 | | namespace FrameTypeValues { |
24 | | extern const EnumEntry strings[5] = { |
25 | | {"auxiliary", 9}, |
26 | | {"top-level", 9}, |
27 | | {"nested", 6}, |
28 | | {"none", 4}, |
29 | | { nullptr, 0 } |
30 | | }; |
31 | | } // namespace FrameTypeValues |
32 | | |
33 | | bool |
34 | | ToJSValue(JSContext* aCx, FrameType aArgument, JS::MutableHandle<JS::Value> aValue) |
35 | 0 | { |
36 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(FrameTypeValues::strings)); |
37 | 0 | JSString* resultStr = |
38 | 0 | JS_NewStringCopyN(aCx, FrameTypeValues::strings[uint32_t(aArgument)].value, |
39 | 0 | FrameTypeValues::strings[uint32_t(aArgument)].length); |
40 | 0 | if (!resultStr) { |
41 | 0 | return false; |
42 | 0 | } |
43 | 0 | aValue.setString(resultStr); |
44 | 0 | return true; |
45 | 0 | } |
46 | | |
47 | | |
48 | | namespace Client_Binding { |
49 | | |
50 | | MOZ_CAN_RUN_SCRIPT static bool |
51 | | get_url(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Client* self, JSJitGetterCallArgs args) |
52 | 0 | { |
53 | 0 | AUTO_PROFILER_LABEL_FAST("get Client.url", DOM, cx); |
54 | 0 |
|
55 | 0 | DOMString result; |
56 | 0 | self->GetUrl(result); |
57 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
58 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
59 | 0 | return false; |
60 | 0 | } |
61 | 0 | return true; |
62 | 0 | } |
63 | | |
64 | | static const JSJitInfo url_getterinfo = { |
65 | | { (JSJitGetterOp)get_url }, |
66 | | { prototypes::id::Client }, |
67 | | { PrototypeTraits<prototypes::id::Client>::Depth }, |
68 | | JSJitInfo::Getter, |
69 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
70 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
71 | | false, /* isInfallible. False in setters. */ |
72 | | false, /* isMovable. Not relevant for setters. */ |
73 | | false, /* isEliminatable. Not relevant for setters. */ |
74 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
75 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
76 | | false, /* isTypedMethod. Only relevant for methods. */ |
77 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
78 | | }; |
79 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
80 | | static_assert(0 < 1, "There is no slot for us"); |
81 | | |
82 | | MOZ_CAN_RUN_SCRIPT static bool |
83 | | get_frameType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Client* self, JSJitGetterCallArgs args) |
84 | 0 | { |
85 | 0 | AUTO_PROFILER_LABEL_FAST("get Client.frameType", DOM, cx); |
86 | 0 |
|
87 | 0 | FrameType result(self->GetFrameType()); |
88 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
89 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
90 | 0 | return false; |
91 | 0 | } |
92 | 0 | return true; |
93 | 0 | } |
94 | | |
95 | | static const JSJitInfo frameType_getterinfo = { |
96 | | { (JSJitGetterOp)get_frameType }, |
97 | | { prototypes::id::Client }, |
98 | | { PrototypeTraits<prototypes::id::Client>::Depth }, |
99 | | JSJitInfo::Getter, |
100 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
101 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
102 | | false, /* isInfallible. False in setters. */ |
103 | | false, /* isMovable. Not relevant for setters. */ |
104 | | false, /* isEliminatable. Not relevant for setters. */ |
105 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
106 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
107 | | false, /* isTypedMethod. Only relevant for methods. */ |
108 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
109 | | }; |
110 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
111 | | static_assert(0 < 1, "There is no slot for us"); |
112 | | |
113 | | MOZ_CAN_RUN_SCRIPT static bool |
114 | | get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Client* self, JSJitGetterCallArgs args) |
115 | 0 | { |
116 | 0 | AUTO_PROFILER_LABEL_FAST("get Client.type", DOM, cx); |
117 | 0 |
|
118 | 0 | ClientType result(self->Type()); |
119 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
120 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
121 | 0 | return false; |
122 | 0 | } |
123 | 0 | return true; |
124 | 0 | } |
125 | | |
126 | | static const JSJitInfo type_getterinfo = { |
127 | | { (JSJitGetterOp)get_type }, |
128 | | { prototypes::id::Client }, |
129 | | { PrototypeTraits<prototypes::id::Client>::Depth }, |
130 | | JSJitInfo::Getter, |
131 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
132 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
133 | | false, /* isInfallible. False in setters. */ |
134 | | false, /* isMovable. Not relevant for setters. */ |
135 | | false, /* isEliminatable. Not relevant for setters. */ |
136 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
137 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
138 | | false, /* isTypedMethod. Only relevant for methods. */ |
139 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
140 | | }; |
141 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
142 | | static_assert(0 < 1, "There is no slot for us"); |
143 | | |
144 | | MOZ_CAN_RUN_SCRIPT static bool |
145 | | get_id(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Client* self, JSJitGetterCallArgs args) |
146 | 0 | { |
147 | 0 | AUTO_PROFILER_LABEL_FAST("get Client.id", DOM, cx); |
148 | 0 |
|
149 | 0 | DOMString result; |
150 | 0 | self->GetId(result); |
151 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
152 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
153 | 0 | return false; |
154 | 0 | } |
155 | 0 | return true; |
156 | 0 | } |
157 | | |
158 | | static const JSJitInfo id_getterinfo = { |
159 | | { (JSJitGetterOp)get_id }, |
160 | | { prototypes::id::Client }, |
161 | | { PrototypeTraits<prototypes::id::Client>::Depth }, |
162 | | JSJitInfo::Getter, |
163 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
164 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
165 | | false, /* isInfallible. False in setters. */ |
166 | | false, /* isMovable. Not relevant for setters. */ |
167 | | false, /* isEliminatable. Not relevant for setters. */ |
168 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
169 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
170 | | false, /* isTypedMethod. Only relevant for methods. */ |
171 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
172 | | }; |
173 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
174 | | static_assert(0 < 1, "There is no slot for us"); |
175 | | |
176 | | MOZ_CAN_RUN_SCRIPT static bool |
177 | | postMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Client* self, const JSJitMethodCallArgs& args) |
178 | 0 | { |
179 | 0 | AUTO_PROFILER_LABEL_FAST("Client.postMessage", DOM, cx); |
180 | 0 |
|
181 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
182 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Client.postMessage"); |
183 | 0 | } |
184 | 0 | JS::Rooted<JS::Value> arg0(cx); |
185 | 0 | arg0 = args[0]; |
186 | 0 | binding_detail::AutoSequence<JSObject*> arg1; |
187 | 0 | SequenceRooter<JSObject*> arg1_holder(cx, &arg1); |
188 | 0 | if (args.hasDefined(1)) { |
189 | 0 | if (args[1].isObject()) { |
190 | 0 | JS::ForOfIterator iter(cx); |
191 | 0 | if (!iter.init(args[1], JS::ForOfIterator::AllowNonIterable)) { |
192 | 0 | return false; |
193 | 0 | } |
194 | 0 | if (!iter.valueIsIterable()) { |
195 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 2 of Client.postMessage"); |
196 | 0 | return false; |
197 | 0 | } |
198 | 0 | binding_detail::AutoSequence<JSObject*> &arr = arg1; |
199 | 0 | JS::Rooted<JS::Value> temp(cx); |
200 | 0 | while (true) { |
201 | 0 | bool done; |
202 | 0 | if (!iter.next(&temp, &done)) { |
203 | 0 | return false; |
204 | 0 | } |
205 | 0 | if (done) { |
206 | 0 | break; |
207 | 0 | } |
208 | 0 | JSObject** slotPtr = arr.AppendElement(mozilla::fallible); |
209 | 0 | if (!slotPtr) { |
210 | 0 | JS_ReportOutOfMemory(cx); |
211 | 0 | return false; |
212 | 0 | } |
213 | 0 | JSObject*& slot = *slotPtr; |
214 | 0 | if (temp.isObject()) { |
215 | 0 | slot = &temp.toObject(); |
216 | 0 | } else { |
217 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of argument 2 of Client.postMessage"); |
218 | 0 | return false; |
219 | 0 | } |
220 | 0 | } |
221 | 0 | } else { |
222 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 2 of Client.postMessage"); |
223 | 0 | return false; |
224 | 0 | } |
225 | 0 | } else { |
226 | 0 | /* Array is already empty; nothing to do */ |
227 | 0 | } |
228 | 0 | FastErrorResult rv; |
229 | 0 | self->PostMessage(cx, arg0, Constify(arg1), rv); |
230 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
231 | 0 | return false; |
232 | 0 | } |
233 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
234 | 0 | args.rval().setUndefined(); |
235 | 0 | return true; |
236 | 0 | } |
237 | | |
238 | | static const JSJitInfo postMessage_methodinfo = { |
239 | | { (JSJitGetterOp)postMessage }, |
240 | | { prototypes::id::Client }, |
241 | | { PrototypeTraits<prototypes::id::Client>::Depth }, |
242 | | JSJitInfo::Method, |
243 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
244 | | JSVAL_TYPE_UNDEFINED, /* 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 < 1, "There is no slot for us"); |
255 | | |
256 | | static bool |
257 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
258 | 0 | { |
259 | 0 | mozilla::dom::Client* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Client>(obj); |
260 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
261 | 0 | // obviously can't preserve if we're not initialized. |
262 | 0 | if (self && self->GetWrapperPreserveColor()) { |
263 | 0 | PreserveWrapper(self); |
264 | 0 | } |
265 | 0 | return true; |
266 | 0 | } |
267 | | |
268 | | static void |
269 | | _finalize(js::FreeOp* fop, JSObject* obj) |
270 | 0 | { |
271 | 0 | mozilla::dom::Client* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Client>(obj); |
272 | 0 | if (self) { |
273 | 0 | ClearWrapper(self, self, obj); |
274 | 0 | AddForDeferredFinalization<mozilla::dom::Client>(self); |
275 | 0 | } |
276 | 0 | } |
277 | | |
278 | | static size_t |
279 | | _objectMoved(JSObject* obj, JSObject* old) |
280 | 0 | { |
281 | 0 | mozilla::dom::Client* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Client>(obj); |
282 | 0 | if (self) { |
283 | 0 | UpdateWrapper(self, self, obj, old); |
284 | 0 | } |
285 | 0 |
|
286 | 0 | return 0; |
287 | 0 | } |
288 | | |
289 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
290 | | #if defined(__clang__) |
291 | | #pragma clang diagnostic push |
292 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
293 | | #endif |
294 | | static const JSFunctionSpec sMethods_specs[] = { |
295 | | JS_FNSPEC("postMessage", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&postMessage_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
296 | | JS_FS_END |
297 | | }; |
298 | | #if defined(__clang__) |
299 | | #pragma clang diagnostic pop |
300 | | #endif |
301 | | |
302 | | |
303 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
304 | | { nullptr, &sMethods_specs[0] }, |
305 | | { nullptr, nullptr } |
306 | | }; |
307 | | |
308 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
309 | | #if defined(__clang__) |
310 | | #pragma clang diagnostic push |
311 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
312 | | #endif |
313 | | static const JSPropertySpec sAttributes_specs[] = { |
314 | | { "url", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &url_getterinfo, nullptr, nullptr }, |
315 | | { "frameType", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &frameType_getterinfo, nullptr, nullptr }, |
316 | | { "type", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &type_getterinfo, nullptr, nullptr }, |
317 | | { "id", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &id_getterinfo, nullptr, nullptr }, |
318 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
319 | | }; |
320 | | #if defined(__clang__) |
321 | | #pragma clang diagnostic pop |
322 | | #endif |
323 | | |
324 | | |
325 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
326 | | { nullptr, &sAttributes_specs[0] }, |
327 | | { nullptr, nullptr } |
328 | | }; |
329 | | |
330 | | |
331 | | static const NativePropertiesN<2> sNativeProperties = { |
332 | | false, 0, |
333 | | false, 0, |
334 | | true, 0 /* sMethods */, |
335 | | true, 1 /* sAttributes */, |
336 | | false, 0, |
337 | | false, 0, |
338 | | false, 0, |
339 | | -1, |
340 | | 0, |
341 | | nullptr, |
342 | | { |
343 | | { sMethods, nullptr }, |
344 | | { sAttributes, nullptr } |
345 | | } |
346 | | }; |
347 | | |
348 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
349 | | { |
350 | | "Function", |
351 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
352 | | &sBoringInterfaceObjectClassClassOps, |
353 | | JS_NULL_CLASS_SPEC, |
354 | | JS_NULL_CLASS_EXT, |
355 | | &sInterfaceObjectClassObjectOps |
356 | | }, |
357 | | eInterface, |
358 | | true, |
359 | | prototypes::id::Client, |
360 | | PrototypeTraits<prototypes::id::Client>::Depth, |
361 | | &sEmptyNativePropertyHooks, |
362 | | "function Client() {\n [native code]\n}", |
363 | | JS::GetRealmFunctionPrototype |
364 | | }; |
365 | | |
366 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
367 | | { |
368 | | "ClientPrototype", |
369 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
370 | | JS_NULL_CLASS_OPS, |
371 | | JS_NULL_CLASS_SPEC, |
372 | | JS_NULL_CLASS_EXT, |
373 | | JS_NULL_OBJECT_OPS |
374 | | }, |
375 | | eInterfacePrototype, |
376 | | false, |
377 | | prototypes::id::Client, |
378 | | PrototypeTraits<prototypes::id::Client>::Depth, |
379 | | &sEmptyNativePropertyHooks, |
380 | | "[object ClientPrototype]", |
381 | | JS::GetRealmObjectPrototype |
382 | | }; |
383 | | |
384 | | bool |
385 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
386 | 0 | { |
387 | 0 | MOZ_ASSERT(!NS_IsMainThread(), "Why did we even get called?"); |
388 | 0 |
|
389 | 0 | const char* name = js::GetObjectClass(aObj)->name; |
390 | 0 | if (strcmp(name, "ServiceWorkerGlobalScope")) { |
391 | 0 | return false; |
392 | 0 | } |
393 | 0 | |
394 | 0 | return true; |
395 | 0 | } |
396 | | |
397 | | static const js::ClassOps sClassOps = { |
398 | | _addProperty, /* addProperty */ |
399 | | nullptr, /* delProperty */ |
400 | | nullptr, /* enumerate */ |
401 | | nullptr, /* newEnumerate */ |
402 | | nullptr, /* resolve */ |
403 | | nullptr, /* mayResolve */ |
404 | | _finalize, /* finalize */ |
405 | | nullptr, /* call */ |
406 | | nullptr, /* hasInstance */ |
407 | | nullptr, /* construct */ |
408 | | nullptr, /* trace */ |
409 | | }; |
410 | | |
411 | | static const js::ClassExtension sClassExtension = { |
412 | | nullptr, /* weakmapKeyDelegateOp */ |
413 | | _objectMoved /* objectMovedOp */ |
414 | | }; |
415 | | |
416 | | static const DOMJSClass sClass = { |
417 | | { "Client", |
418 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
419 | | &sClassOps, |
420 | | JS_NULL_CLASS_SPEC, |
421 | | &sClassExtension, |
422 | | JS_NULL_OBJECT_OPS |
423 | | }, |
424 | | { prototypes::id::Client, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
425 | | IsBaseOf<nsISupports, mozilla::dom::Client >::value, |
426 | | &sEmptyNativePropertyHooks, |
427 | | FindAssociatedGlobalForNative<mozilla::dom::Client>::Get, |
428 | | GetProtoObjectHandle, |
429 | | GetCCParticipant<mozilla::dom::Client>::Get() |
430 | | }; |
431 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
432 | | "Must have the right minimal number of reserved slots."); |
433 | | static_assert(1 >= 1, |
434 | | "Must have enough reserved slots."); |
435 | | |
436 | | const JSClass* |
437 | | GetJSClass() |
438 | 0 | { |
439 | 0 | return sClass.ToJSClass(); |
440 | 0 | } |
441 | | |
442 | | bool |
443 | | Wrap(JSContext* aCx, mozilla::dom::Client* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
444 | 0 | { |
445 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::Client>::value, |
446 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
447 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::Client*>(aObject) == |
448 | 0 | reinterpret_cast<mozilla::dom::Client*>(aObject), |
449 | 0 | "Multiple inheritance for mozilla::dom::Client is broken."); |
450 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
451 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
452 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
453 | 0 | "You should probably not be using Wrap() directly; use " |
454 | 0 | "GetOrCreateDOMReflector instead"); |
455 | 0 |
|
456 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
457 | 0 | "nsISupports must be on our primary inheritance chain"); |
458 | 0 |
|
459 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
460 | 0 | if (!global) { |
461 | 0 | return false; |
462 | 0 | } |
463 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
464 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
465 | 0 |
|
466 | 0 | // That might have ended up wrapping us already, due to the wonders |
467 | 0 | // of XBL. Check for that, and bail out as needed. |
468 | 0 | aReflector.set(aCache->GetWrapper()); |
469 | 0 | if (aReflector) { |
470 | | #ifdef DEBUG |
471 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
472 | | #endif // DEBUG |
473 | | return true; |
474 | 0 | } |
475 | 0 |
|
476 | 0 | JSAutoRealm ar(aCx, global); |
477 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
478 | 0 | if (!canonicalProto) { |
479 | 0 | return false; |
480 | 0 | } |
481 | 0 | JS::Rooted<JSObject*> proto(aCx); |
482 | 0 | if (aGivenProto) { |
483 | 0 | proto = aGivenProto; |
484 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
485 | 0 | // coming in, we changed compartments to that of "parent" so may need |
486 | 0 | // to wrap the proto here. |
487 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
488 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
489 | 0 | return false; |
490 | 0 | } |
491 | 0 | } |
492 | 0 | } else { |
493 | 0 | proto = canonicalProto; |
494 | 0 | } |
495 | 0 |
|
496 | 0 | BindingJSObjectCreator<mozilla::dom::Client> creator(aCx); |
497 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
498 | 0 | if (!aReflector) { |
499 | 0 | return false; |
500 | 0 | } |
501 | 0 | |
502 | 0 | aCache->SetWrapper(aReflector); |
503 | 0 | creator.InitializationSucceeded(); |
504 | 0 |
|
505 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
506 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
507 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
508 | 0 | // otherwise we won't be able to properly recreate it later, since |
509 | 0 | // we won't know what proto to use. Note that we don't check |
510 | 0 | // aGivenProto here, since it's entirely possible (and even |
511 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
512 | 0 | // same as canonicalProto. |
513 | 0 | if (proto != canonicalProto) { |
514 | 0 | PreserveWrapper(aObject); |
515 | 0 | } |
516 | 0 |
|
517 | 0 | return true; |
518 | 0 | } |
519 | | |
520 | | void |
521 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
522 | 0 | { |
523 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
524 | 0 | if (!parentProto) { |
525 | 0 | return; |
526 | 0 | } |
527 | 0 | |
528 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
529 | 0 | if (!constructorProto) { |
530 | 0 | return; |
531 | 0 | } |
532 | 0 | |
533 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Client); |
534 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Client); |
535 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
536 | 0 | &sPrototypeClass.mBase, protoCache, |
537 | 0 | nullptr, |
538 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
539 | 0 | interfaceCache, |
540 | 0 | sNativeProperties.Upcast(), |
541 | 0 | nullptr, |
542 | 0 | "Client", aDefineOnGlobal, |
543 | 0 | nullptr, |
544 | 0 | false); |
545 | 0 | } |
546 | | |
547 | | JSObject* |
548 | | GetProtoObject(JSContext* aCx) |
549 | 0 | { |
550 | 0 | return GetProtoObjectHandle(aCx); |
551 | 0 | } |
552 | | |
553 | | JSObject* |
554 | | GetConstructorObject(JSContext* aCx) |
555 | 0 | { |
556 | 0 | return GetConstructorObjectHandle(aCx); |
557 | 0 | } |
558 | | |
559 | | } // namespace Client_Binding |
560 | | |
561 | | |
562 | | |
563 | | namespace WindowClient_Binding { |
564 | | |
565 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<Client_Binding::NativeType>::value, |
566 | | "Can't inherit from an interface with a different ownership model."); |
567 | | |
568 | | MOZ_CAN_RUN_SCRIPT static bool |
569 | | get_visibilityState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Client* self, JSJitGetterCallArgs args) |
570 | 0 | { |
571 | 0 | AUTO_PROFILER_LABEL_FAST("get WindowClient.visibilityState", DOM, cx); |
572 | 0 |
|
573 | 0 | VisibilityState result(self->GetVisibilityState()); |
574 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
575 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
576 | 0 | return false; |
577 | 0 | } |
578 | 0 | return true; |
579 | 0 | } |
580 | | |
581 | | static const JSJitInfo visibilityState_getterinfo = { |
582 | | { (JSJitGetterOp)get_visibilityState }, |
583 | | { prototypes::id::WindowClient }, |
584 | | { PrototypeTraits<prototypes::id::WindowClient>::Depth }, |
585 | | JSJitInfo::Getter, |
586 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
587 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
588 | | false, /* isInfallible. False in setters. */ |
589 | | false, /* isMovable. Not relevant for setters. */ |
590 | | false, /* isEliminatable. Not relevant for setters. */ |
591 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
592 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
593 | | false, /* isTypedMethod. Only relevant for methods. */ |
594 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
595 | | }; |
596 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
597 | | static_assert(0 < 1, "There is no slot for us"); |
598 | | |
599 | | MOZ_CAN_RUN_SCRIPT static bool |
600 | | get_focused(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Client* self, JSJitGetterCallArgs args) |
601 | 0 | { |
602 | 0 | AUTO_PROFILER_LABEL_FAST("get WindowClient.focused", DOM, cx); |
603 | 0 |
|
604 | 0 | bool result(self->Focused()); |
605 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
606 | 0 | args.rval().setBoolean(result); |
607 | 0 | return true; |
608 | 0 | } |
609 | | |
610 | | static const JSJitInfo focused_getterinfo = { |
611 | | { (JSJitGetterOp)get_focused }, |
612 | | { prototypes::id::WindowClient }, |
613 | | { PrototypeTraits<prototypes::id::WindowClient>::Depth }, |
614 | | JSJitInfo::Getter, |
615 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
616 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
617 | | true, /* isInfallible. False in setters. */ |
618 | | false, /* isMovable. Not relevant for setters. */ |
619 | | false, /* isEliminatable. Not relevant for setters. */ |
620 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
621 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
622 | | false, /* isTypedMethod. Only relevant for methods. */ |
623 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
624 | | }; |
625 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
626 | | static_assert(0 < 1, "There is no slot for us"); |
627 | | |
628 | | MOZ_CAN_RUN_SCRIPT static bool |
629 | | focus(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Client* self, const JSJitMethodCallArgs& args) |
630 | 0 | { |
631 | 0 | AUTO_PROFILER_LABEL_FAST("WindowClient.focus", DOM, cx); |
632 | 0 |
|
633 | 0 | FastErrorResult rv; |
634 | 0 | auto result(StrongOrRawPtr<Promise>(self->Focus(rv))); |
635 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
636 | 0 | return false; |
637 | 0 | } |
638 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
639 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
640 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
641 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
642 | 0 | return false; |
643 | 0 | } |
644 | 0 | return true; |
645 | 0 | } |
646 | | |
647 | | MOZ_CAN_RUN_SCRIPT static bool |
648 | | focus_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Client* self, const JSJitMethodCallArgs& args) |
649 | 0 | { |
650 | 0 | bool ok = focus(cx, obj, self, args); |
651 | 0 | if (ok) { |
652 | 0 | return true; |
653 | 0 | } |
654 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
655 | 0 | } |
656 | | |
657 | | static const JSJitInfo focus_methodinfo = { |
658 | | { (JSJitGetterOp)focus_promiseWrapper }, |
659 | | { prototypes::id::WindowClient }, |
660 | | { PrototypeTraits<prototypes::id::WindowClient>::Depth }, |
661 | | JSJitInfo::Method, |
662 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
663 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
664 | | false, /* isInfallible. False in setters. */ |
665 | | false, /* isMovable. Not relevant for setters. */ |
666 | | false, /* isEliminatable. Not relevant for setters. */ |
667 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
668 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
669 | | false, /* isTypedMethod. Only relevant for methods. */ |
670 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
671 | | }; |
672 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
673 | | static_assert(0 < 1, "There is no slot for us"); |
674 | | |
675 | | MOZ_CAN_RUN_SCRIPT static bool |
676 | | navigate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Client* self, const JSJitMethodCallArgs& args) |
677 | 0 | { |
678 | 0 | AUTO_PROFILER_LABEL_FAST("WindowClient.navigate", DOM, cx); |
679 | 0 |
|
680 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
681 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WindowClient.navigate"); |
682 | 0 | } |
683 | 0 | binding_detail::FakeString arg0; |
684 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
685 | 0 | return false; |
686 | 0 | } |
687 | 0 | NormalizeUSVString(arg0); |
688 | 0 | FastErrorResult rv; |
689 | 0 | auto result(StrongOrRawPtr<Promise>(self->Navigate(Constify(arg0), rv))); |
690 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
691 | 0 | return false; |
692 | 0 | } |
693 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
694 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
695 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
696 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
697 | 0 | return false; |
698 | 0 | } |
699 | 0 | return true; |
700 | 0 | } |
701 | | |
702 | | MOZ_CAN_RUN_SCRIPT static bool |
703 | | navigate_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Client* self, const JSJitMethodCallArgs& args) |
704 | 0 | { |
705 | 0 | bool ok = navigate(cx, obj, self, args); |
706 | 0 | if (ok) { |
707 | 0 | return true; |
708 | 0 | } |
709 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
710 | 0 | } |
711 | | |
712 | | static const JSJitInfo navigate_methodinfo = { |
713 | | { (JSJitGetterOp)navigate_promiseWrapper }, |
714 | | { prototypes::id::WindowClient }, |
715 | | { PrototypeTraits<prototypes::id::WindowClient>::Depth }, |
716 | | JSJitInfo::Method, |
717 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
718 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
719 | | false, /* isInfallible. False in setters. */ |
720 | | false, /* isMovable. Not relevant for setters. */ |
721 | | false, /* isEliminatable. Not relevant for setters. */ |
722 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
723 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
724 | | false, /* isTypedMethod. Only relevant for methods. */ |
725 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
726 | | }; |
727 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
728 | | static_assert(0 < 1, "There is no slot for us"); |
729 | | |
730 | | static bool |
731 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
732 | 0 | { |
733 | 0 | mozilla::dom::Client* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Client>(obj); |
734 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
735 | 0 | // obviously can't preserve if we're not initialized. |
736 | 0 | if (self && self->GetWrapperPreserveColor()) { |
737 | 0 | PreserveWrapper(self); |
738 | 0 | } |
739 | 0 | return true; |
740 | 0 | } |
741 | | |
742 | | static void |
743 | | _finalize(js::FreeOp* fop, JSObject* obj) |
744 | 0 | { |
745 | 0 | mozilla::dom::Client* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Client>(obj); |
746 | 0 | if (self) { |
747 | 0 | ClearWrapper(self, self, obj); |
748 | 0 | AddForDeferredFinalization<mozilla::dom::Client>(self); |
749 | 0 | } |
750 | 0 | } |
751 | | |
752 | | static size_t |
753 | | _objectMoved(JSObject* obj, JSObject* old) |
754 | 0 | { |
755 | 0 | mozilla::dom::Client* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Client>(obj); |
756 | 0 | if (self) { |
757 | 0 | UpdateWrapper(self, self, obj, old); |
758 | 0 | } |
759 | 0 |
|
760 | 0 | return 0; |
761 | 0 | } |
762 | | |
763 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
764 | | #if defined(__clang__) |
765 | | #pragma clang diagnostic push |
766 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
767 | | #endif |
768 | | static const JSFunctionSpec sMethods_specs[] = { |
769 | | JS_FNSPEC("focus", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&focus_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
770 | | JS_FNSPEC("navigate", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&navigate_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
771 | | JS_FS_END |
772 | | }; |
773 | | #if defined(__clang__) |
774 | | #pragma clang diagnostic pop |
775 | | #endif |
776 | | |
777 | | |
778 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
779 | | { nullptr, &sMethods_specs[0] }, |
780 | | { nullptr, nullptr } |
781 | | }; |
782 | | |
783 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
784 | | #if defined(__clang__) |
785 | | #pragma clang diagnostic push |
786 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
787 | | #endif |
788 | | static const JSPropertySpec sAttributes_specs[] = { |
789 | | { "visibilityState", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &visibilityState_getterinfo, nullptr, nullptr }, |
790 | | { "focused", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &focused_getterinfo, nullptr, nullptr }, |
791 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
792 | | }; |
793 | | #if defined(__clang__) |
794 | | #pragma clang diagnostic pop |
795 | | #endif |
796 | | |
797 | | |
798 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
799 | | { nullptr, &sAttributes_specs[0] }, |
800 | | { nullptr, nullptr } |
801 | | }; |
802 | | |
803 | | |
804 | | static const NativePropertiesN<2> sNativeProperties = { |
805 | | false, 0, |
806 | | false, 0, |
807 | | true, 0 /* sMethods */, |
808 | | true, 1 /* sAttributes */, |
809 | | false, 0, |
810 | | false, 0, |
811 | | false, 0, |
812 | | -1, |
813 | | 0, |
814 | | nullptr, |
815 | | { |
816 | | { sMethods, nullptr }, |
817 | | { sAttributes, nullptr } |
818 | | } |
819 | | }; |
820 | | |
821 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
822 | | { |
823 | | "Function", |
824 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
825 | | &sBoringInterfaceObjectClassClassOps, |
826 | | JS_NULL_CLASS_SPEC, |
827 | | JS_NULL_CLASS_EXT, |
828 | | &sInterfaceObjectClassObjectOps |
829 | | }, |
830 | | eInterface, |
831 | | true, |
832 | | prototypes::id::WindowClient, |
833 | | PrototypeTraits<prototypes::id::WindowClient>::Depth, |
834 | | &sEmptyNativePropertyHooks, |
835 | | "function WindowClient() {\n [native code]\n}", |
836 | | Client_Binding::GetConstructorObject |
837 | | }; |
838 | | |
839 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
840 | | { |
841 | | "WindowClientPrototype", |
842 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
843 | | JS_NULL_CLASS_OPS, |
844 | | JS_NULL_CLASS_SPEC, |
845 | | JS_NULL_CLASS_EXT, |
846 | | JS_NULL_OBJECT_OPS |
847 | | }, |
848 | | eInterfacePrototype, |
849 | | false, |
850 | | prototypes::id::WindowClient, |
851 | | PrototypeTraits<prototypes::id::WindowClient>::Depth, |
852 | | &sEmptyNativePropertyHooks, |
853 | | "[object WindowClientPrototype]", |
854 | | Client_Binding::GetProtoObject |
855 | | }; |
856 | | |
857 | | bool |
858 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
859 | 0 | { |
860 | 0 | MOZ_ASSERT(!NS_IsMainThread(), "Why did we even get called?"); |
861 | 0 |
|
862 | 0 | const char* name = js::GetObjectClass(aObj)->name; |
863 | 0 | if (strcmp(name, "ServiceWorkerGlobalScope")) { |
864 | 0 | return false; |
865 | 0 | } |
866 | 0 | |
867 | 0 | return true; |
868 | 0 | } |
869 | | |
870 | | static const js::ClassOps sClassOps = { |
871 | | _addProperty, /* addProperty */ |
872 | | nullptr, /* delProperty */ |
873 | | nullptr, /* enumerate */ |
874 | | nullptr, /* newEnumerate */ |
875 | | nullptr, /* resolve */ |
876 | | nullptr, /* mayResolve */ |
877 | | _finalize, /* finalize */ |
878 | | nullptr, /* call */ |
879 | | nullptr, /* hasInstance */ |
880 | | nullptr, /* construct */ |
881 | | nullptr, /* trace */ |
882 | | }; |
883 | | |
884 | | static const js::ClassExtension sClassExtension = { |
885 | | nullptr, /* weakmapKeyDelegateOp */ |
886 | | _objectMoved /* objectMovedOp */ |
887 | | }; |
888 | | |
889 | | static const DOMJSClass sClass = { |
890 | | { "WindowClient", |
891 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
892 | | &sClassOps, |
893 | | JS_NULL_CLASS_SPEC, |
894 | | &sClassExtension, |
895 | | JS_NULL_OBJECT_OPS |
896 | | }, |
897 | | { prototypes::id::Client, prototypes::id::WindowClient, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
898 | | IsBaseOf<nsISupports, mozilla::dom::Client >::value, |
899 | | &sEmptyNativePropertyHooks, |
900 | | FindAssociatedGlobalForNative<mozilla::dom::Client>::Get, |
901 | | GetProtoObjectHandle, |
902 | | GetCCParticipant<mozilla::dom::Client>::Get() |
903 | | }; |
904 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
905 | | "Must have the right minimal number of reserved slots."); |
906 | | static_assert(1 >= 1, |
907 | | "Must have enough reserved slots."); |
908 | | |
909 | | const JSClass* |
910 | | GetJSClass() |
911 | 0 | { |
912 | 0 | return sClass.ToJSClass(); |
913 | 0 | } |
914 | | |
915 | | bool |
916 | | Wrap(JSContext* aCx, mozilla::dom::Client* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
917 | 0 | { |
918 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::Client>::value, |
919 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
920 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::Client*>(aObject) == |
921 | 0 | reinterpret_cast<mozilla::dom::Client*>(aObject), |
922 | 0 | "Multiple inheritance for mozilla::dom::Client is broken."); |
923 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::Client*>(aObject) == |
924 | 0 | reinterpret_cast<mozilla::dom::Client*>(aObject), |
925 | 0 | "Multiple inheritance for mozilla::dom::Client is broken."); |
926 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
927 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
928 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
929 | 0 | "You should probably not be using Wrap() directly; use " |
930 | 0 | "GetOrCreateDOMReflector instead"); |
931 | 0 |
|
932 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
933 | 0 | "nsISupports must be on our primary inheritance chain"); |
934 | 0 |
|
935 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
936 | 0 | if (!global) { |
937 | 0 | return false; |
938 | 0 | } |
939 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
940 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
941 | 0 |
|
942 | 0 | // That might have ended up wrapping us already, due to the wonders |
943 | 0 | // of XBL. Check for that, and bail out as needed. |
944 | 0 | aReflector.set(aCache->GetWrapper()); |
945 | 0 | if (aReflector) { |
946 | | #ifdef DEBUG |
947 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
948 | | #endif // DEBUG |
949 | | return true; |
950 | 0 | } |
951 | 0 |
|
952 | 0 | JSAutoRealm ar(aCx, global); |
953 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
954 | 0 | if (!canonicalProto) { |
955 | 0 | return false; |
956 | 0 | } |
957 | 0 | JS::Rooted<JSObject*> proto(aCx); |
958 | 0 | if (aGivenProto) { |
959 | 0 | proto = aGivenProto; |
960 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
961 | 0 | // coming in, we changed compartments to that of "parent" so may need |
962 | 0 | // to wrap the proto here. |
963 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
964 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
965 | 0 | return false; |
966 | 0 | } |
967 | 0 | } |
968 | 0 | } else { |
969 | 0 | proto = canonicalProto; |
970 | 0 | } |
971 | 0 |
|
972 | 0 | BindingJSObjectCreator<mozilla::dom::Client> creator(aCx); |
973 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
974 | 0 | if (!aReflector) { |
975 | 0 | return false; |
976 | 0 | } |
977 | 0 | |
978 | 0 | aCache->SetWrapper(aReflector); |
979 | 0 | creator.InitializationSucceeded(); |
980 | 0 |
|
981 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
982 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
983 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
984 | 0 | // otherwise we won't be able to properly recreate it later, since |
985 | 0 | // we won't know what proto to use. Note that we don't check |
986 | 0 | // aGivenProto here, since it's entirely possible (and even |
987 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
988 | 0 | // same as canonicalProto. |
989 | 0 | if (proto != canonicalProto) { |
990 | 0 | PreserveWrapper(aObject); |
991 | 0 | } |
992 | 0 |
|
993 | 0 | return true; |
994 | 0 | } |
995 | | |
996 | | void |
997 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
998 | 0 | { |
999 | 0 | JS::Handle<JSObject*> parentProto(Client_Binding::GetProtoObjectHandle(aCx)); |
1000 | 0 | if (!parentProto) { |
1001 | 0 | return; |
1002 | 0 | } |
1003 | 0 | |
1004 | 0 | JS::Handle<JSObject*> constructorProto(Client_Binding::GetConstructorObjectHandle(aCx)); |
1005 | 0 | if (!constructorProto) { |
1006 | 0 | return; |
1007 | 0 | } |
1008 | 0 | |
1009 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WindowClient); |
1010 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WindowClient); |
1011 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
1012 | 0 | &sPrototypeClass.mBase, protoCache, |
1013 | 0 | nullptr, |
1014 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
1015 | 0 | interfaceCache, |
1016 | 0 | sNativeProperties.Upcast(), |
1017 | 0 | nullptr, |
1018 | 0 | "WindowClient", aDefineOnGlobal, |
1019 | 0 | nullptr, |
1020 | 0 | false); |
1021 | 0 | } |
1022 | | |
1023 | | JSObject* |
1024 | | GetConstructorObject(JSContext* aCx) |
1025 | 0 | { |
1026 | 0 | return GetConstructorObjectHandle(aCx); |
1027 | 0 | } |
1028 | | |
1029 | | } // namespace WindowClient_Binding |
1030 | | |
1031 | | |
1032 | | |
1033 | | } // namespace dom |
1034 | | } // namespace mozilla |