/work/obj-fuzz/dom/bindings/MessageManagerBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM MessageManager.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "EventTargetBinding.h" |
5 | | #include "MessageManagerBinding.h" |
6 | | #include "WrapperFactory.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/dom/BindingUtils.h" |
9 | | #include "mozilla/dom/ChildProcessMessageManager.h" |
10 | | #include "mozilla/dom/ChromeMessageBroadcaster.h" |
11 | | #include "mozilla/dom/ChromeMessageSender.h" |
12 | | #include "mozilla/dom/ContentFrameMessageManager.h" |
13 | | #include "mozilla/dom/ContentProcessMessageManager.h" |
14 | | #include "mozilla/dom/DOMJSClass.h" |
15 | | #include "mozilla/dom/MessageBroadcaster.h" |
16 | | #include "mozilla/dom/MessageListenerManager.h" |
17 | | #include "mozilla/dom/MessageSender.h" |
18 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
19 | | #include "mozilla/dom/Nullable.h" |
20 | | #include "mozilla/dom/ParentProcessMessageManager.h" |
21 | | #include "mozilla/dom/PrimitiveConversions.h" |
22 | | #include "mozilla/dom/ProcessMessageManager.h" |
23 | | #include "mozilla/dom/ScriptSettings.h" |
24 | | #include "mozilla/dom/SyncMessageSender.h" |
25 | | #include "mozilla/dom/XrayExpandoClass.h" |
26 | | #include "mozilla/dom/ipc/SharedMap.h" |
27 | | #include "nsContentUtils.h" |
28 | | #include "nsIDocShell.h" |
29 | | #include "nsIEventTarget.h" |
30 | | #include "nsIPrincipal.h" |
31 | | #include "nsPIDOMWindow.h" |
32 | | |
33 | | namespace mozilla { |
34 | | namespace dom { |
35 | | |
36 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
37 | | using namespace mozilla::dom::binding_detail; |
38 | | |
39 | | |
40 | | |
41 | | ReceiveMessageArgument::ReceiveMessageArgument() |
42 | | : mData(JS::UndefinedValue()), |
43 | | mJson(JS::UndefinedValue()), |
44 | | mObjects(nullptr) |
45 | 0 | { |
46 | 0 | // Safe to pass a null context if we pass a null value |
47 | 0 | Init(nullptr, JS::NullHandleValue); |
48 | 0 | } |
49 | | |
50 | | |
51 | | bool |
52 | | ReceiveMessageArgument::InitIds(JSContext* cx, ReceiveMessageArgumentAtoms* atomsCache) |
53 | 0 | { |
54 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
55 | 0 |
|
56 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
57 | 0 | // uninitialized. |
58 | 0 | if (!atomsCache->targetFrameLoader_id.init(cx, "targetFrameLoader") || |
59 | 0 | !atomsCache->target_id.init(cx, "target") || |
60 | 0 | !atomsCache->sync_id.init(cx, "sync") || |
61 | 0 | !atomsCache->principal_id.init(cx, "principal") || |
62 | 0 | !atomsCache->ports_id.init(cx, "ports") || |
63 | 0 | !atomsCache->objects_id.init(cx, "objects") || |
64 | 0 | !atomsCache->name_id.init(cx, "name") || |
65 | 0 | !atomsCache->json_id.init(cx, "json") || |
66 | 0 | !atomsCache->data_id.init(cx, "data")) { |
67 | 0 | return false; |
68 | 0 | } |
69 | 0 | return true; |
70 | 0 | } |
71 | | |
72 | | bool |
73 | | ReceiveMessageArgument::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
74 | 0 | { |
75 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
76 | 0 | // Since in that case we will not have to do any property gets |
77 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
78 | 0 | // checkers by static analysis tools |
79 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
80 | 0 | ReceiveMessageArgumentAtoms* atomsCache = nullptr; |
81 | 0 | if (cx) { |
82 | 0 | atomsCache = GetAtomCache<ReceiveMessageArgumentAtoms>(cx); |
83 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
84 | 0 | return false; |
85 | 0 | } |
86 | 0 | } |
87 | 0 | |
88 | 0 | if (!IsConvertibleToDictionary(val)) { |
89 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
90 | 0 | } |
91 | 0 | |
92 | 0 | bool isNull = val.isNullOrUndefined(); |
93 | 0 | // We only need these if !isNull, in which case we have |cx|. |
94 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
95 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
96 | 0 | if (!isNull) { |
97 | 0 | MOZ_ASSERT(cx); |
98 | 0 | object.emplace(cx, &val.toObject()); |
99 | 0 | temp.emplace(cx); |
100 | 0 | } |
101 | 0 | if (!isNull) { |
102 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->data_id, temp.ptr())) { |
103 | 0 | return false; |
104 | 0 | } |
105 | 0 | } |
106 | 0 | if (!isNull && !temp->isUndefined()) { |
107 | 0 | #ifdef __clang__ |
108 | 0 | #pragma clang diagnostic push |
109 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code" |
110 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code-return" |
111 | 0 | #endif // __clang__ |
112 | 0 | if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) { |
113 | 0 | ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'data' member of ReceiveMessageArgument"); |
114 | 0 | return false; |
115 | 0 | } |
116 | 0 | #ifdef __clang__ |
117 | 0 | #pragma clang diagnostic pop |
118 | 0 | #endif // __clang__ |
119 | 0 | mData = temp.ref(); |
120 | 0 | } else { |
121 | 0 | mData = JS::NullValue(); |
122 | 0 | } |
123 | 0 | mIsAnyMemberPresent = true; |
124 | 0 |
|
125 | 0 | if (!isNull) { |
126 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->json_id, temp.ptr())) { |
127 | 0 | return false; |
128 | 0 | } |
129 | 0 | } |
130 | 0 | if (!isNull && !temp->isUndefined()) { |
131 | 0 | #ifdef __clang__ |
132 | 0 | #pragma clang diagnostic push |
133 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code" |
134 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code-return" |
135 | 0 | #endif // __clang__ |
136 | 0 | if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) { |
137 | 0 | ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'json' member of ReceiveMessageArgument"); |
138 | 0 | return false; |
139 | 0 | } |
140 | 0 | #ifdef __clang__ |
141 | 0 | #pragma clang diagnostic pop |
142 | 0 | #endif // __clang__ |
143 | 0 | mJson = temp.ref(); |
144 | 0 | } else { |
145 | 0 | mJson = JS::NullValue(); |
146 | 0 | } |
147 | 0 | mIsAnyMemberPresent = true; |
148 | 0 |
|
149 | 0 | if (!isNull) { |
150 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) { |
151 | 0 | return false; |
152 | 0 | } |
153 | 0 | } |
154 | 0 | if (!isNull && !temp->isUndefined()) { |
155 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) { |
156 | 0 | return false; |
157 | 0 | } |
158 | 0 | mIsAnyMemberPresent = true; |
159 | 0 | } else if (cx) { |
160 | 0 | // Don't error out if we have no cx. In that |
161 | 0 | // situation the caller is default-constructing us and we'll |
162 | 0 | // just assume they know what they're doing. |
163 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
164 | 0 | "'name' member of ReceiveMessageArgument"); |
165 | 0 | } |
166 | 0 | |
167 | 0 | if (!isNull) { |
168 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->objects_id, temp.ptr())) { |
169 | 0 | return false; |
170 | 0 | } |
171 | 0 | } |
172 | 0 | if (!isNull && !temp->isUndefined()) { |
173 | 0 | if (temp.ref().isObject()) { |
174 | 0 | #ifdef __clang__ |
175 | 0 | #pragma clang diagnostic push |
176 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code" |
177 | 0 | #pragma clang diagnostic ignored "-Wunreachable-code-return" |
178 | 0 | #endif // __clang__ |
179 | 0 | if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) { |
180 | 0 | ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'objects' member of ReceiveMessageArgument"); |
181 | 0 | return false; |
182 | 0 | } |
183 | 0 | #ifdef __clang__ |
184 | 0 | #pragma clang diagnostic pop |
185 | 0 | #endif // __clang__ |
186 | 0 | mObjects = &temp.ref().toObject(); |
187 | 0 | } else { |
188 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'objects' member of ReceiveMessageArgument"); |
189 | 0 | return false; |
190 | 0 | } |
191 | 0 | mIsAnyMemberPresent = true; |
192 | 0 | } else if (cx) { |
193 | 0 | // Don't error out if we have no cx. In that |
194 | 0 | // situation the caller is default-constructing us and we'll |
195 | 0 | // just assume they know what they're doing. |
196 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
197 | 0 | "'objects' member of ReceiveMessageArgument"); |
198 | 0 | } |
199 | 0 | |
200 | 0 | if (!isNull) { |
201 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->ports_id, temp.ptr())) { |
202 | 0 | return false; |
203 | 0 | } |
204 | 0 | } |
205 | 0 | if (!isNull && !temp->isUndefined()) { |
206 | 0 | mPorts.Construct(); |
207 | 0 | if (temp.ref().isObject()) { |
208 | 0 | JS::ForOfIterator iter(cx); |
209 | 0 | if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) { |
210 | 0 | return false; |
211 | 0 | } |
212 | 0 | if (!iter.valueIsIterable()) { |
213 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'ports' member of ReceiveMessageArgument"); |
214 | 0 | return false; |
215 | 0 | } |
216 | 0 | Sequence<OwningNonNull<mozilla::dom::MessagePort>> &arr = (mPorts.Value()); |
217 | 0 | JS::Rooted<JS::Value> temp(cx); |
218 | 0 | while (true) { |
219 | 0 | bool done; |
220 | 0 | if (!iter.next(&temp, &done)) { |
221 | 0 | return false; |
222 | 0 | } |
223 | 0 | if (done) { |
224 | 0 | break; |
225 | 0 | } |
226 | 0 | OwningNonNull<mozilla::dom::MessagePort>* slotPtr = arr.AppendElement(mozilla::fallible); |
227 | 0 | if (!slotPtr) { |
228 | 0 | JS_ReportOutOfMemory(cx); |
229 | 0 | return false; |
230 | 0 | } |
231 | 0 | OwningNonNull<mozilla::dom::MessagePort>& slot = *slotPtr; |
232 | 0 | if (temp.isObject()) { |
233 | 0 | static_assert(IsRefcounted<mozilla::dom::MessagePort>::value, "We can only store refcounted classes.");{ |
234 | 0 | nsresult rv = UnwrapObject<prototypes::id::MessagePort, mozilla::dom::MessagePort>(&temp, slot); |
235 | 0 | if (NS_FAILED(rv)) { |
236 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of 'ports' member of ReceiveMessageArgument", "MessagePort"); |
237 | 0 | return false; |
238 | 0 | } |
239 | 0 | } |
240 | 0 | } else { |
241 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of 'ports' member of ReceiveMessageArgument"); |
242 | 0 | return false; |
243 | 0 | } |
244 | 0 | } |
245 | 0 | } else { |
246 | 0 | ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'ports' member of ReceiveMessageArgument"); |
247 | 0 | return false; |
248 | 0 | } |
249 | 0 | mIsAnyMemberPresent = true; |
250 | 0 | } |
251 | 0 |
|
252 | 0 | if (!isNull) { |
253 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->principal_id, temp.ptr())) { |
254 | 0 | return false; |
255 | 0 | } |
256 | 0 | } |
257 | 0 | if (!isNull && !temp->isUndefined()) { |
258 | 0 | if (temp.ref().isObject()) { |
259 | 0 | static_assert(IsRefcounted<nsIPrincipal>::value, "We can only store refcounted classes.");RefPtr<nsIPrincipal> holder; |
260 | 0 | JS::Rooted<JSObject*> source(cx, &temp.ref().toObject()); |
261 | 0 | if (NS_FAILED(UnwrapArg<nsIPrincipal>(cx, source, getter_AddRefs(holder)))) { |
262 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'principal' member of ReceiveMessageArgument", "Principal"); |
263 | 0 | return false; |
264 | 0 | } |
265 | 0 | MOZ_ASSERT(holder); |
266 | 0 | mPrincipal = holder; |
267 | 0 | } else if (temp.ref().isNullOrUndefined()) { |
268 | 0 | mPrincipal = nullptr; |
269 | 0 | } else { |
270 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'principal' member of ReceiveMessageArgument"); |
271 | 0 | return false; |
272 | 0 | } |
273 | 0 | mIsAnyMemberPresent = true; |
274 | 0 | } else if (cx) { |
275 | 0 | // Don't error out if we have no cx. In that |
276 | 0 | // situation the caller is default-constructing us and we'll |
277 | 0 | // just assume they know what they're doing. |
278 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
279 | 0 | "'principal' member of ReceiveMessageArgument"); |
280 | 0 | } |
281 | 0 | |
282 | 0 | if (!isNull) { |
283 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->sync_id, temp.ptr())) { |
284 | 0 | return false; |
285 | 0 | } |
286 | 0 | } |
287 | 0 | if (!isNull && !temp->isUndefined()) { |
288 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mSync)) { |
289 | 0 | return false; |
290 | 0 | } |
291 | 0 | mIsAnyMemberPresent = true; |
292 | 0 | } else if (cx) { |
293 | 0 | // Don't error out if we have no cx. In that |
294 | 0 | // situation the caller is default-constructing us and we'll |
295 | 0 | // just assume they know what they're doing. |
296 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
297 | 0 | "'sync' member of ReceiveMessageArgument"); |
298 | 0 | } |
299 | 0 | |
300 | 0 | if (!isNull) { |
301 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->target_id, temp.ptr())) { |
302 | 0 | return false; |
303 | 0 | } |
304 | 0 | } |
305 | 0 | if (!isNull && !temp->isUndefined()) { |
306 | 0 | if (temp.ref().isObject()) { |
307 | 0 | static_assert(IsRefcounted<nsISupports>::value, "We can only store refcounted classes.");RefPtr<nsISupports> holder; |
308 | 0 | JS::Rooted<JSObject*> source(cx, &temp.ref().toObject()); |
309 | 0 | if (NS_FAILED(UnwrapArg<nsISupports>(cx, source, getter_AddRefs(holder)))) { |
310 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'target' member of ReceiveMessageArgument", "nsISupports"); |
311 | 0 | return false; |
312 | 0 | } |
313 | 0 | MOZ_ASSERT(holder); |
314 | 0 | mTarget = holder; |
315 | 0 | } else { |
316 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'target' member of ReceiveMessageArgument"); |
317 | 0 | return false; |
318 | 0 | } |
319 | 0 | mIsAnyMemberPresent = true; |
320 | 0 | } else if (cx) { |
321 | 0 | // Don't error out if we have no cx. In that |
322 | 0 | // situation the caller is default-constructing us and we'll |
323 | 0 | // just assume they know what they're doing. |
324 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER, |
325 | 0 | "'target' member of ReceiveMessageArgument"); |
326 | 0 | } |
327 | 0 | |
328 | 0 | if (!isNull) { |
329 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->targetFrameLoader_id, temp.ptr())) { |
330 | 0 | return false; |
331 | 0 | } |
332 | 0 | } |
333 | 0 | if (!isNull && !temp->isUndefined()) { |
334 | 0 | mTargetFrameLoader.Construct(); |
335 | 0 | if (temp.ref().isObject()) { |
336 | 0 | static_assert(IsRefcounted<nsFrameLoader>::value, "We can only store refcounted classes.");{ |
337 | 0 | nsresult rv = UnwrapObject<prototypes::id::FrameLoader, nsFrameLoader>(temp.ptr(), (mTargetFrameLoader.Value())); |
338 | 0 | if (NS_FAILED(rv)) { |
339 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'targetFrameLoader' member of ReceiveMessageArgument", "FrameLoader"); |
340 | 0 | return false; |
341 | 0 | } |
342 | 0 | } |
343 | 0 | } else { |
344 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'targetFrameLoader' member of ReceiveMessageArgument"); |
345 | 0 | return false; |
346 | 0 | } |
347 | 0 | mIsAnyMemberPresent = true; |
348 | 0 | } |
349 | 0 | return true; |
350 | 0 | } |
351 | | |
352 | | bool |
353 | | ReceiveMessageArgument::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
354 | 0 | { |
355 | 0 | ReceiveMessageArgumentAtoms* atomsCache = GetAtomCache<ReceiveMessageArgumentAtoms>(cx); |
356 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
357 | 0 | return false; |
358 | 0 | } |
359 | 0 | |
360 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
361 | 0 | if (!obj) { |
362 | 0 | return false; |
363 | 0 | } |
364 | 0 | rval.set(JS::ObjectValue(*obj)); |
365 | 0 |
|
366 | 0 | do { |
367 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
368 | 0 | JS::Rooted<JS::Value> temp(cx); |
369 | 0 | JS::Value const & currentValue = mData; |
370 | 0 | JS::ExposeValueToActiveJS(currentValue); |
371 | 0 | temp.set(currentValue); |
372 | 0 | if (!MaybeWrapValue(cx, &temp)) { |
373 | 0 | return false; |
374 | 0 | } |
375 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->data_id, temp, JSPROP_ENUMERATE)) { |
376 | 0 | return false; |
377 | 0 | } |
378 | 0 | break; |
379 | 0 | } while(false); |
380 | 0 |
|
381 | 0 | do { |
382 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
383 | 0 | JS::Rooted<JS::Value> temp(cx); |
384 | 0 | JS::Value const & currentValue = mJson; |
385 | 0 | JS::ExposeValueToActiveJS(currentValue); |
386 | 0 | temp.set(currentValue); |
387 | 0 | if (!MaybeWrapValue(cx, &temp)) { |
388 | 0 | return false; |
389 | 0 | } |
390 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->json_id, temp, JSPROP_ENUMERATE)) { |
391 | 0 | return false; |
392 | 0 | } |
393 | 0 | break; |
394 | 0 | } while(false); |
395 | 0 |
|
396 | 0 | do { |
397 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
398 | 0 | JS::Rooted<JS::Value> temp(cx); |
399 | 0 | nsString const & currentValue = mName; |
400 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
401 | 0 | return false; |
402 | 0 | } |
403 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) { |
404 | 0 | return false; |
405 | 0 | } |
406 | 0 | break; |
407 | 0 | } while(false); |
408 | 0 |
|
409 | 0 | do { |
410 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
411 | 0 | JS::Rooted<JS::Value> temp(cx); |
412 | 0 | JSObject* const & currentValue = mObjects; |
413 | 0 | JS::ExposeObjectToActiveJS(currentValue); |
414 | 0 | temp.setObject(*currentValue); |
415 | 0 | if (!MaybeWrapObjectValue(cx, &temp)) { |
416 | 0 | return false; |
417 | 0 | } |
418 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->objects_id, temp, JSPROP_ENUMERATE)) { |
419 | 0 | return false; |
420 | 0 | } |
421 | 0 | break; |
422 | 0 | } while(false); |
423 | 0 |
|
424 | 0 | if (mPorts.WasPassed()) { |
425 | 0 | do { |
426 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
427 | 0 | JS::Rooted<JS::Value> temp(cx); |
428 | 0 | Sequence<OwningNonNull<mozilla::dom::MessagePort>> const & currentValue = mPorts.InternalValue(); |
429 | 0 |
|
430 | 0 | uint32_t length = currentValue.Length(); |
431 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
432 | 0 | if (!returnArray) { |
433 | 0 | return false; |
434 | 0 | } |
435 | 0 | // Scope for 'tmp' |
436 | 0 | { |
437 | 0 | JS::Rooted<JS::Value> tmp(cx); |
438 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
439 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
440 | 0 | // are different ways to succeed at wrapping the object. |
441 | 0 | do { |
442 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue[sequenceIdx0], &tmp)) { |
443 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
444 | 0 | return false; |
445 | 0 | } |
446 | 0 | break; |
447 | 0 | } while (false); |
448 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
449 | 0 | JSPROP_ENUMERATE)) { |
450 | 0 | return false; |
451 | 0 | } |
452 | 0 | } |
453 | 0 | } |
454 | 0 | temp.setObject(*returnArray); |
455 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->ports_id, temp, JSPROP_ENUMERATE)) { |
456 | 0 | return false; |
457 | 0 | } |
458 | 0 | break; |
459 | 0 | } while(false); |
460 | 0 | } |
461 | 0 |
|
462 | 0 | do { |
463 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
464 | 0 | JS::Rooted<JS::Value> temp(cx); |
465 | 0 | RefPtr<nsIPrincipal> const & currentValue = mPrincipal; |
466 | 0 | if (!currentValue) { |
467 | 0 | temp.setNull(); |
468 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->principal_id, temp, JSPROP_ENUMERATE)) { |
469 | 0 | return false; |
470 | 0 | } |
471 | 0 | break; |
472 | 0 | } |
473 | 0 | if (!WrapObject(cx, currentValue, &NS_GET_IID(nsIPrincipal), &temp)) { |
474 | 0 | return false; |
475 | 0 | } |
476 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->principal_id, temp, JSPROP_ENUMERATE)) { |
477 | 0 | return false; |
478 | 0 | } |
479 | 0 | break; |
480 | 0 | } while(false); |
481 | 0 |
|
482 | 0 | do { |
483 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
484 | 0 | JS::Rooted<JS::Value> temp(cx); |
485 | 0 | bool const & currentValue = mSync; |
486 | 0 | temp.setBoolean(currentValue); |
487 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->sync_id, temp, JSPROP_ENUMERATE)) { |
488 | 0 | return false; |
489 | 0 | } |
490 | 0 | break; |
491 | 0 | } while(false); |
492 | 0 |
|
493 | 0 | do { |
494 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
495 | 0 | JS::Rooted<JS::Value> temp(cx); |
496 | 0 | RefPtr<nsISupports> const & currentValue = mTarget; |
497 | 0 | if (!WrapObject(cx, currentValue, &temp)) { |
498 | 0 | return false; |
499 | 0 | } |
500 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->target_id, temp, JSPROP_ENUMERATE)) { |
501 | 0 | return false; |
502 | 0 | } |
503 | 0 | break; |
504 | 0 | } while(false); |
505 | 0 |
|
506 | 0 | if (mTargetFrameLoader.WasPassed()) { |
507 | 0 | do { |
508 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
509 | 0 | JS::Rooted<JS::Value> temp(cx); |
510 | 0 | OwningNonNull<nsFrameLoader> const & currentValue = mTargetFrameLoader.InternalValue(); |
511 | 0 | if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) { |
512 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
513 | 0 | return false; |
514 | 0 | } |
515 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->targetFrameLoader_id, temp, JSPROP_ENUMERATE)) { |
516 | 0 | return false; |
517 | 0 | } |
518 | 0 | break; |
519 | 0 | } while(false); |
520 | 0 | } |
521 | 0 |
|
522 | 0 | return true; |
523 | 0 | } |
524 | | |
525 | | void |
526 | | ReceiveMessageArgument::TraceDictionary(JSTracer* trc) |
527 | 0 | { |
528 | 0 | JS::UnsafeTraceRoot(trc, &mData, "ReceiveMessageArgument.mData"); |
529 | 0 |
|
530 | 0 | JS::UnsafeTraceRoot(trc, &mJson, "ReceiveMessageArgument.mJson"); |
531 | 0 |
|
532 | 0 | JS::UnsafeTraceRoot(trc, &mObjects, "ReceiveMessageArgument.mObjects"); |
533 | 0 | } |
534 | | |
535 | | |
536 | | |
537 | | namespace binding_detail { |
538 | | } // namespace binding_detail |
539 | | |
540 | | |
541 | | namespace ChildProcessMessageManager_Binding { |
542 | | |
543 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<SyncMessageSender_Binding::NativeType>::value, |
544 | | "Can't inherit from an interface with a different ownership model."); |
545 | | |
546 | | static bool |
547 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
548 | 0 | { |
549 | 0 | mozilla::dom::ChildProcessMessageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ChildProcessMessageManager>(obj); |
550 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
551 | 0 | // obviously can't preserve if we're not initialized. |
552 | 0 | if (self && self->GetWrapperPreserveColor()) { |
553 | 0 | PreserveWrapper(self); |
554 | 0 | } |
555 | 0 | return true; |
556 | 0 | } |
557 | | |
558 | | static void |
559 | | _finalize(js::FreeOp* fop, JSObject* obj) |
560 | 0 | { |
561 | 0 | mozilla::dom::ChildProcessMessageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ChildProcessMessageManager>(obj); |
562 | 0 | if (self) { |
563 | 0 | ClearWrapper(self, self, obj); |
564 | 0 | AddForDeferredFinalization<mozilla::dom::ChildProcessMessageManager>(self); |
565 | 0 | } |
566 | 0 | } |
567 | | |
568 | | static size_t |
569 | | _objectMoved(JSObject* obj, JSObject* old) |
570 | 0 | { |
571 | 0 | mozilla::dom::ChildProcessMessageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ChildProcessMessageManager>(obj); |
572 | 0 | if (self) { |
573 | 0 | UpdateWrapper(self, self, obj, old); |
574 | 0 | } |
575 | 0 |
|
576 | 0 | return 0; |
577 | 0 | } |
578 | | |
579 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
580 | | { |
581 | | "Function", |
582 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
583 | | &sBoringInterfaceObjectClassClassOps, |
584 | | JS_NULL_CLASS_SPEC, |
585 | | JS_NULL_CLASS_EXT, |
586 | | &sInterfaceObjectClassObjectOps |
587 | | }, |
588 | | eInterface, |
589 | | true, |
590 | | prototypes::id::ChildProcessMessageManager, |
591 | | PrototypeTraits<prototypes::id::ChildProcessMessageManager>::Depth, |
592 | | sNativePropertyHooks, |
593 | | "function ChildProcessMessageManager() {\n [native code]\n}", |
594 | | SyncMessageSender_Binding::GetConstructorObject |
595 | | }; |
596 | | |
597 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
598 | | { |
599 | | "ChildProcessMessageManagerPrototype", |
600 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
601 | | JS_NULL_CLASS_OPS, |
602 | | JS_NULL_CLASS_SPEC, |
603 | | JS_NULL_CLASS_EXT, |
604 | | JS_NULL_OBJECT_OPS |
605 | | }, |
606 | | eInterfacePrototype, |
607 | | false, |
608 | | prototypes::id::ChildProcessMessageManager, |
609 | | PrototypeTraits<prototypes::id::ChildProcessMessageManager>::Depth, |
610 | | sNativePropertyHooks, |
611 | | "[object ChildProcessMessageManagerPrototype]", |
612 | | SyncMessageSender_Binding::GetProtoObject |
613 | | }; |
614 | | |
615 | | bool |
616 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
617 | 0 | { |
618 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
619 | 0 | } |
620 | | |
621 | | static const js::ClassOps sClassOps = { |
622 | | _addProperty, /* addProperty */ |
623 | | nullptr, /* delProperty */ |
624 | | nullptr, /* enumerate */ |
625 | | nullptr, /* newEnumerate */ |
626 | | nullptr, /* resolve */ |
627 | | nullptr, /* mayResolve */ |
628 | | _finalize, /* finalize */ |
629 | | nullptr, /* call */ |
630 | | nullptr, /* hasInstance */ |
631 | | nullptr, /* construct */ |
632 | | nullptr, /* trace */ |
633 | | }; |
634 | | |
635 | | static const js::ClassExtension sClassExtension = { |
636 | | nullptr, /* weakmapKeyDelegateOp */ |
637 | | _objectMoved /* objectMovedOp */ |
638 | | }; |
639 | | |
640 | | static const DOMJSClass sClass = { |
641 | | { "ChildProcessMessageManager", |
642 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
643 | | &sClassOps, |
644 | | JS_NULL_CLASS_SPEC, |
645 | | &sClassExtension, |
646 | | JS_NULL_OBJECT_OPS |
647 | | }, |
648 | | { prototypes::id::MessageListenerManager, prototypes::id::MessageSender, prototypes::id::SyncMessageSender, prototypes::id::ChildProcessMessageManager, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
649 | | IsBaseOf<nsISupports, mozilla::dom::ChildProcessMessageManager >::value, |
650 | | sNativePropertyHooks, |
651 | | FindAssociatedGlobalForNative<mozilla::dom::ChildProcessMessageManager>::Get, |
652 | | GetProtoObjectHandle, |
653 | | GetCCParticipant<mozilla::dom::ChildProcessMessageManager>::Get() |
654 | | }; |
655 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
656 | | "Must have the right minimal number of reserved slots."); |
657 | | static_assert(1 >= 1, |
658 | | "Must have enough reserved slots."); |
659 | | |
660 | | const JSClass* |
661 | | GetJSClass() |
662 | 0 | { |
663 | 0 | return sClass.ToJSClass(); |
664 | 0 | } |
665 | | |
666 | | bool |
667 | | Wrap(JSContext* aCx, mozilla::dom::ChildProcessMessageManager* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
668 | 0 | { |
669 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::ChildProcessMessageManager>::value, |
670 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
671 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::ChildProcessMessageManager*>(aObject) == |
672 | 0 | reinterpret_cast<mozilla::dom::ChildProcessMessageManager*>(aObject), |
673 | 0 | "Multiple inheritance for mozilla::dom::ChildProcessMessageManager is broken."); |
674 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::SyncMessageSender*>(aObject) == |
675 | 0 | reinterpret_cast<mozilla::dom::SyncMessageSender*>(aObject), |
676 | 0 | "Multiple inheritance for mozilla::dom::SyncMessageSender is broken."); |
677 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::MessageSender*>(aObject) == |
678 | 0 | reinterpret_cast<mozilla::dom::MessageSender*>(aObject), |
679 | 0 | "Multiple inheritance for mozilla::dom::MessageSender is broken."); |
680 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::MessageListenerManager*>(aObject) == |
681 | 0 | reinterpret_cast<mozilla::dom::MessageListenerManager*>(aObject), |
682 | 0 | "Multiple inheritance for mozilla::dom::MessageListenerManager is broken."); |
683 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
684 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
685 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
686 | 0 | "You should probably not be using Wrap() directly; use " |
687 | 0 | "GetOrCreateDOMReflector instead"); |
688 | 0 |
|
689 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
690 | 0 | "nsISupports must be on our primary inheritance chain"); |
691 | 0 |
|
692 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
693 | 0 | if (!global) { |
694 | 0 | return false; |
695 | 0 | } |
696 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
697 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
698 | 0 |
|
699 | 0 | // That might have ended up wrapping us already, due to the wonders |
700 | 0 | // of XBL. Check for that, and bail out as needed. |
701 | 0 | aReflector.set(aCache->GetWrapper()); |
702 | 0 | if (aReflector) { |
703 | | #ifdef DEBUG |
704 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
705 | | #endif // DEBUG |
706 | | return true; |
707 | 0 | } |
708 | 0 |
|
709 | 0 | JSAutoRealm ar(aCx, global); |
710 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
711 | 0 | if (!canonicalProto) { |
712 | 0 | return false; |
713 | 0 | } |
714 | 0 | JS::Rooted<JSObject*> proto(aCx); |
715 | 0 | if (aGivenProto) { |
716 | 0 | proto = aGivenProto; |
717 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
718 | 0 | // coming in, we changed compartments to that of "parent" so may need |
719 | 0 | // to wrap the proto here. |
720 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
721 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
722 | 0 | return false; |
723 | 0 | } |
724 | 0 | } |
725 | 0 | } else { |
726 | 0 | proto = canonicalProto; |
727 | 0 | } |
728 | 0 |
|
729 | 0 | BindingJSObjectCreator<mozilla::dom::ChildProcessMessageManager> creator(aCx); |
730 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
731 | 0 | if (!aReflector) { |
732 | 0 | return false; |
733 | 0 | } |
734 | 0 | |
735 | 0 | aCache->SetWrapper(aReflector); |
736 | 0 | creator.InitializationSucceeded(); |
737 | 0 |
|
738 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
739 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
740 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
741 | 0 | // otherwise we won't be able to properly recreate it later, since |
742 | 0 | // we won't know what proto to use. Note that we don't check |
743 | 0 | // aGivenProto here, since it's entirely possible (and even |
744 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
745 | 0 | // same as canonicalProto. |
746 | 0 | if (proto != canonicalProto) { |
747 | 0 | PreserveWrapper(aObject); |
748 | 0 | } |
749 | 0 |
|
750 | 0 | return true; |
751 | 0 | } |
752 | | |
753 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
754 | | nullptr, |
755 | | nullptr, |
756 | | nullptr, |
757 | | { nullptr, nullptr }, |
758 | | prototypes::id::ChildProcessMessageManager, |
759 | | constructors::id::ChildProcessMessageManager, |
760 | | SyncMessageSender_Binding::sNativePropertyHooks, |
761 | | &DefaultXrayExpandoObjectClass |
762 | | } }; |
763 | | |
764 | | void |
765 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
766 | 0 | { |
767 | 0 | JS::Handle<JSObject*> parentProto(SyncMessageSender_Binding::GetProtoObjectHandle(aCx)); |
768 | 0 | if (!parentProto) { |
769 | 0 | return; |
770 | 0 | } |
771 | 0 | |
772 | 0 | JS::Handle<JSObject*> constructorProto(SyncMessageSender_Binding::GetConstructorObjectHandle(aCx)); |
773 | 0 | if (!constructorProto) { |
774 | 0 | return; |
775 | 0 | } |
776 | 0 | |
777 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ChildProcessMessageManager); |
778 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ChildProcessMessageManager); |
779 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
780 | 0 | &sPrototypeClass.mBase, protoCache, |
781 | 0 | nullptr, |
782 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
783 | 0 | interfaceCache, |
784 | 0 | nullptr, |
785 | 0 | nullptr, |
786 | 0 | "ChildProcessMessageManager", aDefineOnGlobal, |
787 | 0 | nullptr, |
788 | 0 | false); |
789 | 0 | } |
790 | | |
791 | | JSObject* |
792 | | GetConstructorObject(JSContext* aCx) |
793 | 0 | { |
794 | 0 | return GetConstructorObjectHandle(aCx); |
795 | 0 | } |
796 | | |
797 | | } // namespace ChildProcessMessageManager_Binding |
798 | | |
799 | | |
800 | | |
801 | | namespace ChromeMessageBroadcaster_Binding { |
802 | | |
803 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<MessageBroadcaster_Binding::NativeType>::value, |
804 | | "Can't inherit from an interface with a different ownership model."); |
805 | | |
806 | | MOZ_CAN_RUN_SCRIPT static bool |
807 | | loadFrameScript(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ChromeMessageBroadcaster* self, const JSJitMethodCallArgs& args) |
808 | 0 | { |
809 | 0 | AUTO_PROFILER_LABEL_FAST("ChromeMessageBroadcaster.loadFrameScript", DOM, cx); |
810 | 0 |
|
811 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
812 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ChromeMessageBroadcaster.loadFrameScript"); |
813 | 0 | } |
814 | 0 | binding_detail::FakeString arg0; |
815 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
816 | 0 | return false; |
817 | 0 | } |
818 | 0 | bool arg1; |
819 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, args[1], &arg1)) { |
820 | 0 | return false; |
821 | 0 | } |
822 | 0 | bool arg2; |
823 | 0 | if (args.hasDefined(2)) { |
824 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, args[2], &arg2)) { |
825 | 0 | return false; |
826 | 0 | } |
827 | 0 | } else { |
828 | 0 | arg2 = false; |
829 | 0 | } |
830 | 0 | FastErrorResult rv; |
831 | 0 | self->LoadFrameScript(NonNullHelper(Constify(arg0)), arg1, arg2, rv); |
832 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
833 | 0 | return false; |
834 | 0 | } |
835 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
836 | 0 | args.rval().setUndefined(); |
837 | 0 | return true; |
838 | 0 | } |
839 | | |
840 | | static const JSJitInfo loadFrameScript_methodinfo = { |
841 | | { (JSJitGetterOp)loadFrameScript }, |
842 | | { prototypes::id::ChromeMessageBroadcaster }, |
843 | | { PrototypeTraits<prototypes::id::ChromeMessageBroadcaster>::Depth }, |
844 | | JSJitInfo::Method, |
845 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
846 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
847 | | false, /* isInfallible. False in setters. */ |
848 | | false, /* isMovable. Not relevant for setters. */ |
849 | | false, /* isEliminatable. Not relevant for setters. */ |
850 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
851 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
852 | | false, /* isTypedMethod. Only relevant for methods. */ |
853 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
854 | | }; |
855 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
856 | | static_assert(0 < 1, "There is no slot for us"); |
857 | | |
858 | | MOZ_CAN_RUN_SCRIPT static bool |
859 | | removeDelayedFrameScript(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ChromeMessageBroadcaster* self, const JSJitMethodCallArgs& args) |
860 | 0 | { |
861 | 0 | AUTO_PROFILER_LABEL_FAST("ChromeMessageBroadcaster.removeDelayedFrameScript", DOM, cx); |
862 | 0 |
|
863 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
864 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ChromeMessageBroadcaster.removeDelayedFrameScript"); |
865 | 0 | } |
866 | 0 | binding_detail::FakeString arg0; |
867 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
868 | 0 | return false; |
869 | 0 | } |
870 | 0 | self->RemoveDelayedFrameScript(NonNullHelper(Constify(arg0))); |
871 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
872 | 0 | args.rval().setUndefined(); |
873 | 0 | return true; |
874 | 0 | } |
875 | | |
876 | | static const JSJitInfo removeDelayedFrameScript_methodinfo = { |
877 | | { (JSJitGetterOp)removeDelayedFrameScript }, |
878 | | { prototypes::id::ChromeMessageBroadcaster }, |
879 | | { PrototypeTraits<prototypes::id::ChromeMessageBroadcaster>::Depth }, |
880 | | JSJitInfo::Method, |
881 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
882 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
883 | | false, /* isInfallible. False in setters. */ |
884 | | false, /* isMovable. Not relevant for setters. */ |
885 | | false, /* isEliminatable. Not relevant for setters. */ |
886 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
887 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
888 | | false, /* isTypedMethod. Only relevant for methods. */ |
889 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
890 | | }; |
891 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
892 | | static_assert(0 < 1, "There is no slot for us"); |
893 | | |
894 | | MOZ_CAN_RUN_SCRIPT static bool |
895 | | getDelayedFrameScripts(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ChromeMessageBroadcaster* self, const JSJitMethodCallArgs& args) |
896 | 0 | { |
897 | 0 | AUTO_PROFILER_LABEL_FAST("ChromeMessageBroadcaster.getDelayedFrameScripts", DOM, cx); |
898 | 0 |
|
899 | 0 | FastErrorResult rv; |
900 | 0 | nsTArray<nsTArray<JS::Value>> result; |
901 | 0 | SequenceRooter<nsTArray<JS::Value> > resultRooter(cx, &result); |
902 | 0 | self->GetDelayedFrameScripts(cx, result, rv); |
903 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
904 | 0 | return false; |
905 | 0 | } |
906 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
907 | 0 |
|
908 | 0 | uint32_t length = result.Length(); |
909 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
910 | 0 | if (!returnArray) { |
911 | 0 | return false; |
912 | 0 | } |
913 | 0 | // Scope for 'tmp' |
914 | 0 | { |
915 | 0 | JS::Rooted<JS::Value> tmp(cx); |
916 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
917 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
918 | 0 | // are different ways to succeed at wrapping the object. |
919 | 0 | do { |
920 | 0 |
|
921 | 0 | uint32_t length = result[sequenceIdx0].Length(); |
922 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
923 | 0 | if (!returnArray) { |
924 | 0 | return false; |
925 | 0 | } |
926 | 0 | // Scope for 'tmp' |
927 | 0 | { |
928 | 0 | JS::Rooted<JS::Value> tmp(cx); |
929 | 0 | for (uint32_t sequenceIdx1 = 0; sequenceIdx1 < length; ++sequenceIdx1) { |
930 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
931 | 0 | // are different ways to succeed at wrapping the object. |
932 | 0 | do { |
933 | 0 | JS::ExposeValueToActiveJS(result[sequenceIdx0][sequenceIdx1]); |
934 | 0 | tmp.set(result[sequenceIdx0][sequenceIdx1]); |
935 | 0 | if (!MaybeWrapValue(cx, &tmp)) { |
936 | 0 | return false; |
937 | 0 | } |
938 | 0 | break; |
939 | 0 | } while (false); |
940 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx1, tmp, |
941 | 0 | JSPROP_ENUMERATE)) { |
942 | 0 | return false; |
943 | 0 | } |
944 | 0 | } |
945 | 0 | } |
946 | 0 | tmp.setObject(*returnArray); |
947 | 0 | break; |
948 | 0 | } while (false); |
949 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
950 | 0 | JSPROP_ENUMERATE)) { |
951 | 0 | return false; |
952 | 0 | } |
953 | 0 | } |
954 | 0 | } |
955 | 0 | args.rval().setObject(*returnArray); |
956 | 0 | return true; |
957 | 0 | } |
958 | | |
959 | | static const JSJitInfo getDelayedFrameScripts_methodinfo = { |
960 | | { (JSJitGetterOp)getDelayedFrameScripts }, |
961 | | { prototypes::id::ChromeMessageBroadcaster }, |
962 | | { PrototypeTraits<prototypes::id::ChromeMessageBroadcaster>::Depth }, |
963 | | JSJitInfo::Method, |
964 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
965 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
966 | | false, /* isInfallible. False in setters. */ |
967 | | false, /* isMovable. Not relevant for setters. */ |
968 | | false, /* isEliminatable. Not relevant for setters. */ |
969 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
970 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
971 | | false, /* isTypedMethod. Only relevant for methods. */ |
972 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
973 | | }; |
974 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
975 | | static_assert(0 < 1, "There is no slot for us"); |
976 | | |
977 | | static bool |
978 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
979 | 0 | { |
980 | 0 | mozilla::dom::ChromeMessageBroadcaster* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ChromeMessageBroadcaster>(obj); |
981 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
982 | 0 | // obviously can't preserve if we're not initialized. |
983 | 0 | if (self && self->GetWrapperPreserveColor()) { |
984 | 0 | PreserveWrapper(self); |
985 | 0 | } |
986 | 0 | return true; |
987 | 0 | } |
988 | | |
989 | | static void |
990 | | _finalize(js::FreeOp* fop, JSObject* obj) |
991 | 0 | { |
992 | 0 | mozilla::dom::ChromeMessageBroadcaster* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ChromeMessageBroadcaster>(obj); |
993 | 0 | if (self) { |
994 | 0 | ClearWrapper(self, self, obj); |
995 | 0 | AddForDeferredFinalization<mozilla::dom::ChromeMessageBroadcaster>(self); |
996 | 0 | } |
997 | 0 | } |
998 | | |
999 | | static size_t |
1000 | | _objectMoved(JSObject* obj, JSObject* old) |
1001 | 0 | { |
1002 | 0 | mozilla::dom::ChromeMessageBroadcaster* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ChromeMessageBroadcaster>(obj); |
1003 | 0 | if (self) { |
1004 | 0 | UpdateWrapper(self, self, obj, old); |
1005 | 0 | } |
1006 | 0 |
|
1007 | 0 | return 0; |
1008 | 0 | } |
1009 | | |
1010 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
1011 | | #if defined(__clang__) |
1012 | | #pragma clang diagnostic push |
1013 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
1014 | | #endif |
1015 | | static const JSFunctionSpec sMethods_specs[] = { |
1016 | | JS_FNSPEC("loadFrameScript", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&loadFrameScript_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
1017 | | JS_FNSPEC("removeDelayedFrameScript", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&removeDelayedFrameScript_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
1018 | | JS_FNSPEC("getDelayedFrameScripts", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getDelayedFrameScripts_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
1019 | | JS_FS_END |
1020 | | }; |
1021 | | #if defined(__clang__) |
1022 | | #pragma clang diagnostic pop |
1023 | | #endif |
1024 | | |
1025 | | |
1026 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
1027 | | { nullptr, &sMethods_specs[0] }, |
1028 | | { nullptr, nullptr } |
1029 | | }; |
1030 | | |
1031 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1032 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1033 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1034 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1035 | | |
1036 | | |
1037 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
1038 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
1039 | | |
1040 | | static const NativePropertiesN<1> sNativeProperties = { |
1041 | | false, 0, |
1042 | | false, 0, |
1043 | | true, 0 /* sMethods */, |
1044 | | false, 0, |
1045 | | false, 0, |
1046 | | false, 0, |
1047 | | false, 0, |
1048 | | -1, |
1049 | | 3, |
1050 | | sNativeProperties_sortedPropertyIndices, |
1051 | | { |
1052 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
1053 | | } |
1054 | | }; |
1055 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
1056 | | "We have a property info count that is oversized"); |
1057 | | |
1058 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
1059 | | { |
1060 | | "Function", |
1061 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
1062 | | &sBoringInterfaceObjectClassClassOps, |
1063 | | JS_NULL_CLASS_SPEC, |
1064 | | JS_NULL_CLASS_EXT, |
1065 | | &sInterfaceObjectClassObjectOps |
1066 | | }, |
1067 | | eInterface, |
1068 | | true, |
1069 | | prototypes::id::ChromeMessageBroadcaster, |
1070 | | PrototypeTraits<prototypes::id::ChromeMessageBroadcaster>::Depth, |
1071 | | sNativePropertyHooks, |
1072 | | "function ChromeMessageBroadcaster() {\n [native code]\n}", |
1073 | | MessageBroadcaster_Binding::GetConstructorObject |
1074 | | }; |
1075 | | |
1076 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
1077 | | { |
1078 | | "ChromeMessageBroadcasterPrototype", |
1079 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
1080 | | JS_NULL_CLASS_OPS, |
1081 | | JS_NULL_CLASS_SPEC, |
1082 | | JS_NULL_CLASS_EXT, |
1083 | | JS_NULL_OBJECT_OPS |
1084 | | }, |
1085 | | eInterfacePrototype, |
1086 | | false, |
1087 | | prototypes::id::ChromeMessageBroadcaster, |
1088 | | PrototypeTraits<prototypes::id::ChromeMessageBroadcaster>::Depth, |
1089 | | sNativePropertyHooks, |
1090 | | "[object ChromeMessageBroadcasterPrototype]", |
1091 | | MessageBroadcaster_Binding::GetProtoObject |
1092 | | }; |
1093 | | |
1094 | | bool |
1095 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
1096 | 0 | { |
1097 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
1098 | 0 | } |
1099 | | |
1100 | | static const js::ClassOps sClassOps = { |
1101 | | _addProperty, /* addProperty */ |
1102 | | nullptr, /* delProperty */ |
1103 | | nullptr, /* enumerate */ |
1104 | | nullptr, /* newEnumerate */ |
1105 | | nullptr, /* resolve */ |
1106 | | nullptr, /* mayResolve */ |
1107 | | _finalize, /* finalize */ |
1108 | | nullptr, /* call */ |
1109 | | nullptr, /* hasInstance */ |
1110 | | nullptr, /* construct */ |
1111 | | nullptr, /* trace */ |
1112 | | }; |
1113 | | |
1114 | | static const js::ClassExtension sClassExtension = { |
1115 | | nullptr, /* weakmapKeyDelegateOp */ |
1116 | | _objectMoved /* objectMovedOp */ |
1117 | | }; |
1118 | | |
1119 | | static const DOMJSClass sClass = { |
1120 | | { "ChromeMessageBroadcaster", |
1121 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
1122 | | &sClassOps, |
1123 | | JS_NULL_CLASS_SPEC, |
1124 | | &sClassExtension, |
1125 | | JS_NULL_OBJECT_OPS |
1126 | | }, |
1127 | | { prototypes::id::MessageListenerManager, prototypes::id::MessageBroadcaster, prototypes::id::ChromeMessageBroadcaster, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
1128 | | IsBaseOf<nsISupports, mozilla::dom::ChromeMessageBroadcaster >::value, |
1129 | | sNativePropertyHooks, |
1130 | | FindAssociatedGlobalForNative<mozilla::dom::ChromeMessageBroadcaster>::Get, |
1131 | | GetProtoObjectHandle, |
1132 | | GetCCParticipant<mozilla::dom::ChromeMessageBroadcaster>::Get() |
1133 | | }; |
1134 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
1135 | | "Must have the right minimal number of reserved slots."); |
1136 | | static_assert(1 >= 1, |
1137 | | "Must have enough reserved slots."); |
1138 | | |
1139 | | const JSClass* |
1140 | | GetJSClass() |
1141 | 0 | { |
1142 | 0 | return sClass.ToJSClass(); |
1143 | 0 | } |
1144 | | |
1145 | | bool |
1146 | | Wrap(JSContext* aCx, mozilla::dom::ChromeMessageBroadcaster* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
1147 | 0 | { |
1148 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::ChromeMessageBroadcaster>::value, |
1149 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
1150 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::ChromeMessageBroadcaster*>(aObject) == |
1151 | 0 | reinterpret_cast<mozilla::dom::ChromeMessageBroadcaster*>(aObject), |
1152 | 0 | "Multiple inheritance for mozilla::dom::ChromeMessageBroadcaster is broken."); |
1153 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::MessageBroadcaster*>(aObject) == |
1154 | 0 | reinterpret_cast<mozilla::dom::MessageBroadcaster*>(aObject), |
1155 | 0 | "Multiple inheritance for mozilla::dom::MessageBroadcaster is broken."); |
1156 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::MessageListenerManager*>(aObject) == |
1157 | 0 | reinterpret_cast<mozilla::dom::MessageListenerManager*>(aObject), |
1158 | 0 | "Multiple inheritance for mozilla::dom::MessageListenerManager is broken."); |
1159 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
1160 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
1161 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
1162 | 0 | "You should probably not be using Wrap() directly; use " |
1163 | 0 | "GetOrCreateDOMReflector instead"); |
1164 | 0 |
|
1165 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
1166 | 0 | "nsISupports must be on our primary inheritance chain"); |
1167 | 0 |
|
1168 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
1169 | 0 | if (!global) { |
1170 | 0 | return false; |
1171 | 0 | } |
1172 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
1173 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
1174 | 0 |
|
1175 | 0 | // That might have ended up wrapping us already, due to the wonders |
1176 | 0 | // of XBL. Check for that, and bail out as needed. |
1177 | 0 | aReflector.set(aCache->GetWrapper()); |
1178 | 0 | if (aReflector) { |
1179 | | #ifdef DEBUG |
1180 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
1181 | | #endif // DEBUG |
1182 | | return true; |
1183 | 0 | } |
1184 | 0 |
|
1185 | 0 | JSAutoRealm ar(aCx, global); |
1186 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
1187 | 0 | if (!canonicalProto) { |
1188 | 0 | return false; |
1189 | 0 | } |
1190 | 0 | JS::Rooted<JSObject*> proto(aCx); |
1191 | 0 | if (aGivenProto) { |
1192 | 0 | proto = aGivenProto; |
1193 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
1194 | 0 | // coming in, we changed compartments to that of "parent" so may need |
1195 | 0 | // to wrap the proto here. |
1196 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
1197 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
1198 | 0 | return false; |
1199 | 0 | } |
1200 | 0 | } |
1201 | 0 | } else { |
1202 | 0 | proto = canonicalProto; |
1203 | 0 | } |
1204 | 0 |
|
1205 | 0 | BindingJSObjectCreator<mozilla::dom::ChromeMessageBroadcaster> creator(aCx); |
1206 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
1207 | 0 | if (!aReflector) { |
1208 | 0 | return false; |
1209 | 0 | } |
1210 | 0 | |
1211 | 0 | aCache->SetWrapper(aReflector); |
1212 | 0 | creator.InitializationSucceeded(); |
1213 | 0 |
|
1214 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
1215 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
1216 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
1217 | 0 | // otherwise we won't be able to properly recreate it later, since |
1218 | 0 | // we won't know what proto to use. Note that we don't check |
1219 | 0 | // aGivenProto here, since it's entirely possible (and even |
1220 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
1221 | 0 | // same as canonicalProto. |
1222 | 0 | if (proto != canonicalProto) { |
1223 | 0 | PreserveWrapper(aObject); |
1224 | 0 | } |
1225 | 0 |
|
1226 | 0 | return true; |
1227 | 0 | } |
1228 | | |
1229 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
1230 | | nullptr, |
1231 | | nullptr, |
1232 | | nullptr, |
1233 | | { sNativeProperties.Upcast(), nullptr }, |
1234 | | prototypes::id::ChromeMessageBroadcaster, |
1235 | | constructors::id::ChromeMessageBroadcaster, |
1236 | | MessageBroadcaster_Binding::sNativePropertyHooks, |
1237 | | &DefaultXrayExpandoObjectClass |
1238 | | } }; |
1239 | | |
1240 | | void |
1241 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
1242 | 0 | { |
1243 | 0 | JS::Handle<JSObject*> parentProto(MessageBroadcaster_Binding::GetProtoObjectHandle(aCx)); |
1244 | 0 | if (!parentProto) { |
1245 | 0 | return; |
1246 | 0 | } |
1247 | 0 | |
1248 | 0 | JS::Handle<JSObject*> constructorProto(MessageBroadcaster_Binding::GetConstructorObjectHandle(aCx)); |
1249 | 0 | if (!constructorProto) { |
1250 | 0 | return; |
1251 | 0 | } |
1252 | 0 | |
1253 | 0 | static bool sIdsInited = false; |
1254 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
1255 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
1256 | 0 | return; |
1257 | 0 | } |
1258 | 0 | sIdsInited = true; |
1259 | 0 | } |
1260 | 0 |
|
1261 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ChromeMessageBroadcaster); |
1262 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ChromeMessageBroadcaster); |
1263 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
1264 | 0 | &sPrototypeClass.mBase, protoCache, |
1265 | 0 | nullptr, |
1266 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
1267 | 0 | interfaceCache, |
1268 | 0 | sNativeProperties.Upcast(), |
1269 | 0 | nullptr, |
1270 | 0 | "ChromeMessageBroadcaster", aDefineOnGlobal, |
1271 | 0 | nullptr, |
1272 | 0 | false); |
1273 | 0 | } |
1274 | | |
1275 | | JSObject* |
1276 | | GetConstructorObject(JSContext* aCx) |
1277 | 0 | { |
1278 | 0 | return GetConstructorObjectHandle(aCx); |
1279 | 0 | } |
1280 | | |
1281 | | } // namespace ChromeMessageBroadcaster_Binding |
1282 | | |
1283 | | |
1284 | | |
1285 | | namespace ChromeMessageSender_Binding { |
1286 | | |
1287 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<MessageSender_Binding::NativeType>::value, |
1288 | | "Can't inherit from an interface with a different ownership model."); |
1289 | | |
1290 | | MOZ_CAN_RUN_SCRIPT static bool |
1291 | | loadFrameScript(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ChromeMessageSender* self, const JSJitMethodCallArgs& args) |
1292 | 0 | { |
1293 | 0 | AUTO_PROFILER_LABEL_FAST("ChromeMessageSender.loadFrameScript", DOM, cx); |
1294 | 0 |
|
1295 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
1296 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ChromeMessageSender.loadFrameScript"); |
1297 | 0 | } |
1298 | 0 | binding_detail::FakeString arg0; |
1299 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
1300 | 0 | return false; |
1301 | 0 | } |
1302 | 0 | bool arg1; |
1303 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, args[1], &arg1)) { |
1304 | 0 | return false; |
1305 | 0 | } |
1306 | 0 | bool arg2; |
1307 | 0 | if (args.hasDefined(2)) { |
1308 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, args[2], &arg2)) { |
1309 | 0 | return false; |
1310 | 0 | } |
1311 | 0 | } else { |
1312 | 0 | arg2 = false; |
1313 | 0 | } |
1314 | 0 | FastErrorResult rv; |
1315 | 0 | self->LoadFrameScript(NonNullHelper(Constify(arg0)), arg1, arg2, rv); |
1316 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
1317 | 0 | return false; |
1318 | 0 | } |
1319 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1320 | 0 | args.rval().setUndefined(); |
1321 | 0 | return true; |
1322 | 0 | } |
1323 | | |
1324 | | static const JSJitInfo loadFrameScript_methodinfo = { |
1325 | | { (JSJitGetterOp)loadFrameScript }, |
1326 | | { prototypes::id::ChromeMessageSender }, |
1327 | | { PrototypeTraits<prototypes::id::ChromeMessageSender>::Depth }, |
1328 | | JSJitInfo::Method, |
1329 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1330 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
1331 | | false, /* isInfallible. False in setters. */ |
1332 | | false, /* isMovable. Not relevant for setters. */ |
1333 | | false, /* isEliminatable. Not relevant for setters. */ |
1334 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1335 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1336 | | false, /* isTypedMethod. Only relevant for methods. */ |
1337 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1338 | | }; |
1339 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1340 | | static_assert(0 < 1, "There is no slot for us"); |
1341 | | |
1342 | | MOZ_CAN_RUN_SCRIPT static bool |
1343 | | removeDelayedFrameScript(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ChromeMessageSender* self, const JSJitMethodCallArgs& args) |
1344 | 0 | { |
1345 | 0 | AUTO_PROFILER_LABEL_FAST("ChromeMessageSender.removeDelayedFrameScript", DOM, cx); |
1346 | 0 |
|
1347 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
1348 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ChromeMessageSender.removeDelayedFrameScript"); |
1349 | 0 | } |
1350 | 0 | binding_detail::FakeString arg0; |
1351 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
1352 | 0 | return false; |
1353 | 0 | } |
1354 | 0 | self->RemoveDelayedFrameScript(NonNullHelper(Constify(arg0))); |
1355 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1356 | 0 | args.rval().setUndefined(); |
1357 | 0 | return true; |
1358 | 0 | } |
1359 | | |
1360 | | static const JSJitInfo removeDelayedFrameScript_methodinfo = { |
1361 | | { (JSJitGetterOp)removeDelayedFrameScript }, |
1362 | | { prototypes::id::ChromeMessageSender }, |
1363 | | { PrototypeTraits<prototypes::id::ChromeMessageSender>::Depth }, |
1364 | | JSJitInfo::Method, |
1365 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1366 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
1367 | | false, /* isInfallible. False in setters. */ |
1368 | | false, /* isMovable. Not relevant for setters. */ |
1369 | | false, /* isEliminatable. Not relevant for setters. */ |
1370 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1371 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1372 | | false, /* isTypedMethod. Only relevant for methods. */ |
1373 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1374 | | }; |
1375 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1376 | | static_assert(0 < 1, "There is no slot for us"); |
1377 | | |
1378 | | MOZ_CAN_RUN_SCRIPT static bool |
1379 | | getDelayedFrameScripts(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ChromeMessageSender* self, const JSJitMethodCallArgs& args) |
1380 | 0 | { |
1381 | 0 | AUTO_PROFILER_LABEL_FAST("ChromeMessageSender.getDelayedFrameScripts", DOM, cx); |
1382 | 0 |
|
1383 | 0 | FastErrorResult rv; |
1384 | 0 | nsTArray<nsTArray<JS::Value>> result; |
1385 | 0 | SequenceRooter<nsTArray<JS::Value> > resultRooter(cx, &result); |
1386 | 0 | self->GetDelayedFrameScripts(cx, result, rv); |
1387 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
1388 | 0 | return false; |
1389 | 0 | } |
1390 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1391 | 0 |
|
1392 | 0 | uint32_t length = result.Length(); |
1393 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
1394 | 0 | if (!returnArray) { |
1395 | 0 | return false; |
1396 | 0 | } |
1397 | 0 | // Scope for 'tmp' |
1398 | 0 | { |
1399 | 0 | JS::Rooted<JS::Value> tmp(cx); |
1400 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
1401 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
1402 | 0 | // are different ways to succeed at wrapping the object. |
1403 | 0 | do { |
1404 | 0 |
|
1405 | 0 | uint32_t length = result[sequenceIdx0].Length(); |
1406 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
1407 | 0 | if (!returnArray) { |
1408 | 0 | return false; |
1409 | 0 | } |
1410 | 0 | // Scope for 'tmp' |
1411 | 0 | { |
1412 | 0 | JS::Rooted<JS::Value> tmp(cx); |
1413 | 0 | for (uint32_t sequenceIdx1 = 0; sequenceIdx1 < length; ++sequenceIdx1) { |
1414 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
1415 | 0 | // are different ways to succeed at wrapping the object. |
1416 | 0 | do { |
1417 | 0 | JS::ExposeValueToActiveJS(result[sequenceIdx0][sequenceIdx1]); |
1418 | 0 | tmp.set(result[sequenceIdx0][sequenceIdx1]); |
1419 | 0 | if (!MaybeWrapValue(cx, &tmp)) { |
1420 | 0 | return false; |
1421 | 0 | } |
1422 | 0 | break; |
1423 | 0 | } while (false); |
1424 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx1, tmp, |
1425 | 0 | JSPROP_ENUMERATE)) { |
1426 | 0 | return false; |
1427 | 0 | } |
1428 | 0 | } |
1429 | 0 | } |
1430 | 0 | tmp.setObject(*returnArray); |
1431 | 0 | break; |
1432 | 0 | } while (false); |
1433 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
1434 | 0 | JSPROP_ENUMERATE)) { |
1435 | 0 | return false; |
1436 | 0 | } |
1437 | 0 | } |
1438 | 0 | } |
1439 | 0 | args.rval().setObject(*returnArray); |
1440 | 0 | return true; |
1441 | 0 | } |
1442 | | |
1443 | | static const JSJitInfo getDelayedFrameScripts_methodinfo = { |
1444 | | { (JSJitGetterOp)getDelayedFrameScripts }, |
1445 | | { prototypes::id::ChromeMessageSender }, |
1446 | | { PrototypeTraits<prototypes::id::ChromeMessageSender>::Depth }, |
1447 | | JSJitInfo::Method, |
1448 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1449 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
1450 | | false, /* isInfallible. False in setters. */ |
1451 | | false, /* isMovable. Not relevant for setters. */ |
1452 | | false, /* isEliminatable. Not relevant for setters. */ |
1453 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1454 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1455 | | false, /* isTypedMethod. Only relevant for methods. */ |
1456 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1457 | | }; |
1458 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1459 | | static_assert(0 < 1, "There is no slot for us"); |
1460 | | |
1461 | | static bool |
1462 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
1463 | 0 | { |
1464 | 0 | mozilla::dom::ChromeMessageSender* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ChromeMessageSender>(obj); |
1465 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
1466 | 0 | // obviously can't preserve if we're not initialized. |
1467 | 0 | if (self && self->GetWrapperPreserveColor()) { |
1468 | 0 | PreserveWrapper(self); |
1469 | 0 | } |
1470 | 0 | return true; |
1471 | 0 | } |
1472 | | |
1473 | | static void |
1474 | | _finalize(js::FreeOp* fop, JSObject* obj) |
1475 | 0 | { |
1476 | 0 | mozilla::dom::ChromeMessageSender* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ChromeMessageSender>(obj); |
1477 | 0 | if (self) { |
1478 | 0 | ClearWrapper(self, self, obj); |
1479 | 0 | AddForDeferredFinalization<mozilla::dom::ChromeMessageSender>(self); |
1480 | 0 | } |
1481 | 0 | } |
1482 | | |
1483 | | static size_t |
1484 | | _objectMoved(JSObject* obj, JSObject* old) |
1485 | 0 | { |
1486 | 0 | mozilla::dom::ChromeMessageSender* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ChromeMessageSender>(obj); |
1487 | 0 | if (self) { |
1488 | 0 | UpdateWrapper(self, self, obj, old); |
1489 | 0 | } |
1490 | 0 |
|
1491 | 0 | return 0; |
1492 | 0 | } |
1493 | | |
1494 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
1495 | | #if defined(__clang__) |
1496 | | #pragma clang diagnostic push |
1497 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
1498 | | #endif |
1499 | | static const JSFunctionSpec sMethods_specs[] = { |
1500 | | JS_FNSPEC("loadFrameScript", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&loadFrameScript_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
1501 | | JS_FNSPEC("removeDelayedFrameScript", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&removeDelayedFrameScript_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
1502 | | JS_FNSPEC("getDelayedFrameScripts", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getDelayedFrameScripts_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
1503 | | JS_FS_END |
1504 | | }; |
1505 | | #if defined(__clang__) |
1506 | | #pragma clang diagnostic pop |
1507 | | #endif |
1508 | | |
1509 | | |
1510 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
1511 | | { nullptr, &sMethods_specs[0] }, |
1512 | | { nullptr, nullptr } |
1513 | | }; |
1514 | | |
1515 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1516 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1517 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1518 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1519 | | |
1520 | | |
1521 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
1522 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
1523 | | |
1524 | | static const NativePropertiesN<1> sNativeProperties = { |
1525 | | false, 0, |
1526 | | false, 0, |
1527 | | true, 0 /* sMethods */, |
1528 | | false, 0, |
1529 | | false, 0, |
1530 | | false, 0, |
1531 | | false, 0, |
1532 | | -1, |
1533 | | 3, |
1534 | | sNativeProperties_sortedPropertyIndices, |
1535 | | { |
1536 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
1537 | | } |
1538 | | }; |
1539 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
1540 | | "We have a property info count that is oversized"); |
1541 | | |
1542 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
1543 | | { |
1544 | | "Function", |
1545 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
1546 | | &sBoringInterfaceObjectClassClassOps, |
1547 | | JS_NULL_CLASS_SPEC, |
1548 | | JS_NULL_CLASS_EXT, |
1549 | | &sInterfaceObjectClassObjectOps |
1550 | | }, |
1551 | | eInterface, |
1552 | | true, |
1553 | | prototypes::id::ChromeMessageSender, |
1554 | | PrototypeTraits<prototypes::id::ChromeMessageSender>::Depth, |
1555 | | sNativePropertyHooks, |
1556 | | "function ChromeMessageSender() {\n [native code]\n}", |
1557 | | MessageSender_Binding::GetConstructorObject |
1558 | | }; |
1559 | | |
1560 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
1561 | | { |
1562 | | "ChromeMessageSenderPrototype", |
1563 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
1564 | | JS_NULL_CLASS_OPS, |
1565 | | JS_NULL_CLASS_SPEC, |
1566 | | JS_NULL_CLASS_EXT, |
1567 | | JS_NULL_OBJECT_OPS |
1568 | | }, |
1569 | | eInterfacePrototype, |
1570 | | false, |
1571 | | prototypes::id::ChromeMessageSender, |
1572 | | PrototypeTraits<prototypes::id::ChromeMessageSender>::Depth, |
1573 | | sNativePropertyHooks, |
1574 | | "[object ChromeMessageSenderPrototype]", |
1575 | | MessageSender_Binding::GetProtoObject |
1576 | | }; |
1577 | | |
1578 | | bool |
1579 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
1580 | 0 | { |
1581 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
1582 | 0 | } |
1583 | | |
1584 | | static const js::ClassOps sClassOps = { |
1585 | | _addProperty, /* addProperty */ |
1586 | | nullptr, /* delProperty */ |
1587 | | nullptr, /* enumerate */ |
1588 | | nullptr, /* newEnumerate */ |
1589 | | nullptr, /* resolve */ |
1590 | | nullptr, /* mayResolve */ |
1591 | | _finalize, /* finalize */ |
1592 | | nullptr, /* call */ |
1593 | | nullptr, /* hasInstance */ |
1594 | | nullptr, /* construct */ |
1595 | | nullptr, /* trace */ |
1596 | | }; |
1597 | | |
1598 | | static const js::ClassExtension sClassExtension = { |
1599 | | nullptr, /* weakmapKeyDelegateOp */ |
1600 | | _objectMoved /* objectMovedOp */ |
1601 | | }; |
1602 | | |
1603 | | static const DOMJSClass sClass = { |
1604 | | { "ChromeMessageSender", |
1605 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
1606 | | &sClassOps, |
1607 | | JS_NULL_CLASS_SPEC, |
1608 | | &sClassExtension, |
1609 | | JS_NULL_OBJECT_OPS |
1610 | | }, |
1611 | | { prototypes::id::MessageListenerManager, prototypes::id::MessageSender, prototypes::id::ChromeMessageSender, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
1612 | | IsBaseOf<nsISupports, mozilla::dom::ChromeMessageSender >::value, |
1613 | | sNativePropertyHooks, |
1614 | | FindAssociatedGlobalForNative<mozilla::dom::ChromeMessageSender>::Get, |
1615 | | GetProtoObjectHandle, |
1616 | | GetCCParticipant<mozilla::dom::ChromeMessageSender>::Get() |
1617 | | }; |
1618 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
1619 | | "Must have the right minimal number of reserved slots."); |
1620 | | static_assert(1 >= 1, |
1621 | | "Must have enough reserved slots."); |
1622 | | |
1623 | | const JSClass* |
1624 | | GetJSClass() |
1625 | 0 | { |
1626 | 0 | return sClass.ToJSClass(); |
1627 | 0 | } |
1628 | | |
1629 | | bool |
1630 | | Wrap(JSContext* aCx, mozilla::dom::ChromeMessageSender* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
1631 | 0 | { |
1632 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::ChromeMessageSender>::value, |
1633 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
1634 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::ChromeMessageSender*>(aObject) == |
1635 | 0 | reinterpret_cast<mozilla::dom::ChromeMessageSender*>(aObject), |
1636 | 0 | "Multiple inheritance for mozilla::dom::ChromeMessageSender is broken."); |
1637 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::MessageSender*>(aObject) == |
1638 | 0 | reinterpret_cast<mozilla::dom::MessageSender*>(aObject), |
1639 | 0 | "Multiple inheritance for mozilla::dom::MessageSender is broken."); |
1640 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::MessageListenerManager*>(aObject) == |
1641 | 0 | reinterpret_cast<mozilla::dom::MessageListenerManager*>(aObject), |
1642 | 0 | "Multiple inheritance for mozilla::dom::MessageListenerManager is broken."); |
1643 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
1644 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
1645 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
1646 | 0 | "You should probably not be using Wrap() directly; use " |
1647 | 0 | "GetOrCreateDOMReflector instead"); |
1648 | 0 |
|
1649 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
1650 | 0 | "nsISupports must be on our primary inheritance chain"); |
1651 | 0 |
|
1652 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
1653 | 0 | if (!global) { |
1654 | 0 | return false; |
1655 | 0 | } |
1656 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
1657 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
1658 | 0 |
|
1659 | 0 | // That might have ended up wrapping us already, due to the wonders |
1660 | 0 | // of XBL. Check for that, and bail out as needed. |
1661 | 0 | aReflector.set(aCache->GetWrapper()); |
1662 | 0 | if (aReflector) { |
1663 | | #ifdef DEBUG |
1664 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
1665 | | #endif // DEBUG |
1666 | | return true; |
1667 | 0 | } |
1668 | 0 |
|
1669 | 0 | JSAutoRealm ar(aCx, global); |
1670 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
1671 | 0 | if (!canonicalProto) { |
1672 | 0 | return false; |
1673 | 0 | } |
1674 | 0 | JS::Rooted<JSObject*> proto(aCx); |
1675 | 0 | if (aGivenProto) { |
1676 | 0 | proto = aGivenProto; |
1677 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
1678 | 0 | // coming in, we changed compartments to that of "parent" so may need |
1679 | 0 | // to wrap the proto here. |
1680 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
1681 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
1682 | 0 | return false; |
1683 | 0 | } |
1684 | 0 | } |
1685 | 0 | } else { |
1686 | 0 | proto = canonicalProto; |
1687 | 0 | } |
1688 | 0 |
|
1689 | 0 | BindingJSObjectCreator<mozilla::dom::ChromeMessageSender> creator(aCx); |
1690 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
1691 | 0 | if (!aReflector) { |
1692 | 0 | return false; |
1693 | 0 | } |
1694 | 0 | |
1695 | 0 | aCache->SetWrapper(aReflector); |
1696 | 0 | creator.InitializationSucceeded(); |
1697 | 0 |
|
1698 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
1699 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
1700 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
1701 | 0 | // otherwise we won't be able to properly recreate it later, since |
1702 | 0 | // we won't know what proto to use. Note that we don't check |
1703 | 0 | // aGivenProto here, since it's entirely possible (and even |
1704 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
1705 | 0 | // same as canonicalProto. |
1706 | 0 | if (proto != canonicalProto) { |
1707 | 0 | PreserveWrapper(aObject); |
1708 | 0 | } |
1709 | 0 |
|
1710 | 0 | return true; |
1711 | 0 | } |
1712 | | |
1713 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
1714 | | nullptr, |
1715 | | nullptr, |
1716 | | nullptr, |
1717 | | { sNativeProperties.Upcast(), nullptr }, |
1718 | | prototypes::id::ChromeMessageSender, |
1719 | | constructors::id::ChromeMessageSender, |
1720 | | MessageSender_Binding::sNativePropertyHooks, |
1721 | | &DefaultXrayExpandoObjectClass |
1722 | | } }; |
1723 | | |
1724 | | void |
1725 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
1726 | 0 | { |
1727 | 0 | JS::Handle<JSObject*> parentProto(MessageSender_Binding::GetProtoObjectHandle(aCx)); |
1728 | 0 | if (!parentProto) { |
1729 | 0 | return; |
1730 | 0 | } |
1731 | 0 | |
1732 | 0 | JS::Handle<JSObject*> constructorProto(MessageSender_Binding::GetConstructorObjectHandle(aCx)); |
1733 | 0 | if (!constructorProto) { |
1734 | 0 | return; |
1735 | 0 | } |
1736 | 0 | |
1737 | 0 | static bool sIdsInited = false; |
1738 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
1739 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
1740 | 0 | return; |
1741 | 0 | } |
1742 | 0 | sIdsInited = true; |
1743 | 0 | } |
1744 | 0 |
|
1745 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ChromeMessageSender); |
1746 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ChromeMessageSender); |
1747 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
1748 | 0 | &sPrototypeClass.mBase, protoCache, |
1749 | 0 | nullptr, |
1750 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
1751 | 0 | interfaceCache, |
1752 | 0 | sNativeProperties.Upcast(), |
1753 | 0 | nullptr, |
1754 | 0 | "ChromeMessageSender", aDefineOnGlobal, |
1755 | 0 | nullptr, |
1756 | 0 | false); |
1757 | 0 | } |
1758 | | |
1759 | | JSObject* |
1760 | | GetConstructorObject(JSContext* aCx) |
1761 | 0 | { |
1762 | 0 | return GetConstructorObjectHandle(aCx); |
1763 | 0 | } |
1764 | | |
1765 | | } // namespace ChromeMessageSender_Binding |
1766 | | |
1767 | | |
1768 | | |
1769 | | namespace ContentFrameMessageManager_Binding { |
1770 | | |
1771 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value, |
1772 | | "Can't inherit from an interface with a different ownership model."); |
1773 | | |
1774 | | MOZ_CAN_RUN_SCRIPT static bool |
1775 | | get_content(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, JSJitGetterCallArgs args) |
1776 | 0 | { |
1777 | 0 | AUTO_PROFILER_LABEL_FAST("get ContentFrameMessageManager.content", DOM, cx); |
1778 | 0 |
|
1779 | 0 | FastErrorResult rv; |
1780 | 0 | auto result(StrongOrRawPtr<nsPIDOMWindowOuter>(self->GetContent(rv))); |
1781 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
1782 | 0 | return false; |
1783 | 0 | } |
1784 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1785 | 0 | if (!result) { |
1786 | 0 | args.rval().setNull(); |
1787 | 0 | return true; |
1788 | 0 | } |
1789 | 0 | if (!WrapObject(cx, result, args.rval())) { |
1790 | 0 | return false; |
1791 | 0 | } |
1792 | 0 | return true; |
1793 | 0 | } |
1794 | | |
1795 | | static const JSJitInfo content_getterinfo = { |
1796 | | { (JSJitGetterOp)get_content }, |
1797 | | { prototypes::id::ContentFrameMessageManager }, |
1798 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
1799 | | JSJitInfo::Getter, |
1800 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1801 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
1802 | | false, /* isInfallible. False in setters. */ |
1803 | | false, /* isMovable. Not relevant for setters. */ |
1804 | | false, /* isEliminatable. Not relevant for setters. */ |
1805 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1806 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1807 | | false, /* isTypedMethod. Only relevant for methods. */ |
1808 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1809 | | }; |
1810 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1811 | | static_assert(0 < 1, "There is no slot for us"); |
1812 | | |
1813 | | MOZ_CAN_RUN_SCRIPT static bool |
1814 | | get_docShell(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, JSJitGetterCallArgs args) |
1815 | 0 | { |
1816 | 0 | AUTO_PROFILER_LABEL_FAST("get ContentFrameMessageManager.docShell", DOM, cx); |
1817 | 0 |
|
1818 | 0 | FastErrorResult rv; |
1819 | 0 | auto result(StrongOrRawPtr<nsIDocShell>(self->GetDocShell(rv))); |
1820 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
1821 | 0 | return false; |
1822 | 0 | } |
1823 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1824 | 0 | if (!result) { |
1825 | 0 | args.rval().setNull(); |
1826 | 0 | return true; |
1827 | 0 | } |
1828 | 0 | if (!WrapObject(cx, result, &NS_GET_IID(nsIDocShell), args.rval())) { |
1829 | 0 | return false; |
1830 | 0 | } |
1831 | 0 | return true; |
1832 | 0 | } |
1833 | | |
1834 | | static const JSJitInfo docShell_getterinfo = { |
1835 | | { (JSJitGetterOp)get_docShell }, |
1836 | | { prototypes::id::ContentFrameMessageManager }, |
1837 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
1838 | | JSJitInfo::Getter, |
1839 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1840 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
1841 | | false, /* isInfallible. False in setters. */ |
1842 | | false, /* isMovable. Not relevant for setters. */ |
1843 | | false, /* isEliminatable. Not relevant for setters. */ |
1844 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1845 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1846 | | false, /* isTypedMethod. Only relevant for methods. */ |
1847 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1848 | | }; |
1849 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1850 | | static_assert(0 < 1, "There is no slot for us"); |
1851 | | |
1852 | | MOZ_CAN_RUN_SCRIPT static bool |
1853 | | get_tabEventTarget(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, JSJitGetterCallArgs args) |
1854 | 0 | { |
1855 | 0 | AUTO_PROFILER_LABEL_FAST("get ContentFrameMessageManager.tabEventTarget", DOM, cx); |
1856 | 0 |
|
1857 | 0 | auto result(StrongOrRawPtr<nsIEventTarget>(self->GetTabEventTarget())); |
1858 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1859 | 0 | if (!result) { |
1860 | 0 | args.rval().setNull(); |
1861 | 0 | return true; |
1862 | 0 | } |
1863 | 0 | if (!WrapObject(cx, result, &NS_GET_IID(nsIEventTarget), args.rval())) { |
1864 | 0 | return false; |
1865 | 0 | } |
1866 | 0 | return true; |
1867 | 0 | } |
1868 | | |
1869 | | static const JSJitInfo tabEventTarget_getterinfo = { |
1870 | | { (JSJitGetterOp)get_tabEventTarget }, |
1871 | | { prototypes::id::ContentFrameMessageManager }, |
1872 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
1873 | | JSJitInfo::Getter, |
1874 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1875 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
1876 | | false, /* isInfallible. False in setters. */ |
1877 | | false, /* isMovable. Not relevant for setters. */ |
1878 | | false, /* isEliminatable. Not relevant for setters. */ |
1879 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1880 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1881 | | false, /* isTypedMethod. Only relevant for methods. */ |
1882 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1883 | | }; |
1884 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1885 | | static_assert(0 < 1, "There is no slot for us"); |
1886 | | |
1887 | | MOZ_CAN_RUN_SCRIPT static bool |
1888 | | get_chromeOuterWindowID(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, JSJitGetterCallArgs args) |
1889 | 0 | { |
1890 | 0 | AUTO_PROFILER_LABEL_FAST("get ContentFrameMessageManager.chromeOuterWindowID", DOM, cx); |
1891 | 0 |
|
1892 | 0 | int64_t result(self->ChromeOuterWindowID()); |
1893 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1894 | 0 | args.rval().set(JS_NumberValue(double(result))); |
1895 | 0 | return true; |
1896 | 0 | } |
1897 | | |
1898 | | static const JSJitInfo chromeOuterWindowID_getterinfo = { |
1899 | | { (JSJitGetterOp)get_chromeOuterWindowID }, |
1900 | | { prototypes::id::ContentFrameMessageManager }, |
1901 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
1902 | | JSJitInfo::Getter, |
1903 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1904 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
1905 | | true, /* isInfallible. False in setters. */ |
1906 | | false, /* isMovable. Not relevant for setters. */ |
1907 | | false, /* isEliminatable. Not relevant for setters. */ |
1908 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1909 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1910 | | false, /* isTypedMethod. Only relevant for methods. */ |
1911 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1912 | | }; |
1913 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1914 | | static_assert(0 < 1, "There is no slot for us"); |
1915 | | |
1916 | | MOZ_CAN_RUN_SCRIPT static bool |
1917 | | addMessageListener(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, const JSJitMethodCallArgs& args) |
1918 | 0 | { |
1919 | 0 | AUTO_PROFILER_LABEL_FAST("ContentFrameMessageManager.addMessageListener", DOM, cx); |
1920 | 0 |
|
1921 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
1922 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContentFrameMessageManager.addMessageListener"); |
1923 | 0 | } |
1924 | 0 | binding_detail::FakeString arg0; |
1925 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
1926 | 0 | return false; |
1927 | 0 | } |
1928 | 0 | RootedCallback<OwningNonNull<binding_detail::FastMessageListener>> arg1(cx); |
1929 | 0 | if (args[1].isObject()) { |
1930 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
1931 | 0 | arg1 = new binding_detail::FastMessageListener(&args[1].toObject(), JS::CurrentGlobalOrNull(cx)); |
1932 | 0 | } |
1933 | 0 | } else { |
1934 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of ContentFrameMessageManager.addMessageListener"); |
1935 | 0 | return false; |
1936 | 0 | } |
1937 | 0 | bool arg2; |
1938 | 0 | if (args.hasDefined(2)) { |
1939 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, args[2], &arg2)) { |
1940 | 0 | return false; |
1941 | 0 | } |
1942 | 0 | } else { |
1943 | 0 | arg2 = false; |
1944 | 0 | } |
1945 | 0 | FastErrorResult rv; |
1946 | 0 | self->AddMessageListener(NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), arg2, rv); |
1947 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
1948 | 0 | return false; |
1949 | 0 | } |
1950 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1951 | 0 | args.rval().setUndefined(); |
1952 | 0 | return true; |
1953 | 0 | } |
1954 | | |
1955 | | static const JSJitInfo addMessageListener_methodinfo = { |
1956 | | { (JSJitGetterOp)addMessageListener }, |
1957 | | { prototypes::id::ContentFrameMessageManager }, |
1958 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
1959 | | JSJitInfo::Method, |
1960 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1961 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
1962 | | false, /* isInfallible. False in setters. */ |
1963 | | false, /* isMovable. Not relevant for setters. */ |
1964 | | false, /* isEliminatable. Not relevant for setters. */ |
1965 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1966 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1967 | | false, /* isTypedMethod. Only relevant for methods. */ |
1968 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1969 | | }; |
1970 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1971 | | static_assert(0 < 1, "There is no slot for us"); |
1972 | | |
1973 | | MOZ_CAN_RUN_SCRIPT static bool |
1974 | | removeMessageListener(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, const JSJitMethodCallArgs& args) |
1975 | 0 | { |
1976 | 0 | AUTO_PROFILER_LABEL_FAST("ContentFrameMessageManager.removeMessageListener", DOM, cx); |
1977 | 0 |
|
1978 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
1979 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContentFrameMessageManager.removeMessageListener"); |
1980 | 0 | } |
1981 | 0 | binding_detail::FakeString arg0; |
1982 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
1983 | 0 | return false; |
1984 | 0 | } |
1985 | 0 | RootedCallback<OwningNonNull<binding_detail::FastMessageListener>> arg1(cx); |
1986 | 0 | if (args[1].isObject()) { |
1987 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
1988 | 0 | arg1 = new binding_detail::FastMessageListener(&args[1].toObject(), JS::CurrentGlobalOrNull(cx)); |
1989 | 0 | } |
1990 | 0 | } else { |
1991 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of ContentFrameMessageManager.removeMessageListener"); |
1992 | 0 | return false; |
1993 | 0 | } |
1994 | 0 | FastErrorResult rv; |
1995 | 0 | self->RemoveMessageListener(NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), rv); |
1996 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
1997 | 0 | return false; |
1998 | 0 | } |
1999 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
2000 | 0 | args.rval().setUndefined(); |
2001 | 0 | return true; |
2002 | 0 | } |
2003 | | |
2004 | | static const JSJitInfo removeMessageListener_methodinfo = { |
2005 | | { (JSJitGetterOp)removeMessageListener }, |
2006 | | { prototypes::id::ContentFrameMessageManager }, |
2007 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
2008 | | JSJitInfo::Method, |
2009 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
2010 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
2011 | | false, /* isInfallible. False in setters. */ |
2012 | | false, /* isMovable. Not relevant for setters. */ |
2013 | | false, /* isEliminatable. Not relevant for setters. */ |
2014 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
2015 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
2016 | | false, /* isTypedMethod. Only relevant for methods. */ |
2017 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
2018 | | }; |
2019 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
2020 | | static_assert(0 < 1, "There is no slot for us"); |
2021 | | |
2022 | | MOZ_CAN_RUN_SCRIPT static bool |
2023 | | addWeakMessageListener(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, const JSJitMethodCallArgs& args) |
2024 | 0 | { |
2025 | 0 | AUTO_PROFILER_LABEL_FAST("ContentFrameMessageManager.addWeakMessageListener", DOM, cx); |
2026 | 0 |
|
2027 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
2028 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContentFrameMessageManager.addWeakMessageListener"); |
2029 | 0 | } |
2030 | 0 | binding_detail::FakeString arg0; |
2031 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
2032 | 0 | return false; |
2033 | 0 | } |
2034 | 0 | RootedCallback<OwningNonNull<binding_detail::FastMessageListener>> arg1(cx); |
2035 | 0 | if (args[1].isObject()) { |
2036 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
2037 | 0 | arg1 = new binding_detail::FastMessageListener(&args[1].toObject(), JS::CurrentGlobalOrNull(cx)); |
2038 | 0 | } |
2039 | 0 | } else { |
2040 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of ContentFrameMessageManager.addWeakMessageListener"); |
2041 | 0 | return false; |
2042 | 0 | } |
2043 | 0 | FastErrorResult rv; |
2044 | 0 | self->AddWeakMessageListener(NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), rv); |
2045 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
2046 | 0 | return false; |
2047 | 0 | } |
2048 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
2049 | 0 | args.rval().setUndefined(); |
2050 | 0 | return true; |
2051 | 0 | } |
2052 | | |
2053 | | static const JSJitInfo addWeakMessageListener_methodinfo = { |
2054 | | { (JSJitGetterOp)addWeakMessageListener }, |
2055 | | { prototypes::id::ContentFrameMessageManager }, |
2056 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
2057 | | JSJitInfo::Method, |
2058 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
2059 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
2060 | | false, /* isInfallible. False in setters. */ |
2061 | | false, /* isMovable. Not relevant for setters. */ |
2062 | | false, /* isEliminatable. Not relevant for setters. */ |
2063 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
2064 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
2065 | | false, /* isTypedMethod. Only relevant for methods. */ |
2066 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
2067 | | }; |
2068 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
2069 | | static_assert(0 < 1, "There is no slot for us"); |
2070 | | |
2071 | | MOZ_CAN_RUN_SCRIPT static bool |
2072 | | removeWeakMessageListener(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, const JSJitMethodCallArgs& args) |
2073 | 0 | { |
2074 | 0 | AUTO_PROFILER_LABEL_FAST("ContentFrameMessageManager.removeWeakMessageListener", DOM, cx); |
2075 | 0 |
|
2076 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
2077 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContentFrameMessageManager.removeWeakMessageListener"); |
2078 | 0 | } |
2079 | 0 | binding_detail::FakeString arg0; |
2080 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
2081 | 0 | return false; |
2082 | 0 | } |
2083 | 0 | RootedCallback<OwningNonNull<binding_detail::FastMessageListener>> arg1(cx); |
2084 | 0 | if (args[1].isObject()) { |
2085 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
2086 | 0 | arg1 = new binding_detail::FastMessageListener(&args[1].toObject(), JS::CurrentGlobalOrNull(cx)); |
2087 | 0 | } |
2088 | 0 | } else { |
2089 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of ContentFrameMessageManager.removeWeakMessageListener"); |
2090 | 0 | return false; |
2091 | 0 | } |
2092 | 0 | FastErrorResult rv; |
2093 | 0 | self->RemoveWeakMessageListener(NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), rv); |
2094 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
2095 | 0 | return false; |
2096 | 0 | } |
2097 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
2098 | 0 | args.rval().setUndefined(); |
2099 | 0 | return true; |
2100 | 0 | } |
2101 | | |
2102 | | static const JSJitInfo removeWeakMessageListener_methodinfo = { |
2103 | | { (JSJitGetterOp)removeWeakMessageListener }, |
2104 | | { prototypes::id::ContentFrameMessageManager }, |
2105 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
2106 | | JSJitInfo::Method, |
2107 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
2108 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
2109 | | false, /* isInfallible. False in setters. */ |
2110 | | false, /* isMovable. Not relevant for setters. */ |
2111 | | false, /* isEliminatable. Not relevant for setters. */ |
2112 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
2113 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
2114 | | false, /* isTypedMethod. Only relevant for methods. */ |
2115 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
2116 | | }; |
2117 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
2118 | | static_assert(0 < 1, "There is no slot for us"); |
2119 | | |
2120 | | MOZ_CAN_RUN_SCRIPT static bool |
2121 | | dump(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, const JSJitMethodCallArgs& args) |
2122 | 0 | { |
2123 | 0 | AUTO_PROFILER_LABEL_FAST("ContentFrameMessageManager.dump", DOM, cx); |
2124 | 0 |
|
2125 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
2126 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContentFrameMessageManager.dump"); |
2127 | 0 | } |
2128 | 0 | binding_detail::FakeString arg0; |
2129 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
2130 | 0 | return false; |
2131 | 0 | } |
2132 | 0 | self->Dump(NonNullHelper(Constify(arg0))); |
2133 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
2134 | 0 | args.rval().setUndefined(); |
2135 | 0 | return true; |
2136 | 0 | } |
2137 | | |
2138 | | static const JSJitInfo dump_methodinfo = { |
2139 | | { (JSJitGetterOp)dump }, |
2140 | | { prototypes::id::ContentFrameMessageManager }, |
2141 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
2142 | | JSJitInfo::Method, |
2143 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
2144 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
2145 | | false, /* isInfallible. False in setters. */ |
2146 | | false, /* isMovable. Not relevant for setters. */ |
2147 | | false, /* isEliminatable. Not relevant for setters. */ |
2148 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
2149 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
2150 | | false, /* isTypedMethod. Only relevant for methods. */ |
2151 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
2152 | | }; |
2153 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
2154 | | static_assert(0 < 1, "There is no slot for us"); |
2155 | | |
2156 | | MOZ_CAN_RUN_SCRIPT static bool |
2157 | | privateNoteIntentionalCrash(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, const JSJitMethodCallArgs& args) |
2158 | 0 | { |
2159 | 0 | AUTO_PROFILER_LABEL_FAST("ContentFrameMessageManager.privateNoteIntentionalCrash", DOM, cx); |
2160 | 0 |
|
2161 | 0 | FastErrorResult rv; |
2162 | 0 | self->PrivateNoteIntentionalCrash(rv); |
2163 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
2164 | 0 | return false; |
2165 | 0 | } |
2166 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
2167 | 0 | args.rval().setUndefined(); |
2168 | 0 | return true; |
2169 | 0 | } |
2170 | | |
2171 | | static const JSJitInfo privateNoteIntentionalCrash_methodinfo = { |
2172 | | { (JSJitGetterOp)privateNoteIntentionalCrash }, |
2173 | | { prototypes::id::ContentFrameMessageManager }, |
2174 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
2175 | | JSJitInfo::Method, |
2176 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
2177 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
2178 | | false, /* isInfallible. False in setters. */ |
2179 | | false, /* isMovable. Not relevant for setters. */ |
2180 | | false, /* isEliminatable. Not relevant for setters. */ |
2181 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
2182 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
2183 | | false, /* isTypedMethod. Only relevant for methods. */ |
2184 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
2185 | | }; |
2186 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
2187 | | static_assert(0 < 1, "There is no slot for us"); |
2188 | | |
2189 | | MOZ_CAN_RUN_SCRIPT static bool |
2190 | | atob(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, const JSJitMethodCallArgs& args) |
2191 | 0 | { |
2192 | 0 | AUTO_PROFILER_LABEL_FAST("ContentFrameMessageManager.atob", DOM, cx); |
2193 | 0 |
|
2194 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
2195 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContentFrameMessageManager.atob"); |
2196 | 0 | } |
2197 | 0 | binding_detail::FakeString arg0; |
2198 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
2199 | 0 | return false; |
2200 | 0 | } |
2201 | 0 | FastErrorResult rv; |
2202 | 0 | DOMString result; |
2203 | 0 | self->Atob(NonNullHelper(Constify(arg0)), result, rv); |
2204 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
2205 | 0 | return false; |
2206 | 0 | } |
2207 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
2208 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
2209 | 0 | return false; |
2210 | 0 | } |
2211 | 0 | return true; |
2212 | 0 | } |
2213 | | |
2214 | | static const JSJitInfo atob_methodinfo = { |
2215 | | { (JSJitGetterOp)atob }, |
2216 | | { prototypes::id::ContentFrameMessageManager }, |
2217 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
2218 | | JSJitInfo::Method, |
2219 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
2220 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
2221 | | false, /* isInfallible. False in setters. */ |
2222 | | false, /* isMovable. Not relevant for setters. */ |
2223 | | false, /* isEliminatable. Not relevant for setters. */ |
2224 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
2225 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
2226 | | false, /* isTypedMethod. Only relevant for methods. */ |
2227 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
2228 | | }; |
2229 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
2230 | | static_assert(0 < 1, "There is no slot for us"); |
2231 | | |
2232 | | MOZ_CAN_RUN_SCRIPT static bool |
2233 | | btoa(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, const JSJitMethodCallArgs& args) |
2234 | 0 | { |
2235 | 0 | AUTO_PROFILER_LABEL_FAST("ContentFrameMessageManager.btoa", DOM, cx); |
2236 | 0 |
|
2237 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
2238 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContentFrameMessageManager.btoa"); |
2239 | 0 | } |
2240 | 0 | binding_detail::FakeString arg0; |
2241 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
2242 | 0 | return false; |
2243 | 0 | } |
2244 | 0 | FastErrorResult rv; |
2245 | 0 | DOMString result; |
2246 | 0 | self->Btoa(NonNullHelper(Constify(arg0)), result, rv); |
2247 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
2248 | 0 | return false; |
2249 | 0 | } |
2250 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
2251 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
2252 | 0 | return false; |
2253 | 0 | } |
2254 | 0 | return true; |
2255 | 0 | } |
2256 | | |
2257 | | static const JSJitInfo btoa_methodinfo = { |
2258 | | { (JSJitGetterOp)btoa }, |
2259 | | { prototypes::id::ContentFrameMessageManager }, |
2260 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
2261 | | JSJitInfo::Method, |
2262 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
2263 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
2264 | | false, /* isInfallible. False in setters. */ |
2265 | | false, /* isMovable. Not relevant for setters. */ |
2266 | | false, /* isEliminatable. Not relevant for setters. */ |
2267 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
2268 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
2269 | | false, /* isTypedMethod. Only relevant for methods. */ |
2270 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
2271 | | }; |
2272 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
2273 | | static_assert(0 < 1, "There is no slot for us"); |
2274 | | |
2275 | | MOZ_CAN_RUN_SCRIPT static bool |
2276 | | sendAsyncMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, const JSJitMethodCallArgs& args) |
2277 | 0 | { |
2278 | 0 | AUTO_PROFILER_LABEL_FAST("ContentFrameMessageManager.sendAsyncMessage", DOM, cx); |
2279 | 0 |
|
2280 | 0 | binding_detail::FakeString arg0; |
2281 | 0 | if (args.hasDefined(0)) { |
2282 | 0 | if (!ConvertJSValueToString(cx, args[0], eNull, eNull, arg0)) { |
2283 | 0 | return false; |
2284 | 0 | } |
2285 | 0 | } else { |
2286 | 0 | arg0.SetIsVoid(true); |
2287 | 0 | } |
2288 | 0 | JS::Rooted<JS::Value> arg1(cx); |
2289 | 0 | if (args.hasDefined(1)) { |
2290 | 0 | arg1 = args[1]; |
2291 | 0 | } else { |
2292 | 0 | arg1 = JS::UndefinedValue(); |
2293 | 0 | } |
2294 | 0 | JS::Rooted<JSObject*> arg2(cx); |
2295 | 0 | if (args.hasDefined(2)) { |
2296 | 0 | if (args[2].isObject()) { |
2297 | 0 | arg2 = &args[2].toObject(); |
2298 | 0 | } else if (args[2].isNullOrUndefined()) { |
2299 | 0 | arg2 = nullptr; |
2300 | 0 | } else { |
2301 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of ContentFrameMessageManager.sendAsyncMessage"); |
2302 | 0 | return false; |
2303 | 0 | } |
2304 | 0 | } else { |
2305 | 0 | arg2 = nullptr; |
2306 | 0 | } |
2307 | 0 | nsIPrincipal* arg3; |
2308 | 0 | RefPtr<nsIPrincipal> arg3_holder; |
2309 | 0 | if (args.hasDefined(3)) { |
2310 | 0 | if (args[3].isObject()) { |
2311 | 0 | JS::Rooted<JSObject*> source(cx, &args[3].toObject()); |
2312 | 0 | if (NS_FAILED(UnwrapArg<nsIPrincipal>(cx, source, getter_AddRefs(arg3_holder)))) { |
2313 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 4 of ContentFrameMessageManager.sendAsyncMessage", "Principal"); |
2314 | 0 | return false; |
2315 | 0 | } |
2316 | 0 | MOZ_ASSERT(arg3_holder); |
2317 | 0 | arg3 = arg3_holder; |
2318 | 0 | } else if (args[3].isNullOrUndefined()) { |
2319 | 0 | arg3 = nullptr; |
2320 | 0 | } else { |
2321 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 4 of ContentFrameMessageManager.sendAsyncMessage"); |
2322 | 0 | return false; |
2323 | 0 | } |
2324 | 0 | } else { |
2325 | 0 | arg3 = nullptr; |
2326 | 0 | } |
2327 | 0 | JS::Rooted<JS::Value> arg4(cx); |
2328 | 0 | if (args.hasDefined(4)) { |
2329 | 0 | arg4 = args[4]; |
2330 | 0 | } else { |
2331 | 0 | arg4 = JS::UndefinedValue(); |
2332 | 0 | } |
2333 | 0 | FastErrorResult rv; |
2334 | 0 | self->SendAsyncMessage(cx, NonNullHelper(Constify(arg0)), arg1, arg2, MOZ_KnownLive(Constify(arg3)), arg4, rv); |
2335 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
2336 | 0 | return false; |
2337 | 0 | } |
2338 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
2339 | 0 | args.rval().setUndefined(); |
2340 | 0 | return true; |
2341 | 0 | } |
2342 | | |
2343 | | static const JSJitInfo sendAsyncMessage_methodinfo = { |
2344 | | { (JSJitGetterOp)sendAsyncMessage }, |
2345 | | { prototypes::id::ContentFrameMessageManager }, |
2346 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
2347 | | JSJitInfo::Method, |
2348 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
2349 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
2350 | | false, /* isInfallible. False in setters. */ |
2351 | | false, /* isMovable. Not relevant for setters. */ |
2352 | | false, /* isEliminatable. Not relevant for setters. */ |
2353 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
2354 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
2355 | | false, /* isTypedMethod. Only relevant for methods. */ |
2356 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
2357 | | }; |
2358 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
2359 | | static_assert(0 < 1, "There is no slot for us"); |
2360 | | |
2361 | | MOZ_CAN_RUN_SCRIPT static bool |
2362 | | get_processMessageManager(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, JSJitGetterCallArgs args) |
2363 | 0 | { |
2364 | 0 | AUTO_PROFILER_LABEL_FAST("get ContentFrameMessageManager.processMessageManager", DOM, cx); |
2365 | 0 |
|
2366 | 0 | FastErrorResult rv; |
2367 | 0 | auto result(StrongOrRawPtr<mozilla::dom::MessageSender>(self->GetProcessMessageManager(rv))); |
2368 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
2369 | 0 | return false; |
2370 | 0 | } |
2371 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
2372 | 0 | if (!result) { |
2373 | 0 | args.rval().setNull(); |
2374 | 0 | return true; |
2375 | 0 | } |
2376 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
2377 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
2378 | 0 | return false; |
2379 | 0 | } |
2380 | 0 | return true; |
2381 | 0 | } |
2382 | | |
2383 | | static const JSJitInfo processMessageManager_getterinfo = { |
2384 | | { (JSJitGetterOp)get_processMessageManager }, |
2385 | | { prototypes::id::ContentFrameMessageManager }, |
2386 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
2387 | | JSJitInfo::Getter, |
2388 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
2389 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
2390 | | false, /* isInfallible. False in setters. */ |
2391 | | false, /* isMovable. Not relevant for setters. */ |
2392 | | false, /* isEliminatable. Not relevant for setters. */ |
2393 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
2394 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
2395 | | false, /* isTypedMethod. Only relevant for methods. */ |
2396 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
2397 | | }; |
2398 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
2399 | | static_assert(0 < 1, "There is no slot for us"); |
2400 | | |
2401 | | MOZ_CAN_RUN_SCRIPT static bool |
2402 | | get_remoteType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, JSJitGetterCallArgs args) |
2403 | 0 | { |
2404 | 0 | AUTO_PROFILER_LABEL_FAST("get ContentFrameMessageManager.remoteType", DOM, cx); |
2405 | 0 |
|
2406 | 0 | FastErrorResult rv; |
2407 | 0 | DOMString result; |
2408 | 0 | self->GetRemoteType(result, rv); |
2409 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
2410 | 0 | return false; |
2411 | 0 | } |
2412 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
2413 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
2414 | 0 | return false; |
2415 | 0 | } |
2416 | 0 | return true; |
2417 | 0 | } |
2418 | | |
2419 | | static const JSJitInfo remoteType_getterinfo = { |
2420 | | { (JSJitGetterOp)get_remoteType }, |
2421 | | { prototypes::id::ContentFrameMessageManager }, |
2422 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
2423 | | JSJitInfo::Getter, |
2424 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
2425 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
2426 | | false, /* isInfallible. False in setters. */ |
2427 | | false, /* isMovable. Not relevant for setters. */ |
2428 | | false, /* isEliminatable. Not relevant for setters. */ |
2429 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
2430 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
2431 | | false, /* isTypedMethod. Only relevant for methods. */ |
2432 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
2433 | | }; |
2434 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
2435 | | static_assert(0 < 1, "There is no slot for us"); |
2436 | | |
2437 | | MOZ_CAN_RUN_SCRIPT static bool |
2438 | | sendSyncMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, const JSJitMethodCallArgs& args) |
2439 | 0 | { |
2440 | 0 | AUTO_PROFILER_LABEL_FAST("ContentFrameMessageManager.sendSyncMessage", DOM, cx); |
2441 | 0 |
|
2442 | 0 | binding_detail::FakeString arg0; |
2443 | 0 | if (args.hasDefined(0)) { |
2444 | 0 | if (!ConvertJSValueToString(cx, args[0], eNull, eNull, arg0)) { |
2445 | 0 | return false; |
2446 | 0 | } |
2447 | 0 | } else { |
2448 | 0 | arg0.SetIsVoid(true); |
2449 | 0 | } |
2450 | 0 | JS::Rooted<JS::Value> arg1(cx); |
2451 | 0 | if (args.hasDefined(1)) { |
2452 | 0 | arg1 = args[1]; |
2453 | 0 | } else { |
2454 | 0 | arg1 = JS::UndefinedValue(); |
2455 | 0 | } |
2456 | 0 | JS::Rooted<JSObject*> arg2(cx); |
2457 | 0 | if (args.hasDefined(2)) { |
2458 | 0 | if (args[2].isObject()) { |
2459 | 0 | arg2 = &args[2].toObject(); |
2460 | 0 | } else if (args[2].isNullOrUndefined()) { |
2461 | 0 | arg2 = nullptr; |
2462 | 0 | } else { |
2463 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of ContentFrameMessageManager.sendSyncMessage"); |
2464 | 0 | return false; |
2465 | 0 | } |
2466 | 0 | } else { |
2467 | 0 | arg2 = nullptr; |
2468 | 0 | } |
2469 | 0 | nsIPrincipal* arg3; |
2470 | 0 | RefPtr<nsIPrincipal> arg3_holder; |
2471 | 0 | if (args.hasDefined(3)) { |
2472 | 0 | if (args[3].isObject()) { |
2473 | 0 | JS::Rooted<JSObject*> source(cx, &args[3].toObject()); |
2474 | 0 | if (NS_FAILED(UnwrapArg<nsIPrincipal>(cx, source, getter_AddRefs(arg3_holder)))) { |
2475 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 4 of ContentFrameMessageManager.sendSyncMessage", "Principal"); |
2476 | 0 | return false; |
2477 | 0 | } |
2478 | 0 | MOZ_ASSERT(arg3_holder); |
2479 | 0 | arg3 = arg3_holder; |
2480 | 0 | } else if (args[3].isNullOrUndefined()) { |
2481 | 0 | arg3 = nullptr; |
2482 | 0 | } else { |
2483 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 4 of ContentFrameMessageManager.sendSyncMessage"); |
2484 | 0 | return false; |
2485 | 0 | } |
2486 | 0 | } else { |
2487 | 0 | arg3 = nullptr; |
2488 | 0 | } |
2489 | 0 | FastErrorResult rv; |
2490 | 0 | nsTArray<JS::Value> result; |
2491 | 0 | SequenceRooter<JS::Value > resultRooter(cx, &result); |
2492 | 0 | self->SendSyncMessage(cx, NonNullHelper(Constify(arg0)), arg1, arg2, MOZ_KnownLive(Constify(arg3)), result, rv); |
2493 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
2494 | 0 | return false; |
2495 | 0 | } |
2496 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
2497 | 0 |
|
2498 | 0 | uint32_t length = result.Length(); |
2499 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
2500 | 0 | if (!returnArray) { |
2501 | 0 | return false; |
2502 | 0 | } |
2503 | 0 | // Scope for 'tmp' |
2504 | 0 | { |
2505 | 0 | JS::Rooted<JS::Value> tmp(cx); |
2506 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
2507 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
2508 | 0 | // are different ways to succeed at wrapping the object. |
2509 | 0 | do { |
2510 | 0 | JS::ExposeValueToActiveJS(result[sequenceIdx0]); |
2511 | 0 | tmp.set(result[sequenceIdx0]); |
2512 | 0 | if (!MaybeWrapValue(cx, &tmp)) { |
2513 | 0 | return false; |
2514 | 0 | } |
2515 | 0 | break; |
2516 | 0 | } while (false); |
2517 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
2518 | 0 | JSPROP_ENUMERATE)) { |
2519 | 0 | return false; |
2520 | 0 | } |
2521 | 0 | } |
2522 | 0 | } |
2523 | 0 | args.rval().setObject(*returnArray); |
2524 | 0 | return true; |
2525 | 0 | } |
2526 | | |
2527 | | static const JSJitInfo sendSyncMessage_methodinfo = { |
2528 | | { (JSJitGetterOp)sendSyncMessage }, |
2529 | | { prototypes::id::ContentFrameMessageManager }, |
2530 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
2531 | | JSJitInfo::Method, |
2532 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
2533 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
2534 | | false, /* isInfallible. False in setters. */ |
2535 | | false, /* isMovable. Not relevant for setters. */ |
2536 | | false, /* isEliminatable. Not relevant for setters. */ |
2537 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
2538 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
2539 | | false, /* isTypedMethod. Only relevant for methods. */ |
2540 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
2541 | | }; |
2542 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
2543 | | static_assert(0 < 1, "There is no slot for us"); |
2544 | | |
2545 | | MOZ_CAN_RUN_SCRIPT static bool |
2546 | | sendRpcMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentFrameMessageManager* self, const JSJitMethodCallArgs& args) |
2547 | 0 | { |
2548 | 0 | AUTO_PROFILER_LABEL_FAST("ContentFrameMessageManager.sendRpcMessage", DOM, cx); |
2549 | 0 |
|
2550 | 0 | binding_detail::FakeString arg0; |
2551 | 0 | if (args.hasDefined(0)) { |
2552 | 0 | if (!ConvertJSValueToString(cx, args[0], eNull, eNull, arg0)) { |
2553 | 0 | return false; |
2554 | 0 | } |
2555 | 0 | } else { |
2556 | 0 | arg0.SetIsVoid(true); |
2557 | 0 | } |
2558 | 0 | JS::Rooted<JS::Value> arg1(cx); |
2559 | 0 | if (args.hasDefined(1)) { |
2560 | 0 | arg1 = args[1]; |
2561 | 0 | } else { |
2562 | 0 | arg1 = JS::UndefinedValue(); |
2563 | 0 | } |
2564 | 0 | JS::Rooted<JSObject*> arg2(cx); |
2565 | 0 | if (args.hasDefined(2)) { |
2566 | 0 | if (args[2].isObject()) { |
2567 | 0 | arg2 = &args[2].toObject(); |
2568 | 0 | } else if (args[2].isNullOrUndefined()) { |
2569 | 0 | arg2 = nullptr; |
2570 | 0 | } else { |
2571 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of ContentFrameMessageManager.sendRpcMessage"); |
2572 | 0 | return false; |
2573 | 0 | } |
2574 | 0 | } else { |
2575 | 0 | arg2 = nullptr; |
2576 | 0 | } |
2577 | 0 | nsIPrincipal* arg3; |
2578 | 0 | RefPtr<nsIPrincipal> arg3_holder; |
2579 | 0 | if (args.hasDefined(3)) { |
2580 | 0 | if (args[3].isObject()) { |
2581 | 0 | JS::Rooted<JSObject*> source(cx, &args[3].toObject()); |
2582 | 0 | if (NS_FAILED(UnwrapArg<nsIPrincipal>(cx, source, getter_AddRefs(arg3_holder)))) { |
2583 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 4 of ContentFrameMessageManager.sendRpcMessage", "Principal"); |
2584 | 0 | return false; |
2585 | 0 | } |
2586 | 0 | MOZ_ASSERT(arg3_holder); |
2587 | 0 | arg3 = arg3_holder; |
2588 | 0 | } else if (args[3].isNullOrUndefined()) { |
2589 | 0 | arg3 = nullptr; |
2590 | 0 | } else { |
2591 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 4 of ContentFrameMessageManager.sendRpcMessage"); |
2592 | 0 | return false; |
2593 | 0 | } |
2594 | 0 | } else { |
2595 | 0 | arg3 = nullptr; |
2596 | 0 | } |
2597 | 0 | FastErrorResult rv; |
2598 | 0 | nsTArray<JS::Value> result; |
2599 | 0 | SequenceRooter<JS::Value > resultRooter(cx, &result); |
2600 | 0 | self->SendRpcMessage(cx, NonNullHelper(Constify(arg0)), arg1, arg2, MOZ_KnownLive(Constify(arg3)), result, rv); |
2601 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
2602 | 0 | return false; |
2603 | 0 | } |
2604 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
2605 | 0 |
|
2606 | 0 | uint32_t length = result.Length(); |
2607 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
2608 | 0 | if (!returnArray) { |
2609 | 0 | return false; |
2610 | 0 | } |
2611 | 0 | // Scope for 'tmp' |
2612 | 0 | { |
2613 | 0 | JS::Rooted<JS::Value> tmp(cx); |
2614 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
2615 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
2616 | 0 | // are different ways to succeed at wrapping the object. |
2617 | 0 | do { |
2618 | 0 | JS::ExposeValueToActiveJS(result[sequenceIdx0]); |
2619 | 0 | tmp.set(result[sequenceIdx0]); |
2620 | 0 | if (!MaybeWrapValue(cx, &tmp)) { |
2621 | 0 | return false; |
2622 | 0 | } |
2623 | 0 | break; |
2624 | 0 | } while (false); |
2625 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
2626 | 0 | JSPROP_ENUMERATE)) { |
2627 | 0 | return false; |
2628 | 0 | } |
2629 | 0 | } |
2630 | 0 | } |
2631 | 0 | args.rval().setObject(*returnArray); |
2632 | 0 | return true; |
2633 | 0 | } |
2634 | | |
2635 | | static const JSJitInfo sendRpcMessage_methodinfo = { |
2636 | | { (JSJitGetterOp)sendRpcMessage }, |
2637 | | { prototypes::id::ContentFrameMessageManager }, |
2638 | | { PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth }, |
2639 | | JSJitInfo::Method, |
2640 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
2641 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
2642 | | false, /* isInfallible. False in setters. */ |
2643 | | false, /* isMovable. Not relevant for setters. */ |
2644 | | false, /* isEliminatable. Not relevant for setters. */ |
2645 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
2646 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
2647 | | false, /* isTypedMethod. Only relevant for methods. */ |
2648 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
2649 | | }; |
2650 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
2651 | | static_assert(0 < 1, "There is no slot for us"); |
2652 | | |
2653 | | static bool |
2654 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
2655 | 0 | { |
2656 | 0 | mozilla::dom::ContentFrameMessageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ContentFrameMessageManager>(obj); |
2657 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
2658 | 0 | // obviously can't preserve if we're not initialized. |
2659 | 0 | if (self && self->GetWrapperPreserveColor()) { |
2660 | 0 | PreserveWrapper(self); |
2661 | 0 | } |
2662 | 0 | return true; |
2663 | 0 | } |
2664 | | |
2665 | | static void |
2666 | | _finalize(js::FreeOp* fop, JSObject* obj) |
2667 | 0 | { |
2668 | 0 | mozilla::dom::ContentFrameMessageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ContentFrameMessageManager>(obj); |
2669 | 0 | if (self) { |
2670 | 0 | ClearWrapper(self, self, obj); |
2671 | 0 | AddForDeferredFinalization<mozilla::dom::ContentFrameMessageManager>(self); |
2672 | 0 | } |
2673 | 0 | } |
2674 | | |
2675 | | static size_t |
2676 | | _objectMoved(JSObject* obj, JSObject* old) |
2677 | 0 | { |
2678 | 0 | mozilla::dom::ContentFrameMessageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ContentFrameMessageManager>(obj); |
2679 | 0 | if (self) { |
2680 | 0 | UpdateWrapper(self, self, obj, old); |
2681 | 0 | } |
2682 | 0 |
|
2683 | 0 | return 0; |
2684 | 0 | } |
2685 | | |
2686 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
2687 | | #if defined(__clang__) |
2688 | | #pragma clang diagnostic push |
2689 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
2690 | | #endif |
2691 | | static const JSFunctionSpec sMethods_specs[] = { |
2692 | | JS_FNSPEC("addMessageListener", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&addMessageListener_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
2693 | | JS_FNSPEC("removeMessageListener", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&removeMessageListener_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
2694 | | JS_FNSPEC("addWeakMessageListener", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&addWeakMessageListener_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
2695 | | JS_FNSPEC("removeWeakMessageListener", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&removeWeakMessageListener_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
2696 | | JS_FNSPEC("dump", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&dump_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
2697 | | JS_FNSPEC("privateNoteIntentionalCrash", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&privateNoteIntentionalCrash_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
2698 | | JS_FNSPEC("atob", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&atob_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
2699 | | JS_FNSPEC("btoa", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&btoa_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
2700 | | JS_FNSPEC("sendAsyncMessage", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&sendAsyncMessage_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
2701 | | JS_FNSPEC("sendSyncMessage", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&sendSyncMessage_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
2702 | | JS_FNSPEC("sendRpcMessage", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&sendRpcMessage_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
2703 | | JS_FS_END |
2704 | | }; |
2705 | | #if defined(__clang__) |
2706 | | #pragma clang diagnostic pop |
2707 | | #endif |
2708 | | |
2709 | | |
2710 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
2711 | | { nullptr, &sMethods_specs[0] }, |
2712 | | { nullptr, nullptr } |
2713 | | }; |
2714 | | |
2715 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
2716 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
2717 | | static_assert(11 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
2718 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
2719 | | |
2720 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
2721 | | #if defined(__clang__) |
2722 | | #pragma clang diagnostic push |
2723 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
2724 | | #endif |
2725 | | static const JSPropertySpec sAttributes_specs[] = { |
2726 | | { "content", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &content_getterinfo, nullptr, nullptr }, |
2727 | | { "docShell", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &docShell_getterinfo, nullptr, nullptr }, |
2728 | | { "tabEventTarget", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &tabEventTarget_getterinfo, nullptr, nullptr }, |
2729 | | { "chromeOuterWindowID", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &chromeOuterWindowID_getterinfo, nullptr, nullptr }, |
2730 | | { "processMessageManager", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &processMessageManager_getterinfo, nullptr, nullptr }, |
2731 | | { "remoteType", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &remoteType_getterinfo, nullptr, nullptr }, |
2732 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
2733 | | }; |
2734 | | #if defined(__clang__) |
2735 | | #pragma clang diagnostic pop |
2736 | | #endif |
2737 | | |
2738 | | |
2739 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
2740 | | { nullptr, &sAttributes_specs[0] }, |
2741 | | { nullptr, nullptr } |
2742 | | }; |
2743 | | |
2744 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
2745 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
2746 | | static_assert(6 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
2747 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
2748 | | |
2749 | | |
2750 | | static uint16_t sNativeProperties_sortedPropertyIndices[17]; |
2751 | | static PropertyInfo sNativeProperties_propertyInfos[17]; |
2752 | | |
2753 | | static const NativePropertiesN<2> sNativeProperties = { |
2754 | | false, 0, |
2755 | | false, 0, |
2756 | | true, 0 /* sMethods */, |
2757 | | true, 1 /* sAttributes */, |
2758 | | false, 0, |
2759 | | false, 0, |
2760 | | false, 0, |
2761 | | -1, |
2762 | | 17, |
2763 | | sNativeProperties_sortedPropertyIndices, |
2764 | | { |
2765 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
2766 | | { sAttributes, &sNativeProperties_propertyInfos[11] } |
2767 | | } |
2768 | | }; |
2769 | | static_assert(17 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
2770 | | "We have a property info count that is oversized"); |
2771 | | |
2772 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
2773 | | { |
2774 | | "Function", |
2775 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
2776 | | &sBoringInterfaceObjectClassClassOps, |
2777 | | JS_NULL_CLASS_SPEC, |
2778 | | JS_NULL_CLASS_EXT, |
2779 | | &sInterfaceObjectClassObjectOps |
2780 | | }, |
2781 | | eInterface, |
2782 | | true, |
2783 | | prototypes::id::ContentFrameMessageManager, |
2784 | | PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth, |
2785 | | sNativePropertyHooks, |
2786 | | "function ContentFrameMessageManager() {\n [native code]\n}", |
2787 | | EventTarget_Binding::GetConstructorObject |
2788 | | }; |
2789 | | |
2790 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
2791 | | { |
2792 | | "ContentFrameMessageManagerPrototype", |
2793 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
2794 | | JS_NULL_CLASS_OPS, |
2795 | | JS_NULL_CLASS_SPEC, |
2796 | | JS_NULL_CLASS_EXT, |
2797 | | JS_NULL_OBJECT_OPS |
2798 | | }, |
2799 | | eInterfacePrototype, |
2800 | | false, |
2801 | | prototypes::id::ContentFrameMessageManager, |
2802 | | PrototypeTraits<prototypes::id::ContentFrameMessageManager>::Depth, |
2803 | | sNativePropertyHooks, |
2804 | | "[object ContentFrameMessageManagerPrototype]", |
2805 | | EventTarget_Binding::GetProtoObject |
2806 | | }; |
2807 | | |
2808 | | bool |
2809 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
2810 | 0 | { |
2811 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
2812 | 0 | } |
2813 | | |
2814 | | static const js::ClassOps sClassOps = { |
2815 | | _addProperty, /* addProperty */ |
2816 | | nullptr, /* delProperty */ |
2817 | | nullptr, /* enumerate */ |
2818 | | nullptr, /* newEnumerate */ |
2819 | | nullptr, /* resolve */ |
2820 | | nullptr, /* mayResolve */ |
2821 | | _finalize, /* finalize */ |
2822 | | nullptr, /* call */ |
2823 | | nullptr, /* hasInstance */ |
2824 | | nullptr, /* construct */ |
2825 | | nullptr, /* trace */ |
2826 | | }; |
2827 | | |
2828 | | static const js::ClassExtension sClassExtension = { |
2829 | | nullptr, /* weakmapKeyDelegateOp */ |
2830 | | _objectMoved /* objectMovedOp */ |
2831 | | }; |
2832 | | |
2833 | | static const DOMJSClass sClass = { |
2834 | | { "ContentFrameMessageManager", |
2835 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
2836 | | &sClassOps, |
2837 | | JS_NULL_CLASS_SPEC, |
2838 | | &sClassExtension, |
2839 | | JS_NULL_OBJECT_OPS |
2840 | | }, |
2841 | | { prototypes::id::EventTarget, prototypes::id::ContentFrameMessageManager, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
2842 | | IsBaseOf<nsISupports, mozilla::dom::ContentFrameMessageManager >::value, |
2843 | | sNativePropertyHooks, |
2844 | | FindAssociatedGlobalForNative<mozilla::dom::ContentFrameMessageManager>::Get, |
2845 | | GetProtoObjectHandle, |
2846 | | GetCCParticipant<mozilla::dom::ContentFrameMessageManager>::Get() |
2847 | | }; |
2848 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
2849 | | "Must have the right minimal number of reserved slots."); |
2850 | | static_assert(1 >= 1, |
2851 | | "Must have enough reserved slots."); |
2852 | | |
2853 | | const JSClass* |
2854 | | GetJSClass() |
2855 | 0 | { |
2856 | 0 | return sClass.ToJSClass(); |
2857 | 0 | } |
2858 | | |
2859 | | bool |
2860 | | Wrap(JSContext* aCx, mozilla::dom::ContentFrameMessageManager* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
2861 | 0 | { |
2862 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::ContentFrameMessageManager>::value, |
2863 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
2864 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::ContentFrameMessageManager*>(aObject) == |
2865 | 0 | reinterpret_cast<mozilla::dom::ContentFrameMessageManager*>(aObject), |
2866 | 0 | "Multiple inheritance for mozilla::dom::ContentFrameMessageManager is broken."); |
2867 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
2868 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
2869 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
2870 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
2871 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
2872 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
2873 | 0 | "You should probably not be using Wrap() directly; use " |
2874 | 0 | "GetOrCreateDOMReflector instead"); |
2875 | 0 |
|
2876 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
2877 | 0 | "nsISupports must be on our primary inheritance chain"); |
2878 | 0 |
|
2879 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
2880 | 0 | if (!global) { |
2881 | 0 | return false; |
2882 | 0 | } |
2883 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
2884 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
2885 | 0 |
|
2886 | 0 | // That might have ended up wrapping us already, due to the wonders |
2887 | 0 | // of XBL. Check for that, and bail out as needed. |
2888 | 0 | aReflector.set(aCache->GetWrapper()); |
2889 | 0 | if (aReflector) { |
2890 | | #ifdef DEBUG |
2891 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
2892 | | #endif // DEBUG |
2893 | | return true; |
2894 | 0 | } |
2895 | 0 |
|
2896 | 0 | JSAutoRealm ar(aCx, global); |
2897 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
2898 | 0 | if (!canonicalProto) { |
2899 | 0 | return false; |
2900 | 0 | } |
2901 | 0 | JS::Rooted<JSObject*> proto(aCx); |
2902 | 0 | if (aGivenProto) { |
2903 | 0 | proto = aGivenProto; |
2904 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
2905 | 0 | // coming in, we changed compartments to that of "parent" so may need |
2906 | 0 | // to wrap the proto here. |
2907 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
2908 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
2909 | 0 | return false; |
2910 | 0 | } |
2911 | 0 | } |
2912 | 0 | } else { |
2913 | 0 | proto = canonicalProto; |
2914 | 0 | } |
2915 | 0 |
|
2916 | 0 | BindingJSObjectCreator<mozilla::dom::ContentFrameMessageManager> creator(aCx); |
2917 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
2918 | 0 | if (!aReflector) { |
2919 | 0 | return false; |
2920 | 0 | } |
2921 | 0 | |
2922 | 0 | aCache->SetWrapper(aReflector); |
2923 | 0 | creator.InitializationSucceeded(); |
2924 | 0 |
|
2925 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
2926 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
2927 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
2928 | 0 | // otherwise we won't be able to properly recreate it later, since |
2929 | 0 | // we won't know what proto to use. Note that we don't check |
2930 | 0 | // aGivenProto here, since it's entirely possible (and even |
2931 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
2932 | 0 | // same as canonicalProto. |
2933 | 0 | if (proto != canonicalProto) { |
2934 | 0 | PreserveWrapper(aObject); |
2935 | 0 | } |
2936 | 0 |
|
2937 | 0 | return true; |
2938 | 0 | } |
2939 | | |
2940 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
2941 | | nullptr, |
2942 | | nullptr, |
2943 | | nullptr, |
2944 | | { sNativeProperties.Upcast(), nullptr }, |
2945 | | prototypes::id::ContentFrameMessageManager, |
2946 | | constructors::id::ContentFrameMessageManager, |
2947 | | EventTarget_Binding::sNativePropertyHooks, |
2948 | | &DefaultXrayExpandoObjectClass |
2949 | | } }; |
2950 | | |
2951 | | void |
2952 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
2953 | 0 | { |
2954 | 0 | JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx)); |
2955 | 0 | if (!parentProto) { |
2956 | 0 | return; |
2957 | 0 | } |
2958 | 0 | |
2959 | 0 | JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx)); |
2960 | 0 | if (!constructorProto) { |
2961 | 0 | return; |
2962 | 0 | } |
2963 | 0 | |
2964 | 0 | static bool sIdsInited = false; |
2965 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
2966 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
2967 | 0 | return; |
2968 | 0 | } |
2969 | 0 | sIdsInited = true; |
2970 | 0 | } |
2971 | 0 |
|
2972 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ContentFrameMessageManager); |
2973 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ContentFrameMessageManager); |
2974 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
2975 | 0 | &sPrototypeClass.mBase, protoCache, |
2976 | 0 | nullptr, |
2977 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
2978 | 0 | interfaceCache, |
2979 | 0 | sNativeProperties.Upcast(), |
2980 | 0 | nullptr, |
2981 | 0 | "ContentFrameMessageManager", aDefineOnGlobal, |
2982 | 0 | nullptr, |
2983 | 0 | false); |
2984 | 0 | } |
2985 | | |
2986 | | JSObject* |
2987 | | GetConstructorObject(JSContext* aCx) |
2988 | 0 | { |
2989 | 0 | return GetConstructorObjectHandle(aCx); |
2990 | 0 | } |
2991 | | |
2992 | | } // namespace ContentFrameMessageManager_Binding |
2993 | | |
2994 | | |
2995 | | |
2996 | | namespace ContentProcessMessageManager_Binding { |
2997 | | |
2998 | | MOZ_CAN_RUN_SCRIPT static bool |
2999 | | get_initialProcessData(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentProcessMessageManager* self, JSJitGetterCallArgs args) |
3000 | 0 | { |
3001 | 0 | AUTO_PROFILER_LABEL_FAST("get ContentProcessMessageManager.initialProcessData", DOM, cx); |
3002 | 0 |
|
3003 | 0 | FastErrorResult rv; |
3004 | 0 | JS::Rooted<JS::Value> result(cx); |
3005 | 0 | self->GetInitialProcessData(cx, &result, rv); |
3006 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3007 | 0 | return false; |
3008 | 0 | } |
3009 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3010 | 0 | JS::ExposeValueToActiveJS(result); |
3011 | 0 | args.rval().set(result); |
3012 | 0 | if (!MaybeWrapValue(cx, args.rval())) { |
3013 | 0 | return false; |
3014 | 0 | } |
3015 | 0 | return true; |
3016 | 0 | } |
3017 | | |
3018 | | static const JSJitInfo initialProcessData_getterinfo = { |
3019 | | { (JSJitGetterOp)get_initialProcessData }, |
3020 | | { prototypes::id::ContentProcessMessageManager }, |
3021 | | { PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth }, |
3022 | | JSJitInfo::Getter, |
3023 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3024 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
3025 | | false, /* isInfallible. False in setters. */ |
3026 | | false, /* isMovable. Not relevant for setters. */ |
3027 | | false, /* isEliminatable. Not relevant for setters. */ |
3028 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3029 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3030 | | false, /* isTypedMethod. Only relevant for methods. */ |
3031 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3032 | | }; |
3033 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3034 | | static_assert(0 < 1, "There is no slot for us"); |
3035 | | |
3036 | | MOZ_CAN_RUN_SCRIPT static bool |
3037 | | get_sharedData(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentProcessMessageManager* self, JSJitGetterCallArgs args) |
3038 | 0 | { |
3039 | 0 | AUTO_PROFILER_LABEL_FAST("get ContentProcessMessageManager.sharedData", DOM, cx); |
3040 | 0 |
|
3041 | 0 | auto result(StrongOrRawPtr<mozilla::dom::ipc::SharedMap>(self->SharedData())); |
3042 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3043 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
3044 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
3045 | 0 | return false; |
3046 | 0 | } |
3047 | 0 | return true; |
3048 | 0 | } |
3049 | | |
3050 | | static const JSJitInfo sharedData_getterinfo = { |
3051 | | { (JSJitGetterOp)get_sharedData }, |
3052 | | { prototypes::id::ContentProcessMessageManager }, |
3053 | | { PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth }, |
3054 | | JSJitInfo::Getter, |
3055 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3056 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
3057 | | false, /* isInfallible. False in setters. */ |
3058 | | false, /* isMovable. Not relevant for setters. */ |
3059 | | false, /* isEliminatable. Not relevant for setters. */ |
3060 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3061 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3062 | | false, /* isTypedMethod. Only relevant for methods. */ |
3063 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3064 | | }; |
3065 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3066 | | static_assert(0 < 1, "There is no slot for us"); |
3067 | | |
3068 | | MOZ_CAN_RUN_SCRIPT static bool |
3069 | | addMessageListener(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentProcessMessageManager* self, const JSJitMethodCallArgs& args) |
3070 | 0 | { |
3071 | 0 | AUTO_PROFILER_LABEL_FAST("ContentProcessMessageManager.addMessageListener", DOM, cx); |
3072 | 0 |
|
3073 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
3074 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContentProcessMessageManager.addMessageListener"); |
3075 | 0 | } |
3076 | 0 | binding_detail::FakeString arg0; |
3077 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
3078 | 0 | return false; |
3079 | 0 | } |
3080 | 0 | RootedCallback<OwningNonNull<binding_detail::FastMessageListener>> arg1(cx); |
3081 | 0 | if (args[1].isObject()) { |
3082 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
3083 | 0 | arg1 = new binding_detail::FastMessageListener(&args[1].toObject(), JS::CurrentGlobalOrNull(cx)); |
3084 | 0 | } |
3085 | 0 | } else { |
3086 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of ContentProcessMessageManager.addMessageListener"); |
3087 | 0 | return false; |
3088 | 0 | } |
3089 | 0 | bool arg2; |
3090 | 0 | if (args.hasDefined(2)) { |
3091 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, args[2], &arg2)) { |
3092 | 0 | return false; |
3093 | 0 | } |
3094 | 0 | } else { |
3095 | 0 | arg2 = false; |
3096 | 0 | } |
3097 | 0 | FastErrorResult rv; |
3098 | 0 | self->AddMessageListener(NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), arg2, rv); |
3099 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3100 | 0 | return false; |
3101 | 0 | } |
3102 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3103 | 0 | args.rval().setUndefined(); |
3104 | 0 | return true; |
3105 | 0 | } |
3106 | | |
3107 | | static const JSJitInfo addMessageListener_methodinfo = { |
3108 | | { (JSJitGetterOp)addMessageListener }, |
3109 | | { prototypes::id::ContentProcessMessageManager }, |
3110 | | { PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth }, |
3111 | | JSJitInfo::Method, |
3112 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3113 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
3114 | | false, /* isInfallible. False in setters. */ |
3115 | | false, /* isMovable. Not relevant for setters. */ |
3116 | | false, /* isEliminatable. Not relevant for setters. */ |
3117 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3118 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3119 | | false, /* isTypedMethod. Only relevant for methods. */ |
3120 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3121 | | }; |
3122 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3123 | | static_assert(0 < 1, "There is no slot for us"); |
3124 | | |
3125 | | MOZ_CAN_RUN_SCRIPT static bool |
3126 | | removeMessageListener(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentProcessMessageManager* self, const JSJitMethodCallArgs& args) |
3127 | 0 | { |
3128 | 0 | AUTO_PROFILER_LABEL_FAST("ContentProcessMessageManager.removeMessageListener", DOM, cx); |
3129 | 0 |
|
3130 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
3131 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContentProcessMessageManager.removeMessageListener"); |
3132 | 0 | } |
3133 | 0 | binding_detail::FakeString arg0; |
3134 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
3135 | 0 | return false; |
3136 | 0 | } |
3137 | 0 | RootedCallback<OwningNonNull<binding_detail::FastMessageListener>> arg1(cx); |
3138 | 0 | if (args[1].isObject()) { |
3139 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
3140 | 0 | arg1 = new binding_detail::FastMessageListener(&args[1].toObject(), JS::CurrentGlobalOrNull(cx)); |
3141 | 0 | } |
3142 | 0 | } else { |
3143 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of ContentProcessMessageManager.removeMessageListener"); |
3144 | 0 | return false; |
3145 | 0 | } |
3146 | 0 | FastErrorResult rv; |
3147 | 0 | self->RemoveMessageListener(NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), rv); |
3148 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3149 | 0 | return false; |
3150 | 0 | } |
3151 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3152 | 0 | args.rval().setUndefined(); |
3153 | 0 | return true; |
3154 | 0 | } |
3155 | | |
3156 | | static const JSJitInfo removeMessageListener_methodinfo = { |
3157 | | { (JSJitGetterOp)removeMessageListener }, |
3158 | | { prototypes::id::ContentProcessMessageManager }, |
3159 | | { PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth }, |
3160 | | JSJitInfo::Method, |
3161 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3162 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
3163 | | false, /* isInfallible. False in setters. */ |
3164 | | false, /* isMovable. Not relevant for setters. */ |
3165 | | false, /* isEliminatable. Not relevant for setters. */ |
3166 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3167 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3168 | | false, /* isTypedMethod. Only relevant for methods. */ |
3169 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3170 | | }; |
3171 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3172 | | static_assert(0 < 1, "There is no slot for us"); |
3173 | | |
3174 | | MOZ_CAN_RUN_SCRIPT static bool |
3175 | | addWeakMessageListener(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentProcessMessageManager* self, const JSJitMethodCallArgs& args) |
3176 | 0 | { |
3177 | 0 | AUTO_PROFILER_LABEL_FAST("ContentProcessMessageManager.addWeakMessageListener", DOM, cx); |
3178 | 0 |
|
3179 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
3180 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContentProcessMessageManager.addWeakMessageListener"); |
3181 | 0 | } |
3182 | 0 | binding_detail::FakeString arg0; |
3183 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
3184 | 0 | return false; |
3185 | 0 | } |
3186 | 0 | RootedCallback<OwningNonNull<binding_detail::FastMessageListener>> arg1(cx); |
3187 | 0 | if (args[1].isObject()) { |
3188 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
3189 | 0 | arg1 = new binding_detail::FastMessageListener(&args[1].toObject(), JS::CurrentGlobalOrNull(cx)); |
3190 | 0 | } |
3191 | 0 | } else { |
3192 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of ContentProcessMessageManager.addWeakMessageListener"); |
3193 | 0 | return false; |
3194 | 0 | } |
3195 | 0 | FastErrorResult rv; |
3196 | 0 | self->AddWeakMessageListener(NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), rv); |
3197 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3198 | 0 | return false; |
3199 | 0 | } |
3200 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3201 | 0 | args.rval().setUndefined(); |
3202 | 0 | return true; |
3203 | 0 | } |
3204 | | |
3205 | | static const JSJitInfo addWeakMessageListener_methodinfo = { |
3206 | | { (JSJitGetterOp)addWeakMessageListener }, |
3207 | | { prototypes::id::ContentProcessMessageManager }, |
3208 | | { PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth }, |
3209 | | JSJitInfo::Method, |
3210 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3211 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
3212 | | false, /* isInfallible. False in setters. */ |
3213 | | false, /* isMovable. Not relevant for setters. */ |
3214 | | false, /* isEliminatable. Not relevant for setters. */ |
3215 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3216 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3217 | | false, /* isTypedMethod. Only relevant for methods. */ |
3218 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3219 | | }; |
3220 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3221 | | static_assert(0 < 1, "There is no slot for us"); |
3222 | | |
3223 | | MOZ_CAN_RUN_SCRIPT static bool |
3224 | | removeWeakMessageListener(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentProcessMessageManager* self, const JSJitMethodCallArgs& args) |
3225 | 0 | { |
3226 | 0 | AUTO_PROFILER_LABEL_FAST("ContentProcessMessageManager.removeWeakMessageListener", DOM, cx); |
3227 | 0 |
|
3228 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
3229 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContentProcessMessageManager.removeWeakMessageListener"); |
3230 | 0 | } |
3231 | 0 | binding_detail::FakeString arg0; |
3232 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
3233 | 0 | return false; |
3234 | 0 | } |
3235 | 0 | RootedCallback<OwningNonNull<binding_detail::FastMessageListener>> arg1(cx); |
3236 | 0 | if (args[1].isObject()) { |
3237 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
3238 | 0 | arg1 = new binding_detail::FastMessageListener(&args[1].toObject(), JS::CurrentGlobalOrNull(cx)); |
3239 | 0 | } |
3240 | 0 | } else { |
3241 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of ContentProcessMessageManager.removeWeakMessageListener"); |
3242 | 0 | return false; |
3243 | 0 | } |
3244 | 0 | FastErrorResult rv; |
3245 | 0 | self->RemoveWeakMessageListener(NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), rv); |
3246 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3247 | 0 | return false; |
3248 | 0 | } |
3249 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3250 | 0 | args.rval().setUndefined(); |
3251 | 0 | return true; |
3252 | 0 | } |
3253 | | |
3254 | | static const JSJitInfo removeWeakMessageListener_methodinfo = { |
3255 | | { (JSJitGetterOp)removeWeakMessageListener }, |
3256 | | { prototypes::id::ContentProcessMessageManager }, |
3257 | | { PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth }, |
3258 | | JSJitInfo::Method, |
3259 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3260 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
3261 | | false, /* isInfallible. False in setters. */ |
3262 | | false, /* isMovable. Not relevant for setters. */ |
3263 | | false, /* isEliminatable. Not relevant for setters. */ |
3264 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3265 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3266 | | false, /* isTypedMethod. Only relevant for methods. */ |
3267 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3268 | | }; |
3269 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3270 | | static_assert(0 < 1, "There is no slot for us"); |
3271 | | |
3272 | | MOZ_CAN_RUN_SCRIPT static bool |
3273 | | dump(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentProcessMessageManager* self, const JSJitMethodCallArgs& args) |
3274 | 0 | { |
3275 | 0 | AUTO_PROFILER_LABEL_FAST("ContentProcessMessageManager.dump", DOM, cx); |
3276 | 0 |
|
3277 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
3278 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContentProcessMessageManager.dump"); |
3279 | 0 | } |
3280 | 0 | binding_detail::FakeString arg0; |
3281 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
3282 | 0 | return false; |
3283 | 0 | } |
3284 | 0 | self->Dump(NonNullHelper(Constify(arg0))); |
3285 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3286 | 0 | args.rval().setUndefined(); |
3287 | 0 | return true; |
3288 | 0 | } |
3289 | | |
3290 | | static const JSJitInfo dump_methodinfo = { |
3291 | | { (JSJitGetterOp)dump }, |
3292 | | { prototypes::id::ContentProcessMessageManager }, |
3293 | | { PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth }, |
3294 | | JSJitInfo::Method, |
3295 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3296 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
3297 | | false, /* isInfallible. False in setters. */ |
3298 | | false, /* isMovable. Not relevant for setters. */ |
3299 | | false, /* isEliminatable. Not relevant for setters. */ |
3300 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3301 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3302 | | false, /* isTypedMethod. Only relevant for methods. */ |
3303 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3304 | | }; |
3305 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3306 | | static_assert(0 < 1, "There is no slot for us"); |
3307 | | |
3308 | | MOZ_CAN_RUN_SCRIPT static bool |
3309 | | privateNoteIntentionalCrash(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentProcessMessageManager* self, const JSJitMethodCallArgs& args) |
3310 | 0 | { |
3311 | 0 | AUTO_PROFILER_LABEL_FAST("ContentProcessMessageManager.privateNoteIntentionalCrash", DOM, cx); |
3312 | 0 |
|
3313 | 0 | FastErrorResult rv; |
3314 | 0 | self->PrivateNoteIntentionalCrash(rv); |
3315 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3316 | 0 | return false; |
3317 | 0 | } |
3318 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3319 | 0 | args.rval().setUndefined(); |
3320 | 0 | return true; |
3321 | 0 | } |
3322 | | |
3323 | | static const JSJitInfo privateNoteIntentionalCrash_methodinfo = { |
3324 | | { (JSJitGetterOp)privateNoteIntentionalCrash }, |
3325 | | { prototypes::id::ContentProcessMessageManager }, |
3326 | | { PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth }, |
3327 | | JSJitInfo::Method, |
3328 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3329 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
3330 | | false, /* isInfallible. False in setters. */ |
3331 | | false, /* isMovable. Not relevant for setters. */ |
3332 | | false, /* isEliminatable. Not relevant for setters. */ |
3333 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3334 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3335 | | false, /* isTypedMethod. Only relevant for methods. */ |
3336 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3337 | | }; |
3338 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3339 | | static_assert(0 < 1, "There is no slot for us"); |
3340 | | |
3341 | | MOZ_CAN_RUN_SCRIPT static bool |
3342 | | atob(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentProcessMessageManager* self, const JSJitMethodCallArgs& args) |
3343 | 0 | { |
3344 | 0 | AUTO_PROFILER_LABEL_FAST("ContentProcessMessageManager.atob", DOM, cx); |
3345 | 0 |
|
3346 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
3347 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContentProcessMessageManager.atob"); |
3348 | 0 | } |
3349 | 0 | binding_detail::FakeString arg0; |
3350 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
3351 | 0 | return false; |
3352 | 0 | } |
3353 | 0 | FastErrorResult rv; |
3354 | 0 | DOMString result; |
3355 | 0 | self->Atob(NonNullHelper(Constify(arg0)), result, rv); |
3356 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3357 | 0 | return false; |
3358 | 0 | } |
3359 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3360 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
3361 | 0 | return false; |
3362 | 0 | } |
3363 | 0 | return true; |
3364 | 0 | } |
3365 | | |
3366 | | static const JSJitInfo atob_methodinfo = { |
3367 | | { (JSJitGetterOp)atob }, |
3368 | | { prototypes::id::ContentProcessMessageManager }, |
3369 | | { PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth }, |
3370 | | JSJitInfo::Method, |
3371 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3372 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
3373 | | false, /* isInfallible. False in setters. */ |
3374 | | false, /* isMovable. Not relevant for setters. */ |
3375 | | false, /* isEliminatable. Not relevant for setters. */ |
3376 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3377 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3378 | | false, /* isTypedMethod. Only relevant for methods. */ |
3379 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3380 | | }; |
3381 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3382 | | static_assert(0 < 1, "There is no slot for us"); |
3383 | | |
3384 | | MOZ_CAN_RUN_SCRIPT static bool |
3385 | | btoa(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentProcessMessageManager* self, const JSJitMethodCallArgs& args) |
3386 | 0 | { |
3387 | 0 | AUTO_PROFILER_LABEL_FAST("ContentProcessMessageManager.btoa", DOM, cx); |
3388 | 0 |
|
3389 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
3390 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContentProcessMessageManager.btoa"); |
3391 | 0 | } |
3392 | 0 | binding_detail::FakeString arg0; |
3393 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
3394 | 0 | return false; |
3395 | 0 | } |
3396 | 0 | FastErrorResult rv; |
3397 | 0 | DOMString result; |
3398 | 0 | self->Btoa(NonNullHelper(Constify(arg0)), result, rv); |
3399 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3400 | 0 | return false; |
3401 | 0 | } |
3402 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3403 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
3404 | 0 | return false; |
3405 | 0 | } |
3406 | 0 | return true; |
3407 | 0 | } |
3408 | | |
3409 | | static const JSJitInfo btoa_methodinfo = { |
3410 | | { (JSJitGetterOp)btoa }, |
3411 | | { prototypes::id::ContentProcessMessageManager }, |
3412 | | { PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth }, |
3413 | | JSJitInfo::Method, |
3414 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3415 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
3416 | | false, /* isInfallible. False in setters. */ |
3417 | | false, /* isMovable. Not relevant for setters. */ |
3418 | | false, /* isEliminatable. Not relevant for setters. */ |
3419 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3420 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3421 | | false, /* isTypedMethod. Only relevant for methods. */ |
3422 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3423 | | }; |
3424 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3425 | | static_assert(0 < 1, "There is no slot for us"); |
3426 | | |
3427 | | MOZ_CAN_RUN_SCRIPT static bool |
3428 | | sendAsyncMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentProcessMessageManager* self, const JSJitMethodCallArgs& args) |
3429 | 0 | { |
3430 | 0 | AUTO_PROFILER_LABEL_FAST("ContentProcessMessageManager.sendAsyncMessage", DOM, cx); |
3431 | 0 |
|
3432 | 0 | binding_detail::FakeString arg0; |
3433 | 0 | if (args.hasDefined(0)) { |
3434 | 0 | if (!ConvertJSValueToString(cx, args[0], eNull, eNull, arg0)) { |
3435 | 0 | return false; |
3436 | 0 | } |
3437 | 0 | } else { |
3438 | 0 | arg0.SetIsVoid(true); |
3439 | 0 | } |
3440 | 0 | JS::Rooted<JS::Value> arg1(cx); |
3441 | 0 | if (args.hasDefined(1)) { |
3442 | 0 | arg1 = args[1]; |
3443 | 0 | } else { |
3444 | 0 | arg1 = JS::UndefinedValue(); |
3445 | 0 | } |
3446 | 0 | JS::Rooted<JSObject*> arg2(cx); |
3447 | 0 | if (args.hasDefined(2)) { |
3448 | 0 | if (args[2].isObject()) { |
3449 | 0 | arg2 = &args[2].toObject(); |
3450 | 0 | } else if (args[2].isNullOrUndefined()) { |
3451 | 0 | arg2 = nullptr; |
3452 | 0 | } else { |
3453 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of ContentProcessMessageManager.sendAsyncMessage"); |
3454 | 0 | return false; |
3455 | 0 | } |
3456 | 0 | } else { |
3457 | 0 | arg2 = nullptr; |
3458 | 0 | } |
3459 | 0 | nsIPrincipal* arg3; |
3460 | 0 | RefPtr<nsIPrincipal> arg3_holder; |
3461 | 0 | if (args.hasDefined(3)) { |
3462 | 0 | if (args[3].isObject()) { |
3463 | 0 | JS::Rooted<JSObject*> source(cx, &args[3].toObject()); |
3464 | 0 | if (NS_FAILED(UnwrapArg<nsIPrincipal>(cx, source, getter_AddRefs(arg3_holder)))) { |
3465 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 4 of ContentProcessMessageManager.sendAsyncMessage", "Principal"); |
3466 | 0 | return false; |
3467 | 0 | } |
3468 | 0 | MOZ_ASSERT(arg3_holder); |
3469 | 0 | arg3 = arg3_holder; |
3470 | 0 | } else if (args[3].isNullOrUndefined()) { |
3471 | 0 | arg3 = nullptr; |
3472 | 0 | } else { |
3473 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 4 of ContentProcessMessageManager.sendAsyncMessage"); |
3474 | 0 | return false; |
3475 | 0 | } |
3476 | 0 | } else { |
3477 | 0 | arg3 = nullptr; |
3478 | 0 | } |
3479 | 0 | JS::Rooted<JS::Value> arg4(cx); |
3480 | 0 | if (args.hasDefined(4)) { |
3481 | 0 | arg4 = args[4]; |
3482 | 0 | } else { |
3483 | 0 | arg4 = JS::UndefinedValue(); |
3484 | 0 | } |
3485 | 0 | FastErrorResult rv; |
3486 | 0 | self->SendAsyncMessage(cx, NonNullHelper(Constify(arg0)), arg1, arg2, MOZ_KnownLive(Constify(arg3)), arg4, rv); |
3487 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3488 | 0 | return false; |
3489 | 0 | } |
3490 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3491 | 0 | args.rval().setUndefined(); |
3492 | 0 | return true; |
3493 | 0 | } |
3494 | | |
3495 | | static const JSJitInfo sendAsyncMessage_methodinfo = { |
3496 | | { (JSJitGetterOp)sendAsyncMessage }, |
3497 | | { prototypes::id::ContentProcessMessageManager }, |
3498 | | { PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth }, |
3499 | | JSJitInfo::Method, |
3500 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3501 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
3502 | | false, /* isInfallible. False in setters. */ |
3503 | | false, /* isMovable. Not relevant for setters. */ |
3504 | | false, /* isEliminatable. Not relevant for setters. */ |
3505 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3506 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3507 | | false, /* isTypedMethod. Only relevant for methods. */ |
3508 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3509 | | }; |
3510 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3511 | | static_assert(0 < 1, "There is no slot for us"); |
3512 | | |
3513 | | MOZ_CAN_RUN_SCRIPT static bool |
3514 | | get_processMessageManager(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentProcessMessageManager* self, JSJitGetterCallArgs args) |
3515 | 0 | { |
3516 | 0 | AUTO_PROFILER_LABEL_FAST("get ContentProcessMessageManager.processMessageManager", DOM, cx); |
3517 | 0 |
|
3518 | 0 | FastErrorResult rv; |
3519 | 0 | auto result(StrongOrRawPtr<mozilla::dom::MessageSender>(self->GetProcessMessageManager(rv))); |
3520 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3521 | 0 | return false; |
3522 | 0 | } |
3523 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3524 | 0 | if (!result) { |
3525 | 0 | args.rval().setNull(); |
3526 | 0 | return true; |
3527 | 0 | } |
3528 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
3529 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
3530 | 0 | return false; |
3531 | 0 | } |
3532 | 0 | return true; |
3533 | 0 | } |
3534 | | |
3535 | | static const JSJitInfo processMessageManager_getterinfo = { |
3536 | | { (JSJitGetterOp)get_processMessageManager }, |
3537 | | { prototypes::id::ContentProcessMessageManager }, |
3538 | | { PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth }, |
3539 | | JSJitInfo::Getter, |
3540 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3541 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
3542 | | false, /* isInfallible. False in setters. */ |
3543 | | false, /* isMovable. Not relevant for setters. */ |
3544 | | false, /* isEliminatable. Not relevant for setters. */ |
3545 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3546 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3547 | | false, /* isTypedMethod. Only relevant for methods. */ |
3548 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3549 | | }; |
3550 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3551 | | static_assert(0 < 1, "There is no slot for us"); |
3552 | | |
3553 | | MOZ_CAN_RUN_SCRIPT static bool |
3554 | | get_remoteType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentProcessMessageManager* self, JSJitGetterCallArgs args) |
3555 | 0 | { |
3556 | 0 | AUTO_PROFILER_LABEL_FAST("get ContentProcessMessageManager.remoteType", DOM, cx); |
3557 | 0 |
|
3558 | 0 | FastErrorResult rv; |
3559 | 0 | DOMString result; |
3560 | 0 | self->GetRemoteType(result, rv); |
3561 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3562 | 0 | return false; |
3563 | 0 | } |
3564 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3565 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
3566 | 0 | return false; |
3567 | 0 | } |
3568 | 0 | return true; |
3569 | 0 | } |
3570 | | |
3571 | | static const JSJitInfo remoteType_getterinfo = { |
3572 | | { (JSJitGetterOp)get_remoteType }, |
3573 | | { prototypes::id::ContentProcessMessageManager }, |
3574 | | { PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth }, |
3575 | | JSJitInfo::Getter, |
3576 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3577 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
3578 | | false, /* isInfallible. False in setters. */ |
3579 | | false, /* isMovable. Not relevant for setters. */ |
3580 | | false, /* isEliminatable. Not relevant for setters. */ |
3581 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3582 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3583 | | false, /* isTypedMethod. Only relevant for methods. */ |
3584 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3585 | | }; |
3586 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3587 | | static_assert(0 < 1, "There is no slot for us"); |
3588 | | |
3589 | | MOZ_CAN_RUN_SCRIPT static bool |
3590 | | sendSyncMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentProcessMessageManager* self, const JSJitMethodCallArgs& args) |
3591 | 0 | { |
3592 | 0 | AUTO_PROFILER_LABEL_FAST("ContentProcessMessageManager.sendSyncMessage", DOM, cx); |
3593 | 0 |
|
3594 | 0 | binding_detail::FakeString arg0; |
3595 | 0 | if (args.hasDefined(0)) { |
3596 | 0 | if (!ConvertJSValueToString(cx, args[0], eNull, eNull, arg0)) { |
3597 | 0 | return false; |
3598 | 0 | } |
3599 | 0 | } else { |
3600 | 0 | arg0.SetIsVoid(true); |
3601 | 0 | } |
3602 | 0 | JS::Rooted<JS::Value> arg1(cx); |
3603 | 0 | if (args.hasDefined(1)) { |
3604 | 0 | arg1 = args[1]; |
3605 | 0 | } else { |
3606 | 0 | arg1 = JS::UndefinedValue(); |
3607 | 0 | } |
3608 | 0 | JS::Rooted<JSObject*> arg2(cx); |
3609 | 0 | if (args.hasDefined(2)) { |
3610 | 0 | if (args[2].isObject()) { |
3611 | 0 | arg2 = &args[2].toObject(); |
3612 | 0 | } else if (args[2].isNullOrUndefined()) { |
3613 | 0 | arg2 = nullptr; |
3614 | 0 | } else { |
3615 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of ContentProcessMessageManager.sendSyncMessage"); |
3616 | 0 | return false; |
3617 | 0 | } |
3618 | 0 | } else { |
3619 | 0 | arg2 = nullptr; |
3620 | 0 | } |
3621 | 0 | nsIPrincipal* arg3; |
3622 | 0 | RefPtr<nsIPrincipal> arg3_holder; |
3623 | 0 | if (args.hasDefined(3)) { |
3624 | 0 | if (args[3].isObject()) { |
3625 | 0 | JS::Rooted<JSObject*> source(cx, &args[3].toObject()); |
3626 | 0 | if (NS_FAILED(UnwrapArg<nsIPrincipal>(cx, source, getter_AddRefs(arg3_holder)))) { |
3627 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 4 of ContentProcessMessageManager.sendSyncMessage", "Principal"); |
3628 | 0 | return false; |
3629 | 0 | } |
3630 | 0 | MOZ_ASSERT(arg3_holder); |
3631 | 0 | arg3 = arg3_holder; |
3632 | 0 | } else if (args[3].isNullOrUndefined()) { |
3633 | 0 | arg3 = nullptr; |
3634 | 0 | } else { |
3635 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 4 of ContentProcessMessageManager.sendSyncMessage"); |
3636 | 0 | return false; |
3637 | 0 | } |
3638 | 0 | } else { |
3639 | 0 | arg3 = nullptr; |
3640 | 0 | } |
3641 | 0 | FastErrorResult rv; |
3642 | 0 | nsTArray<JS::Value> result; |
3643 | 0 | SequenceRooter<JS::Value > resultRooter(cx, &result); |
3644 | 0 | self->SendSyncMessage(cx, NonNullHelper(Constify(arg0)), arg1, arg2, MOZ_KnownLive(Constify(arg3)), result, rv); |
3645 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3646 | 0 | return false; |
3647 | 0 | } |
3648 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3649 | 0 |
|
3650 | 0 | uint32_t length = result.Length(); |
3651 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
3652 | 0 | if (!returnArray) { |
3653 | 0 | return false; |
3654 | 0 | } |
3655 | 0 | // Scope for 'tmp' |
3656 | 0 | { |
3657 | 0 | JS::Rooted<JS::Value> tmp(cx); |
3658 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
3659 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
3660 | 0 | // are different ways to succeed at wrapping the object. |
3661 | 0 | do { |
3662 | 0 | JS::ExposeValueToActiveJS(result[sequenceIdx0]); |
3663 | 0 | tmp.set(result[sequenceIdx0]); |
3664 | 0 | if (!MaybeWrapValue(cx, &tmp)) { |
3665 | 0 | return false; |
3666 | 0 | } |
3667 | 0 | break; |
3668 | 0 | } while (false); |
3669 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
3670 | 0 | JSPROP_ENUMERATE)) { |
3671 | 0 | return false; |
3672 | 0 | } |
3673 | 0 | } |
3674 | 0 | } |
3675 | 0 | args.rval().setObject(*returnArray); |
3676 | 0 | return true; |
3677 | 0 | } |
3678 | | |
3679 | | static const JSJitInfo sendSyncMessage_methodinfo = { |
3680 | | { (JSJitGetterOp)sendSyncMessage }, |
3681 | | { prototypes::id::ContentProcessMessageManager }, |
3682 | | { PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth }, |
3683 | | JSJitInfo::Method, |
3684 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3685 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
3686 | | false, /* isInfallible. False in setters. */ |
3687 | | false, /* isMovable. Not relevant for setters. */ |
3688 | | false, /* isEliminatable. Not relevant for setters. */ |
3689 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3690 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3691 | | false, /* isTypedMethod. Only relevant for methods. */ |
3692 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3693 | | }; |
3694 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3695 | | static_assert(0 < 1, "There is no slot for us"); |
3696 | | |
3697 | | MOZ_CAN_RUN_SCRIPT static bool |
3698 | | sendRpcMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ContentProcessMessageManager* self, const JSJitMethodCallArgs& args) |
3699 | 0 | { |
3700 | 0 | AUTO_PROFILER_LABEL_FAST("ContentProcessMessageManager.sendRpcMessage", DOM, cx); |
3701 | 0 |
|
3702 | 0 | binding_detail::FakeString arg0; |
3703 | 0 | if (args.hasDefined(0)) { |
3704 | 0 | if (!ConvertJSValueToString(cx, args[0], eNull, eNull, arg0)) { |
3705 | 0 | return false; |
3706 | 0 | } |
3707 | 0 | } else { |
3708 | 0 | arg0.SetIsVoid(true); |
3709 | 0 | } |
3710 | 0 | JS::Rooted<JS::Value> arg1(cx); |
3711 | 0 | if (args.hasDefined(1)) { |
3712 | 0 | arg1 = args[1]; |
3713 | 0 | } else { |
3714 | 0 | arg1 = JS::UndefinedValue(); |
3715 | 0 | } |
3716 | 0 | JS::Rooted<JSObject*> arg2(cx); |
3717 | 0 | if (args.hasDefined(2)) { |
3718 | 0 | if (args[2].isObject()) { |
3719 | 0 | arg2 = &args[2].toObject(); |
3720 | 0 | } else if (args[2].isNullOrUndefined()) { |
3721 | 0 | arg2 = nullptr; |
3722 | 0 | } else { |
3723 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of ContentProcessMessageManager.sendRpcMessage"); |
3724 | 0 | return false; |
3725 | 0 | } |
3726 | 0 | } else { |
3727 | 0 | arg2 = nullptr; |
3728 | 0 | } |
3729 | 0 | nsIPrincipal* arg3; |
3730 | 0 | RefPtr<nsIPrincipal> arg3_holder; |
3731 | 0 | if (args.hasDefined(3)) { |
3732 | 0 | if (args[3].isObject()) { |
3733 | 0 | JS::Rooted<JSObject*> source(cx, &args[3].toObject()); |
3734 | 0 | if (NS_FAILED(UnwrapArg<nsIPrincipal>(cx, source, getter_AddRefs(arg3_holder)))) { |
3735 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 4 of ContentProcessMessageManager.sendRpcMessage", "Principal"); |
3736 | 0 | return false; |
3737 | 0 | } |
3738 | 0 | MOZ_ASSERT(arg3_holder); |
3739 | 0 | arg3 = arg3_holder; |
3740 | 0 | } else if (args[3].isNullOrUndefined()) { |
3741 | 0 | arg3 = nullptr; |
3742 | 0 | } else { |
3743 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 4 of ContentProcessMessageManager.sendRpcMessage"); |
3744 | 0 | return false; |
3745 | 0 | } |
3746 | 0 | } else { |
3747 | 0 | arg3 = nullptr; |
3748 | 0 | } |
3749 | 0 | FastErrorResult rv; |
3750 | 0 | nsTArray<JS::Value> result; |
3751 | 0 | SequenceRooter<JS::Value > resultRooter(cx, &result); |
3752 | 0 | self->SendRpcMessage(cx, NonNullHelper(Constify(arg0)), arg1, arg2, MOZ_KnownLive(Constify(arg3)), result, rv); |
3753 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
3754 | 0 | return false; |
3755 | 0 | } |
3756 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
3757 | 0 |
|
3758 | 0 | uint32_t length = result.Length(); |
3759 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
3760 | 0 | if (!returnArray) { |
3761 | 0 | return false; |
3762 | 0 | } |
3763 | 0 | // Scope for 'tmp' |
3764 | 0 | { |
3765 | 0 | JS::Rooted<JS::Value> tmp(cx); |
3766 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
3767 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
3768 | 0 | // are different ways to succeed at wrapping the object. |
3769 | 0 | do { |
3770 | 0 | JS::ExposeValueToActiveJS(result[sequenceIdx0]); |
3771 | 0 | tmp.set(result[sequenceIdx0]); |
3772 | 0 | if (!MaybeWrapValue(cx, &tmp)) { |
3773 | 0 | return false; |
3774 | 0 | } |
3775 | 0 | break; |
3776 | 0 | } while (false); |
3777 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
3778 | 0 | JSPROP_ENUMERATE)) { |
3779 | 0 | return false; |
3780 | 0 | } |
3781 | 0 | } |
3782 | 0 | } |
3783 | 0 | args.rval().setObject(*returnArray); |
3784 | 0 | return true; |
3785 | 0 | } |
3786 | | |
3787 | | static const JSJitInfo sendRpcMessage_methodinfo = { |
3788 | | { (JSJitGetterOp)sendRpcMessage }, |
3789 | | { prototypes::id::ContentProcessMessageManager }, |
3790 | | { PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth }, |
3791 | | JSJitInfo::Method, |
3792 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
3793 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
3794 | | false, /* isInfallible. False in setters. */ |
3795 | | false, /* isMovable. Not relevant for setters. */ |
3796 | | false, /* isEliminatable. Not relevant for setters. */ |
3797 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
3798 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
3799 | | false, /* isTypedMethod. Only relevant for methods. */ |
3800 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
3801 | | }; |
3802 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
3803 | | static_assert(0 < 1, "There is no slot for us"); |
3804 | | |
3805 | | static bool |
3806 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
3807 | 0 | { |
3808 | 0 | mozilla::dom::ContentProcessMessageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ContentProcessMessageManager>(obj); |
3809 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
3810 | 0 | // obviously can't preserve if we're not initialized. |
3811 | 0 | if (self && self->GetWrapperPreserveColor()) { |
3812 | 0 | PreserveWrapper(self); |
3813 | 0 | } |
3814 | 0 | return true; |
3815 | 0 | } |
3816 | | |
3817 | | static void |
3818 | | _finalize(js::FreeOp* fop, JSObject* obj) |
3819 | 0 | { |
3820 | 0 | mozilla::dom::ContentProcessMessageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ContentProcessMessageManager>(obj); |
3821 | 0 | if (self) { |
3822 | 0 | ClearWrapper(self, self, obj); |
3823 | 0 | AddForDeferredFinalization<mozilla::dom::ContentProcessMessageManager>(self); |
3824 | 0 | } |
3825 | 0 | } |
3826 | | |
3827 | | static size_t |
3828 | | _objectMoved(JSObject* obj, JSObject* old) |
3829 | 0 | { |
3830 | 0 | mozilla::dom::ContentProcessMessageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ContentProcessMessageManager>(obj); |
3831 | 0 | if (self) { |
3832 | 0 | UpdateWrapper(self, self, obj, old); |
3833 | 0 | } |
3834 | 0 |
|
3835 | 0 | return 0; |
3836 | 0 | } |
3837 | | |
3838 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
3839 | | #if defined(__clang__) |
3840 | | #pragma clang diagnostic push |
3841 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
3842 | | #endif |
3843 | | static const JSFunctionSpec sMethods_specs[] = { |
3844 | | JS_FNSPEC("addMessageListener", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&addMessageListener_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
3845 | | JS_FNSPEC("removeMessageListener", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&removeMessageListener_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
3846 | | JS_FNSPEC("addWeakMessageListener", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&addWeakMessageListener_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
3847 | | JS_FNSPEC("removeWeakMessageListener", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&removeWeakMessageListener_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
3848 | | JS_FNSPEC("dump", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&dump_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
3849 | | JS_FNSPEC("privateNoteIntentionalCrash", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&privateNoteIntentionalCrash_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
3850 | | JS_FNSPEC("atob", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&atob_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
3851 | | JS_FNSPEC("btoa", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&btoa_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
3852 | | JS_FNSPEC("sendAsyncMessage", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&sendAsyncMessage_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
3853 | | JS_FNSPEC("sendSyncMessage", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&sendSyncMessage_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
3854 | | JS_FNSPEC("sendRpcMessage", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&sendRpcMessage_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
3855 | | JS_FS_END |
3856 | | }; |
3857 | | #if defined(__clang__) |
3858 | | #pragma clang diagnostic pop |
3859 | | #endif |
3860 | | |
3861 | | |
3862 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
3863 | | { nullptr, &sMethods_specs[0] }, |
3864 | | { nullptr, nullptr } |
3865 | | }; |
3866 | | |
3867 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
3868 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
3869 | | static_assert(11 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
3870 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
3871 | | |
3872 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
3873 | | #if defined(__clang__) |
3874 | | #pragma clang diagnostic push |
3875 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
3876 | | #endif |
3877 | | static const JSPropertySpec sAttributes_specs[] = { |
3878 | | { "initialProcessData", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &initialProcessData_getterinfo, nullptr, nullptr }, |
3879 | | { "sharedData", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &sharedData_getterinfo, nullptr, nullptr }, |
3880 | | { "processMessageManager", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &processMessageManager_getterinfo, nullptr, nullptr }, |
3881 | | { "remoteType", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &remoteType_getterinfo, nullptr, nullptr }, |
3882 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
3883 | | }; |
3884 | | #if defined(__clang__) |
3885 | | #pragma clang diagnostic pop |
3886 | | #endif |
3887 | | |
3888 | | |
3889 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
3890 | | { nullptr, &sAttributes_specs[0] }, |
3891 | | { nullptr, nullptr } |
3892 | | }; |
3893 | | |
3894 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
3895 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
3896 | | static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
3897 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
3898 | | |
3899 | | |
3900 | | static uint16_t sNativeProperties_sortedPropertyIndices[15]; |
3901 | | static PropertyInfo sNativeProperties_propertyInfos[15]; |
3902 | | |
3903 | | static const NativePropertiesN<2> sNativeProperties = { |
3904 | | false, 0, |
3905 | | false, 0, |
3906 | | true, 0 /* sMethods */, |
3907 | | true, 1 /* sAttributes */, |
3908 | | false, 0, |
3909 | | false, 0, |
3910 | | false, 0, |
3911 | | -1, |
3912 | | 15, |
3913 | | sNativeProperties_sortedPropertyIndices, |
3914 | | { |
3915 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
3916 | | { sAttributes, &sNativeProperties_propertyInfos[11] } |
3917 | | } |
3918 | | }; |
3919 | | static_assert(15 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
3920 | | "We have a property info count that is oversized"); |
3921 | | |
3922 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
3923 | | { |
3924 | | "Function", |
3925 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
3926 | | &sBoringInterfaceObjectClassClassOps, |
3927 | | JS_NULL_CLASS_SPEC, |
3928 | | JS_NULL_CLASS_EXT, |
3929 | | &sInterfaceObjectClassObjectOps |
3930 | | }, |
3931 | | eInterface, |
3932 | | true, |
3933 | | prototypes::id::ContentProcessMessageManager, |
3934 | | PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth, |
3935 | | sNativePropertyHooks, |
3936 | | "function ContentProcessMessageManager() {\n [native code]\n}", |
3937 | | JS::GetRealmFunctionPrototype |
3938 | | }; |
3939 | | |
3940 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
3941 | | { |
3942 | | "ContentProcessMessageManagerPrototype", |
3943 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
3944 | | JS_NULL_CLASS_OPS, |
3945 | | JS_NULL_CLASS_SPEC, |
3946 | | JS_NULL_CLASS_EXT, |
3947 | | JS_NULL_OBJECT_OPS |
3948 | | }, |
3949 | | eInterfacePrototype, |
3950 | | false, |
3951 | | prototypes::id::ContentProcessMessageManager, |
3952 | | PrototypeTraits<prototypes::id::ContentProcessMessageManager>::Depth, |
3953 | | sNativePropertyHooks, |
3954 | | "[object ContentProcessMessageManagerPrototype]", |
3955 | | JS::GetRealmObjectPrototype |
3956 | | }; |
3957 | | |
3958 | | bool |
3959 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
3960 | 0 | { |
3961 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
3962 | 0 | } |
3963 | | |
3964 | | static const js::ClassOps sClassOps = { |
3965 | | _addProperty, /* addProperty */ |
3966 | | nullptr, /* delProperty */ |
3967 | | nullptr, /* enumerate */ |
3968 | | nullptr, /* newEnumerate */ |
3969 | | nullptr, /* resolve */ |
3970 | | nullptr, /* mayResolve */ |
3971 | | _finalize, /* finalize */ |
3972 | | nullptr, /* call */ |
3973 | | nullptr, /* hasInstance */ |
3974 | | nullptr, /* construct */ |
3975 | | nullptr, /* trace */ |
3976 | | }; |
3977 | | |
3978 | | static const js::ClassExtension sClassExtension = { |
3979 | | nullptr, /* weakmapKeyDelegateOp */ |
3980 | | _objectMoved /* objectMovedOp */ |
3981 | | }; |
3982 | | |
3983 | | static const DOMJSClass sClass = { |
3984 | | { "ContentProcessMessageManager", |
3985 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
3986 | | &sClassOps, |
3987 | | JS_NULL_CLASS_SPEC, |
3988 | | &sClassExtension, |
3989 | | JS_NULL_OBJECT_OPS |
3990 | | }, |
3991 | | { prototypes::id::ContentProcessMessageManager, 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 }, |
3992 | | IsBaseOf<nsISupports, mozilla::dom::ContentProcessMessageManager >::value, |
3993 | | sNativePropertyHooks, |
3994 | | FindAssociatedGlobalForNative<mozilla::dom::ContentProcessMessageManager>::Get, |
3995 | | GetProtoObjectHandle, |
3996 | | GetCCParticipant<mozilla::dom::ContentProcessMessageManager>::Get() |
3997 | | }; |
3998 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
3999 | | "Must have the right minimal number of reserved slots."); |
4000 | | static_assert(1 >= 1, |
4001 | | "Must have enough reserved slots."); |
4002 | | |
4003 | | const JSClass* |
4004 | | GetJSClass() |
4005 | 0 | { |
4006 | 0 | return sClass.ToJSClass(); |
4007 | 0 | } |
4008 | | |
4009 | | bool |
4010 | | Wrap(JSContext* aCx, mozilla::dom::ContentProcessMessageManager* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
4011 | 0 | { |
4012 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::ContentProcessMessageManager>::value, |
4013 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
4014 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::ContentProcessMessageManager*>(aObject) == |
4015 | 0 | reinterpret_cast<mozilla::dom::ContentProcessMessageManager*>(aObject), |
4016 | 0 | "Multiple inheritance for mozilla::dom::ContentProcessMessageManager is broken."); |
4017 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
4018 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
4019 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
4020 | 0 | "You should probably not be using Wrap() directly; use " |
4021 | 0 | "GetOrCreateDOMReflector instead"); |
4022 | 0 |
|
4023 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
4024 | 0 | "nsISupports must be on our primary inheritance chain"); |
4025 | 0 |
|
4026 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
4027 | 0 | if (!global) { |
4028 | 0 | return false; |
4029 | 0 | } |
4030 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
4031 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
4032 | 0 |
|
4033 | 0 | // That might have ended up wrapping us already, due to the wonders |
4034 | 0 | // of XBL. Check for that, and bail out as needed. |
4035 | 0 | aReflector.set(aCache->GetWrapper()); |
4036 | 0 | if (aReflector) { |
4037 | | #ifdef DEBUG |
4038 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
4039 | | #endif // DEBUG |
4040 | | return true; |
4041 | 0 | } |
4042 | 0 |
|
4043 | 0 | JSAutoRealm ar(aCx, global); |
4044 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
4045 | 0 | if (!canonicalProto) { |
4046 | 0 | return false; |
4047 | 0 | } |
4048 | 0 | JS::Rooted<JSObject*> proto(aCx); |
4049 | 0 | if (aGivenProto) { |
4050 | 0 | proto = aGivenProto; |
4051 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
4052 | 0 | // coming in, we changed compartments to that of "parent" so may need |
4053 | 0 | // to wrap the proto here. |
4054 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
4055 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
4056 | 0 | return false; |
4057 | 0 | } |
4058 | 0 | } |
4059 | 0 | } else { |
4060 | 0 | proto = canonicalProto; |
4061 | 0 | } |
4062 | 0 |
|
4063 | 0 | BindingJSObjectCreator<mozilla::dom::ContentProcessMessageManager> creator(aCx); |
4064 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
4065 | 0 | if (!aReflector) { |
4066 | 0 | return false; |
4067 | 0 | } |
4068 | 0 | |
4069 | 0 | aCache->SetWrapper(aReflector); |
4070 | 0 | creator.InitializationSucceeded(); |
4071 | 0 |
|
4072 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
4073 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
4074 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
4075 | 0 | // otherwise we won't be able to properly recreate it later, since |
4076 | 0 | // we won't know what proto to use. Note that we don't check |
4077 | 0 | // aGivenProto here, since it's entirely possible (and even |
4078 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
4079 | 0 | // same as canonicalProto. |
4080 | 0 | if (proto != canonicalProto) { |
4081 | 0 | PreserveWrapper(aObject); |
4082 | 0 | } |
4083 | 0 |
|
4084 | 0 | return true; |
4085 | 0 | } |
4086 | | |
4087 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
4088 | | nullptr, |
4089 | | nullptr, |
4090 | | nullptr, |
4091 | | { sNativeProperties.Upcast(), nullptr }, |
4092 | | prototypes::id::ContentProcessMessageManager, |
4093 | | constructors::id::ContentProcessMessageManager, |
4094 | | nullptr, |
4095 | | &DefaultXrayExpandoObjectClass |
4096 | | } }; |
4097 | | |
4098 | | void |
4099 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
4100 | 0 | { |
4101 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
4102 | 0 | if (!parentProto) { |
4103 | 0 | return; |
4104 | 0 | } |
4105 | 0 | |
4106 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
4107 | 0 | if (!constructorProto) { |
4108 | 0 | return; |
4109 | 0 | } |
4110 | 0 | |
4111 | 0 | static bool sIdsInited = false; |
4112 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
4113 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
4114 | 0 | return; |
4115 | 0 | } |
4116 | 0 | sIdsInited = true; |
4117 | 0 | } |
4118 | 0 |
|
4119 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ContentProcessMessageManager); |
4120 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ContentProcessMessageManager); |
4121 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
4122 | 0 | &sPrototypeClass.mBase, protoCache, |
4123 | 0 | nullptr, |
4124 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
4125 | 0 | interfaceCache, |
4126 | 0 | sNativeProperties.Upcast(), |
4127 | 0 | nullptr, |
4128 | 0 | "ContentProcessMessageManager", aDefineOnGlobal, |
4129 | 0 | nullptr, |
4130 | 0 | false); |
4131 | 0 | } |
4132 | | |
4133 | | JSObject* |
4134 | | GetConstructorObject(JSContext* aCx) |
4135 | 0 | { |
4136 | 0 | return GetConstructorObjectHandle(aCx); |
4137 | 0 | } |
4138 | | |
4139 | | } // namespace ContentProcessMessageManager_Binding |
4140 | | |
4141 | | |
4142 | | |
4143 | | namespace MessageBroadcaster_Binding { |
4144 | | |
4145 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<MessageListenerManager_Binding::NativeType>::value, |
4146 | | "Can't inherit from an interface with a different ownership model."); |
4147 | | |
4148 | | MOZ_CAN_RUN_SCRIPT static bool |
4149 | | broadcastAsyncMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageBroadcaster* self, const JSJitMethodCallArgs& args) |
4150 | 0 | { |
4151 | 0 | AUTO_PROFILER_LABEL_FAST("MessageBroadcaster.broadcastAsyncMessage", DOM, cx); |
4152 | 0 |
|
4153 | 0 | binding_detail::FakeString arg0; |
4154 | 0 | if (args.hasDefined(0)) { |
4155 | 0 | if (!ConvertJSValueToString(cx, args[0], eNull, eNull, arg0)) { |
4156 | 0 | return false; |
4157 | 0 | } |
4158 | 0 | } else { |
4159 | 0 | arg0.SetIsVoid(true); |
4160 | 0 | } |
4161 | 0 | JS::Rooted<JS::Value> arg1(cx); |
4162 | 0 | if (args.hasDefined(1)) { |
4163 | 0 | arg1 = args[1]; |
4164 | 0 | } else { |
4165 | 0 | arg1 = JS::UndefinedValue(); |
4166 | 0 | } |
4167 | 0 | JS::Rooted<JSObject*> arg2(cx); |
4168 | 0 | if (args.hasDefined(2)) { |
4169 | 0 | if (args[2].isObject()) { |
4170 | 0 | arg2 = &args[2].toObject(); |
4171 | 0 | } else if (args[2].isNullOrUndefined()) { |
4172 | 0 | arg2 = nullptr; |
4173 | 0 | } else { |
4174 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of MessageBroadcaster.broadcastAsyncMessage"); |
4175 | 0 | return false; |
4176 | 0 | } |
4177 | 0 | } else { |
4178 | 0 | arg2 = nullptr; |
4179 | 0 | } |
4180 | 0 | FastErrorResult rv; |
4181 | 0 | self->BroadcastAsyncMessage(cx, NonNullHelper(Constify(arg0)), arg1, arg2, rv); |
4182 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
4183 | 0 | return false; |
4184 | 0 | } |
4185 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
4186 | 0 | args.rval().setUndefined(); |
4187 | 0 | return true; |
4188 | 0 | } |
4189 | | |
4190 | | static const JSJitInfo broadcastAsyncMessage_methodinfo = { |
4191 | | { (JSJitGetterOp)broadcastAsyncMessage }, |
4192 | | { prototypes::id::MessageBroadcaster }, |
4193 | | { PrototypeTraits<prototypes::id::MessageBroadcaster>::Depth }, |
4194 | | JSJitInfo::Method, |
4195 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
4196 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
4197 | | false, /* isInfallible. False in setters. */ |
4198 | | false, /* isMovable. Not relevant for setters. */ |
4199 | | false, /* isEliminatable. Not relevant for setters. */ |
4200 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
4201 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
4202 | | false, /* isTypedMethod. Only relevant for methods. */ |
4203 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
4204 | | }; |
4205 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
4206 | | static_assert(0 < 1, "There is no slot for us"); |
4207 | | |
4208 | | MOZ_CAN_RUN_SCRIPT static bool |
4209 | | get_childCount(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageBroadcaster* self, JSJitGetterCallArgs args) |
4210 | 0 | { |
4211 | 0 | AUTO_PROFILER_LABEL_FAST("get MessageBroadcaster.childCount", DOM, cx); |
4212 | 0 |
|
4213 | 0 | uint32_t result(self->ChildCount()); |
4214 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
4215 | 0 | args.rval().setNumber(result); |
4216 | 0 | return true; |
4217 | 0 | } |
4218 | | |
4219 | | static const JSJitInfo childCount_getterinfo = { |
4220 | | { (JSJitGetterOp)get_childCount }, |
4221 | | { prototypes::id::MessageBroadcaster }, |
4222 | | { PrototypeTraits<prototypes::id::MessageBroadcaster>::Depth }, |
4223 | | JSJitInfo::Getter, |
4224 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
4225 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
4226 | | true, /* isInfallible. False in setters. */ |
4227 | | false, /* isMovable. Not relevant for setters. */ |
4228 | | false, /* isEliminatable. Not relevant for setters. */ |
4229 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
4230 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
4231 | | false, /* isTypedMethod. Only relevant for methods. */ |
4232 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
4233 | | }; |
4234 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
4235 | | static_assert(0 < 1, "There is no slot for us"); |
4236 | | |
4237 | | MOZ_CAN_RUN_SCRIPT static bool |
4238 | | getChildAt(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageBroadcaster* self, const JSJitMethodCallArgs& args) |
4239 | 0 | { |
4240 | 0 | AUTO_PROFILER_LABEL_FAST("MessageBroadcaster.getChildAt", DOM, cx); |
4241 | 0 |
|
4242 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
4243 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MessageBroadcaster.getChildAt"); |
4244 | 0 | } |
4245 | 0 | uint32_t arg0; |
4246 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) { |
4247 | 0 | return false; |
4248 | 0 | } |
4249 | 0 | auto result(StrongOrRawPtr<mozilla::dom::MessageListenerManager>(self->GetChildAt(arg0))); |
4250 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
4251 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
4252 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
4253 | 0 | return false; |
4254 | 0 | } |
4255 | 0 | return true; |
4256 | 0 | } |
4257 | | |
4258 | | static const JSJitInfo getChildAt_methodinfo = { |
4259 | | { (JSJitGetterOp)getChildAt }, |
4260 | | { prototypes::id::MessageBroadcaster }, |
4261 | | { PrototypeTraits<prototypes::id::MessageBroadcaster>::Depth }, |
4262 | | JSJitInfo::Method, |
4263 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
4264 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
4265 | | false, /* isInfallible. False in setters. */ |
4266 | | false, /* isMovable. Not relevant for setters. */ |
4267 | | false, /* isEliminatable. Not relevant for setters. */ |
4268 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
4269 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
4270 | | false, /* isTypedMethod. Only relevant for methods. */ |
4271 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
4272 | | }; |
4273 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
4274 | | static_assert(0 < 1, "There is no slot for us"); |
4275 | | |
4276 | | MOZ_CAN_RUN_SCRIPT static bool |
4277 | | releaseCachedProcesses(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageBroadcaster* self, const JSJitMethodCallArgs& args) |
4278 | 0 | { |
4279 | 0 | AUTO_PROFILER_LABEL_FAST("MessageBroadcaster.releaseCachedProcesses", DOM, cx); |
4280 | 0 |
|
4281 | 0 | self->ReleaseCachedProcesses(); |
4282 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
4283 | 0 | args.rval().setUndefined(); |
4284 | 0 | return true; |
4285 | 0 | } |
4286 | | |
4287 | | static const JSJitInfo releaseCachedProcesses_methodinfo = { |
4288 | | { (JSJitGetterOp)releaseCachedProcesses }, |
4289 | | { prototypes::id::MessageBroadcaster }, |
4290 | | { PrototypeTraits<prototypes::id::MessageBroadcaster>::Depth }, |
4291 | | JSJitInfo::Method, |
4292 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
4293 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
4294 | | true, /* isInfallible. False in setters. */ |
4295 | | false, /* isMovable. Not relevant for setters. */ |
4296 | | false, /* isEliminatable. Not relevant for setters. */ |
4297 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
4298 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
4299 | | false, /* isTypedMethod. Only relevant for methods. */ |
4300 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
4301 | | }; |
4302 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
4303 | | static_assert(0 < 1, "There is no slot for us"); |
4304 | | |
4305 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
4306 | | #if defined(__clang__) |
4307 | | #pragma clang diagnostic push |
4308 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
4309 | | #endif |
4310 | | static const JSFunctionSpec sMethods_specs[] = { |
4311 | | JS_FNSPEC("broadcastAsyncMessage", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&broadcastAsyncMessage_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
4312 | | JS_FNSPEC("getChildAt", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getChildAt_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
4313 | | JS_FNSPEC("releaseCachedProcesses", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&releaseCachedProcesses_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
4314 | | JS_FS_END |
4315 | | }; |
4316 | | #if defined(__clang__) |
4317 | | #pragma clang diagnostic pop |
4318 | | #endif |
4319 | | |
4320 | | |
4321 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
4322 | | { nullptr, &sMethods_specs[0] }, |
4323 | | { nullptr, nullptr } |
4324 | | }; |
4325 | | |
4326 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
4327 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
4328 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
4329 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
4330 | | |
4331 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
4332 | | #if defined(__clang__) |
4333 | | #pragma clang diagnostic push |
4334 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
4335 | | #endif |
4336 | | static const JSPropertySpec sAttributes_specs[] = { |
4337 | | { "childCount", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &childCount_getterinfo, nullptr, nullptr }, |
4338 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
4339 | | }; |
4340 | | #if defined(__clang__) |
4341 | | #pragma clang diagnostic pop |
4342 | | #endif |
4343 | | |
4344 | | |
4345 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
4346 | | { nullptr, &sAttributes_specs[0] }, |
4347 | | { nullptr, nullptr } |
4348 | | }; |
4349 | | |
4350 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
4351 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
4352 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
4353 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
4354 | | |
4355 | | |
4356 | | static uint16_t sNativeProperties_sortedPropertyIndices[4]; |
4357 | | static PropertyInfo sNativeProperties_propertyInfos[4]; |
4358 | | |
4359 | | static const NativePropertiesN<2> sNativeProperties = { |
4360 | | false, 0, |
4361 | | false, 0, |
4362 | | true, 0 /* sMethods */, |
4363 | | true, 1 /* sAttributes */, |
4364 | | false, 0, |
4365 | | false, 0, |
4366 | | false, 0, |
4367 | | -1, |
4368 | | 4, |
4369 | | sNativeProperties_sortedPropertyIndices, |
4370 | | { |
4371 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
4372 | | { sAttributes, &sNativeProperties_propertyInfos[3] } |
4373 | | } |
4374 | | }; |
4375 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
4376 | | "We have a property info count that is oversized"); |
4377 | | |
4378 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
4379 | | { |
4380 | | "Function", |
4381 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
4382 | | &sBoringInterfaceObjectClassClassOps, |
4383 | | JS_NULL_CLASS_SPEC, |
4384 | | JS_NULL_CLASS_EXT, |
4385 | | &sInterfaceObjectClassObjectOps |
4386 | | }, |
4387 | | eInterface, |
4388 | | true, |
4389 | | prototypes::id::MessageBroadcaster, |
4390 | | PrototypeTraits<prototypes::id::MessageBroadcaster>::Depth, |
4391 | | sNativePropertyHooks, |
4392 | | "function MessageBroadcaster() {\n [native code]\n}", |
4393 | | MessageListenerManager_Binding::GetConstructorObject |
4394 | | }; |
4395 | | |
4396 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
4397 | | { |
4398 | | "MessageBroadcasterPrototype", |
4399 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
4400 | | JS_NULL_CLASS_OPS, |
4401 | | JS_NULL_CLASS_SPEC, |
4402 | | JS_NULL_CLASS_EXT, |
4403 | | JS_NULL_OBJECT_OPS |
4404 | | }, |
4405 | | eInterfacePrototype, |
4406 | | false, |
4407 | | prototypes::id::MessageBroadcaster, |
4408 | | PrototypeTraits<prototypes::id::MessageBroadcaster>::Depth, |
4409 | | sNativePropertyHooks, |
4410 | | "[object MessageBroadcasterPrototype]", |
4411 | | MessageListenerManager_Binding::GetProtoObject |
4412 | | }; |
4413 | | |
4414 | | bool |
4415 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
4416 | 0 | { |
4417 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
4418 | 0 | } |
4419 | | |
4420 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
4421 | | nullptr, |
4422 | | nullptr, |
4423 | | nullptr, |
4424 | | { sNativeProperties.Upcast(), nullptr }, |
4425 | | prototypes::id::MessageBroadcaster, |
4426 | | constructors::id::MessageBroadcaster, |
4427 | | MessageListenerManager_Binding::sNativePropertyHooks, |
4428 | | &DefaultXrayExpandoObjectClass |
4429 | | } }; |
4430 | | |
4431 | | void |
4432 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
4433 | 0 | { |
4434 | 0 | JS::Handle<JSObject*> parentProto(MessageListenerManager_Binding::GetProtoObjectHandle(aCx)); |
4435 | 0 | if (!parentProto) { |
4436 | 0 | return; |
4437 | 0 | } |
4438 | 0 | |
4439 | 0 | JS::Handle<JSObject*> constructorProto(MessageListenerManager_Binding::GetConstructorObjectHandle(aCx)); |
4440 | 0 | if (!constructorProto) { |
4441 | 0 | return; |
4442 | 0 | } |
4443 | 0 | |
4444 | 0 | static bool sIdsInited = false; |
4445 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
4446 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
4447 | 0 | return; |
4448 | 0 | } |
4449 | 0 | sIdsInited = true; |
4450 | 0 | } |
4451 | 0 |
|
4452 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MessageBroadcaster); |
4453 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MessageBroadcaster); |
4454 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
4455 | 0 | &sPrototypeClass.mBase, protoCache, |
4456 | 0 | nullptr, |
4457 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
4458 | 0 | interfaceCache, |
4459 | 0 | sNativeProperties.Upcast(), |
4460 | 0 | nullptr, |
4461 | 0 | "MessageBroadcaster", aDefineOnGlobal, |
4462 | 0 | nullptr, |
4463 | 0 | false); |
4464 | 0 | } |
4465 | | |
4466 | | JSObject* |
4467 | | GetProtoObject(JSContext* aCx) |
4468 | 0 | { |
4469 | 0 | return GetProtoObjectHandle(aCx); |
4470 | 0 | } |
4471 | | |
4472 | | JSObject* |
4473 | | GetConstructorObject(JSContext* aCx) |
4474 | 0 | { |
4475 | 0 | return GetConstructorObjectHandle(aCx); |
4476 | 0 | } |
4477 | | |
4478 | | } // namespace MessageBroadcaster_Binding |
4479 | | |
4480 | | |
4481 | | |
4482 | | namespace MessageListenerManager_Binding { |
4483 | | |
4484 | | MOZ_CAN_RUN_SCRIPT static bool |
4485 | | addMessageListener(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageListenerManager* self, const JSJitMethodCallArgs& args) |
4486 | 0 | { |
4487 | 0 | AUTO_PROFILER_LABEL_FAST("MessageListenerManager.addMessageListener", DOM, cx); |
4488 | 0 |
|
4489 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
4490 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MessageListenerManager.addMessageListener"); |
4491 | 0 | } |
4492 | 0 | binding_detail::FakeString arg0; |
4493 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
4494 | 0 | return false; |
4495 | 0 | } |
4496 | 0 | RootedCallback<OwningNonNull<binding_detail::FastMessageListener>> arg1(cx); |
4497 | 0 | if (args[1].isObject()) { |
4498 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
4499 | 0 | arg1 = new binding_detail::FastMessageListener(&args[1].toObject(), JS::CurrentGlobalOrNull(cx)); |
4500 | 0 | } |
4501 | 0 | } else { |
4502 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of MessageListenerManager.addMessageListener"); |
4503 | 0 | return false; |
4504 | 0 | } |
4505 | 0 | bool arg2; |
4506 | 0 | if (args.hasDefined(2)) { |
4507 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, args[2], &arg2)) { |
4508 | 0 | return false; |
4509 | 0 | } |
4510 | 0 | } else { |
4511 | 0 | arg2 = false; |
4512 | 0 | } |
4513 | 0 | FastErrorResult rv; |
4514 | 0 | self->AddMessageListener(NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), arg2, rv); |
4515 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
4516 | 0 | return false; |
4517 | 0 | } |
4518 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
4519 | 0 | args.rval().setUndefined(); |
4520 | 0 | return true; |
4521 | 0 | } |
4522 | | |
4523 | | static const JSJitInfo addMessageListener_methodinfo = { |
4524 | | { (JSJitGetterOp)addMessageListener }, |
4525 | | { prototypes::id::MessageListenerManager }, |
4526 | | { PrototypeTraits<prototypes::id::MessageListenerManager>::Depth }, |
4527 | | JSJitInfo::Method, |
4528 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
4529 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
4530 | | false, /* isInfallible. False in setters. */ |
4531 | | false, /* isMovable. Not relevant for setters. */ |
4532 | | false, /* isEliminatable. Not relevant for setters. */ |
4533 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
4534 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
4535 | | false, /* isTypedMethod. Only relevant for methods. */ |
4536 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
4537 | | }; |
4538 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
4539 | | static_assert(0 < 1, "There is no slot for us"); |
4540 | | |
4541 | | MOZ_CAN_RUN_SCRIPT static bool |
4542 | | removeMessageListener(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageListenerManager* self, const JSJitMethodCallArgs& args) |
4543 | 0 | { |
4544 | 0 | AUTO_PROFILER_LABEL_FAST("MessageListenerManager.removeMessageListener", DOM, cx); |
4545 | 0 |
|
4546 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
4547 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MessageListenerManager.removeMessageListener"); |
4548 | 0 | } |
4549 | 0 | binding_detail::FakeString arg0; |
4550 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
4551 | 0 | return false; |
4552 | 0 | } |
4553 | 0 | RootedCallback<OwningNonNull<binding_detail::FastMessageListener>> arg1(cx); |
4554 | 0 | if (args[1].isObject()) { |
4555 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
4556 | 0 | arg1 = new binding_detail::FastMessageListener(&args[1].toObject(), JS::CurrentGlobalOrNull(cx)); |
4557 | 0 | } |
4558 | 0 | } else { |
4559 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of MessageListenerManager.removeMessageListener"); |
4560 | 0 | return false; |
4561 | 0 | } |
4562 | 0 | FastErrorResult rv; |
4563 | 0 | self->RemoveMessageListener(NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), rv); |
4564 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
4565 | 0 | return false; |
4566 | 0 | } |
4567 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
4568 | 0 | args.rval().setUndefined(); |
4569 | 0 | return true; |
4570 | 0 | } |
4571 | | |
4572 | | static const JSJitInfo removeMessageListener_methodinfo = { |
4573 | | { (JSJitGetterOp)removeMessageListener }, |
4574 | | { prototypes::id::MessageListenerManager }, |
4575 | | { PrototypeTraits<prototypes::id::MessageListenerManager>::Depth }, |
4576 | | JSJitInfo::Method, |
4577 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
4578 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
4579 | | false, /* isInfallible. False in setters. */ |
4580 | | false, /* isMovable. Not relevant for setters. */ |
4581 | | false, /* isEliminatable. Not relevant for setters. */ |
4582 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
4583 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
4584 | | false, /* isTypedMethod. Only relevant for methods. */ |
4585 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
4586 | | }; |
4587 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
4588 | | static_assert(0 < 1, "There is no slot for us"); |
4589 | | |
4590 | | MOZ_CAN_RUN_SCRIPT static bool |
4591 | | addWeakMessageListener(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageListenerManager* self, const JSJitMethodCallArgs& args) |
4592 | 0 | { |
4593 | 0 | AUTO_PROFILER_LABEL_FAST("MessageListenerManager.addWeakMessageListener", DOM, cx); |
4594 | 0 |
|
4595 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
4596 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MessageListenerManager.addWeakMessageListener"); |
4597 | 0 | } |
4598 | 0 | binding_detail::FakeString arg0; |
4599 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
4600 | 0 | return false; |
4601 | 0 | } |
4602 | 0 | RootedCallback<OwningNonNull<binding_detail::FastMessageListener>> arg1(cx); |
4603 | 0 | if (args[1].isObject()) { |
4604 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
4605 | 0 | arg1 = new binding_detail::FastMessageListener(&args[1].toObject(), JS::CurrentGlobalOrNull(cx)); |
4606 | 0 | } |
4607 | 0 | } else { |
4608 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of MessageListenerManager.addWeakMessageListener"); |
4609 | 0 | return false; |
4610 | 0 | } |
4611 | 0 | FastErrorResult rv; |
4612 | 0 | self->AddWeakMessageListener(NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), rv); |
4613 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
4614 | 0 | return false; |
4615 | 0 | } |
4616 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
4617 | 0 | args.rval().setUndefined(); |
4618 | 0 | return true; |
4619 | 0 | } |
4620 | | |
4621 | | static const JSJitInfo addWeakMessageListener_methodinfo = { |
4622 | | { (JSJitGetterOp)addWeakMessageListener }, |
4623 | | { prototypes::id::MessageListenerManager }, |
4624 | | { PrototypeTraits<prototypes::id::MessageListenerManager>::Depth }, |
4625 | | JSJitInfo::Method, |
4626 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
4627 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
4628 | | false, /* isInfallible. False in setters. */ |
4629 | | false, /* isMovable. Not relevant for setters. */ |
4630 | | false, /* isEliminatable. Not relevant for setters. */ |
4631 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
4632 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
4633 | | false, /* isTypedMethod. Only relevant for methods. */ |
4634 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
4635 | | }; |
4636 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
4637 | | static_assert(0 < 1, "There is no slot for us"); |
4638 | | |
4639 | | MOZ_CAN_RUN_SCRIPT static bool |
4640 | | removeWeakMessageListener(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageListenerManager* self, const JSJitMethodCallArgs& args) |
4641 | 0 | { |
4642 | 0 | AUTO_PROFILER_LABEL_FAST("MessageListenerManager.removeWeakMessageListener", DOM, cx); |
4643 | 0 |
|
4644 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
4645 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MessageListenerManager.removeWeakMessageListener"); |
4646 | 0 | } |
4647 | 0 | binding_detail::FakeString arg0; |
4648 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
4649 | 0 | return false; |
4650 | 0 | } |
4651 | 0 | RootedCallback<OwningNonNull<binding_detail::FastMessageListener>> arg1(cx); |
4652 | 0 | if (args[1].isObject()) { |
4653 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
4654 | 0 | arg1 = new binding_detail::FastMessageListener(&args[1].toObject(), JS::CurrentGlobalOrNull(cx)); |
4655 | 0 | } |
4656 | 0 | } else { |
4657 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of MessageListenerManager.removeWeakMessageListener"); |
4658 | 0 | return false; |
4659 | 0 | } |
4660 | 0 | FastErrorResult rv; |
4661 | 0 | self->RemoveWeakMessageListener(NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), rv); |
4662 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
4663 | 0 | return false; |
4664 | 0 | } |
4665 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
4666 | 0 | args.rval().setUndefined(); |
4667 | 0 | return true; |
4668 | 0 | } |
4669 | | |
4670 | | static const JSJitInfo removeWeakMessageListener_methodinfo = { |
4671 | | { (JSJitGetterOp)removeWeakMessageListener }, |
4672 | | { prototypes::id::MessageListenerManager }, |
4673 | | { PrototypeTraits<prototypes::id::MessageListenerManager>::Depth }, |
4674 | | JSJitInfo::Method, |
4675 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
4676 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
4677 | | false, /* isInfallible. False in setters. */ |
4678 | | false, /* isMovable. Not relevant for setters. */ |
4679 | | false, /* isEliminatable. Not relevant for setters. */ |
4680 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
4681 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
4682 | | false, /* isTypedMethod. Only relevant for methods. */ |
4683 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
4684 | | }; |
4685 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
4686 | | static_assert(0 < 1, "There is no slot for us"); |
4687 | | |
4688 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
4689 | | #if defined(__clang__) |
4690 | | #pragma clang diagnostic push |
4691 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
4692 | | #endif |
4693 | | static const JSFunctionSpec sMethods_specs[] = { |
4694 | | JS_FNSPEC("addMessageListener", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&addMessageListener_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
4695 | | JS_FNSPEC("removeMessageListener", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&removeMessageListener_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
4696 | | JS_FNSPEC("addWeakMessageListener", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&addWeakMessageListener_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
4697 | | JS_FNSPEC("removeWeakMessageListener", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&removeWeakMessageListener_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
4698 | | JS_FS_END |
4699 | | }; |
4700 | | #if defined(__clang__) |
4701 | | #pragma clang diagnostic pop |
4702 | | #endif |
4703 | | |
4704 | | |
4705 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
4706 | | { nullptr, &sMethods_specs[0] }, |
4707 | | { nullptr, nullptr } |
4708 | | }; |
4709 | | |
4710 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
4711 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
4712 | | static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
4713 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
4714 | | |
4715 | | |
4716 | | static uint16_t sNativeProperties_sortedPropertyIndices[4]; |
4717 | | static PropertyInfo sNativeProperties_propertyInfos[4]; |
4718 | | |
4719 | | static const NativePropertiesN<1> sNativeProperties = { |
4720 | | false, 0, |
4721 | | false, 0, |
4722 | | true, 0 /* sMethods */, |
4723 | | false, 0, |
4724 | | false, 0, |
4725 | | false, 0, |
4726 | | false, 0, |
4727 | | -1, |
4728 | | 4, |
4729 | | sNativeProperties_sortedPropertyIndices, |
4730 | | { |
4731 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
4732 | | } |
4733 | | }; |
4734 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
4735 | | "We have a property info count that is oversized"); |
4736 | | |
4737 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
4738 | | { |
4739 | | "Function", |
4740 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
4741 | | &sBoringInterfaceObjectClassClassOps, |
4742 | | JS_NULL_CLASS_SPEC, |
4743 | | JS_NULL_CLASS_EXT, |
4744 | | &sInterfaceObjectClassObjectOps |
4745 | | }, |
4746 | | eInterface, |
4747 | | true, |
4748 | | prototypes::id::MessageListenerManager, |
4749 | | PrototypeTraits<prototypes::id::MessageListenerManager>::Depth, |
4750 | | sNativePropertyHooks, |
4751 | | "function MessageListenerManager() {\n [native code]\n}", |
4752 | | JS::GetRealmFunctionPrototype |
4753 | | }; |
4754 | | |
4755 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
4756 | | { |
4757 | | "MessageListenerManagerPrototype", |
4758 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
4759 | | JS_NULL_CLASS_OPS, |
4760 | | JS_NULL_CLASS_SPEC, |
4761 | | JS_NULL_CLASS_EXT, |
4762 | | JS_NULL_OBJECT_OPS |
4763 | | }, |
4764 | | eInterfacePrototype, |
4765 | | false, |
4766 | | prototypes::id::MessageListenerManager, |
4767 | | PrototypeTraits<prototypes::id::MessageListenerManager>::Depth, |
4768 | | sNativePropertyHooks, |
4769 | | "[object MessageListenerManagerPrototype]", |
4770 | | JS::GetRealmObjectPrototype |
4771 | | }; |
4772 | | |
4773 | | bool |
4774 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
4775 | 0 | { |
4776 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
4777 | 0 | } |
4778 | | |
4779 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
4780 | | nullptr, |
4781 | | nullptr, |
4782 | | nullptr, |
4783 | | { sNativeProperties.Upcast(), nullptr }, |
4784 | | prototypes::id::MessageListenerManager, |
4785 | | constructors::id::MessageListenerManager, |
4786 | | nullptr, |
4787 | | &DefaultXrayExpandoObjectClass |
4788 | | } }; |
4789 | | |
4790 | | void |
4791 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
4792 | 0 | { |
4793 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
4794 | 0 | if (!parentProto) { |
4795 | 0 | return; |
4796 | 0 | } |
4797 | 0 | |
4798 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
4799 | 0 | if (!constructorProto) { |
4800 | 0 | return; |
4801 | 0 | } |
4802 | 0 | |
4803 | 0 | static bool sIdsInited = false; |
4804 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
4805 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
4806 | 0 | return; |
4807 | 0 | } |
4808 | 0 | sIdsInited = true; |
4809 | 0 | } |
4810 | 0 |
|
4811 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MessageListenerManager); |
4812 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MessageListenerManager); |
4813 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
4814 | 0 | &sPrototypeClass.mBase, protoCache, |
4815 | 0 | nullptr, |
4816 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
4817 | 0 | interfaceCache, |
4818 | 0 | sNativeProperties.Upcast(), |
4819 | 0 | nullptr, |
4820 | 0 | "MessageListenerManager", aDefineOnGlobal, |
4821 | 0 | nullptr, |
4822 | 0 | false); |
4823 | 0 | } |
4824 | | |
4825 | | JSObject* |
4826 | | GetProtoObject(JSContext* aCx) |
4827 | 0 | { |
4828 | 0 | return GetProtoObjectHandle(aCx); |
4829 | 0 | } |
4830 | | |
4831 | | JSObject* |
4832 | | GetConstructorObject(JSContext* aCx) |
4833 | 0 | { |
4834 | 0 | return GetConstructorObjectHandle(aCx); |
4835 | 0 | } |
4836 | | |
4837 | | } // namespace MessageListenerManager_Binding |
4838 | | |
4839 | | |
4840 | | |
4841 | | namespace MessageSender_Binding { |
4842 | | |
4843 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<MessageListenerManager_Binding::NativeType>::value, |
4844 | | "Can't inherit from an interface with a different ownership model."); |
4845 | | |
4846 | | MOZ_CAN_RUN_SCRIPT static bool |
4847 | | sendAsyncMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageSender* self, const JSJitMethodCallArgs& args) |
4848 | 0 | { |
4849 | 0 | AUTO_PROFILER_LABEL_FAST("MessageSender.sendAsyncMessage", DOM, cx); |
4850 | 0 |
|
4851 | 0 | binding_detail::FakeString arg0; |
4852 | 0 | if (args.hasDefined(0)) { |
4853 | 0 | if (!ConvertJSValueToString(cx, args[0], eNull, eNull, arg0)) { |
4854 | 0 | return false; |
4855 | 0 | } |
4856 | 0 | } else { |
4857 | 0 | arg0.SetIsVoid(true); |
4858 | 0 | } |
4859 | 0 | JS::Rooted<JS::Value> arg1(cx); |
4860 | 0 | if (args.hasDefined(1)) { |
4861 | 0 | arg1 = args[1]; |
4862 | 0 | } else { |
4863 | 0 | arg1 = JS::UndefinedValue(); |
4864 | 0 | } |
4865 | 0 | JS::Rooted<JSObject*> arg2(cx); |
4866 | 0 | if (args.hasDefined(2)) { |
4867 | 0 | if (args[2].isObject()) { |
4868 | 0 | arg2 = &args[2].toObject(); |
4869 | 0 | } else if (args[2].isNullOrUndefined()) { |
4870 | 0 | arg2 = nullptr; |
4871 | 0 | } else { |
4872 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of MessageSender.sendAsyncMessage"); |
4873 | 0 | return false; |
4874 | 0 | } |
4875 | 0 | } else { |
4876 | 0 | arg2 = nullptr; |
4877 | 0 | } |
4878 | 0 | nsIPrincipal* arg3; |
4879 | 0 | RefPtr<nsIPrincipal> arg3_holder; |
4880 | 0 | if (args.hasDefined(3)) { |
4881 | 0 | if (args[3].isObject()) { |
4882 | 0 | JS::Rooted<JSObject*> source(cx, &args[3].toObject()); |
4883 | 0 | if (NS_FAILED(UnwrapArg<nsIPrincipal>(cx, source, getter_AddRefs(arg3_holder)))) { |
4884 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 4 of MessageSender.sendAsyncMessage", "Principal"); |
4885 | 0 | return false; |
4886 | 0 | } |
4887 | 0 | MOZ_ASSERT(arg3_holder); |
4888 | 0 | arg3 = arg3_holder; |
4889 | 0 | } else if (args[3].isNullOrUndefined()) { |
4890 | 0 | arg3 = nullptr; |
4891 | 0 | } else { |
4892 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 4 of MessageSender.sendAsyncMessage"); |
4893 | 0 | return false; |
4894 | 0 | } |
4895 | 0 | } else { |
4896 | 0 | arg3 = nullptr; |
4897 | 0 | } |
4898 | 0 | JS::Rooted<JS::Value> arg4(cx); |
4899 | 0 | if (args.hasDefined(4)) { |
4900 | 0 | arg4 = args[4]; |
4901 | 0 | } else { |
4902 | 0 | arg4 = JS::UndefinedValue(); |
4903 | 0 | } |
4904 | 0 | FastErrorResult rv; |
4905 | 0 | self->SendAsyncMessage(cx, NonNullHelper(Constify(arg0)), arg1, arg2, MOZ_KnownLive(Constify(arg3)), arg4, rv); |
4906 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
4907 | 0 | return false; |
4908 | 0 | } |
4909 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
4910 | 0 | args.rval().setUndefined(); |
4911 | 0 | return true; |
4912 | 0 | } |
4913 | | |
4914 | | static const JSJitInfo sendAsyncMessage_methodinfo = { |
4915 | | { (JSJitGetterOp)sendAsyncMessage }, |
4916 | | { prototypes::id::MessageSender }, |
4917 | | { PrototypeTraits<prototypes::id::MessageSender>::Depth }, |
4918 | | JSJitInfo::Method, |
4919 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
4920 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
4921 | | false, /* isInfallible. False in setters. */ |
4922 | | false, /* isMovable. Not relevant for setters. */ |
4923 | | false, /* isEliminatable. Not relevant for setters. */ |
4924 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
4925 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
4926 | | false, /* isTypedMethod. Only relevant for methods. */ |
4927 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
4928 | | }; |
4929 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
4930 | | static_assert(0 < 1, "There is no slot for us"); |
4931 | | |
4932 | | MOZ_CAN_RUN_SCRIPT static bool |
4933 | | get_processMessageManager(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageSender* self, JSJitGetterCallArgs args) |
4934 | 0 | { |
4935 | 0 | AUTO_PROFILER_LABEL_FAST("get MessageSender.processMessageManager", DOM, cx); |
4936 | 0 |
|
4937 | 0 | FastErrorResult rv; |
4938 | 0 | auto result(StrongOrRawPtr<mozilla::dom::MessageSender>(self->GetProcessMessageManager(rv))); |
4939 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
4940 | 0 | return false; |
4941 | 0 | } |
4942 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
4943 | 0 | if (!result) { |
4944 | 0 | args.rval().setNull(); |
4945 | 0 | return true; |
4946 | 0 | } |
4947 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
4948 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
4949 | 0 | return false; |
4950 | 0 | } |
4951 | 0 | return true; |
4952 | 0 | } |
4953 | | |
4954 | | static const JSJitInfo processMessageManager_getterinfo = { |
4955 | | { (JSJitGetterOp)get_processMessageManager }, |
4956 | | { prototypes::id::MessageSender }, |
4957 | | { PrototypeTraits<prototypes::id::MessageSender>::Depth }, |
4958 | | JSJitInfo::Getter, |
4959 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
4960 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
4961 | | false, /* isInfallible. False in setters. */ |
4962 | | false, /* isMovable. Not relevant for setters. */ |
4963 | | false, /* isEliminatable. Not relevant for setters. */ |
4964 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
4965 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
4966 | | false, /* isTypedMethod. Only relevant for methods. */ |
4967 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
4968 | | }; |
4969 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
4970 | | static_assert(0 < 1, "There is no slot for us"); |
4971 | | |
4972 | | MOZ_CAN_RUN_SCRIPT static bool |
4973 | | get_remoteType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageSender* self, JSJitGetterCallArgs args) |
4974 | 0 | { |
4975 | 0 | AUTO_PROFILER_LABEL_FAST("get MessageSender.remoteType", DOM, cx); |
4976 | 0 |
|
4977 | 0 | FastErrorResult rv; |
4978 | 0 | DOMString result; |
4979 | 0 | self->GetRemoteType(result, rv); |
4980 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
4981 | 0 | return false; |
4982 | 0 | } |
4983 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
4984 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
4985 | 0 | return false; |
4986 | 0 | } |
4987 | 0 | return true; |
4988 | 0 | } |
4989 | | |
4990 | | static const JSJitInfo remoteType_getterinfo = { |
4991 | | { (JSJitGetterOp)get_remoteType }, |
4992 | | { prototypes::id::MessageSender }, |
4993 | | { PrototypeTraits<prototypes::id::MessageSender>::Depth }, |
4994 | | JSJitInfo::Getter, |
4995 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
4996 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
4997 | | false, /* isInfallible. False in setters. */ |
4998 | | false, /* isMovable. Not relevant for setters. */ |
4999 | | false, /* isEliminatable. Not relevant for setters. */ |
5000 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
5001 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
5002 | | false, /* isTypedMethod. Only relevant for methods. */ |
5003 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
5004 | | }; |
5005 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
5006 | | static_assert(0 < 1, "There is no slot for us"); |
5007 | | |
5008 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
5009 | | #if defined(__clang__) |
5010 | | #pragma clang diagnostic push |
5011 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
5012 | | #endif |
5013 | | static const JSFunctionSpec sMethods_specs[] = { |
5014 | | JS_FNSPEC("sendAsyncMessage", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&sendAsyncMessage_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
5015 | | JS_FS_END |
5016 | | }; |
5017 | | #if defined(__clang__) |
5018 | | #pragma clang diagnostic pop |
5019 | | #endif |
5020 | | |
5021 | | |
5022 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
5023 | | { nullptr, &sMethods_specs[0] }, |
5024 | | { nullptr, nullptr } |
5025 | | }; |
5026 | | |
5027 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
5028 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
5029 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
5030 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
5031 | | |
5032 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
5033 | | #if defined(__clang__) |
5034 | | #pragma clang diagnostic push |
5035 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
5036 | | #endif |
5037 | | static const JSPropertySpec sAttributes_specs[] = { |
5038 | | { "processMessageManager", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &processMessageManager_getterinfo, nullptr, nullptr }, |
5039 | | { "remoteType", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &remoteType_getterinfo, nullptr, nullptr }, |
5040 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
5041 | | }; |
5042 | | #if defined(__clang__) |
5043 | | #pragma clang diagnostic pop |
5044 | | #endif |
5045 | | |
5046 | | |
5047 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
5048 | | { nullptr, &sAttributes_specs[0] }, |
5049 | | { nullptr, nullptr } |
5050 | | }; |
5051 | | |
5052 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
5053 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
5054 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
5055 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
5056 | | |
5057 | | |
5058 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
5059 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
5060 | | |
5061 | | static const NativePropertiesN<2> sNativeProperties = { |
5062 | | false, 0, |
5063 | | false, 0, |
5064 | | true, 0 /* sMethods */, |
5065 | | true, 1 /* sAttributes */, |
5066 | | false, 0, |
5067 | | false, 0, |
5068 | | false, 0, |
5069 | | -1, |
5070 | | 3, |
5071 | | sNativeProperties_sortedPropertyIndices, |
5072 | | { |
5073 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
5074 | | { sAttributes, &sNativeProperties_propertyInfos[1] } |
5075 | | } |
5076 | | }; |
5077 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
5078 | | "We have a property info count that is oversized"); |
5079 | | |
5080 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
5081 | | { |
5082 | | "Function", |
5083 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
5084 | | &sBoringInterfaceObjectClassClassOps, |
5085 | | JS_NULL_CLASS_SPEC, |
5086 | | JS_NULL_CLASS_EXT, |
5087 | | &sInterfaceObjectClassObjectOps |
5088 | | }, |
5089 | | eInterface, |
5090 | | true, |
5091 | | prototypes::id::MessageSender, |
5092 | | PrototypeTraits<prototypes::id::MessageSender>::Depth, |
5093 | | sNativePropertyHooks, |
5094 | | "function MessageSender() {\n [native code]\n}", |
5095 | | MessageListenerManager_Binding::GetConstructorObject |
5096 | | }; |
5097 | | |
5098 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
5099 | | { |
5100 | | "MessageSenderPrototype", |
5101 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
5102 | | JS_NULL_CLASS_OPS, |
5103 | | JS_NULL_CLASS_SPEC, |
5104 | | JS_NULL_CLASS_EXT, |
5105 | | JS_NULL_OBJECT_OPS |
5106 | | }, |
5107 | | eInterfacePrototype, |
5108 | | false, |
5109 | | prototypes::id::MessageSender, |
5110 | | PrototypeTraits<prototypes::id::MessageSender>::Depth, |
5111 | | sNativePropertyHooks, |
5112 | | "[object MessageSenderPrototype]", |
5113 | | MessageListenerManager_Binding::GetProtoObject |
5114 | | }; |
5115 | | |
5116 | | bool |
5117 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
5118 | 0 | { |
5119 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
5120 | 0 | } |
5121 | | |
5122 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
5123 | | nullptr, |
5124 | | nullptr, |
5125 | | nullptr, |
5126 | | { sNativeProperties.Upcast(), nullptr }, |
5127 | | prototypes::id::MessageSender, |
5128 | | constructors::id::MessageSender, |
5129 | | MessageListenerManager_Binding::sNativePropertyHooks, |
5130 | | &DefaultXrayExpandoObjectClass |
5131 | | } }; |
5132 | | |
5133 | | void |
5134 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
5135 | 0 | { |
5136 | 0 | JS::Handle<JSObject*> parentProto(MessageListenerManager_Binding::GetProtoObjectHandle(aCx)); |
5137 | 0 | if (!parentProto) { |
5138 | 0 | return; |
5139 | 0 | } |
5140 | 0 | |
5141 | 0 | JS::Handle<JSObject*> constructorProto(MessageListenerManager_Binding::GetConstructorObjectHandle(aCx)); |
5142 | 0 | if (!constructorProto) { |
5143 | 0 | return; |
5144 | 0 | } |
5145 | 0 | |
5146 | 0 | static bool sIdsInited = false; |
5147 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
5148 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
5149 | 0 | return; |
5150 | 0 | } |
5151 | 0 | sIdsInited = true; |
5152 | 0 | } |
5153 | 0 |
|
5154 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MessageSender); |
5155 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MessageSender); |
5156 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
5157 | 0 | &sPrototypeClass.mBase, protoCache, |
5158 | 0 | nullptr, |
5159 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
5160 | 0 | interfaceCache, |
5161 | 0 | sNativeProperties.Upcast(), |
5162 | 0 | nullptr, |
5163 | 0 | "MessageSender", aDefineOnGlobal, |
5164 | 0 | nullptr, |
5165 | 0 | false); |
5166 | 0 | } |
5167 | | |
5168 | | JSObject* |
5169 | | GetProtoObject(JSContext* aCx) |
5170 | 0 | { |
5171 | 0 | return GetProtoObjectHandle(aCx); |
5172 | 0 | } |
5173 | | |
5174 | | JSObject* |
5175 | | GetConstructorObject(JSContext* aCx) |
5176 | 0 | { |
5177 | 0 | return GetConstructorObjectHandle(aCx); |
5178 | 0 | } |
5179 | | |
5180 | | } // namespace MessageSender_Binding |
5181 | | |
5182 | | |
5183 | | |
5184 | | namespace ParentProcessMessageManager_Binding { |
5185 | | |
5186 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<MessageBroadcaster_Binding::NativeType>::value, |
5187 | | "Can't inherit from an interface with a different ownership model."); |
5188 | | |
5189 | | MOZ_CAN_RUN_SCRIPT static bool |
5190 | | get_initialProcessData(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ParentProcessMessageManager* self, JSJitGetterCallArgs args) |
5191 | 0 | { |
5192 | 0 | AUTO_PROFILER_LABEL_FAST("get ParentProcessMessageManager.initialProcessData", DOM, cx); |
5193 | 0 |
|
5194 | 0 | FastErrorResult rv; |
5195 | 0 | JS::Rooted<JS::Value> result(cx); |
5196 | 0 | self->GetInitialProcessData(cx, &result, rv); |
5197 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
5198 | 0 | return false; |
5199 | 0 | } |
5200 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
5201 | 0 | JS::ExposeValueToActiveJS(result); |
5202 | 0 | args.rval().set(result); |
5203 | 0 | if (!MaybeWrapValue(cx, args.rval())) { |
5204 | 0 | return false; |
5205 | 0 | } |
5206 | 0 | return true; |
5207 | 0 | } |
5208 | | |
5209 | | static const JSJitInfo initialProcessData_getterinfo = { |
5210 | | { (JSJitGetterOp)get_initialProcessData }, |
5211 | | { prototypes::id::ParentProcessMessageManager }, |
5212 | | { PrototypeTraits<prototypes::id::ParentProcessMessageManager>::Depth }, |
5213 | | JSJitInfo::Getter, |
5214 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
5215 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
5216 | | false, /* isInfallible. False in setters. */ |
5217 | | false, /* isMovable. Not relevant for setters. */ |
5218 | | false, /* isEliminatable. Not relevant for setters. */ |
5219 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
5220 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
5221 | | false, /* isTypedMethod. Only relevant for methods. */ |
5222 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
5223 | | }; |
5224 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
5225 | | static_assert(0 < 1, "There is no slot for us"); |
5226 | | |
5227 | | MOZ_CAN_RUN_SCRIPT static bool |
5228 | | get_sharedData(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ParentProcessMessageManager* self, JSJitGetterCallArgs args) |
5229 | 0 | { |
5230 | 0 | AUTO_PROFILER_LABEL_FAST("get ParentProcessMessageManager.sharedData", DOM, cx); |
5231 | 0 |
|
5232 | 0 | auto result(StrongOrRawPtr<mozilla::dom::ipc::WritableSharedMap>(self->SharedData())); |
5233 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
5234 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
5235 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
5236 | 0 | return false; |
5237 | 0 | } |
5238 | 0 | return true; |
5239 | 0 | } |
5240 | | |
5241 | | static const JSJitInfo sharedData_getterinfo = { |
5242 | | { (JSJitGetterOp)get_sharedData }, |
5243 | | { prototypes::id::ParentProcessMessageManager }, |
5244 | | { PrototypeTraits<prototypes::id::ParentProcessMessageManager>::Depth }, |
5245 | | JSJitInfo::Getter, |
5246 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
5247 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
5248 | | false, /* isInfallible. False in setters. */ |
5249 | | false, /* isMovable. Not relevant for setters. */ |
5250 | | false, /* isEliminatable. Not relevant for setters. */ |
5251 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
5252 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
5253 | | false, /* isTypedMethod. Only relevant for methods. */ |
5254 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
5255 | | }; |
5256 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
5257 | | static_assert(0 < 1, "There is no slot for us"); |
5258 | | |
5259 | | MOZ_CAN_RUN_SCRIPT static bool |
5260 | | loadProcessScript(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ParentProcessMessageManager* self, const JSJitMethodCallArgs& args) |
5261 | 0 | { |
5262 | 0 | AUTO_PROFILER_LABEL_FAST("ParentProcessMessageManager.loadProcessScript", DOM, cx); |
5263 | 0 |
|
5264 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
5265 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ParentProcessMessageManager.loadProcessScript"); |
5266 | 0 | } |
5267 | 0 | binding_detail::FakeString arg0; |
5268 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
5269 | 0 | return false; |
5270 | 0 | } |
5271 | 0 | bool arg1; |
5272 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, args[1], &arg1)) { |
5273 | 0 | return false; |
5274 | 0 | } |
5275 | 0 | FastErrorResult rv; |
5276 | 0 | self->LoadProcessScript(NonNullHelper(Constify(arg0)), arg1, rv); |
5277 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
5278 | 0 | return false; |
5279 | 0 | } |
5280 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
5281 | 0 | args.rval().setUndefined(); |
5282 | 0 | return true; |
5283 | 0 | } |
5284 | | |
5285 | | static const JSJitInfo loadProcessScript_methodinfo = { |
5286 | | { (JSJitGetterOp)loadProcessScript }, |
5287 | | { prototypes::id::ParentProcessMessageManager }, |
5288 | | { PrototypeTraits<prototypes::id::ParentProcessMessageManager>::Depth }, |
5289 | | JSJitInfo::Method, |
5290 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
5291 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
5292 | | false, /* isInfallible. False in setters. */ |
5293 | | false, /* isMovable. Not relevant for setters. */ |
5294 | | false, /* isEliminatable. Not relevant for setters. */ |
5295 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
5296 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
5297 | | false, /* isTypedMethod. Only relevant for methods. */ |
5298 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
5299 | | }; |
5300 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
5301 | | static_assert(0 < 1, "There is no slot for us"); |
5302 | | |
5303 | | MOZ_CAN_RUN_SCRIPT static bool |
5304 | | removeDelayedProcessScript(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ParentProcessMessageManager* self, const JSJitMethodCallArgs& args) |
5305 | 0 | { |
5306 | 0 | AUTO_PROFILER_LABEL_FAST("ParentProcessMessageManager.removeDelayedProcessScript", DOM, cx); |
5307 | 0 |
|
5308 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
5309 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ParentProcessMessageManager.removeDelayedProcessScript"); |
5310 | 0 | } |
5311 | 0 | binding_detail::FakeString arg0; |
5312 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
5313 | 0 | return false; |
5314 | 0 | } |
5315 | 0 | self->RemoveDelayedProcessScript(NonNullHelper(Constify(arg0))); |
5316 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
5317 | 0 | args.rval().setUndefined(); |
5318 | 0 | return true; |
5319 | 0 | } |
5320 | | |
5321 | | static const JSJitInfo removeDelayedProcessScript_methodinfo = { |
5322 | | { (JSJitGetterOp)removeDelayedProcessScript }, |
5323 | | { prototypes::id::ParentProcessMessageManager }, |
5324 | | { PrototypeTraits<prototypes::id::ParentProcessMessageManager>::Depth }, |
5325 | | JSJitInfo::Method, |
5326 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
5327 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
5328 | | false, /* isInfallible. False in setters. */ |
5329 | | false, /* isMovable. Not relevant for setters. */ |
5330 | | false, /* isEliminatable. Not relevant for setters. */ |
5331 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
5332 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
5333 | | false, /* isTypedMethod. Only relevant for methods. */ |
5334 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
5335 | | }; |
5336 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
5337 | | static_assert(0 < 1, "There is no slot for us"); |
5338 | | |
5339 | | MOZ_CAN_RUN_SCRIPT static bool |
5340 | | getDelayedProcessScripts(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ParentProcessMessageManager* self, const JSJitMethodCallArgs& args) |
5341 | 0 | { |
5342 | 0 | AUTO_PROFILER_LABEL_FAST("ParentProcessMessageManager.getDelayedProcessScripts", DOM, cx); |
5343 | 0 |
|
5344 | 0 | FastErrorResult rv; |
5345 | 0 | nsTArray<nsTArray<JS::Value>> result; |
5346 | 0 | SequenceRooter<nsTArray<JS::Value> > resultRooter(cx, &result); |
5347 | 0 | self->GetDelayedProcessScripts(cx, result, rv); |
5348 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
5349 | 0 | return false; |
5350 | 0 | } |
5351 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
5352 | 0 |
|
5353 | 0 | uint32_t length = result.Length(); |
5354 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
5355 | 0 | if (!returnArray) { |
5356 | 0 | return false; |
5357 | 0 | } |
5358 | 0 | // Scope for 'tmp' |
5359 | 0 | { |
5360 | 0 | JS::Rooted<JS::Value> tmp(cx); |
5361 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
5362 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
5363 | 0 | // are different ways to succeed at wrapping the object. |
5364 | 0 | do { |
5365 | 0 |
|
5366 | 0 | uint32_t length = result[sequenceIdx0].Length(); |
5367 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
5368 | 0 | if (!returnArray) { |
5369 | 0 | return false; |
5370 | 0 | } |
5371 | 0 | // Scope for 'tmp' |
5372 | 0 | { |
5373 | 0 | JS::Rooted<JS::Value> tmp(cx); |
5374 | 0 | for (uint32_t sequenceIdx1 = 0; sequenceIdx1 < length; ++sequenceIdx1) { |
5375 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
5376 | 0 | // are different ways to succeed at wrapping the object. |
5377 | 0 | do { |
5378 | 0 | JS::ExposeValueToActiveJS(result[sequenceIdx0][sequenceIdx1]); |
5379 | 0 | tmp.set(result[sequenceIdx0][sequenceIdx1]); |
5380 | 0 | if (!MaybeWrapValue(cx, &tmp)) { |
5381 | 0 | return false; |
5382 | 0 | } |
5383 | 0 | break; |
5384 | 0 | } while (false); |
5385 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx1, tmp, |
5386 | 0 | JSPROP_ENUMERATE)) { |
5387 | 0 | return false; |
5388 | 0 | } |
5389 | 0 | } |
5390 | 0 | } |
5391 | 0 | tmp.setObject(*returnArray); |
5392 | 0 | break; |
5393 | 0 | } while (false); |
5394 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
5395 | 0 | JSPROP_ENUMERATE)) { |
5396 | 0 | return false; |
5397 | 0 | } |
5398 | 0 | } |
5399 | 0 | } |
5400 | 0 | args.rval().setObject(*returnArray); |
5401 | 0 | return true; |
5402 | 0 | } |
5403 | | |
5404 | | static const JSJitInfo getDelayedProcessScripts_methodinfo = { |
5405 | | { (JSJitGetterOp)getDelayedProcessScripts }, |
5406 | | { prototypes::id::ParentProcessMessageManager }, |
5407 | | { PrototypeTraits<prototypes::id::ParentProcessMessageManager>::Depth }, |
5408 | | JSJitInfo::Method, |
5409 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
5410 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
5411 | | false, /* isInfallible. False in setters. */ |
5412 | | false, /* isMovable. Not relevant for setters. */ |
5413 | | false, /* isEliminatable. Not relevant for setters. */ |
5414 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
5415 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
5416 | | false, /* isTypedMethod. Only relevant for methods. */ |
5417 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
5418 | | }; |
5419 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
5420 | | static_assert(0 < 1, "There is no slot for us"); |
5421 | | |
5422 | | static bool |
5423 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
5424 | 0 | { |
5425 | 0 | mozilla::dom::ParentProcessMessageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ParentProcessMessageManager>(obj); |
5426 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
5427 | 0 | // obviously can't preserve if we're not initialized. |
5428 | 0 | if (self && self->GetWrapperPreserveColor()) { |
5429 | 0 | PreserveWrapper(self); |
5430 | 0 | } |
5431 | 0 | return true; |
5432 | 0 | } |
5433 | | |
5434 | | static void |
5435 | | _finalize(js::FreeOp* fop, JSObject* obj) |
5436 | 0 | { |
5437 | 0 | mozilla::dom::ParentProcessMessageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ParentProcessMessageManager>(obj); |
5438 | 0 | if (self) { |
5439 | 0 | ClearWrapper(self, self, obj); |
5440 | 0 | AddForDeferredFinalization<mozilla::dom::ParentProcessMessageManager>(self); |
5441 | 0 | } |
5442 | 0 | } |
5443 | | |
5444 | | static size_t |
5445 | | _objectMoved(JSObject* obj, JSObject* old) |
5446 | 0 | { |
5447 | 0 | mozilla::dom::ParentProcessMessageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ParentProcessMessageManager>(obj); |
5448 | 0 | if (self) { |
5449 | 0 | UpdateWrapper(self, self, obj, old); |
5450 | 0 | } |
5451 | 0 |
|
5452 | 0 | return 0; |
5453 | 0 | } |
5454 | | |
5455 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
5456 | | #if defined(__clang__) |
5457 | | #pragma clang diagnostic push |
5458 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
5459 | | #endif |
5460 | | static const JSFunctionSpec sMethods_specs[] = { |
5461 | | JS_FNSPEC("loadProcessScript", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&loadProcessScript_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
5462 | | JS_FNSPEC("removeDelayedProcessScript", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&removeDelayedProcessScript_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
5463 | | JS_FNSPEC("getDelayedProcessScripts", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getDelayedProcessScripts_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
5464 | | JS_FS_END |
5465 | | }; |
5466 | | #if defined(__clang__) |
5467 | | #pragma clang diagnostic pop |
5468 | | #endif |
5469 | | |
5470 | | |
5471 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
5472 | | { nullptr, &sMethods_specs[0] }, |
5473 | | { nullptr, nullptr } |
5474 | | }; |
5475 | | |
5476 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
5477 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
5478 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
5479 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
5480 | | |
5481 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
5482 | | #if defined(__clang__) |
5483 | | #pragma clang diagnostic push |
5484 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
5485 | | #endif |
5486 | | static const JSPropertySpec sAttributes_specs[] = { |
5487 | | { "initialProcessData", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &initialProcessData_getterinfo, nullptr, nullptr }, |
5488 | | { "sharedData", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &sharedData_getterinfo, nullptr, nullptr }, |
5489 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
5490 | | }; |
5491 | | #if defined(__clang__) |
5492 | | #pragma clang diagnostic pop |
5493 | | #endif |
5494 | | |
5495 | | |
5496 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
5497 | | { nullptr, &sAttributes_specs[0] }, |
5498 | | { nullptr, nullptr } |
5499 | | }; |
5500 | | |
5501 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
5502 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
5503 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
5504 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
5505 | | |
5506 | | |
5507 | | static uint16_t sNativeProperties_sortedPropertyIndices[5]; |
5508 | | static PropertyInfo sNativeProperties_propertyInfos[5]; |
5509 | | |
5510 | | static const NativePropertiesN<2> sNativeProperties = { |
5511 | | false, 0, |
5512 | | false, 0, |
5513 | | true, 0 /* sMethods */, |
5514 | | true, 1 /* sAttributes */, |
5515 | | false, 0, |
5516 | | false, 0, |
5517 | | false, 0, |
5518 | | -1, |
5519 | | 5, |
5520 | | sNativeProperties_sortedPropertyIndices, |
5521 | | { |
5522 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
5523 | | { sAttributes, &sNativeProperties_propertyInfos[3] } |
5524 | | } |
5525 | | }; |
5526 | | static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
5527 | | "We have a property info count that is oversized"); |
5528 | | |
5529 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
5530 | | { |
5531 | | "Function", |
5532 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
5533 | | &sBoringInterfaceObjectClassClassOps, |
5534 | | JS_NULL_CLASS_SPEC, |
5535 | | JS_NULL_CLASS_EXT, |
5536 | | &sInterfaceObjectClassObjectOps |
5537 | | }, |
5538 | | eInterface, |
5539 | | true, |
5540 | | prototypes::id::ParentProcessMessageManager, |
5541 | | PrototypeTraits<prototypes::id::ParentProcessMessageManager>::Depth, |
5542 | | sNativePropertyHooks, |
5543 | | "function ParentProcessMessageManager() {\n [native code]\n}", |
5544 | | MessageBroadcaster_Binding::GetConstructorObject |
5545 | | }; |
5546 | | |
5547 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
5548 | | { |
5549 | | "ParentProcessMessageManagerPrototype", |
5550 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
5551 | | JS_NULL_CLASS_OPS, |
5552 | | JS_NULL_CLASS_SPEC, |
5553 | | JS_NULL_CLASS_EXT, |
5554 | | JS_NULL_OBJECT_OPS |
5555 | | }, |
5556 | | eInterfacePrototype, |
5557 | | false, |
5558 | | prototypes::id::ParentProcessMessageManager, |
5559 | | PrototypeTraits<prototypes::id::ParentProcessMessageManager>::Depth, |
5560 | | sNativePropertyHooks, |
5561 | | "[object ParentProcessMessageManagerPrototype]", |
5562 | | MessageBroadcaster_Binding::GetProtoObject |
5563 | | }; |
5564 | | |
5565 | | bool |
5566 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
5567 | 0 | { |
5568 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
5569 | 0 | } |
5570 | | |
5571 | | static const js::ClassOps sClassOps = { |
5572 | | _addProperty, /* addProperty */ |
5573 | | nullptr, /* delProperty */ |
5574 | | nullptr, /* enumerate */ |
5575 | | nullptr, /* newEnumerate */ |
5576 | | nullptr, /* resolve */ |
5577 | | nullptr, /* mayResolve */ |
5578 | | _finalize, /* finalize */ |
5579 | | nullptr, /* call */ |
5580 | | nullptr, /* hasInstance */ |
5581 | | nullptr, /* construct */ |
5582 | | nullptr, /* trace */ |
5583 | | }; |
5584 | | |
5585 | | static const js::ClassExtension sClassExtension = { |
5586 | | nullptr, /* weakmapKeyDelegateOp */ |
5587 | | _objectMoved /* objectMovedOp */ |
5588 | | }; |
5589 | | |
5590 | | static const DOMJSClass sClass = { |
5591 | | { "ParentProcessMessageManager", |
5592 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
5593 | | &sClassOps, |
5594 | | JS_NULL_CLASS_SPEC, |
5595 | | &sClassExtension, |
5596 | | JS_NULL_OBJECT_OPS |
5597 | | }, |
5598 | | { prototypes::id::MessageListenerManager, prototypes::id::MessageBroadcaster, prototypes::id::ParentProcessMessageManager, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
5599 | | IsBaseOf<nsISupports, mozilla::dom::ParentProcessMessageManager >::value, |
5600 | | sNativePropertyHooks, |
5601 | | FindAssociatedGlobalForNative<mozilla::dom::ParentProcessMessageManager>::Get, |
5602 | | GetProtoObjectHandle, |
5603 | | GetCCParticipant<mozilla::dom::ParentProcessMessageManager>::Get() |
5604 | | }; |
5605 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
5606 | | "Must have the right minimal number of reserved slots."); |
5607 | | static_assert(1 >= 1, |
5608 | | "Must have enough reserved slots."); |
5609 | | |
5610 | | const JSClass* |
5611 | | GetJSClass() |
5612 | 0 | { |
5613 | 0 | return sClass.ToJSClass(); |
5614 | 0 | } |
5615 | | |
5616 | | bool |
5617 | | Wrap(JSContext* aCx, mozilla::dom::ParentProcessMessageManager* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
5618 | 0 | { |
5619 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::ParentProcessMessageManager>::value, |
5620 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
5621 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::ParentProcessMessageManager*>(aObject) == |
5622 | 0 | reinterpret_cast<mozilla::dom::ParentProcessMessageManager*>(aObject), |
5623 | 0 | "Multiple inheritance for mozilla::dom::ParentProcessMessageManager is broken."); |
5624 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::MessageBroadcaster*>(aObject) == |
5625 | 0 | reinterpret_cast<mozilla::dom::MessageBroadcaster*>(aObject), |
5626 | 0 | "Multiple inheritance for mozilla::dom::MessageBroadcaster is broken."); |
5627 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::MessageListenerManager*>(aObject) == |
5628 | 0 | reinterpret_cast<mozilla::dom::MessageListenerManager*>(aObject), |
5629 | 0 | "Multiple inheritance for mozilla::dom::MessageListenerManager is broken."); |
5630 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
5631 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
5632 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
5633 | 0 | "You should probably not be using Wrap() directly; use " |
5634 | 0 | "GetOrCreateDOMReflector instead"); |
5635 | 0 |
|
5636 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
5637 | 0 | "nsISupports must be on our primary inheritance chain"); |
5638 | 0 |
|
5639 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
5640 | 0 | if (!global) { |
5641 | 0 | return false; |
5642 | 0 | } |
5643 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
5644 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
5645 | 0 |
|
5646 | 0 | // That might have ended up wrapping us already, due to the wonders |
5647 | 0 | // of XBL. Check for that, and bail out as needed. |
5648 | 0 | aReflector.set(aCache->GetWrapper()); |
5649 | 0 | if (aReflector) { |
5650 | | #ifdef DEBUG |
5651 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
5652 | | #endif // DEBUG |
5653 | | return true; |
5654 | 0 | } |
5655 | 0 |
|
5656 | 0 | JSAutoRealm ar(aCx, global); |
5657 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
5658 | 0 | if (!canonicalProto) { |
5659 | 0 | return false; |
5660 | 0 | } |
5661 | 0 | JS::Rooted<JSObject*> proto(aCx); |
5662 | 0 | if (aGivenProto) { |
5663 | 0 | proto = aGivenProto; |
5664 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
5665 | 0 | // coming in, we changed compartments to that of "parent" so may need |
5666 | 0 | // to wrap the proto here. |
5667 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
5668 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
5669 | 0 | return false; |
5670 | 0 | } |
5671 | 0 | } |
5672 | 0 | } else { |
5673 | 0 | proto = canonicalProto; |
5674 | 0 | } |
5675 | 0 |
|
5676 | 0 | BindingJSObjectCreator<mozilla::dom::ParentProcessMessageManager> creator(aCx); |
5677 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
5678 | 0 | if (!aReflector) { |
5679 | 0 | return false; |
5680 | 0 | } |
5681 | 0 | |
5682 | 0 | aCache->SetWrapper(aReflector); |
5683 | 0 | creator.InitializationSucceeded(); |
5684 | 0 |
|
5685 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
5686 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
5687 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
5688 | 0 | // otherwise we won't be able to properly recreate it later, since |
5689 | 0 | // we won't know what proto to use. Note that we don't check |
5690 | 0 | // aGivenProto here, since it's entirely possible (and even |
5691 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
5692 | 0 | // same as canonicalProto. |
5693 | 0 | if (proto != canonicalProto) { |
5694 | 0 | PreserveWrapper(aObject); |
5695 | 0 | } |
5696 | 0 |
|
5697 | 0 | return true; |
5698 | 0 | } |
5699 | | |
5700 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
5701 | | nullptr, |
5702 | | nullptr, |
5703 | | nullptr, |
5704 | | { sNativeProperties.Upcast(), nullptr }, |
5705 | | prototypes::id::ParentProcessMessageManager, |
5706 | | constructors::id::ParentProcessMessageManager, |
5707 | | MessageBroadcaster_Binding::sNativePropertyHooks, |
5708 | | &DefaultXrayExpandoObjectClass |
5709 | | } }; |
5710 | | |
5711 | | void |
5712 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
5713 | 0 | { |
5714 | 0 | JS::Handle<JSObject*> parentProto(MessageBroadcaster_Binding::GetProtoObjectHandle(aCx)); |
5715 | 0 | if (!parentProto) { |
5716 | 0 | return; |
5717 | 0 | } |
5718 | 0 | |
5719 | 0 | JS::Handle<JSObject*> constructorProto(MessageBroadcaster_Binding::GetConstructorObjectHandle(aCx)); |
5720 | 0 | if (!constructorProto) { |
5721 | 0 | return; |
5722 | 0 | } |
5723 | 0 | |
5724 | 0 | static bool sIdsInited = false; |
5725 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
5726 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
5727 | 0 | return; |
5728 | 0 | } |
5729 | 0 | sIdsInited = true; |
5730 | 0 | } |
5731 | 0 |
|
5732 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ParentProcessMessageManager); |
5733 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ParentProcessMessageManager); |
5734 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
5735 | 0 | &sPrototypeClass.mBase, protoCache, |
5736 | 0 | nullptr, |
5737 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
5738 | 0 | interfaceCache, |
5739 | 0 | sNativeProperties.Upcast(), |
5740 | 0 | nullptr, |
5741 | 0 | "ParentProcessMessageManager", aDefineOnGlobal, |
5742 | 0 | nullptr, |
5743 | 0 | false); |
5744 | 0 | } |
5745 | | |
5746 | | JSObject* |
5747 | | GetConstructorObject(JSContext* aCx) |
5748 | 0 | { |
5749 | 0 | return GetConstructorObjectHandle(aCx); |
5750 | 0 | } |
5751 | | |
5752 | | } // namespace ParentProcessMessageManager_Binding |
5753 | | |
5754 | | |
5755 | | |
5756 | | namespace ProcessMessageManager_Binding { |
5757 | | |
5758 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<MessageSender_Binding::NativeType>::value, |
5759 | | "Can't inherit from an interface with a different ownership model."); |
5760 | | |
5761 | | MOZ_CAN_RUN_SCRIPT static bool |
5762 | | loadProcessScript(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ProcessMessageManager* self, const JSJitMethodCallArgs& args) |
5763 | 0 | { |
5764 | 0 | AUTO_PROFILER_LABEL_FAST("ProcessMessageManager.loadProcessScript", DOM, cx); |
5765 | 0 |
|
5766 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
5767 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ProcessMessageManager.loadProcessScript"); |
5768 | 0 | } |
5769 | 0 | binding_detail::FakeString arg0; |
5770 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
5771 | 0 | return false; |
5772 | 0 | } |
5773 | 0 | bool arg1; |
5774 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, args[1], &arg1)) { |
5775 | 0 | return false; |
5776 | 0 | } |
5777 | 0 | FastErrorResult rv; |
5778 | 0 | self->LoadProcessScript(NonNullHelper(Constify(arg0)), arg1, rv); |
5779 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
5780 | 0 | return false; |
5781 | 0 | } |
5782 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
5783 | 0 | args.rval().setUndefined(); |
5784 | 0 | return true; |
5785 | 0 | } |
5786 | | |
5787 | | static const JSJitInfo loadProcessScript_methodinfo = { |
5788 | | { (JSJitGetterOp)loadProcessScript }, |
5789 | | { prototypes::id::ProcessMessageManager }, |
5790 | | { PrototypeTraits<prototypes::id::ProcessMessageManager>::Depth }, |
5791 | | JSJitInfo::Method, |
5792 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
5793 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
5794 | | false, /* isInfallible. False in setters. */ |
5795 | | false, /* isMovable. Not relevant for setters. */ |
5796 | | false, /* isEliminatable. Not relevant for setters. */ |
5797 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
5798 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
5799 | | false, /* isTypedMethod. Only relevant for methods. */ |
5800 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
5801 | | }; |
5802 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
5803 | | static_assert(0 < 1, "There is no slot for us"); |
5804 | | |
5805 | | MOZ_CAN_RUN_SCRIPT static bool |
5806 | | removeDelayedProcessScript(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ProcessMessageManager* self, const JSJitMethodCallArgs& args) |
5807 | 0 | { |
5808 | 0 | AUTO_PROFILER_LABEL_FAST("ProcessMessageManager.removeDelayedProcessScript", DOM, cx); |
5809 | 0 |
|
5810 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
5811 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ProcessMessageManager.removeDelayedProcessScript"); |
5812 | 0 | } |
5813 | 0 | binding_detail::FakeString arg0; |
5814 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
5815 | 0 | return false; |
5816 | 0 | } |
5817 | 0 | self->RemoveDelayedProcessScript(NonNullHelper(Constify(arg0))); |
5818 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
5819 | 0 | args.rval().setUndefined(); |
5820 | 0 | return true; |
5821 | 0 | } |
5822 | | |
5823 | | static const JSJitInfo removeDelayedProcessScript_methodinfo = { |
5824 | | { (JSJitGetterOp)removeDelayedProcessScript }, |
5825 | | { prototypes::id::ProcessMessageManager }, |
5826 | | { PrototypeTraits<prototypes::id::ProcessMessageManager>::Depth }, |
5827 | | JSJitInfo::Method, |
5828 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
5829 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
5830 | | false, /* isInfallible. False in setters. */ |
5831 | | false, /* isMovable. Not relevant for setters. */ |
5832 | | false, /* isEliminatable. Not relevant for setters. */ |
5833 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
5834 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
5835 | | false, /* isTypedMethod. Only relevant for methods. */ |
5836 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
5837 | | }; |
5838 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
5839 | | static_assert(0 < 1, "There is no slot for us"); |
5840 | | |
5841 | | MOZ_CAN_RUN_SCRIPT static bool |
5842 | | getDelayedProcessScripts(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ProcessMessageManager* self, const JSJitMethodCallArgs& args) |
5843 | 0 | { |
5844 | 0 | AUTO_PROFILER_LABEL_FAST("ProcessMessageManager.getDelayedProcessScripts", DOM, cx); |
5845 | 0 |
|
5846 | 0 | FastErrorResult rv; |
5847 | 0 | nsTArray<nsTArray<JS::Value>> result; |
5848 | 0 | SequenceRooter<nsTArray<JS::Value> > resultRooter(cx, &result); |
5849 | 0 | self->GetDelayedProcessScripts(cx, result, rv); |
5850 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
5851 | 0 | return false; |
5852 | 0 | } |
5853 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
5854 | 0 |
|
5855 | 0 | uint32_t length = result.Length(); |
5856 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
5857 | 0 | if (!returnArray) { |
5858 | 0 | return false; |
5859 | 0 | } |
5860 | 0 | // Scope for 'tmp' |
5861 | 0 | { |
5862 | 0 | JS::Rooted<JS::Value> tmp(cx); |
5863 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
5864 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
5865 | 0 | // are different ways to succeed at wrapping the object. |
5866 | 0 | do { |
5867 | 0 |
|
5868 | 0 | uint32_t length = result[sequenceIdx0].Length(); |
5869 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
5870 | 0 | if (!returnArray) { |
5871 | 0 | return false; |
5872 | 0 | } |
5873 | 0 | // Scope for 'tmp' |
5874 | 0 | { |
5875 | 0 | JS::Rooted<JS::Value> tmp(cx); |
5876 | 0 | for (uint32_t sequenceIdx1 = 0; sequenceIdx1 < length; ++sequenceIdx1) { |
5877 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
5878 | 0 | // are different ways to succeed at wrapping the object. |
5879 | 0 | do { |
5880 | 0 | JS::ExposeValueToActiveJS(result[sequenceIdx0][sequenceIdx1]); |
5881 | 0 | tmp.set(result[sequenceIdx0][sequenceIdx1]); |
5882 | 0 | if (!MaybeWrapValue(cx, &tmp)) { |
5883 | 0 | return false; |
5884 | 0 | } |
5885 | 0 | break; |
5886 | 0 | } while (false); |
5887 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx1, tmp, |
5888 | 0 | JSPROP_ENUMERATE)) { |
5889 | 0 | return false; |
5890 | 0 | } |
5891 | 0 | } |
5892 | 0 | } |
5893 | 0 | tmp.setObject(*returnArray); |
5894 | 0 | break; |
5895 | 0 | } while (false); |
5896 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
5897 | 0 | JSPROP_ENUMERATE)) { |
5898 | 0 | return false; |
5899 | 0 | } |
5900 | 0 | } |
5901 | 0 | } |
5902 | 0 | args.rval().setObject(*returnArray); |
5903 | 0 | return true; |
5904 | 0 | } |
5905 | | |
5906 | | static const JSJitInfo getDelayedProcessScripts_methodinfo = { |
5907 | | { (JSJitGetterOp)getDelayedProcessScripts }, |
5908 | | { prototypes::id::ProcessMessageManager }, |
5909 | | { PrototypeTraits<prototypes::id::ProcessMessageManager>::Depth }, |
5910 | | JSJitInfo::Method, |
5911 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
5912 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
5913 | | false, /* isInfallible. False in setters. */ |
5914 | | false, /* isMovable. Not relevant for setters. */ |
5915 | | false, /* isEliminatable. Not relevant for setters. */ |
5916 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
5917 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
5918 | | false, /* isTypedMethod. Only relevant for methods. */ |
5919 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
5920 | | }; |
5921 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
5922 | | static_assert(0 < 1, "There is no slot for us"); |
5923 | | |
5924 | | static bool |
5925 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
5926 | 0 | { |
5927 | 0 | mozilla::dom::ProcessMessageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ProcessMessageManager>(obj); |
5928 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
5929 | 0 | // obviously can't preserve if we're not initialized. |
5930 | 0 | if (self && self->GetWrapperPreserveColor()) { |
5931 | 0 | PreserveWrapper(self); |
5932 | 0 | } |
5933 | 0 | return true; |
5934 | 0 | } |
5935 | | |
5936 | | static void |
5937 | | _finalize(js::FreeOp* fop, JSObject* obj) |
5938 | 0 | { |
5939 | 0 | mozilla::dom::ProcessMessageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ProcessMessageManager>(obj); |
5940 | 0 | if (self) { |
5941 | 0 | ClearWrapper(self, self, obj); |
5942 | 0 | AddForDeferredFinalization<mozilla::dom::ProcessMessageManager>(self); |
5943 | 0 | } |
5944 | 0 | } |
5945 | | |
5946 | | static size_t |
5947 | | _objectMoved(JSObject* obj, JSObject* old) |
5948 | 0 | { |
5949 | 0 | mozilla::dom::ProcessMessageManager* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ProcessMessageManager>(obj); |
5950 | 0 | if (self) { |
5951 | 0 | UpdateWrapper(self, self, obj, old); |
5952 | 0 | } |
5953 | 0 |
|
5954 | 0 | return 0; |
5955 | 0 | } |
5956 | | |
5957 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
5958 | | #if defined(__clang__) |
5959 | | #pragma clang diagnostic push |
5960 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
5961 | | #endif |
5962 | | static const JSFunctionSpec sMethods_specs[] = { |
5963 | | JS_FNSPEC("loadProcessScript", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&loadProcessScript_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
5964 | | JS_FNSPEC("removeDelayedProcessScript", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&removeDelayedProcessScript_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
5965 | | JS_FNSPEC("getDelayedProcessScripts", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getDelayedProcessScripts_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
5966 | | JS_FS_END |
5967 | | }; |
5968 | | #if defined(__clang__) |
5969 | | #pragma clang diagnostic pop |
5970 | | #endif |
5971 | | |
5972 | | |
5973 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
5974 | | { nullptr, &sMethods_specs[0] }, |
5975 | | { nullptr, nullptr } |
5976 | | }; |
5977 | | |
5978 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
5979 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
5980 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
5981 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
5982 | | |
5983 | | |
5984 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
5985 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
5986 | | |
5987 | | static const NativePropertiesN<1> sNativeProperties = { |
5988 | | false, 0, |
5989 | | false, 0, |
5990 | | true, 0 /* sMethods */, |
5991 | | false, 0, |
5992 | | false, 0, |
5993 | | false, 0, |
5994 | | false, 0, |
5995 | | -1, |
5996 | | 3, |
5997 | | sNativeProperties_sortedPropertyIndices, |
5998 | | { |
5999 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
6000 | | } |
6001 | | }; |
6002 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
6003 | | "We have a property info count that is oversized"); |
6004 | | |
6005 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
6006 | | { |
6007 | | "Function", |
6008 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
6009 | | &sBoringInterfaceObjectClassClassOps, |
6010 | | JS_NULL_CLASS_SPEC, |
6011 | | JS_NULL_CLASS_EXT, |
6012 | | &sInterfaceObjectClassObjectOps |
6013 | | }, |
6014 | | eInterface, |
6015 | | true, |
6016 | | prototypes::id::ProcessMessageManager, |
6017 | | PrototypeTraits<prototypes::id::ProcessMessageManager>::Depth, |
6018 | | sNativePropertyHooks, |
6019 | | "function ProcessMessageManager() {\n [native code]\n}", |
6020 | | MessageSender_Binding::GetConstructorObject |
6021 | | }; |
6022 | | |
6023 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
6024 | | { |
6025 | | "ProcessMessageManagerPrototype", |
6026 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
6027 | | JS_NULL_CLASS_OPS, |
6028 | | JS_NULL_CLASS_SPEC, |
6029 | | JS_NULL_CLASS_EXT, |
6030 | | JS_NULL_OBJECT_OPS |
6031 | | }, |
6032 | | eInterfacePrototype, |
6033 | | false, |
6034 | | prototypes::id::ProcessMessageManager, |
6035 | | PrototypeTraits<prototypes::id::ProcessMessageManager>::Depth, |
6036 | | sNativePropertyHooks, |
6037 | | "[object ProcessMessageManagerPrototype]", |
6038 | | MessageSender_Binding::GetProtoObject |
6039 | | }; |
6040 | | |
6041 | | bool |
6042 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
6043 | 0 | { |
6044 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
6045 | 0 | } |
6046 | | |
6047 | | static const js::ClassOps sClassOps = { |
6048 | | _addProperty, /* addProperty */ |
6049 | | nullptr, /* delProperty */ |
6050 | | nullptr, /* enumerate */ |
6051 | | nullptr, /* newEnumerate */ |
6052 | | nullptr, /* resolve */ |
6053 | | nullptr, /* mayResolve */ |
6054 | | _finalize, /* finalize */ |
6055 | | nullptr, /* call */ |
6056 | | nullptr, /* hasInstance */ |
6057 | | nullptr, /* construct */ |
6058 | | nullptr, /* trace */ |
6059 | | }; |
6060 | | |
6061 | | static const js::ClassExtension sClassExtension = { |
6062 | | nullptr, /* weakmapKeyDelegateOp */ |
6063 | | _objectMoved /* objectMovedOp */ |
6064 | | }; |
6065 | | |
6066 | | static const DOMJSClass sClass = { |
6067 | | { "ProcessMessageManager", |
6068 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
6069 | | &sClassOps, |
6070 | | JS_NULL_CLASS_SPEC, |
6071 | | &sClassExtension, |
6072 | | JS_NULL_OBJECT_OPS |
6073 | | }, |
6074 | | { prototypes::id::MessageListenerManager, prototypes::id::MessageSender, prototypes::id::ProcessMessageManager, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
6075 | | IsBaseOf<nsISupports, mozilla::dom::ProcessMessageManager >::value, |
6076 | | sNativePropertyHooks, |
6077 | | FindAssociatedGlobalForNative<mozilla::dom::ProcessMessageManager>::Get, |
6078 | | GetProtoObjectHandle, |
6079 | | GetCCParticipant<mozilla::dom::ProcessMessageManager>::Get() |
6080 | | }; |
6081 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
6082 | | "Must have the right minimal number of reserved slots."); |
6083 | | static_assert(1 >= 1, |
6084 | | "Must have enough reserved slots."); |
6085 | | |
6086 | | const JSClass* |
6087 | | GetJSClass() |
6088 | 0 | { |
6089 | 0 | return sClass.ToJSClass(); |
6090 | 0 | } |
6091 | | |
6092 | | bool |
6093 | | Wrap(JSContext* aCx, mozilla::dom::ProcessMessageManager* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
6094 | 0 | { |
6095 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::ProcessMessageManager>::value, |
6096 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
6097 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::ProcessMessageManager*>(aObject) == |
6098 | 0 | reinterpret_cast<mozilla::dom::ProcessMessageManager*>(aObject), |
6099 | 0 | "Multiple inheritance for mozilla::dom::ProcessMessageManager is broken."); |
6100 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::MessageSender*>(aObject) == |
6101 | 0 | reinterpret_cast<mozilla::dom::MessageSender*>(aObject), |
6102 | 0 | "Multiple inheritance for mozilla::dom::MessageSender is broken."); |
6103 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::MessageListenerManager*>(aObject) == |
6104 | 0 | reinterpret_cast<mozilla::dom::MessageListenerManager*>(aObject), |
6105 | 0 | "Multiple inheritance for mozilla::dom::MessageListenerManager is broken."); |
6106 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
6107 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
6108 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
6109 | 0 | "You should probably not be using Wrap() directly; use " |
6110 | 0 | "GetOrCreateDOMReflector instead"); |
6111 | 0 |
|
6112 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
6113 | 0 | "nsISupports must be on our primary inheritance chain"); |
6114 | 0 |
|
6115 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
6116 | 0 | if (!global) { |
6117 | 0 | return false; |
6118 | 0 | } |
6119 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
6120 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
6121 | 0 |
|
6122 | 0 | // That might have ended up wrapping us already, due to the wonders |
6123 | 0 | // of XBL. Check for that, and bail out as needed. |
6124 | 0 | aReflector.set(aCache->GetWrapper()); |
6125 | 0 | if (aReflector) { |
6126 | | #ifdef DEBUG |
6127 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
6128 | | #endif // DEBUG |
6129 | | return true; |
6130 | 0 | } |
6131 | 0 |
|
6132 | 0 | JSAutoRealm ar(aCx, global); |
6133 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
6134 | 0 | if (!canonicalProto) { |
6135 | 0 | return false; |
6136 | 0 | } |
6137 | 0 | JS::Rooted<JSObject*> proto(aCx); |
6138 | 0 | if (aGivenProto) { |
6139 | 0 | proto = aGivenProto; |
6140 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
6141 | 0 | // coming in, we changed compartments to that of "parent" so may need |
6142 | 0 | // to wrap the proto here. |
6143 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
6144 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
6145 | 0 | return false; |
6146 | 0 | } |
6147 | 0 | } |
6148 | 0 | } else { |
6149 | 0 | proto = canonicalProto; |
6150 | 0 | } |
6151 | 0 |
|
6152 | 0 | BindingJSObjectCreator<mozilla::dom::ProcessMessageManager> creator(aCx); |
6153 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
6154 | 0 | if (!aReflector) { |
6155 | 0 | return false; |
6156 | 0 | } |
6157 | 0 | |
6158 | 0 | aCache->SetWrapper(aReflector); |
6159 | 0 | creator.InitializationSucceeded(); |
6160 | 0 |
|
6161 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
6162 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
6163 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
6164 | 0 | // otherwise we won't be able to properly recreate it later, since |
6165 | 0 | // we won't know what proto to use. Note that we don't check |
6166 | 0 | // aGivenProto here, since it's entirely possible (and even |
6167 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
6168 | 0 | // same as canonicalProto. |
6169 | 0 | if (proto != canonicalProto) { |
6170 | 0 | PreserveWrapper(aObject); |
6171 | 0 | } |
6172 | 0 |
|
6173 | 0 | return true; |
6174 | 0 | } |
6175 | | |
6176 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
6177 | | nullptr, |
6178 | | nullptr, |
6179 | | nullptr, |
6180 | | { sNativeProperties.Upcast(), nullptr }, |
6181 | | prototypes::id::ProcessMessageManager, |
6182 | | constructors::id::ProcessMessageManager, |
6183 | | MessageSender_Binding::sNativePropertyHooks, |
6184 | | &DefaultXrayExpandoObjectClass |
6185 | | } }; |
6186 | | |
6187 | | void |
6188 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
6189 | 0 | { |
6190 | 0 | JS::Handle<JSObject*> parentProto(MessageSender_Binding::GetProtoObjectHandle(aCx)); |
6191 | 0 | if (!parentProto) { |
6192 | 0 | return; |
6193 | 0 | } |
6194 | 0 | |
6195 | 0 | JS::Handle<JSObject*> constructorProto(MessageSender_Binding::GetConstructorObjectHandle(aCx)); |
6196 | 0 | if (!constructorProto) { |
6197 | 0 | return; |
6198 | 0 | } |
6199 | 0 | |
6200 | 0 | static bool sIdsInited = false; |
6201 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
6202 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
6203 | 0 | return; |
6204 | 0 | } |
6205 | 0 | sIdsInited = true; |
6206 | 0 | } |
6207 | 0 |
|
6208 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ProcessMessageManager); |
6209 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ProcessMessageManager); |
6210 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
6211 | 0 | &sPrototypeClass.mBase, protoCache, |
6212 | 0 | nullptr, |
6213 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
6214 | 0 | interfaceCache, |
6215 | 0 | sNativeProperties.Upcast(), |
6216 | 0 | nullptr, |
6217 | 0 | "ProcessMessageManager", aDefineOnGlobal, |
6218 | 0 | nullptr, |
6219 | 0 | false); |
6220 | 0 | } |
6221 | | |
6222 | | JSObject* |
6223 | | GetConstructorObject(JSContext* aCx) |
6224 | 0 | { |
6225 | 0 | return GetConstructorObjectHandle(aCx); |
6226 | 0 | } |
6227 | | |
6228 | | } // namespace ProcessMessageManager_Binding |
6229 | | |
6230 | | |
6231 | | |
6232 | | namespace SyncMessageSender_Binding { |
6233 | | |
6234 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<MessageSender_Binding::NativeType>::value, |
6235 | | "Can't inherit from an interface with a different ownership model."); |
6236 | | |
6237 | | MOZ_CAN_RUN_SCRIPT static bool |
6238 | | sendSyncMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SyncMessageSender* self, const JSJitMethodCallArgs& args) |
6239 | 0 | { |
6240 | 0 | AUTO_PROFILER_LABEL_FAST("SyncMessageSender.sendSyncMessage", DOM, cx); |
6241 | 0 |
|
6242 | 0 | binding_detail::FakeString arg0; |
6243 | 0 | if (args.hasDefined(0)) { |
6244 | 0 | if (!ConvertJSValueToString(cx, args[0], eNull, eNull, arg0)) { |
6245 | 0 | return false; |
6246 | 0 | } |
6247 | 0 | } else { |
6248 | 0 | arg0.SetIsVoid(true); |
6249 | 0 | } |
6250 | 0 | JS::Rooted<JS::Value> arg1(cx); |
6251 | 0 | if (args.hasDefined(1)) { |
6252 | 0 | arg1 = args[1]; |
6253 | 0 | } else { |
6254 | 0 | arg1 = JS::UndefinedValue(); |
6255 | 0 | } |
6256 | 0 | JS::Rooted<JSObject*> arg2(cx); |
6257 | 0 | if (args.hasDefined(2)) { |
6258 | 0 | if (args[2].isObject()) { |
6259 | 0 | arg2 = &args[2].toObject(); |
6260 | 0 | } else if (args[2].isNullOrUndefined()) { |
6261 | 0 | arg2 = nullptr; |
6262 | 0 | } else { |
6263 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of SyncMessageSender.sendSyncMessage"); |
6264 | 0 | return false; |
6265 | 0 | } |
6266 | 0 | } else { |
6267 | 0 | arg2 = nullptr; |
6268 | 0 | } |
6269 | 0 | nsIPrincipal* arg3; |
6270 | 0 | RefPtr<nsIPrincipal> arg3_holder; |
6271 | 0 | if (args.hasDefined(3)) { |
6272 | 0 | if (args[3].isObject()) { |
6273 | 0 | JS::Rooted<JSObject*> source(cx, &args[3].toObject()); |
6274 | 0 | if (NS_FAILED(UnwrapArg<nsIPrincipal>(cx, source, getter_AddRefs(arg3_holder)))) { |
6275 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 4 of SyncMessageSender.sendSyncMessage", "Principal"); |
6276 | 0 | return false; |
6277 | 0 | } |
6278 | 0 | MOZ_ASSERT(arg3_holder); |
6279 | 0 | arg3 = arg3_holder; |
6280 | 0 | } else if (args[3].isNullOrUndefined()) { |
6281 | 0 | arg3 = nullptr; |
6282 | 0 | } else { |
6283 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 4 of SyncMessageSender.sendSyncMessage"); |
6284 | 0 | return false; |
6285 | 0 | } |
6286 | 0 | } else { |
6287 | 0 | arg3 = nullptr; |
6288 | 0 | } |
6289 | 0 | FastErrorResult rv; |
6290 | 0 | nsTArray<JS::Value> result; |
6291 | 0 | SequenceRooter<JS::Value > resultRooter(cx, &result); |
6292 | 0 | self->SendSyncMessage(cx, NonNullHelper(Constify(arg0)), arg1, arg2, MOZ_KnownLive(Constify(arg3)), result, rv); |
6293 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
6294 | 0 | return false; |
6295 | 0 | } |
6296 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
6297 | 0 |
|
6298 | 0 | uint32_t length = result.Length(); |
6299 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
6300 | 0 | if (!returnArray) { |
6301 | 0 | return false; |
6302 | 0 | } |
6303 | 0 | // Scope for 'tmp' |
6304 | 0 | { |
6305 | 0 | JS::Rooted<JS::Value> tmp(cx); |
6306 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
6307 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
6308 | 0 | // are different ways to succeed at wrapping the object. |
6309 | 0 | do { |
6310 | 0 | JS::ExposeValueToActiveJS(result[sequenceIdx0]); |
6311 | 0 | tmp.set(result[sequenceIdx0]); |
6312 | 0 | if (!MaybeWrapValue(cx, &tmp)) { |
6313 | 0 | return false; |
6314 | 0 | } |
6315 | 0 | break; |
6316 | 0 | } while (false); |
6317 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
6318 | 0 | JSPROP_ENUMERATE)) { |
6319 | 0 | return false; |
6320 | 0 | } |
6321 | 0 | } |
6322 | 0 | } |
6323 | 0 | args.rval().setObject(*returnArray); |
6324 | 0 | return true; |
6325 | 0 | } |
6326 | | |
6327 | | static const JSJitInfo sendSyncMessage_methodinfo = { |
6328 | | { (JSJitGetterOp)sendSyncMessage }, |
6329 | | { prototypes::id::SyncMessageSender }, |
6330 | | { PrototypeTraits<prototypes::id::SyncMessageSender>::Depth }, |
6331 | | JSJitInfo::Method, |
6332 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
6333 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
6334 | | false, /* isInfallible. False in setters. */ |
6335 | | false, /* isMovable. Not relevant for setters. */ |
6336 | | false, /* isEliminatable. Not relevant for setters. */ |
6337 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
6338 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
6339 | | false, /* isTypedMethod. Only relevant for methods. */ |
6340 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
6341 | | }; |
6342 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
6343 | | static_assert(0 < 1, "There is no slot for us"); |
6344 | | |
6345 | | MOZ_CAN_RUN_SCRIPT static bool |
6346 | | sendRpcMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SyncMessageSender* self, const JSJitMethodCallArgs& args) |
6347 | 0 | { |
6348 | 0 | AUTO_PROFILER_LABEL_FAST("SyncMessageSender.sendRpcMessage", DOM, cx); |
6349 | 0 |
|
6350 | 0 | binding_detail::FakeString arg0; |
6351 | 0 | if (args.hasDefined(0)) { |
6352 | 0 | if (!ConvertJSValueToString(cx, args[0], eNull, eNull, arg0)) { |
6353 | 0 | return false; |
6354 | 0 | } |
6355 | 0 | } else { |
6356 | 0 | arg0.SetIsVoid(true); |
6357 | 0 | } |
6358 | 0 | JS::Rooted<JS::Value> arg1(cx); |
6359 | 0 | if (args.hasDefined(1)) { |
6360 | 0 | arg1 = args[1]; |
6361 | 0 | } else { |
6362 | 0 | arg1 = JS::UndefinedValue(); |
6363 | 0 | } |
6364 | 0 | JS::Rooted<JSObject*> arg2(cx); |
6365 | 0 | if (args.hasDefined(2)) { |
6366 | 0 | if (args[2].isObject()) { |
6367 | 0 | arg2 = &args[2].toObject(); |
6368 | 0 | } else if (args[2].isNullOrUndefined()) { |
6369 | 0 | arg2 = nullptr; |
6370 | 0 | } else { |
6371 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of SyncMessageSender.sendRpcMessage"); |
6372 | 0 | return false; |
6373 | 0 | } |
6374 | 0 | } else { |
6375 | 0 | arg2 = nullptr; |
6376 | 0 | } |
6377 | 0 | nsIPrincipal* arg3; |
6378 | 0 | RefPtr<nsIPrincipal> arg3_holder; |
6379 | 0 | if (args.hasDefined(3)) { |
6380 | 0 | if (args[3].isObject()) { |
6381 | 0 | JS::Rooted<JSObject*> source(cx, &args[3].toObject()); |
6382 | 0 | if (NS_FAILED(UnwrapArg<nsIPrincipal>(cx, source, getter_AddRefs(arg3_holder)))) { |
6383 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 4 of SyncMessageSender.sendRpcMessage", "Principal"); |
6384 | 0 | return false; |
6385 | 0 | } |
6386 | 0 | MOZ_ASSERT(arg3_holder); |
6387 | 0 | arg3 = arg3_holder; |
6388 | 0 | } else if (args[3].isNullOrUndefined()) { |
6389 | 0 | arg3 = nullptr; |
6390 | 0 | } else { |
6391 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 4 of SyncMessageSender.sendRpcMessage"); |
6392 | 0 | return false; |
6393 | 0 | } |
6394 | 0 | } else { |
6395 | 0 | arg3 = nullptr; |
6396 | 0 | } |
6397 | 0 | FastErrorResult rv; |
6398 | 0 | nsTArray<JS::Value> result; |
6399 | 0 | SequenceRooter<JS::Value > resultRooter(cx, &result); |
6400 | 0 | self->SendRpcMessage(cx, NonNullHelper(Constify(arg0)), arg1, arg2, MOZ_KnownLive(Constify(arg3)), result, rv); |
6401 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
6402 | 0 | return false; |
6403 | 0 | } |
6404 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
6405 | 0 |
|
6406 | 0 | uint32_t length = result.Length(); |
6407 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
6408 | 0 | if (!returnArray) { |
6409 | 0 | return false; |
6410 | 0 | } |
6411 | 0 | // Scope for 'tmp' |
6412 | 0 | { |
6413 | 0 | JS::Rooted<JS::Value> tmp(cx); |
6414 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
6415 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
6416 | 0 | // are different ways to succeed at wrapping the object. |
6417 | 0 | do { |
6418 | 0 | JS::ExposeValueToActiveJS(result[sequenceIdx0]); |
6419 | 0 | tmp.set(result[sequenceIdx0]); |
6420 | 0 | if (!MaybeWrapValue(cx, &tmp)) { |
6421 | 0 | return false; |
6422 | 0 | } |
6423 | 0 | break; |
6424 | 0 | } while (false); |
6425 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
6426 | 0 | JSPROP_ENUMERATE)) { |
6427 | 0 | return false; |
6428 | 0 | } |
6429 | 0 | } |
6430 | 0 | } |
6431 | 0 | args.rval().setObject(*returnArray); |
6432 | 0 | return true; |
6433 | 0 | } |
6434 | | |
6435 | | static const JSJitInfo sendRpcMessage_methodinfo = { |
6436 | | { (JSJitGetterOp)sendRpcMessage }, |
6437 | | { prototypes::id::SyncMessageSender }, |
6438 | | { PrototypeTraits<prototypes::id::SyncMessageSender>::Depth }, |
6439 | | JSJitInfo::Method, |
6440 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
6441 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
6442 | | false, /* isInfallible. False in setters. */ |
6443 | | false, /* isMovable. Not relevant for setters. */ |
6444 | | false, /* isEliminatable. Not relevant for setters. */ |
6445 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
6446 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
6447 | | false, /* isTypedMethod. Only relevant for methods. */ |
6448 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
6449 | | }; |
6450 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
6451 | | static_assert(0 < 1, "There is no slot for us"); |
6452 | | |
6453 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
6454 | | #if defined(__clang__) |
6455 | | #pragma clang diagnostic push |
6456 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
6457 | | #endif |
6458 | | static const JSFunctionSpec sMethods_specs[] = { |
6459 | | JS_FNSPEC("sendSyncMessage", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&sendSyncMessage_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
6460 | | JS_FNSPEC("sendRpcMessage", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&sendRpcMessage_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
6461 | | JS_FS_END |
6462 | | }; |
6463 | | #if defined(__clang__) |
6464 | | #pragma clang diagnostic pop |
6465 | | #endif |
6466 | | |
6467 | | |
6468 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
6469 | | { nullptr, &sMethods_specs[0] }, |
6470 | | { nullptr, nullptr } |
6471 | | }; |
6472 | | |
6473 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
6474 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
6475 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
6476 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
6477 | | |
6478 | | |
6479 | | static uint16_t sNativeProperties_sortedPropertyIndices[2]; |
6480 | | static PropertyInfo sNativeProperties_propertyInfos[2]; |
6481 | | |
6482 | | static const NativePropertiesN<1> sNativeProperties = { |
6483 | | false, 0, |
6484 | | false, 0, |
6485 | | true, 0 /* sMethods */, |
6486 | | false, 0, |
6487 | | false, 0, |
6488 | | false, 0, |
6489 | | false, 0, |
6490 | | -1, |
6491 | | 2, |
6492 | | sNativeProperties_sortedPropertyIndices, |
6493 | | { |
6494 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
6495 | | } |
6496 | | }; |
6497 | | static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
6498 | | "We have a property info count that is oversized"); |
6499 | | |
6500 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
6501 | | { |
6502 | | "Function", |
6503 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
6504 | | &sBoringInterfaceObjectClassClassOps, |
6505 | | JS_NULL_CLASS_SPEC, |
6506 | | JS_NULL_CLASS_EXT, |
6507 | | &sInterfaceObjectClassObjectOps |
6508 | | }, |
6509 | | eInterface, |
6510 | | true, |
6511 | | prototypes::id::SyncMessageSender, |
6512 | | PrototypeTraits<prototypes::id::SyncMessageSender>::Depth, |
6513 | | sNativePropertyHooks, |
6514 | | "function SyncMessageSender() {\n [native code]\n}", |
6515 | | MessageSender_Binding::GetConstructorObject |
6516 | | }; |
6517 | | |
6518 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
6519 | | { |
6520 | | "SyncMessageSenderPrototype", |
6521 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
6522 | | JS_NULL_CLASS_OPS, |
6523 | | JS_NULL_CLASS_SPEC, |
6524 | | JS_NULL_CLASS_EXT, |
6525 | | JS_NULL_OBJECT_OPS |
6526 | | }, |
6527 | | eInterfacePrototype, |
6528 | | false, |
6529 | | prototypes::id::SyncMessageSender, |
6530 | | PrototypeTraits<prototypes::id::SyncMessageSender>::Depth, |
6531 | | sNativePropertyHooks, |
6532 | | "[object SyncMessageSenderPrototype]", |
6533 | | MessageSender_Binding::GetProtoObject |
6534 | | }; |
6535 | | |
6536 | | bool |
6537 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
6538 | 0 | { |
6539 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
6540 | 0 | } |
6541 | | |
6542 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
6543 | | nullptr, |
6544 | | nullptr, |
6545 | | nullptr, |
6546 | | { sNativeProperties.Upcast(), nullptr }, |
6547 | | prototypes::id::SyncMessageSender, |
6548 | | constructors::id::SyncMessageSender, |
6549 | | MessageSender_Binding::sNativePropertyHooks, |
6550 | | &DefaultXrayExpandoObjectClass |
6551 | | } }; |
6552 | | |
6553 | | void |
6554 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
6555 | 0 | { |
6556 | 0 | JS::Handle<JSObject*> parentProto(MessageSender_Binding::GetProtoObjectHandle(aCx)); |
6557 | 0 | if (!parentProto) { |
6558 | 0 | return; |
6559 | 0 | } |
6560 | 0 | |
6561 | 0 | JS::Handle<JSObject*> constructorProto(MessageSender_Binding::GetConstructorObjectHandle(aCx)); |
6562 | 0 | if (!constructorProto) { |
6563 | 0 | return; |
6564 | 0 | } |
6565 | 0 | |
6566 | 0 | static bool sIdsInited = false; |
6567 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
6568 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
6569 | 0 | return; |
6570 | 0 | } |
6571 | 0 | sIdsInited = true; |
6572 | 0 | } |
6573 | 0 |
|
6574 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::SyncMessageSender); |
6575 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::SyncMessageSender); |
6576 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
6577 | 0 | &sPrototypeClass.mBase, protoCache, |
6578 | 0 | nullptr, |
6579 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
6580 | 0 | interfaceCache, |
6581 | 0 | sNativeProperties.Upcast(), |
6582 | 0 | nullptr, |
6583 | 0 | "SyncMessageSender", aDefineOnGlobal, |
6584 | 0 | nullptr, |
6585 | 0 | false); |
6586 | 0 | } |
6587 | | |
6588 | | JSObject* |
6589 | | GetProtoObject(JSContext* aCx) |
6590 | 0 | { |
6591 | 0 | return GetProtoObjectHandle(aCx); |
6592 | 0 | } |
6593 | | |
6594 | | JSObject* |
6595 | | GetConstructorObject(JSContext* aCx) |
6596 | 0 | { |
6597 | 0 | return GetConstructorObjectHandle(aCx); |
6598 | 0 | } |
6599 | | |
6600 | | } // namespace SyncMessageSender_Binding |
6601 | | |
6602 | | |
6603 | | |
6604 | | void |
6605 | | MessageListener::ReceiveMessage(JSContext* cx, JS::Handle<JS::Value> aThisVal, const ReceiveMessageArgument& argument, JS::MutableHandle<JS::Value> aRetVal, ErrorResult& aRv) |
6606 | 0 | { |
6607 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
6608 | 0 | JS::AutoValueVector argv(cx); |
6609 | 0 | if (!argv.resize(1)) { |
6610 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
6611 | 0 | return; |
6612 | 0 | } |
6613 | 0 | unsigned argc = 1; |
6614 | 0 |
|
6615 | 0 | do { |
6616 | 0 | if (!argument.ToObjectInternal(cx, argv[0])) { |
6617 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
6618 | 0 | return; |
6619 | 0 | } |
6620 | 0 | break; |
6621 | 0 | } while (false); |
6622 | 0 |
|
6623 | 0 | bool isCallable = JS::IsCallable(mCallback); |
6624 | 0 | JS::Rooted<JS::Value> callable(cx); |
6625 | 0 | if (isCallable) { |
6626 | 0 | callable = JS::ObjectValue(*mCallback); |
6627 | 0 | } else { |
6628 | 0 | MessageListenerAtoms* atomsCache = GetAtomCache<MessageListenerAtoms>(cx); |
6629 | 0 | if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) || |
6630 | 0 | !GetCallableProperty(cx, atomsCache->receiveMessage_id, &callable)) { |
6631 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
6632 | 0 | return; |
6633 | 0 | } |
6634 | 0 | } |
6635 | 0 | JS::Rooted<JS::Value> thisValue(cx, isCallable ? aThisVal.get() |
6636 | 0 | : JS::ObjectValue(*mCallback)); |
6637 | 0 | if (!JS::Call(cx, thisValue, callable, |
6638 | 0 | JS::HandleValueArray::subarray(argv, 0, argc), &rval)) { |
6639 | 0 | aRv.NoteJSContextException(cx); |
6640 | 0 | return; |
6641 | 0 | } |
6642 | 0 | JS::Rooted<JS::Value> rvalDecl(cx); |
6643 | 0 | rvalDecl = rval; |
6644 | 0 | aRetVal.set(rvalDecl); |
6645 | 0 | } |
6646 | | |
6647 | | bool |
6648 | | MessageListener::InitIds(JSContext* cx, MessageListenerAtoms* atomsCache) |
6649 | 0 | { |
6650 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
6651 | 0 |
|
6652 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
6653 | 0 | // uninitialized. |
6654 | 0 | if (!atomsCache->receiveMessage_id.init(cx, "receiveMessage")) { |
6655 | 0 | return false; |
6656 | 0 | } |
6657 | 0 | return true; |
6658 | 0 | } |
6659 | | |
6660 | | |
6661 | | |
6662 | | namespace binding_detail { |
6663 | | } // namespace binding_detail |
6664 | | |
6665 | | |
6666 | | } // namespace dom |
6667 | | } // namespace mozilla |