/work/obj-fuzz/dom/bindings/InstallTriggerBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM InstallTrigger.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "InstallTriggerBinding.h" |
5 | | #include "WrapperFactory.h" |
6 | | #include "mozilla/OwningNonNull.h" |
7 | | #include "mozilla/dom/BindingUtils.h" |
8 | | #include "mozilla/dom/DOMJSClass.h" |
9 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
10 | | #include "mozilla/dom/PrimitiveConversions.h" |
11 | | #include "mozilla/dom/ScriptSettings.h" |
12 | | #include "mozilla/dom/SimpleGlobalObject.h" |
13 | | #include "mozilla/dom/UnionConversions.h" |
14 | | #include "mozilla/dom/XrayExpandoClass.h" |
15 | | #include "nsContentUtils.h" |
16 | | #include "nsIGlobalObject.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 | | InstallTriggerData::InstallTriggerData() |
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 | | |
34 | | bool |
35 | | InstallTriggerData::InitIds(JSContext* cx, InstallTriggerDataAtoms* atomsCache) |
36 | 0 | { |
37 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
38 | 0 |
|
39 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
40 | 0 | // uninitialized. |
41 | 0 | if (!atomsCache->URL_id.init(cx, "URL") || |
42 | 0 | !atomsCache->IconURL_id.init(cx, "IconURL") || |
43 | 0 | !atomsCache->Hash_id.init(cx, "Hash")) { |
44 | 0 | return false; |
45 | 0 | } |
46 | 0 | return true; |
47 | 0 | } |
48 | | |
49 | | bool |
50 | | InstallTriggerData::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
51 | 0 | { |
52 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
53 | 0 | // Since in that case we will not have to do any property gets |
54 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
55 | 0 | // checkers by static analysis tools |
56 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
57 | 0 | InstallTriggerDataAtoms* atomsCache = nullptr; |
58 | 0 | if (cx) { |
59 | 0 | atomsCache = GetAtomCache<InstallTriggerDataAtoms>(cx); |
60 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
61 | 0 | return false; |
62 | 0 | } |
63 | 0 | } |
64 | 0 | |
65 | 0 | if (!IsConvertibleToDictionary(val)) { |
66 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
67 | 0 | } |
68 | 0 | |
69 | 0 | bool isNull = val.isNullOrUndefined(); |
70 | 0 | // We only need these if !isNull, in which case we have |cx|. |
71 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
72 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
73 | 0 | if (!isNull) { |
74 | 0 | MOZ_ASSERT(cx); |
75 | 0 | object.emplace(cx, &val.toObject()); |
76 | 0 | temp.emplace(cx); |
77 | 0 | } |
78 | 0 | if (!isNull) { |
79 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->Hash_id, temp.ptr())) { |
80 | 0 | return false; |
81 | 0 | } |
82 | 0 | } |
83 | 0 | if (!isNull && !temp->isUndefined()) { |
84 | 0 | mHash.Construct(); |
85 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, (mHash.Value()))) { |
86 | 0 | return false; |
87 | 0 | } |
88 | 0 | mIsAnyMemberPresent = true; |
89 | 0 | } |
90 | 0 |
|
91 | 0 | if (!isNull) { |
92 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->IconURL_id, temp.ptr())) { |
93 | 0 | return false; |
94 | 0 | } |
95 | 0 | } |
96 | 0 | if (!isNull && !temp->isUndefined()) { |
97 | 0 | mIconURL.Construct(); |
98 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eNull, eNull, (mIconURL.Value()))) { |
99 | 0 | return false; |
100 | 0 | } |
101 | 0 | mIsAnyMemberPresent = true; |
102 | 0 | } |
103 | 0 |
|
104 | 0 | if (!isNull) { |
105 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->URL_id, temp.ptr())) { |
106 | 0 | return false; |
107 | 0 | } |
108 | 0 | } |
109 | 0 | if (!isNull && !temp->isUndefined()) { |
110 | 0 | mURL.Construct(); |
111 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mURL.Value()))) { |
112 | 0 | return false; |
113 | 0 | } |
114 | 0 | mIsAnyMemberPresent = true; |
115 | 0 | } |
116 | 0 | return true; |
117 | 0 | } |
118 | | |
119 | | bool |
120 | | InstallTriggerData::Init(const nsAString& aJSON) |
121 | 0 | { |
122 | 0 | AutoJSAPI jsapi; |
123 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
124 | 0 | if (!cleanGlobal) { |
125 | 0 | return false; |
126 | 0 | } |
127 | 0 | if (!jsapi.Init(cleanGlobal)) { |
128 | 0 | return false; |
129 | 0 | } |
130 | 0 | JSContext* cx = jsapi.cx(); |
131 | 0 | JS::Rooted<JS::Value> json(cx); |
132 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
133 | 0 | NS_ENSURE_TRUE(ok, false); |
134 | 0 | return Init(cx, json); |
135 | 0 | } |
136 | | |
137 | | bool |
138 | | InstallTriggerData::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
139 | 0 | { |
140 | 0 | InstallTriggerDataAtoms* atomsCache = GetAtomCache<InstallTriggerDataAtoms>(cx); |
141 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
142 | 0 | return false; |
143 | 0 | } |
144 | 0 | |
145 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
146 | 0 | if (!obj) { |
147 | 0 | return false; |
148 | 0 | } |
149 | 0 | rval.set(JS::ObjectValue(*obj)); |
150 | 0 |
|
151 | 0 | if (mHash.WasPassed()) { |
152 | 0 | do { |
153 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
154 | 0 | JS::Rooted<JS::Value> temp(cx); |
155 | 0 | nsString const & currentValue = mHash.InternalValue(); |
156 | 0 | if (!xpc::StringToJsval(cx, currentValue, &temp)) { |
157 | 0 | return false; |
158 | 0 | } |
159 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->Hash_id, temp, JSPROP_ENUMERATE)) { |
160 | 0 | return false; |
161 | 0 | } |
162 | 0 | break; |
163 | 0 | } while(false); |
164 | 0 | } |
165 | 0 |
|
166 | 0 | if (mIconURL.WasPassed()) { |
167 | 0 | do { |
168 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
169 | 0 | JS::Rooted<JS::Value> temp(cx); |
170 | 0 | nsString const & currentValue = mIconURL.InternalValue(); |
171 | 0 | if (!xpc::StringToJsval(cx, currentValue, &temp)) { |
172 | 0 | return false; |
173 | 0 | } |
174 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->IconURL_id, temp, JSPROP_ENUMERATE)) { |
175 | 0 | return false; |
176 | 0 | } |
177 | 0 | break; |
178 | 0 | } while(false); |
179 | 0 | } |
180 | 0 |
|
181 | 0 | if (mURL.WasPassed()) { |
182 | 0 | do { |
183 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
184 | 0 | JS::Rooted<JS::Value> temp(cx); |
185 | 0 | nsString const & currentValue = mURL.InternalValue(); |
186 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
187 | 0 | return false; |
188 | 0 | } |
189 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->URL_id, temp, JSPROP_ENUMERATE)) { |
190 | 0 | return false; |
191 | 0 | } |
192 | 0 | break; |
193 | 0 | } while(false); |
194 | 0 | } |
195 | 0 |
|
196 | 0 | return true; |
197 | 0 | } |
198 | | |
199 | | bool |
200 | | InstallTriggerData::ToJSON(nsAString& aJSON) const |
201 | 0 | { |
202 | 0 | AutoJSAPI jsapi; |
203 | 0 | jsapi.Init(); |
204 | 0 | JSContext *cx = jsapi.cx(); |
205 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
206 | 0 | // because we'll only be creating objects, in ways that have no |
207 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
208 | 0 | // which likewise guarantees no side-effects for the sorts of |
209 | 0 | // things we will pass it. |
210 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
211 | 0 | JS::Rooted<JS::Value> val(cx); |
212 | 0 | if (!ToObjectInternal(cx, &val)) { |
213 | 0 | return false; |
214 | 0 | } |
215 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
216 | 0 | return StringifyToJSON(cx, obj, aJSON); |
217 | 0 | } |
218 | | |
219 | | void |
220 | | InstallTriggerData::TraceDictionary(JSTracer* trc) |
221 | 0 | { |
222 | 0 | } |
223 | | |
224 | | InstallTriggerData& |
225 | | InstallTriggerData::operator=(const InstallTriggerData& aOther) |
226 | 0 | { |
227 | 0 | DictionaryBase::operator=(aOther); |
228 | 0 | mHash.Reset(); |
229 | 0 | if (aOther.mHash.WasPassed()) { |
230 | 0 | mHash.Construct(aOther.mHash.Value()); |
231 | 0 | } |
232 | 0 | mIconURL.Reset(); |
233 | 0 | if (aOther.mIconURL.WasPassed()) { |
234 | 0 | mIconURL.Construct(aOther.mIconURL.Value()); |
235 | 0 | } |
236 | 0 | mURL.Reset(); |
237 | 0 | if (aOther.mURL.WasPassed()) { |
238 | 0 | mURL.Construct(aOther.mURL.Value()); |
239 | 0 | } |
240 | 0 | return *this; |
241 | 0 | } |
242 | | |
243 | | namespace binding_detail { |
244 | | } // namespace binding_detail |
245 | | |
246 | | |
247 | | bool |
248 | | StringOrInstallTriggerData::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const |
249 | 0 | { |
250 | 0 | switch (mType) { |
251 | 0 | case eUninitialized: { |
252 | 0 | return false; |
253 | 0 | break; |
254 | 0 | } |
255 | 0 | case eString: { |
256 | 0 | if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) { |
257 | 0 | return false; |
258 | 0 | } |
259 | 0 | return true; |
260 | 0 | break; |
261 | 0 | } |
262 | 0 | case eInstallTriggerData: { |
263 | 0 | if (!mValue.mInstallTriggerData.Value().ToObjectInternal(cx, rval)) { |
264 | 0 | return false; |
265 | 0 | } |
266 | 0 | return true; |
267 | 0 | break; |
268 | 0 | } |
269 | 0 | default: { |
270 | 0 | return false; |
271 | 0 | break; |
272 | 0 | } |
273 | 0 | } |
274 | 0 | |
275 | 0 | return false; |
276 | 0 | } |
277 | | |
278 | | |
279 | | nsString& |
280 | | OwningStringOrInstallTriggerData::RawSetAsString() |
281 | 0 | { |
282 | 0 | if (mType == eString) { |
283 | 0 | return mValue.mString.Value(); |
284 | 0 | } |
285 | 0 | MOZ_ASSERT(mType == eUninitialized); |
286 | 0 | mType = eString; |
287 | 0 | return mValue.mString.SetValue(); |
288 | 0 | } |
289 | | |
290 | | nsString& |
291 | | OwningStringOrInstallTriggerData::SetAsString() |
292 | 0 | { |
293 | 0 | if (mType == eString) { |
294 | 0 | return mValue.mString.Value(); |
295 | 0 | } |
296 | 0 | Uninit(); |
297 | 0 | mType = eString; |
298 | 0 | return mValue.mString.SetValue(); |
299 | 0 | } |
300 | | |
301 | | bool |
302 | | OwningStringOrInstallTriggerData::TrySetToString(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl) |
303 | 0 | { |
304 | 0 | tryNext = false; |
305 | 0 | { // scope for memberSlot |
306 | 0 | nsString& memberSlot = RawSetAsString(); |
307 | 0 | if (!ConvertJSValueToString(cx, value, eStringify, eStringify, memberSlot)) { |
308 | 0 | return false; |
309 | 0 | } |
310 | 0 | } |
311 | 0 | return true; |
312 | 0 | } |
313 | | |
314 | | |
315 | | void |
316 | | OwningStringOrInstallTriggerData::DestroyString() |
317 | 0 | { |
318 | 0 | MOZ_ASSERT(IsString(), "Wrong type!"); |
319 | 0 | mValue.mString.Destroy(); |
320 | 0 | mType = eUninitialized; |
321 | 0 | } |
322 | | |
323 | | |
324 | | |
325 | | |
326 | | InstallTriggerData& |
327 | | OwningStringOrInstallTriggerData::RawSetAsInstallTriggerData() |
328 | 0 | { |
329 | 0 | if (mType == eInstallTriggerData) { |
330 | 0 | return mValue.mInstallTriggerData.Value(); |
331 | 0 | } |
332 | 0 | MOZ_ASSERT(mType == eUninitialized); |
333 | 0 | mType = eInstallTriggerData; |
334 | 0 | return mValue.mInstallTriggerData.SetValue(); |
335 | 0 | } |
336 | | |
337 | | InstallTriggerData& |
338 | | OwningStringOrInstallTriggerData::SetAsInstallTriggerData() |
339 | 0 | { |
340 | 0 | if (mType == eInstallTriggerData) { |
341 | 0 | return mValue.mInstallTriggerData.Value(); |
342 | 0 | } |
343 | 0 | Uninit(); |
344 | 0 | mType = eInstallTriggerData; |
345 | 0 | return mValue.mInstallTriggerData.SetValue(); |
346 | 0 | } |
347 | | |
348 | | bool |
349 | | OwningStringOrInstallTriggerData::TrySetToInstallTriggerData(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl) |
350 | 0 | { |
351 | 0 | tryNext = false; |
352 | 0 | { // scope for memberSlot |
353 | 0 | InstallTriggerData& memberSlot = RawSetAsInstallTriggerData(); |
354 | 0 | if (!IsConvertibleToDictionary(value)) { |
355 | 0 | DestroyInstallTriggerData(); |
356 | 0 | tryNext = true; |
357 | 0 | return true; |
358 | 0 | } |
359 | 0 | if (!memberSlot.Init(cx, value, "Member of StringOrInstallTriggerData", passedToJSImpl)) { |
360 | 0 | return false; |
361 | 0 | } |
362 | 0 | } |
363 | 0 | return true; |
364 | 0 | } |
365 | | |
366 | | void |
367 | | OwningStringOrInstallTriggerData::DestroyInstallTriggerData() |
368 | 0 | { |
369 | 0 | MOZ_ASSERT(IsInstallTriggerData(), "Wrong type!"); |
370 | 0 | mValue.mInstallTriggerData.Destroy(); |
371 | 0 | mType = eUninitialized; |
372 | 0 | } |
373 | | |
374 | | |
375 | | |
376 | | |
377 | | void |
378 | | OwningStringOrInstallTriggerData::Uninit() |
379 | | { |
380 | | switch (mType) { |
381 | | case eUninitialized: { |
382 | | break; |
383 | | } |
384 | | case eString: { |
385 | | DestroyString(); |
386 | | break; |
387 | | } |
388 | | case eInstallTriggerData: { |
389 | | DestroyInstallTriggerData(); |
390 | | break; |
391 | | } |
392 | | } |
393 | | } |
394 | | |
395 | | bool |
396 | | OwningStringOrInstallTriggerData::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const |
397 | 0 | { |
398 | 0 | switch (mType) { |
399 | 0 | case eUninitialized: { |
400 | 0 | return false; |
401 | 0 | break; |
402 | 0 | } |
403 | 0 | case eString: { |
404 | 0 | if (!xpc::NonVoidStringToJsval(cx, mValue.mString.Value(), rval)) { |
405 | 0 | return false; |
406 | 0 | } |
407 | 0 | return true; |
408 | 0 | break; |
409 | 0 | } |
410 | 0 | case eInstallTriggerData: { |
411 | 0 | if (!mValue.mInstallTriggerData.Value().ToObjectInternal(cx, rval)) { |
412 | 0 | return false; |
413 | 0 | } |
414 | 0 | return true; |
415 | 0 | break; |
416 | 0 | } |
417 | 0 | default: { |
418 | 0 | return false; |
419 | 0 | break; |
420 | 0 | } |
421 | 0 | } |
422 | 0 | |
423 | 0 | return false; |
424 | 0 | } |
425 | | |
426 | | void |
427 | | OwningStringOrInstallTriggerData::TraceUnion(JSTracer* trc) |
428 | 0 | { |
429 | 0 | } |
430 | | |
431 | | OwningStringOrInstallTriggerData& |
432 | | OwningStringOrInstallTriggerData::operator=(const OwningStringOrInstallTriggerData& aOther) |
433 | 0 | { |
434 | 0 | switch (aOther.mType) { |
435 | 0 | case eUninitialized: { |
436 | 0 | MOZ_ASSERT(mType == eUninitialized, |
437 | 0 | "We need to destroy ourselves?"); |
438 | 0 | break; |
439 | 0 | } |
440 | 0 | case eString: { |
441 | 0 | SetAsString() = aOther.GetAsString(); |
442 | 0 | break; |
443 | 0 | } |
444 | 0 | case eInstallTriggerData: { |
445 | 0 | SetAsInstallTriggerData() = aOther.GetAsInstallTriggerData(); |
446 | 0 | break; |
447 | 0 | } |
448 | 0 | } |
449 | 0 | return *this; |
450 | 0 | } |
451 | | |
452 | | |
453 | | void |
454 | | InstallTriggerCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, const nsAString& url, int16_t status, ErrorResult& aRv) |
455 | 0 | { |
456 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
457 | 0 | JS::AutoValueVector argv(cx); |
458 | 0 | if (!argv.resize(2)) { |
459 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
460 | 0 | return; |
461 | 0 | } |
462 | 0 | unsigned argc = 2; |
463 | 0 |
|
464 | 0 | do { |
465 | 0 | argv[1].setInt32(int32_t(status)); |
466 | 0 | break; |
467 | 0 | } while (false); |
468 | 0 |
|
469 | 0 | do { |
470 | 0 | nsString mutableStr(url); |
471 | 0 | if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) { |
472 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
473 | 0 | return; |
474 | 0 | } |
475 | 0 | break; |
476 | 0 | } while (false); |
477 | 0 |
|
478 | 0 | JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback)); |
479 | 0 | if (!JS::Call(cx, aThisVal, callable, |
480 | 0 | JS::HandleValueArray::subarray(argv, 0, argc), &rval)) { |
481 | 0 | aRv.NoteJSContextException(cx); |
482 | 0 | return; |
483 | 0 | } |
484 | 0 | } |
485 | | |
486 | | |
487 | | |
488 | | namespace binding_detail { |
489 | | } // namespace binding_detail |
490 | | |
491 | | |
492 | | namespace InstallTriggerImpl_Binding { |
493 | | |
494 | | MOZ_CAN_RUN_SCRIPT static bool |
495 | | enabled(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::InstallTriggerImpl* self, const JSJitMethodCallArgs& args) |
496 | 0 | { |
497 | 0 | AUTO_PROFILER_LABEL_FAST("InstallTriggerImpl.enabled", DOM, cx); |
498 | 0 |
|
499 | 0 | Maybe<JS::Rooted<JSObject*> > unwrappedObj; |
500 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
501 | 0 | if (objIsXray) { |
502 | 0 | unwrappedObj.emplace(cx, obj); |
503 | 0 | } |
504 | 0 | if (objIsXray) { |
505 | 0 | unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref()); |
506 | 0 | if (!unwrappedObj.ref()) { |
507 | 0 | return false; |
508 | 0 | } |
509 | 0 | } |
510 | 0 | FastErrorResult rv; |
511 | 0 | bool result(self->Enabled(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))); |
512 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
513 | 0 | return false; |
514 | 0 | } |
515 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
516 | 0 | args.rval().setBoolean(result); |
517 | 0 | return true; |
518 | 0 | } |
519 | | |
520 | | static const JSJitInfo enabled_methodinfo = { |
521 | | { (JSJitGetterOp)enabled }, |
522 | | { prototypes::id::InstallTriggerImpl }, |
523 | | { PrototypeTraits<prototypes::id::InstallTriggerImpl>::Depth }, |
524 | | JSJitInfo::Method, |
525 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
526 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
527 | | false, /* isInfallible. False in setters. */ |
528 | | false, /* isMovable. Not relevant for setters. */ |
529 | | false, /* isEliminatable. Not relevant for setters. */ |
530 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
531 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
532 | | false, /* isTypedMethod. Only relevant for methods. */ |
533 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
534 | | }; |
535 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
536 | | static_assert(0 < 1, "There is no slot for us"); |
537 | | |
538 | | MOZ_CAN_RUN_SCRIPT static bool |
539 | | updateEnabled(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::InstallTriggerImpl* self, const JSJitMethodCallArgs& args) |
540 | 0 | { |
541 | 0 | AUTO_PROFILER_LABEL_FAST("InstallTriggerImpl.updateEnabled", DOM, cx); |
542 | 0 |
|
543 | 0 | Maybe<JS::Rooted<JSObject*> > unwrappedObj; |
544 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
545 | 0 | if (objIsXray) { |
546 | 0 | unwrappedObj.emplace(cx, obj); |
547 | 0 | } |
548 | 0 | if (objIsXray) { |
549 | 0 | unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref()); |
550 | 0 | if (!unwrappedObj.ref()) { |
551 | 0 | return false; |
552 | 0 | } |
553 | 0 | } |
554 | 0 | FastErrorResult rv; |
555 | 0 | bool result(self->UpdateEnabled(rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))); |
556 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
557 | 0 | return false; |
558 | 0 | } |
559 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
560 | 0 | args.rval().setBoolean(result); |
561 | 0 | return true; |
562 | 0 | } |
563 | | |
564 | | static const JSJitInfo updateEnabled_methodinfo = { |
565 | | { (JSJitGetterOp)updateEnabled }, |
566 | | { prototypes::id::InstallTriggerImpl }, |
567 | | { PrototypeTraits<prototypes::id::InstallTriggerImpl>::Depth }, |
568 | | JSJitInfo::Method, |
569 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
570 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
571 | | false, /* isInfallible. False in setters. */ |
572 | | false, /* isMovable. Not relevant for setters. */ |
573 | | false, /* isEliminatable. Not relevant for setters. */ |
574 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
575 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
576 | | false, /* isTypedMethod. Only relevant for methods. */ |
577 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
578 | | }; |
579 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
580 | | static_assert(0 < 1, "There is no slot for us"); |
581 | | |
582 | | MOZ_CAN_RUN_SCRIPT static bool |
583 | | install(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::InstallTriggerImpl* self, const JSJitMethodCallArgs& args) |
584 | 0 | { |
585 | 0 | AUTO_PROFILER_LABEL_FAST("InstallTriggerImpl.install", DOM, cx); |
586 | 0 |
|
587 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
588 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "InstallTriggerImpl.install"); |
589 | 0 | } |
590 | 0 | Maybe<JS::Rooted<JSObject*> > unwrappedObj; |
591 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
592 | 0 | if (objIsXray) { |
593 | 0 | unwrappedObj.emplace(cx, obj); |
594 | 0 | } |
595 | 0 | Record<nsString, OwningStringOrInstallTriggerData> arg0; |
596 | 0 | if (args[0].isObject()) { |
597 | 0 | auto& recordEntries = arg0.Entries(); |
598 | 0 |
|
599 | 0 | JS::Rooted<JSObject*> recordObj(cx, &args[0].toObject()); |
600 | 0 | JS::AutoIdVector ids(cx); |
601 | 0 | if (!js::GetPropertyKeys(cx, recordObj, |
602 | 0 | JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) { |
603 | 0 | return false; |
604 | 0 | } |
605 | 0 | if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) { |
606 | 0 | JS_ReportOutOfMemory(cx); |
607 | 0 | return false; |
608 | 0 | } |
609 | 0 | JS::Rooted<JS::Value> propNameValue(cx); |
610 | 0 | JS::Rooted<JS::Value> temp(cx); |
611 | 0 | JS::Rooted<jsid> curId(cx); |
612 | 0 | JS::Rooted<JS::Value> idVal(cx); |
613 | 0 | // Use a hashset to keep track of ids seen, to avoid |
614 | 0 | // introducing nasty O(N^2) behavior scanning for them all the |
615 | 0 | // time. Ideally we'd use a data structure with O(1) lookup |
616 | 0 | // _and_ ordering for the MozMap, but we don't have one lying |
617 | 0 | // around. |
618 | 0 | nsTHashtable<nsStringHashKey> idsSeen; |
619 | 0 | for (size_t i = 0; i < ids.length(); ++i) { |
620 | 0 | curId = ids[i]; |
621 | 0 |
|
622 | 0 | JS::Rooted<JS::PropertyDescriptor> desc(cx); |
623 | 0 | if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId, |
624 | 0 | &desc)) { |
625 | 0 | return false; |
626 | 0 | } |
627 | 0 | |
628 | 0 | if (!desc.object() /* == undefined in spec terms */ || |
629 | 0 | !desc.enumerable()) { |
630 | 0 | continue; |
631 | 0 | } |
632 | 0 | |
633 | 0 | idVal = js::IdToValue(curId); |
634 | 0 | nsString propName; |
635 | 0 | // This will just throw if idVal is a Symbol, like the spec says |
636 | 0 | // to do. |
637 | 0 | if (!ConvertJSValueToString(cx, idVal, propName)) { |
638 | 0 | return false; |
639 | 0 | } |
640 | 0 | |
641 | 0 | if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) { |
642 | 0 | return false; |
643 | 0 | } |
644 | 0 | |
645 | 0 | Record<nsString, OwningStringOrInstallTriggerData>::EntryType* entry; |
646 | 0 | if (!idsSeen.EnsureInserted(propName)) { |
647 | 0 | // Find the existing entry. |
648 | 0 | auto idx = recordEntries.IndexOf(propName); |
649 | 0 | MOZ_ASSERT(idx != recordEntries.NoIndex, |
650 | 0 | "Why is it not found?"); |
651 | 0 | // Now blow it away to make it look like it was just added |
652 | 0 | // to the array, because it's not obvious that it's |
653 | 0 | // safe to write to its already-initialized mValue via our |
654 | 0 | // normal codegen conversions. For example, the value |
655 | 0 | // could be a union and this would change its type, but |
656 | 0 | // codegen assumes we won't do that. |
657 | 0 | entry = recordEntries.ReconstructElementAt(idx); |
658 | 0 | } else { |
659 | 0 | // Safe to do an infallible append here, because we did a |
660 | 0 | // SetCapacity above to the right capacity. |
661 | 0 | entry = recordEntries.AppendElement(); |
662 | 0 | } |
663 | 0 | entry->mKey = propName; |
664 | 0 | OwningStringOrInstallTriggerData& slot = entry->mValue; |
665 | 0 | { |
666 | 0 | bool done = false, failed = false, tryNext; |
667 | 0 | if (!done) { |
668 | 0 | done = (failed = !slot.TrySetToInstallTriggerData(cx, temp, tryNext, true)) || !tryNext; |
669 | 0 | } |
670 | 0 | if (!done) { |
671 | 0 | do { |
672 | 0 | done = (failed = !slot.TrySetToString(cx, temp, tryNext)) || !tryNext; |
673 | 0 | break; |
674 | 0 | } while (false); |
675 | 0 | } |
676 | 0 | if (failed) { |
677 | 0 | return false; |
678 | 0 | } |
679 | 0 | if (!done) { |
680 | 0 | ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Value in argument 1 of InstallTriggerImpl.install", "InstallTriggerData"); |
681 | 0 | return false; |
682 | 0 | } |
683 | 0 | } |
684 | 0 | } |
685 | 0 | } else { |
686 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of InstallTriggerImpl.install"); |
687 | 0 | return false; |
688 | 0 | } |
689 | 0 | Optional<OwningNonNull<InstallTriggerCallback>> arg1; |
690 | 0 | if (args.hasDefined(1)) { |
691 | 0 | arg1.Construct(); |
692 | 0 | if (args[1].isObject()) { |
693 | 0 | if (JS::IsCallable(&args[1].toObject())) { |
694 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
695 | 0 | JS::Rooted<JSObject*> tempRoot(cx, &args[1].toObject()); |
696 | 0 | JS::Rooted<JSObject*> tempGlobalRoot(cx, JS::CurrentGlobalOrNull(cx)); |
697 | 0 | arg1.Value() = new InstallTriggerCallback(cx, tempRoot, tempGlobalRoot, GetIncumbentGlobal()); |
698 | 0 | } |
699 | 0 | } else { |
700 | 0 | ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of InstallTriggerImpl.install"); |
701 | 0 | return false; |
702 | 0 | } |
703 | 0 | } else { |
704 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of InstallTriggerImpl.install"); |
705 | 0 | return false; |
706 | 0 | } |
707 | 0 | } |
708 | 0 | if (objIsXray) { |
709 | 0 | unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref()); |
710 | 0 | if (!unwrappedObj.ref()) { |
711 | 0 | return false; |
712 | 0 | } |
713 | 0 | } |
714 | 0 | FastErrorResult rv; |
715 | 0 | bool result(self->Install(Constify(arg0), NonNullHelper(Constify(arg1)), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))); |
716 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
717 | 0 | return false; |
718 | 0 | } |
719 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
720 | 0 | args.rval().setBoolean(result); |
721 | 0 | return true; |
722 | 0 | } |
723 | | |
724 | | static const JSJitInfo install_methodinfo = { |
725 | | { (JSJitGetterOp)install }, |
726 | | { prototypes::id::InstallTriggerImpl }, |
727 | | { PrototypeTraits<prototypes::id::InstallTriggerImpl>::Depth }, |
728 | | JSJitInfo::Method, |
729 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
730 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
731 | | false, /* isInfallible. False in setters. */ |
732 | | false, /* isMovable. Not relevant for setters. */ |
733 | | false, /* isEliminatable. Not relevant for setters. */ |
734 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
735 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
736 | | false, /* isTypedMethod. Only relevant for methods. */ |
737 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
738 | | }; |
739 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
740 | | static_assert(0 < 1, "There is no slot for us"); |
741 | | |
742 | | MOZ_CAN_RUN_SCRIPT static bool |
743 | | installChrome(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::InstallTriggerImpl* self, const JSJitMethodCallArgs& args) |
744 | 0 | { |
745 | 0 | AUTO_PROFILER_LABEL_FAST("InstallTriggerImpl.installChrome", DOM, cx); |
746 | 0 |
|
747 | 0 | if (MOZ_UNLIKELY(args.length() < 3)) { |
748 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "InstallTriggerImpl.installChrome"); |
749 | 0 | } |
750 | 0 | Maybe<JS::Rooted<JSObject*> > unwrappedObj; |
751 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
752 | 0 | if (objIsXray) { |
753 | 0 | unwrappedObj.emplace(cx, obj); |
754 | 0 | } |
755 | 0 | uint16_t arg0; |
756 | 0 | if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[0], &arg0)) { |
757 | 0 | return false; |
758 | 0 | } |
759 | 0 | binding_detail::FakeString arg1; |
760 | 0 | if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) { |
761 | 0 | return false; |
762 | 0 | } |
763 | 0 | binding_detail::FakeString arg2; |
764 | 0 | if (!ConvertJSValueToString(cx, args[2], eStringify, eStringify, arg2)) { |
765 | 0 | return false; |
766 | 0 | } |
767 | 0 | if (objIsXray) { |
768 | 0 | unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref()); |
769 | 0 | if (!unwrappedObj.ref()) { |
770 | 0 | return false; |
771 | 0 | } |
772 | 0 | } |
773 | 0 | FastErrorResult rv; |
774 | 0 | bool result(self->InstallChrome(arg0, NonNullHelper(Constify(arg1)), NonNullHelper(Constify(arg2)), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))); |
775 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
776 | 0 | return false; |
777 | 0 | } |
778 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
779 | 0 | args.rval().setBoolean(result); |
780 | 0 | return true; |
781 | 0 | } |
782 | | |
783 | | static const JSJitInfo installChrome_methodinfo = { |
784 | | { (JSJitGetterOp)installChrome }, |
785 | | { prototypes::id::InstallTriggerImpl }, |
786 | | { PrototypeTraits<prototypes::id::InstallTriggerImpl>::Depth }, |
787 | | JSJitInfo::Method, |
788 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
789 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
790 | | false, /* isInfallible. False in setters. */ |
791 | | false, /* isMovable. Not relevant for setters. */ |
792 | | false, /* isEliminatable. Not relevant for setters. */ |
793 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
794 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
795 | | false, /* isTypedMethod. Only relevant for methods. */ |
796 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
797 | | }; |
798 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
799 | | static_assert(0 < 1, "There is no slot for us"); |
800 | | |
801 | | MOZ_CAN_RUN_SCRIPT static bool |
802 | | startSoftwareUpdate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::InstallTriggerImpl* self, const JSJitMethodCallArgs& args) |
803 | 0 | { |
804 | 0 | AUTO_PROFILER_LABEL_FAST("InstallTriggerImpl.startSoftwareUpdate", DOM, cx); |
805 | 0 |
|
806 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
807 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "InstallTriggerImpl.startSoftwareUpdate"); |
808 | 0 | } |
809 | 0 | Maybe<JS::Rooted<JSObject*> > unwrappedObj; |
810 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
811 | 0 | if (objIsXray) { |
812 | 0 | unwrappedObj.emplace(cx, obj); |
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 | Optional<uint16_t> arg1; |
819 | 0 | if (args.hasDefined(1)) { |
820 | 0 | arg1.Construct(); |
821 | 0 | if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[1], &arg1.Value())) { |
822 | 0 | return false; |
823 | 0 | } |
824 | 0 | } |
825 | 0 | if (objIsXray) { |
826 | 0 | unwrappedObj.ref() = js::CheckedUnwrap(unwrappedObj.ref()); |
827 | 0 | if (!unwrappedObj.ref()) { |
828 | 0 | return false; |
829 | 0 | } |
830 | 0 | } |
831 | 0 | FastErrorResult rv; |
832 | 0 | bool result(self->StartSoftwareUpdate(NonNullHelper(Constify(arg0)), Constify(arg1), rv, (unwrappedObj ? js::GetNonCCWObjectRealm(*unwrappedObj) : js::GetContextRealm(cx)))); |
833 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
834 | 0 | return false; |
835 | 0 | } |
836 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
837 | 0 | args.rval().setBoolean(result); |
838 | 0 | return true; |
839 | 0 | } |
840 | | |
841 | | static const JSJitInfo startSoftwareUpdate_methodinfo = { |
842 | | { (JSJitGetterOp)startSoftwareUpdate }, |
843 | | { prototypes::id::InstallTriggerImpl }, |
844 | | { PrototypeTraits<prototypes::id::InstallTriggerImpl>::Depth }, |
845 | | JSJitInfo::Method, |
846 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
847 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
848 | | false, /* isInfallible. False in setters. */ |
849 | | false, /* isMovable. Not relevant for setters. */ |
850 | | false, /* isEliminatable. Not relevant for setters. */ |
851 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
852 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
853 | | false, /* isTypedMethod. Only relevant for methods. */ |
854 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
855 | | }; |
856 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
857 | | static_assert(0 < 1, "There is no slot for us"); |
858 | | |
859 | | static bool |
860 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
861 | 0 | { |
862 | 0 | mozilla::dom::InstallTriggerImpl* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::InstallTriggerImpl>(obj); |
863 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
864 | 0 | // obviously can't preserve if we're not initialized. |
865 | 0 | if (self && self->GetWrapperPreserveColor()) { |
866 | 0 | PreserveWrapper(self); |
867 | 0 | } |
868 | 0 | return true; |
869 | 0 | } |
870 | | |
871 | | static void |
872 | | _finalize(js::FreeOp* fop, JSObject* obj) |
873 | 0 | { |
874 | 0 | mozilla::dom::InstallTriggerImpl* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::InstallTriggerImpl>(obj); |
875 | 0 | if (self) { |
876 | 0 | ClearWrapper(self, self, obj); |
877 | 0 | AddForDeferredFinalization<mozilla::dom::InstallTriggerImpl>(self); |
878 | 0 | } |
879 | 0 | } |
880 | | |
881 | | static size_t |
882 | | _objectMoved(JSObject* obj, JSObject* old) |
883 | 0 | { |
884 | 0 | mozilla::dom::InstallTriggerImpl* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::InstallTriggerImpl>(obj); |
885 | 0 | if (self) { |
886 | 0 | UpdateWrapper(self, self, obj, old); |
887 | 0 | } |
888 | 0 |
|
889 | 0 | return 0; |
890 | 0 | } |
891 | | |
892 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
893 | | #if defined(__clang__) |
894 | | #pragma clang diagnostic push |
895 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
896 | | #endif |
897 | | static const JSFunctionSpec sChromeStaticMethods_specs[] = { |
898 | | JS_FNSPEC("_create", InstallTriggerImpl::_Create, nullptr, 2, 0, nullptr), |
899 | | JS_FS_END |
900 | | }; |
901 | | #if defined(__clang__) |
902 | | #pragma clang diagnostic pop |
903 | | #endif |
904 | | |
905 | | |
906 | | static const Prefable<const JSFunctionSpec> sChromeStaticMethods[] = { |
907 | | { nullptr, &sChromeStaticMethods_specs[0] }, |
908 | | { nullptr, nullptr } |
909 | | }; |
910 | | |
911 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
912 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
913 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
914 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
915 | | |
916 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
917 | | #if defined(__clang__) |
918 | | #pragma clang diagnostic push |
919 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
920 | | #endif |
921 | | static const JSFunctionSpec sMethods_specs[] = { |
922 | | JS_FNSPEC("enabled", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&enabled_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
923 | | JS_FNSPEC("updateEnabled", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&updateEnabled_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
924 | | JS_FNSPEC("install", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&install_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
925 | | JS_FNSPEC("installChrome", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&installChrome_methodinfo), 3, JSPROP_ENUMERATE, nullptr), |
926 | | JS_FNSPEC("startSoftwareUpdate", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&startSoftwareUpdate_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
927 | | JS_FS_END |
928 | | }; |
929 | | #if defined(__clang__) |
930 | | #pragma clang diagnostic pop |
931 | | #endif |
932 | | |
933 | | |
934 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
935 | | { nullptr, &sMethods_specs[0] }, |
936 | | { nullptr, nullptr } |
937 | | }; |
938 | | |
939 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
940 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
941 | | static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
942 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
943 | | |
944 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
945 | | #if defined(__clang__) |
946 | | #pragma clang diagnostic push |
947 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
948 | | #endif |
949 | | static const ConstantSpec sConstants_specs[] = { |
950 | | { "SKIN", JS::Int32Value(1) }, |
951 | | { "LOCALE", JS::Int32Value(2) }, |
952 | | { "CONTENT", JS::Int32Value(4) }, |
953 | | { "PACKAGE", JS::Int32Value(7) }, |
954 | | { 0, JS::UndefinedValue() } |
955 | | }; |
956 | | #if defined(__clang__) |
957 | | #pragma clang diagnostic pop |
958 | | #endif |
959 | | |
960 | | |
961 | | static const Prefable<const ConstantSpec> sConstants[] = { |
962 | | { nullptr, &sConstants_specs[0] }, |
963 | | { nullptr, nullptr } |
964 | | }; |
965 | | |
966 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
967 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
968 | | static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
969 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
970 | | |
971 | | |
972 | | static uint16_t sNativeProperties_sortedPropertyIndices[9]; |
973 | | static PropertyInfo sNativeProperties_propertyInfos[9]; |
974 | | |
975 | | static const NativePropertiesN<2> sNativeProperties = { |
976 | | false, 0, |
977 | | false, 0, |
978 | | true, 0 /* sMethods */, |
979 | | false, 0, |
980 | | false, 0, |
981 | | false, 0, |
982 | | true, 1 /* sConstants */, |
983 | | -1, |
984 | | 9, |
985 | | sNativeProperties_sortedPropertyIndices, |
986 | | { |
987 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
988 | | { sConstants, &sNativeProperties_propertyInfos[5] } |
989 | | } |
990 | | }; |
991 | | static_assert(9 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
992 | | "We have a property info count that is oversized"); |
993 | | |
994 | | static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1]; |
995 | | static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1]; |
996 | | |
997 | | static const NativePropertiesN<1> sChromeOnlyNativeProperties = { |
998 | | true, 0 /* sChromeStaticMethods */, |
999 | | false, 0, |
1000 | | false, 0, |
1001 | | false, 0, |
1002 | | false, 0, |
1003 | | false, 0, |
1004 | | false, 0, |
1005 | | -1, |
1006 | | 1, |
1007 | | sChromeOnlyNativeProperties_sortedPropertyIndices, |
1008 | | { |
1009 | | { sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] } |
1010 | | } |
1011 | | }; |
1012 | | static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount), |
1013 | | "We have a property info count that is oversized"); |
1014 | | |
1015 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
1016 | | { |
1017 | | "Function", |
1018 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
1019 | | &sBoringInterfaceObjectClassClassOps, |
1020 | | JS_NULL_CLASS_SPEC, |
1021 | | JS_NULL_CLASS_EXT, |
1022 | | &sInterfaceObjectClassObjectOps |
1023 | | }, |
1024 | | eInterface, |
1025 | | true, |
1026 | | prototypes::id::InstallTriggerImpl, |
1027 | | PrototypeTraits<prototypes::id::InstallTriggerImpl>::Depth, |
1028 | | sNativePropertyHooks, |
1029 | | "function InstallTriggerImpl() {\n [native code]\n}", |
1030 | | JS::GetRealmFunctionPrototype |
1031 | | }; |
1032 | | |
1033 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
1034 | | { |
1035 | | "InstallTriggerImplPrototype", |
1036 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
1037 | | JS_NULL_CLASS_OPS, |
1038 | | JS_NULL_CLASS_SPEC, |
1039 | | JS_NULL_CLASS_EXT, |
1040 | | JS_NULL_OBJECT_OPS |
1041 | | }, |
1042 | | eInterfacePrototype, |
1043 | | false, |
1044 | | prototypes::id::InstallTriggerImpl, |
1045 | | PrototypeTraits<prototypes::id::InstallTriggerImpl>::Depth, |
1046 | | sNativePropertyHooks, |
1047 | | "[object InstallTriggerImplPrototype]", |
1048 | | JS::GetRealmObjectPrototype |
1049 | | }; |
1050 | | |
1051 | | bool |
1052 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
1053 | 0 | { |
1054 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
1055 | 0 | } |
1056 | | |
1057 | | static const js::ClassOps sClassOps = { |
1058 | | _addProperty, /* addProperty */ |
1059 | | nullptr, /* delProperty */ |
1060 | | nullptr, /* enumerate */ |
1061 | | nullptr, /* newEnumerate */ |
1062 | | nullptr, /* resolve */ |
1063 | | nullptr, /* mayResolve */ |
1064 | | _finalize, /* finalize */ |
1065 | | nullptr, /* call */ |
1066 | | nullptr, /* hasInstance */ |
1067 | | nullptr, /* construct */ |
1068 | | nullptr, /* trace */ |
1069 | | }; |
1070 | | |
1071 | | static const js::ClassExtension sClassExtension = { |
1072 | | nullptr, /* weakmapKeyDelegateOp */ |
1073 | | _objectMoved /* objectMovedOp */ |
1074 | | }; |
1075 | | |
1076 | | static const DOMJSClass sClass = { |
1077 | | { "InstallTriggerImpl", |
1078 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
1079 | | &sClassOps, |
1080 | | JS_NULL_CLASS_SPEC, |
1081 | | &sClassExtension, |
1082 | | JS_NULL_OBJECT_OPS |
1083 | | }, |
1084 | | { prototypes::id::InstallTriggerImpl, 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 }, |
1085 | | IsBaseOf<nsISupports, mozilla::dom::InstallTriggerImpl >::value, |
1086 | | sNativePropertyHooks, |
1087 | | FindAssociatedGlobalForNative<mozilla::dom::InstallTriggerImpl>::Get, |
1088 | | GetProtoObjectHandle, |
1089 | | GetCCParticipant<mozilla::dom::InstallTriggerImpl>::Get() |
1090 | | }; |
1091 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
1092 | | "Must have the right minimal number of reserved slots."); |
1093 | | static_assert(1 >= 1, |
1094 | | "Must have enough reserved slots."); |
1095 | | |
1096 | | const JSClass* |
1097 | | GetJSClass() |
1098 | 0 | { |
1099 | 0 | return sClass.ToJSClass(); |
1100 | 0 | } |
1101 | | |
1102 | | bool |
1103 | | Wrap(JSContext* aCx, mozilla::dom::InstallTriggerImpl* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
1104 | 0 | { |
1105 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::InstallTriggerImpl>::value, |
1106 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
1107 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::InstallTriggerImpl*>(aObject) == |
1108 | 0 | reinterpret_cast<mozilla::dom::InstallTriggerImpl*>(aObject), |
1109 | 0 | "Multiple inheritance for mozilla::dom::InstallTriggerImpl is broken."); |
1110 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
1111 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
1112 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
1113 | 0 | "You should probably not be using Wrap() directly; use " |
1114 | 0 | "GetOrCreateDOMReflector instead"); |
1115 | 0 |
|
1116 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
1117 | 0 | "nsISupports must be on our primary inheritance chain"); |
1118 | 0 |
|
1119 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
1120 | 0 | if (!global) { |
1121 | 0 | return false; |
1122 | 0 | } |
1123 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
1124 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
1125 | 0 |
|
1126 | 0 | // That might have ended up wrapping us already, due to the wonders |
1127 | 0 | // of XBL. Check for that, and bail out as needed. |
1128 | 0 | aReflector.set(aCache->GetWrapper()); |
1129 | 0 | if (aReflector) { |
1130 | | #ifdef DEBUG |
1131 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
1132 | | #endif // DEBUG |
1133 | | return true; |
1134 | 0 | } |
1135 | 0 |
|
1136 | 0 | JSAutoRealm ar(aCx, global); |
1137 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
1138 | 0 | if (!canonicalProto) { |
1139 | 0 | return false; |
1140 | 0 | } |
1141 | 0 | JS::Rooted<JSObject*> proto(aCx); |
1142 | 0 | if (aGivenProto) { |
1143 | 0 | proto = aGivenProto; |
1144 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
1145 | 0 | // coming in, we changed compartments to that of "parent" so may need |
1146 | 0 | // to wrap the proto here. |
1147 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
1148 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
1149 | 0 | return false; |
1150 | 0 | } |
1151 | 0 | } |
1152 | 0 | } else { |
1153 | 0 | proto = canonicalProto; |
1154 | 0 | } |
1155 | 0 |
|
1156 | 0 | BindingJSObjectCreator<mozilla::dom::InstallTriggerImpl> creator(aCx); |
1157 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
1158 | 0 | if (!aReflector) { |
1159 | 0 | return false; |
1160 | 0 | } |
1161 | 0 | |
1162 | 0 | aCache->SetWrapper(aReflector); |
1163 | 0 | creator.InitializationSucceeded(); |
1164 | 0 |
|
1165 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
1166 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
1167 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
1168 | 0 | // otherwise we won't be able to properly recreate it later, since |
1169 | 0 | // we won't know what proto to use. Note that we don't check |
1170 | 0 | // aGivenProto here, since it's entirely possible (and even |
1171 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
1172 | 0 | // same as canonicalProto. |
1173 | 0 | if (proto != canonicalProto) { |
1174 | 0 | PreserveWrapper(aObject); |
1175 | 0 | } |
1176 | 0 |
|
1177 | 0 | return true; |
1178 | 0 | } |
1179 | | |
1180 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
1181 | | nullptr, |
1182 | | nullptr, |
1183 | | nullptr, |
1184 | | { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() }, |
1185 | | prototypes::id::InstallTriggerImpl, |
1186 | | constructors::id::InstallTriggerImpl, |
1187 | | nullptr, |
1188 | | &DefaultXrayExpandoObjectClass |
1189 | | } }; |
1190 | | |
1191 | | void |
1192 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
1193 | 0 | { |
1194 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
1195 | 0 | if (!parentProto) { |
1196 | 0 | return; |
1197 | 0 | } |
1198 | 0 | |
1199 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
1200 | 0 | if (!constructorProto) { |
1201 | 0 | return; |
1202 | 0 | } |
1203 | 0 | |
1204 | 0 | static bool sIdsInited = false; |
1205 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
1206 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
1207 | 0 | return; |
1208 | 0 | } |
1209 | 0 | if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) { |
1210 | 0 | return; |
1211 | 0 | } |
1212 | 0 | sIdsInited = true; |
1213 | 0 | } |
1214 | 0 |
|
1215 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::InstallTriggerImpl); |
1216 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::InstallTriggerImpl); |
1217 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
1218 | 0 | &sPrototypeClass.mBase, protoCache, |
1219 | 0 | nullptr, |
1220 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
1221 | 0 | interfaceCache, |
1222 | 0 | sNativeProperties.Upcast(), |
1223 | 0 | sChromeOnlyNativeProperties.Upcast(), |
1224 | 0 | "InstallTriggerImpl", aDefineOnGlobal, |
1225 | 0 | nullptr, |
1226 | 0 | false); |
1227 | 0 | } |
1228 | | |
1229 | | JSObject* |
1230 | | GetConstructorObject(JSContext* aCx) |
1231 | 0 | { |
1232 | 0 | return GetConstructorObjectHandle(aCx); |
1233 | 0 | } |
1234 | | |
1235 | | } // namespace InstallTriggerImpl_Binding |
1236 | | |
1237 | | |
1238 | | |
1239 | | bool |
1240 | | InstallTriggerImplJSImpl::Enabled(ErrorResult& aRv, JS::Realm* aRealm) |
1241 | 0 | { |
1242 | 0 | CallSetup s(this, aRv, "InstallTriggerImpl.enabled", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true); |
1243 | 0 | JSContext* cx = s.GetContext(); |
1244 | 0 | if (!cx) { |
1245 | 0 | MOZ_ASSERT(aRv.Failed()); |
1246 | 0 | return bool(0); |
1247 | 0 | } |
1248 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
1249 | 0 |
|
1250 | 0 | JS::Rooted<JS::Value> callable(cx); |
1251 | 0 | InstallTriggerImplAtoms* atomsCache = GetAtomCache<InstallTriggerImplAtoms>(cx); |
1252 | 0 | if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) || |
1253 | 0 | !GetCallableProperty(cx, atomsCache->enabled_id, &callable)) { |
1254 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1255 | 0 | return bool(0); |
1256 | 0 | } |
1257 | 0 | JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback)); |
1258 | 0 | if (!JS::Call(cx, thisValue, callable, |
1259 | 0 | JS::HandleValueArray::empty(), &rval)) { |
1260 | 0 | aRv.NoteJSContextException(cx); |
1261 | 0 | return bool(0); |
1262 | 0 | } |
1263 | 0 | bool rvalDecl; |
1264 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, rval, &rvalDecl)) { |
1265 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1266 | 0 | return bool(0); |
1267 | 0 | } |
1268 | 0 | return rvalDecl; |
1269 | 0 | } |
1270 | | |
1271 | | bool |
1272 | | InstallTriggerImplJSImpl::UpdateEnabled(ErrorResult& aRv, JS::Realm* aRealm) |
1273 | 0 | { |
1274 | 0 | CallSetup s(this, aRv, "InstallTriggerImpl.updateEnabled", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true); |
1275 | 0 | JSContext* cx = s.GetContext(); |
1276 | 0 | if (!cx) { |
1277 | 0 | MOZ_ASSERT(aRv.Failed()); |
1278 | 0 | return bool(0); |
1279 | 0 | } |
1280 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
1281 | 0 |
|
1282 | 0 | JS::Rooted<JS::Value> callable(cx); |
1283 | 0 | InstallTriggerImplAtoms* atomsCache = GetAtomCache<InstallTriggerImplAtoms>(cx); |
1284 | 0 | if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) || |
1285 | 0 | !GetCallableProperty(cx, atomsCache->updateEnabled_id, &callable)) { |
1286 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1287 | 0 | return bool(0); |
1288 | 0 | } |
1289 | 0 | JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback)); |
1290 | 0 | if (!JS::Call(cx, thisValue, callable, |
1291 | 0 | JS::HandleValueArray::empty(), &rval)) { |
1292 | 0 | aRv.NoteJSContextException(cx); |
1293 | 0 | return bool(0); |
1294 | 0 | } |
1295 | 0 | bool rvalDecl; |
1296 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, rval, &rvalDecl)) { |
1297 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1298 | 0 | return bool(0); |
1299 | 0 | } |
1300 | 0 | return rvalDecl; |
1301 | 0 | } |
1302 | | |
1303 | | bool |
1304 | | InstallTriggerImplJSImpl::Install(const Record<nsString, OwningStringOrInstallTriggerData>& installs, const Optional<OwningNonNull<InstallTriggerCallback>>& callback, ErrorResult& aRv, JS::Realm* aRealm) |
1305 | 0 | { |
1306 | 0 | CallSetup s(this, aRv, "InstallTriggerImpl.install", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true); |
1307 | 0 | JSContext* cx = s.GetContext(); |
1308 | 0 | if (!cx) { |
1309 | 0 | MOZ_ASSERT(aRv.Failed()); |
1310 | 0 | return bool(0); |
1311 | 0 | } |
1312 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
1313 | 0 | JS::AutoValueVector argv(cx); |
1314 | 0 | if (!argv.resize(2)) { |
1315 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
1316 | 0 | return bool(0); |
1317 | 0 | } |
1318 | 0 | unsigned argc = 2; |
1319 | 0 |
|
1320 | 0 | do { |
1321 | 0 | if (callback.WasPassed()) { |
1322 | 0 | argv[1].setObjectOrNull(GetCallbackFromCallbackObject(cx, callback.Value())); |
1323 | 0 | if (!MaybeWrapObjectValue(cx, argv[1])) { |
1324 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1325 | 0 | return bool(0); |
1326 | 0 | } |
1327 | 0 | break; |
1328 | 0 | } else if (argc == 2) { |
1329 | 0 | // This is our current trailing argument; reduce argc |
1330 | 0 | --argc; |
1331 | 0 | } else { |
1332 | 0 | argv[1].setUndefined(); |
1333 | 0 | } |
1334 | 0 | } while (false); |
1335 | 0 |
|
1336 | 0 | do { |
1337 | 0 |
|
1338 | 0 | JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx)); |
1339 | 0 | if (!returnObj) { |
1340 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1341 | 0 | return bool(0); |
1342 | 0 | } |
1343 | 0 | // Scope for 'tmp' |
1344 | 0 | { |
1345 | 0 | JS::Rooted<JS::Value> tmp(cx); |
1346 | 0 | for (auto& entry : installs.Entries()) { |
1347 | 0 | auto& recordValue0 = entry.mValue; |
1348 | 0 | // Control block to let us common up the JS_DefineUCProperty calls when there |
1349 | 0 | // are different ways to succeed at wrapping the value. |
1350 | 0 | do { |
1351 | 0 | if (!recordValue0.ToJSVal(cx, returnObj, &tmp)) { |
1352 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1353 | 0 | return bool(0); |
1354 | 0 | } |
1355 | 0 | break; |
1356 | 0 | } while (false); |
1357 | 0 | if (!JS_DefineUCProperty(cx, returnObj, |
1358 | 0 | entry.mKey.BeginReading(), |
1359 | 0 | entry.mKey.Length(), tmp, |
1360 | 0 | JSPROP_ENUMERATE)) { |
1361 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1362 | 0 | return bool(0); |
1363 | 0 | } |
1364 | 0 | } |
1365 | 0 | } |
1366 | 0 | argv[0].setObject(*returnObj); |
1367 | 0 | break; |
1368 | 0 | } while (false); |
1369 | 0 |
|
1370 | 0 | JS::Rooted<JS::Value> callable(cx); |
1371 | 0 | InstallTriggerImplAtoms* atomsCache = GetAtomCache<InstallTriggerImplAtoms>(cx); |
1372 | 0 | if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) || |
1373 | 0 | !GetCallableProperty(cx, atomsCache->install_id, &callable)) { |
1374 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1375 | 0 | return bool(0); |
1376 | 0 | } |
1377 | 0 | JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback)); |
1378 | 0 | if (!JS::Call(cx, thisValue, callable, |
1379 | 0 | JS::HandleValueArray::subarray(argv, 0, argc), &rval)) { |
1380 | 0 | aRv.NoteJSContextException(cx); |
1381 | 0 | return bool(0); |
1382 | 0 | } |
1383 | 0 | bool rvalDecl; |
1384 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, rval, &rvalDecl)) { |
1385 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1386 | 0 | return bool(0); |
1387 | 0 | } |
1388 | 0 | return rvalDecl; |
1389 | 0 | } |
1390 | | |
1391 | | bool |
1392 | | InstallTriggerImplJSImpl::InstallChrome(uint16_t type, const nsAString& url, const nsAString& skin, ErrorResult& aRv, JS::Realm* aRealm) |
1393 | 0 | { |
1394 | 0 | CallSetup s(this, aRv, "InstallTriggerImpl.installChrome", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true); |
1395 | 0 | JSContext* cx = s.GetContext(); |
1396 | 0 | if (!cx) { |
1397 | 0 | MOZ_ASSERT(aRv.Failed()); |
1398 | 0 | return bool(0); |
1399 | 0 | } |
1400 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
1401 | 0 | JS::AutoValueVector argv(cx); |
1402 | 0 | if (!argv.resize(3)) { |
1403 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
1404 | 0 | return bool(0); |
1405 | 0 | } |
1406 | 0 | unsigned argc = 3; |
1407 | 0 |
|
1408 | 0 | do { |
1409 | 0 | nsString mutableStr(skin); |
1410 | 0 | if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[2])) { |
1411 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1412 | 0 | return bool(0); |
1413 | 0 | } |
1414 | 0 | break; |
1415 | 0 | } while (false); |
1416 | 0 |
|
1417 | 0 | do { |
1418 | 0 | nsString mutableStr(url); |
1419 | 0 | if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[1])) { |
1420 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1421 | 0 | return bool(0); |
1422 | 0 | } |
1423 | 0 | break; |
1424 | 0 | } while (false); |
1425 | 0 |
|
1426 | 0 | do { |
1427 | 0 | argv[0].setInt32(int32_t(type)); |
1428 | 0 | break; |
1429 | 0 | } while (false); |
1430 | 0 |
|
1431 | 0 | JS::Rooted<JS::Value> callable(cx); |
1432 | 0 | InstallTriggerImplAtoms* atomsCache = GetAtomCache<InstallTriggerImplAtoms>(cx); |
1433 | 0 | if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) || |
1434 | 0 | !GetCallableProperty(cx, atomsCache->installChrome_id, &callable)) { |
1435 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1436 | 0 | return bool(0); |
1437 | 0 | } |
1438 | 0 | JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback)); |
1439 | 0 | if (!JS::Call(cx, thisValue, callable, |
1440 | 0 | JS::HandleValueArray::subarray(argv, 0, argc), &rval)) { |
1441 | 0 | aRv.NoteJSContextException(cx); |
1442 | 0 | return bool(0); |
1443 | 0 | } |
1444 | 0 | bool rvalDecl; |
1445 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, rval, &rvalDecl)) { |
1446 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1447 | 0 | return bool(0); |
1448 | 0 | } |
1449 | 0 | return rvalDecl; |
1450 | 0 | } |
1451 | | |
1452 | | bool |
1453 | | InstallTriggerImplJSImpl::StartSoftwareUpdate(const nsAString& url, const Optional<uint16_t>& flags, ErrorResult& aRv, JS::Realm* aRealm) |
1454 | 0 | { |
1455 | 0 | CallSetup s(this, aRv, "InstallTriggerImpl.startSoftwareUpdate", eRethrowContentExceptions, aRealm, /* aIsJSImplementedWebIDL = */ true); |
1456 | 0 | JSContext* cx = s.GetContext(); |
1457 | 0 | if (!cx) { |
1458 | 0 | MOZ_ASSERT(aRv.Failed()); |
1459 | 0 | return bool(0); |
1460 | 0 | } |
1461 | 0 | JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); |
1462 | 0 | JS::AutoValueVector argv(cx); |
1463 | 0 | if (!argv.resize(2)) { |
1464 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
1465 | 0 | return bool(0); |
1466 | 0 | } |
1467 | 0 | unsigned argc = 2; |
1468 | 0 |
|
1469 | 0 | do { |
1470 | 0 | if (flags.WasPassed()) { |
1471 | 0 | argv[1].setInt32(int32_t(flags.Value())); |
1472 | 0 | break; |
1473 | 0 | } else if (argc == 2) { |
1474 | 0 | // This is our current trailing argument; reduce argc |
1475 | 0 | --argc; |
1476 | 0 | } else { |
1477 | 0 | argv[1].setUndefined(); |
1478 | 0 | } |
1479 | 0 | } while (false); |
1480 | 0 |
|
1481 | 0 | do { |
1482 | 0 | nsString mutableStr(url); |
1483 | 0 | if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) { |
1484 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1485 | 0 | return bool(0); |
1486 | 0 | } |
1487 | 0 | break; |
1488 | 0 | } while (false); |
1489 | 0 |
|
1490 | 0 | JS::Rooted<JS::Value> callable(cx); |
1491 | 0 | InstallTriggerImplAtoms* atomsCache = GetAtomCache<InstallTriggerImplAtoms>(cx); |
1492 | 0 | if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) || |
1493 | 0 | !GetCallableProperty(cx, atomsCache->startSoftwareUpdate_id, &callable)) { |
1494 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1495 | 0 | return bool(0); |
1496 | 0 | } |
1497 | 0 | JS::Rooted<JS::Value> thisValue(cx, JS::ObjectValue(*mCallback)); |
1498 | 0 | if (!JS::Call(cx, thisValue, callable, |
1499 | 0 | JS::HandleValueArray::subarray(argv, 0, argc), &rval)) { |
1500 | 0 | aRv.NoteJSContextException(cx); |
1501 | 0 | return bool(0); |
1502 | 0 | } |
1503 | 0 | bool rvalDecl; |
1504 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, rval, &rvalDecl)) { |
1505 | 0 | aRv.Throw(NS_ERROR_UNEXPECTED); |
1506 | 0 | return bool(0); |
1507 | 0 | } |
1508 | 0 | return rvalDecl; |
1509 | 0 | } |
1510 | | |
1511 | | bool |
1512 | | InstallTriggerImplJSImpl::InitIds(JSContext* cx, InstallTriggerImplAtoms* atomsCache) |
1513 | 0 | { |
1514 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
1515 | 0 |
|
1516 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
1517 | 0 | // uninitialized. |
1518 | 0 | if (!atomsCache->startSoftwareUpdate_id.init(cx, "startSoftwareUpdate") || |
1519 | 0 | !atomsCache->installChrome_id.init(cx, "installChrome") || |
1520 | 0 | !atomsCache->install_id.init(cx, "install") || |
1521 | 0 | !atomsCache->updateEnabled_id.init(cx, "updateEnabled") || |
1522 | 0 | !atomsCache->enabled_id.init(cx, "enabled")) { |
1523 | 0 | return false; |
1524 | 0 | } |
1525 | 0 | return true; |
1526 | 0 | } |
1527 | | |
1528 | | |
1529 | | |
1530 | | NS_IMPL_CYCLE_COLLECTION_CLASS(InstallTriggerImpl) |
1531 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(InstallTriggerImpl) |
1532 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK(mImpl) |
1533 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent) |
1534 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER |
1535 | 0 | tmp->ClearWeakReferences(); |
1536 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_END |
1537 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(InstallTriggerImpl) |
1538 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mImpl) |
1539 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent) |
1540 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
1541 | | NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(InstallTriggerImpl) |
1542 | | NS_IMPL_CYCLE_COLLECTING_ADDREF(InstallTriggerImpl) |
1543 | | NS_IMPL_CYCLE_COLLECTING_RELEASE(InstallTriggerImpl) |
1544 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(InstallTriggerImpl) |
1545 | 0 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
1546 | 0 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
1547 | 0 | NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) |
1548 | 0 | NS_INTERFACE_MAP_END |
1549 | | |
1550 | | InstallTriggerImpl::InstallTriggerImpl(JS::Handle<JSObject*> aJSImplObject, JS::Handle<JSObject*> aJSImplGlobal, nsIGlobalObject* aParent) |
1551 | | : mImpl(new InstallTriggerImplJSImpl(nullptr, aJSImplObject, aJSImplGlobal, /* aIncumbentGlobal = */ nullptr)), |
1552 | | mParent(aParent) |
1553 | 0 | { |
1554 | 0 | } |
1555 | | |
1556 | | |
1557 | | InstallTriggerImpl::~InstallTriggerImpl() |
1558 | 0 | { |
1559 | 0 | } |
1560 | | |
1561 | | nsISupports* |
1562 | | InstallTriggerImpl::GetParentObject() const |
1563 | 0 | { |
1564 | 0 | return mParent; |
1565 | 0 | } |
1566 | | |
1567 | | JSObject* |
1568 | | InstallTriggerImpl::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
1569 | 0 | { |
1570 | 0 | JS::Rooted<JSObject*> obj(aCx, InstallTriggerImpl_Binding::Wrap(aCx, this, aGivenProto)); |
1571 | 0 | if (!obj) { |
1572 | 0 | return nullptr; |
1573 | 0 | } |
1574 | 0 | |
1575 | 0 | // Now define it on our chrome object |
1576 | 0 | JSAutoRealm ar(aCx, mImpl->CallbackGlobalOrNull()); |
1577 | 0 | if (!JS_WrapObject(aCx, &obj)) { |
1578 | 0 | return nullptr; |
1579 | 0 | } |
1580 | 0 | if (!JS_DefineProperty(aCx, mImpl->CallbackOrNull(), "__DOM_IMPL__", obj, 0)) { |
1581 | 0 | return nullptr; |
1582 | 0 | } |
1583 | 0 | return obj; |
1584 | 0 | } |
1585 | | |
1586 | | bool |
1587 | | InstallTriggerImpl::Enabled(ErrorResult& aRv, JS::Realm* aRealm) |
1588 | 0 | { |
1589 | 0 | return mImpl->Enabled(aRv, aRealm); |
1590 | 0 | } |
1591 | | |
1592 | | bool |
1593 | | InstallTriggerImpl::UpdateEnabled(ErrorResult& aRv, JS::Realm* aRealm) |
1594 | 0 | { |
1595 | 0 | return mImpl->UpdateEnabled(aRv, aRealm); |
1596 | 0 | } |
1597 | | |
1598 | | bool |
1599 | | InstallTriggerImpl::Install(const Record<nsString, OwningStringOrInstallTriggerData>& installs, const Optional<OwningNonNull<InstallTriggerCallback>>& callback, ErrorResult& aRv, JS::Realm* aRealm) |
1600 | 0 | { |
1601 | 0 | return mImpl->Install(installs, callback, aRv, aRealm); |
1602 | 0 | } |
1603 | | |
1604 | | bool |
1605 | | InstallTriggerImpl::InstallChrome(uint16_t type, const nsAString& url, const nsAString& skin, ErrorResult& aRv, JS::Realm* aRealm) |
1606 | 0 | { |
1607 | 0 | return mImpl->InstallChrome(type, url, skin, aRv, aRealm); |
1608 | 0 | } |
1609 | | |
1610 | | bool |
1611 | | InstallTriggerImpl::StartSoftwareUpdate(const nsAString& url, const Optional<uint16_t>& flags, ErrorResult& aRv, JS::Realm* aRealm) |
1612 | 0 | { |
1613 | 0 | return mImpl->StartSoftwareUpdate(url, flags, aRv, aRealm); |
1614 | 0 | } |
1615 | | |
1616 | | bool |
1617 | | InstallTriggerImpl::_Create(JSContext* cx, unsigned argc, JS::Value* vp) |
1618 | 0 | { |
1619 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
1620 | 0 | if (args.length() < 2) { |
1621 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "InstallTriggerImpl._create"); |
1622 | 0 | } |
1623 | 0 | if (!args[0].isObject()) { |
1624 | 0 | return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of InstallTriggerImpl._create"); |
1625 | 0 | } |
1626 | 0 | if (!args[1].isObject()) { |
1627 | 0 | return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of InstallTriggerImpl._create"); |
1628 | 0 | } |
1629 | 0 | |
1630 | 0 | // GlobalObject will go through wrappers as needed for us, and |
1631 | 0 | // is simpler than the right UnwrapArg incantation. |
1632 | 0 | GlobalObject global(cx, &args[0].toObject()); |
1633 | 0 | if (global.Failed()) { |
1634 | 0 | return false; |
1635 | 0 | } |
1636 | 0 | nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(global.GetAsSupports()); |
1637 | 0 | MOZ_ASSERT(globalHolder); |
1638 | 0 | JS::Rooted<JSObject*> arg(cx, &args[1].toObject()); |
1639 | 0 | JS::Rooted<JSObject*> argGlobal(cx, JS::CurrentGlobalOrNull(cx)); |
1640 | 0 | RefPtr<InstallTriggerImpl> impl = new InstallTriggerImpl(arg, argGlobal, globalHolder); |
1641 | 0 | MOZ_ASSERT(js::IsObjectInContextCompartment(arg, cx)); |
1642 | 0 | return GetOrCreateDOMReflector(cx, impl, args.rval()); |
1643 | 0 | } |
1644 | | |
1645 | | |
1646 | | } // namespace dom |
1647 | | } // namespace mozilla |