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