/work/obj-fuzz/dom/bindings/WorkerNavigatorBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM WorkerNavigator.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "WorkerNavigatorBinding.h" |
4 | | #include "WrapperFactory.h" |
5 | | #include "mozilla/OwningNonNull.h" |
6 | | #include "mozilla/dom/BindingUtils.h" |
7 | | #include "mozilla/dom/DOMJSClass.h" |
8 | | #include "mozilla/dom/DOMPrefs.h" |
9 | | #include "mozilla/dom/MediaCapabilities.h" |
10 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
11 | | #include "mozilla/dom/Nullable.h" |
12 | | #include "mozilla/dom/PrimitiveConversions.h" |
13 | | #include "mozilla/dom/StorageManager.h" |
14 | | #include "mozilla/dom/WorkerNavigator.h" |
15 | | #include "mozilla/dom/network/Connection.h" |
16 | | #include "nsContentUtils.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 | | namespace WorkerNavigator_Binding { |
26 | | |
27 | | MOZ_CAN_RUN_SCRIPT static bool |
28 | | get_connection(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerNavigator* self, JSJitGetterCallArgs args) |
29 | 0 | { |
30 | 0 | AUTO_PROFILER_LABEL_FAST("get WorkerNavigator.connection", DOM, cx); |
31 | 0 |
|
32 | 0 | FastErrorResult rv; |
33 | 0 | auto result(StrongOrRawPtr<mozilla::dom::network::Connection>(self->GetConnection(rv))); |
34 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
35 | 0 | return false; |
36 | 0 | } |
37 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
38 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
39 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
40 | 0 | return false; |
41 | 0 | } |
42 | 0 | return true; |
43 | 0 | } |
44 | | |
45 | | static const JSJitInfo connection_getterinfo = { |
46 | | { (JSJitGetterOp)get_connection }, |
47 | | { prototypes::id::WorkerNavigator }, |
48 | | { PrototypeTraits<prototypes::id::WorkerNavigator>::Depth }, |
49 | | JSJitInfo::Getter, |
50 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
51 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
52 | | false, /* isInfallible. False in setters. */ |
53 | | false, /* isMovable. Not relevant for setters. */ |
54 | | false, /* isEliminatable. Not relevant for setters. */ |
55 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
56 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
57 | | false, /* isTypedMethod. Only relevant for methods. */ |
58 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
59 | | }; |
60 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
61 | | static_assert(0 < 9, "There is no slot for us"); |
62 | | |
63 | | MOZ_CAN_RUN_SCRIPT static bool |
64 | | get_mediaCapabilities(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerNavigator* self, JSJitGetterCallArgs args) |
65 | 0 | { |
66 | 0 | AUTO_PROFILER_LABEL_FAST("get WorkerNavigator.mediaCapabilities", DOM, cx); |
67 | 0 |
|
68 | 0 | auto result(StrongOrRawPtr<mozilla::dom::MediaCapabilities>(self->MediaCapabilities())); |
69 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
70 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
71 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
72 | 0 | return false; |
73 | 0 | } |
74 | 0 | return true; |
75 | 0 | } |
76 | | |
77 | | static const JSJitInfo mediaCapabilities_getterinfo = { |
78 | | { (JSJitGetterOp)get_mediaCapabilities }, |
79 | | { prototypes::id::WorkerNavigator }, |
80 | | { PrototypeTraits<prototypes::id::WorkerNavigator>::Depth }, |
81 | | JSJitInfo::Getter, |
82 | | JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */ |
83 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
84 | | false, /* isInfallible. False in setters. */ |
85 | | true, /* isMovable. Not relevant for setters. */ |
86 | | true, /* isEliminatable. Not relevant for setters. */ |
87 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
88 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
89 | | false, /* isTypedMethod. Only relevant for methods. */ |
90 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
91 | | }; |
92 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
93 | | static_assert(0 < 9, "There is no slot for us"); |
94 | | |
95 | | MOZ_CAN_RUN_SCRIPT static bool |
96 | | get_hardwareConcurrency(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerNavigator* self, JSJitGetterCallArgs args) |
97 | 0 | { |
98 | 0 | AUTO_PROFILER_LABEL_FAST("get WorkerNavigator.hardwareConcurrency", DOM, cx); |
99 | 0 |
|
100 | 0 | uint64_t result(self->HardwareConcurrency()); |
101 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
102 | 0 | args.rval().set(JS_NumberValue(double(result))); |
103 | 0 | return true; |
104 | 0 | } |
105 | | |
106 | | static const JSJitInfo hardwareConcurrency_getterinfo = { |
107 | | { (JSJitGetterOp)get_hardwareConcurrency }, |
108 | | { prototypes::id::WorkerNavigator }, |
109 | | { PrototypeTraits<prototypes::id::WorkerNavigator>::Depth }, |
110 | | JSJitInfo::Getter, |
111 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
112 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
113 | | true, /* isInfallible. False in setters. */ |
114 | | false, /* isMovable. Not relevant for setters. */ |
115 | | false, /* isEliminatable. Not relevant for setters. */ |
116 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
117 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
118 | | false, /* isTypedMethod. Only relevant for methods. */ |
119 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
120 | | }; |
121 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
122 | | static_assert(0 < 9, "There is no slot for us"); |
123 | | |
124 | | MOZ_CAN_RUN_SCRIPT static bool |
125 | | get_appCodeName(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerNavigator* self, JSJitGetterCallArgs args) |
126 | 0 | { |
127 | 0 | AUTO_PROFILER_LABEL_FAST("get WorkerNavigator.appCodeName", DOM, cx); |
128 | 0 |
|
129 | 0 | // Have to either root across the getter call or reget after. |
130 | 0 | JS::Rooted<JSObject*> slotStorage(cx, js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false)); |
131 | 0 | MOZ_ASSERT(IsDOMObject(slotStorage)); |
132 | 0 | const size_t slotIndex = (DOM_INSTANCE_RESERVED_SLOTS + 0); |
133 | 0 | MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex); |
134 | 0 | { |
135 | 0 | // Scope for cachedVal |
136 | 0 | JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex); |
137 | 0 | if (!cachedVal.isUndefined()) { |
138 | 0 | args.rval().set(cachedVal); |
139 | 0 | // The cached value is in the compartment of slotStorage, |
140 | 0 | // so wrap into the caller compartment as needed. |
141 | 0 | if (MaybeWrapValue(cx, args.rval())) { |
142 | 0 | return true; |
143 | 0 | } |
144 | 0 | return false; |
145 | 0 | } |
146 | 0 | } |
147 | 0 | |
148 | 0 | FastErrorResult rv; |
149 | 0 | DOMString result; |
150 | 0 | self->GetAppCodeName(result, rv); |
151 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
152 | 0 | return false; |
153 | 0 | } |
154 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
155 | 0 | { |
156 | 0 | JS::Rooted<JSObject*> conversionScope(cx, slotStorage); |
157 | 0 | JSAutoRealm ar(cx, conversionScope); |
158 | 0 | do { // block we break out of when done wrapping |
159 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
160 | 0 | return false; |
161 | 0 | } |
162 | 0 | break; |
163 | 0 | } while (false); |
164 | 0 | } |
165 | 0 | { // And now store things in the realm of our slotStorage. |
166 | 0 | JSAutoRealm ar(cx, slotStorage); |
167 | 0 | // Make a copy so that we don't do unnecessary wrapping on args.rval(). |
168 | 0 | JS::Rooted<JS::Value> storedVal(cx, args.rval()); |
169 | 0 | if (!MaybeWrapValue(cx, &storedVal)) { |
170 | 0 | return false; |
171 | 0 | } |
172 | 0 | js::SetReservedSlot(slotStorage, slotIndex, storedVal); |
173 | 0 | PreserveWrapper(self); |
174 | 0 | } |
175 | 0 | // And now make sure args.rval() is in the caller realm. |
176 | 0 | if (MaybeWrapValue(cx, args.rval())) { |
177 | 0 | return true; |
178 | 0 | } |
179 | 0 | return false; |
180 | 0 | } |
181 | | |
182 | | static const JSJitInfo appCodeName_getterinfo = { |
183 | | { (JSJitGetterOp)get_appCodeName }, |
184 | | { prototypes::id::WorkerNavigator }, |
185 | | { PrototypeTraits<prototypes::id::WorkerNavigator>::Depth }, |
186 | | JSJitInfo::Getter, |
187 | | JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */ |
188 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
189 | | false, /* isInfallible. False in setters. */ |
190 | | false, /* isMovable. Not relevant for setters. */ |
191 | | false, /* isEliminatable. Not relevant for setters. */ |
192 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
193 | | true, /* isLazilyCachedInSlot. Only relevant for getters. */ |
194 | | false, /* isTypedMethod. Only relevant for methods. */ |
195 | | (DOM_INSTANCE_RESERVED_SLOTS + 0) /* Reserved slot index, if we're stored in a slot, else 0. */ |
196 | | }; |
197 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) <= JSJitInfo::maxSlotIndex, "We won't fit"); |
198 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) < 9, "There is no slot for us"); |
199 | | |
200 | | MOZ_CAN_RUN_SCRIPT static bool |
201 | | get_appName(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerNavigator* self, JSJitGetterCallArgs args) |
202 | 0 | { |
203 | 0 | AUTO_PROFILER_LABEL_FAST("get WorkerNavigator.appName", DOM, cx); |
204 | 0 |
|
205 | 0 | // Have to either root across the getter call or reget after. |
206 | 0 | JS::Rooted<JSObject*> slotStorage(cx, js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false)); |
207 | 0 | MOZ_ASSERT(IsDOMObject(slotStorage)); |
208 | 0 | const size_t slotIndex = (DOM_INSTANCE_RESERVED_SLOTS + 1); |
209 | 0 | MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex); |
210 | 0 | { |
211 | 0 | // Scope for cachedVal |
212 | 0 | JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex); |
213 | 0 | if (!cachedVal.isUndefined()) { |
214 | 0 | args.rval().set(cachedVal); |
215 | 0 | // The cached value is in the compartment of slotStorage, |
216 | 0 | // so wrap into the caller compartment as needed. |
217 | 0 | if (MaybeWrapValue(cx, args.rval())) { |
218 | 0 | return true; |
219 | 0 | } |
220 | 0 | return false; |
221 | 0 | } |
222 | 0 | } |
223 | 0 | |
224 | 0 | DOMString result; |
225 | 0 | self->GetAppName(result, nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem); |
226 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
227 | 0 | { |
228 | 0 | JS::Rooted<JSObject*> conversionScope(cx, slotStorage); |
229 | 0 | JSAutoRealm ar(cx, conversionScope); |
230 | 0 | do { // block we break out of when done wrapping |
231 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
232 | 0 | return false; |
233 | 0 | } |
234 | 0 | break; |
235 | 0 | } while (false); |
236 | 0 | } |
237 | 0 | { // And now store things in the realm of our slotStorage. |
238 | 0 | JSAutoRealm ar(cx, slotStorage); |
239 | 0 | // Make a copy so that we don't do unnecessary wrapping on args.rval(). |
240 | 0 | JS::Rooted<JS::Value> storedVal(cx, args.rval()); |
241 | 0 | if (!MaybeWrapValue(cx, &storedVal)) { |
242 | 0 | return false; |
243 | 0 | } |
244 | 0 | js::SetReservedSlot(slotStorage, slotIndex, storedVal); |
245 | 0 | PreserveWrapper(self); |
246 | 0 | } |
247 | 0 | // And now make sure args.rval() is in the caller realm. |
248 | 0 | if (MaybeWrapValue(cx, args.rval())) { |
249 | 0 | return true; |
250 | 0 | } |
251 | 0 | return false; |
252 | 0 | } |
253 | | |
254 | | static const JSJitInfo appName_getterinfo = { |
255 | | { (JSJitGetterOp)get_appName }, |
256 | | { prototypes::id::WorkerNavigator }, |
257 | | { PrototypeTraits<prototypes::id::WorkerNavigator>::Depth }, |
258 | | JSJitInfo::Getter, |
259 | | JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */ |
260 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
261 | | false, /* isInfallible. False in setters. */ |
262 | | true, /* isMovable. Not relevant for setters. */ |
263 | | true, /* isEliminatable. Not relevant for setters. */ |
264 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
265 | | true, /* isLazilyCachedInSlot. Only relevant for getters. */ |
266 | | false, /* isTypedMethod. Only relevant for methods. */ |
267 | | (DOM_INSTANCE_RESERVED_SLOTS + 1) /* Reserved slot index, if we're stored in a slot, else 0. */ |
268 | | }; |
269 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 1) <= JSJitInfo::maxSlotIndex, "We won't fit"); |
270 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 1) < 9, "There is no slot for us"); |
271 | | |
272 | | MOZ_CAN_RUN_SCRIPT static bool |
273 | | get_appVersion(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerNavigator* self, JSJitGetterCallArgs args) |
274 | 0 | { |
275 | 0 | AUTO_PROFILER_LABEL_FAST("get WorkerNavigator.appVersion", DOM, cx); |
276 | 0 |
|
277 | 0 | // Have to either root across the getter call or reget after. |
278 | 0 | JS::Rooted<JSObject*> slotStorage(cx, js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false)); |
279 | 0 | MOZ_ASSERT(IsDOMObject(slotStorage)); |
280 | 0 | const size_t slotIndex = (DOM_INSTANCE_RESERVED_SLOTS + 2); |
281 | 0 | MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex); |
282 | 0 | { |
283 | 0 | // Scope for cachedVal |
284 | 0 | JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex); |
285 | 0 | if (!cachedVal.isUndefined()) { |
286 | 0 | args.rval().set(cachedVal); |
287 | 0 | // The cached value is in the compartment of slotStorage, |
288 | 0 | // so wrap into the caller compartment as needed. |
289 | 0 | if (MaybeWrapValue(cx, args.rval())) { |
290 | 0 | return true; |
291 | 0 | } |
292 | 0 | return false; |
293 | 0 | } |
294 | 0 | } |
295 | 0 | |
296 | 0 | FastErrorResult rv; |
297 | 0 | DOMString result; |
298 | 0 | self->GetAppVersion(result, nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv); |
299 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
300 | 0 | return false; |
301 | 0 | } |
302 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
303 | 0 | { |
304 | 0 | JS::Rooted<JSObject*> conversionScope(cx, slotStorage); |
305 | 0 | JSAutoRealm ar(cx, conversionScope); |
306 | 0 | do { // block we break out of when done wrapping |
307 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
308 | 0 | return false; |
309 | 0 | } |
310 | 0 | break; |
311 | 0 | } while (false); |
312 | 0 | } |
313 | 0 | { // And now store things in the realm of our slotStorage. |
314 | 0 | JSAutoRealm ar(cx, slotStorage); |
315 | 0 | // Make a copy so that we don't do unnecessary wrapping on args.rval(). |
316 | 0 | JS::Rooted<JS::Value> storedVal(cx, args.rval()); |
317 | 0 | if (!MaybeWrapValue(cx, &storedVal)) { |
318 | 0 | return false; |
319 | 0 | } |
320 | 0 | js::SetReservedSlot(slotStorage, slotIndex, storedVal); |
321 | 0 | PreserveWrapper(self); |
322 | 0 | } |
323 | 0 | // And now make sure args.rval() is in the caller realm. |
324 | 0 | if (MaybeWrapValue(cx, args.rval())) { |
325 | 0 | return true; |
326 | 0 | } |
327 | 0 | return false; |
328 | 0 | } |
329 | | |
330 | | static const JSJitInfo appVersion_getterinfo = { |
331 | | { (JSJitGetterOp)get_appVersion }, |
332 | | { prototypes::id::WorkerNavigator }, |
333 | | { PrototypeTraits<prototypes::id::WorkerNavigator>::Depth }, |
334 | | JSJitInfo::Getter, |
335 | | JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */ |
336 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
337 | | false, /* isInfallible. False in setters. */ |
338 | | false, /* isMovable. Not relevant for setters. */ |
339 | | false, /* isEliminatable. Not relevant for setters. */ |
340 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
341 | | true, /* isLazilyCachedInSlot. Only relevant for getters. */ |
342 | | false, /* isTypedMethod. Only relevant for methods. */ |
343 | | (DOM_INSTANCE_RESERVED_SLOTS + 2) /* Reserved slot index, if we're stored in a slot, else 0. */ |
344 | | }; |
345 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 2) <= JSJitInfo::maxSlotIndex, "We won't fit"); |
346 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 2) < 9, "There is no slot for us"); |
347 | | |
348 | | MOZ_CAN_RUN_SCRIPT static bool |
349 | | get_platform(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerNavigator* self, JSJitGetterCallArgs args) |
350 | 0 | { |
351 | 0 | AUTO_PROFILER_LABEL_FAST("get WorkerNavigator.platform", DOM, cx); |
352 | 0 |
|
353 | 0 | // Have to either root across the getter call or reget after. |
354 | 0 | JS::Rooted<JSObject*> slotStorage(cx, js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false)); |
355 | 0 | MOZ_ASSERT(IsDOMObject(slotStorage)); |
356 | 0 | const size_t slotIndex = (DOM_INSTANCE_RESERVED_SLOTS + 3); |
357 | 0 | MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex); |
358 | 0 | { |
359 | 0 | // Scope for cachedVal |
360 | 0 | JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex); |
361 | 0 | if (!cachedVal.isUndefined()) { |
362 | 0 | args.rval().set(cachedVal); |
363 | 0 | // The cached value is in the compartment of slotStorage, |
364 | 0 | // so wrap into the caller compartment as needed. |
365 | 0 | if (MaybeWrapValue(cx, args.rval())) { |
366 | 0 | return true; |
367 | 0 | } |
368 | 0 | return false; |
369 | 0 | } |
370 | 0 | } |
371 | 0 | |
372 | 0 | FastErrorResult rv; |
373 | 0 | DOMString result; |
374 | 0 | self->GetPlatform(result, nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv); |
375 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
376 | 0 | return false; |
377 | 0 | } |
378 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
379 | 0 | { |
380 | 0 | JS::Rooted<JSObject*> conversionScope(cx, slotStorage); |
381 | 0 | JSAutoRealm ar(cx, conversionScope); |
382 | 0 | do { // block we break out of when done wrapping |
383 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
384 | 0 | return false; |
385 | 0 | } |
386 | 0 | break; |
387 | 0 | } while (false); |
388 | 0 | } |
389 | 0 | { // And now store things in the realm of our slotStorage. |
390 | 0 | JSAutoRealm ar(cx, slotStorage); |
391 | 0 | // Make a copy so that we don't do unnecessary wrapping on args.rval(). |
392 | 0 | JS::Rooted<JS::Value> storedVal(cx, args.rval()); |
393 | 0 | if (!MaybeWrapValue(cx, &storedVal)) { |
394 | 0 | return false; |
395 | 0 | } |
396 | 0 | js::SetReservedSlot(slotStorage, slotIndex, storedVal); |
397 | 0 | PreserveWrapper(self); |
398 | 0 | } |
399 | 0 | // And now make sure args.rval() is in the caller realm. |
400 | 0 | if (MaybeWrapValue(cx, args.rval())) { |
401 | 0 | return true; |
402 | 0 | } |
403 | 0 | return false; |
404 | 0 | } |
405 | | |
406 | | static const JSJitInfo platform_getterinfo = { |
407 | | { (JSJitGetterOp)get_platform }, |
408 | | { prototypes::id::WorkerNavigator }, |
409 | | { PrototypeTraits<prototypes::id::WorkerNavigator>::Depth }, |
410 | | JSJitInfo::Getter, |
411 | | JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */ |
412 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
413 | | false, /* isInfallible. False in setters. */ |
414 | | false, /* isMovable. Not relevant for setters. */ |
415 | | false, /* isEliminatable. Not relevant for setters. */ |
416 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
417 | | true, /* isLazilyCachedInSlot. Only relevant for getters. */ |
418 | | false, /* isTypedMethod. Only relevant for methods. */ |
419 | | (DOM_INSTANCE_RESERVED_SLOTS + 3) /* Reserved slot index, if we're stored in a slot, else 0. */ |
420 | | }; |
421 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 3) <= JSJitInfo::maxSlotIndex, "We won't fit"); |
422 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 3) < 9, "There is no slot for us"); |
423 | | |
424 | | MOZ_CAN_RUN_SCRIPT static bool |
425 | | get_userAgent(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerNavigator* self, JSJitGetterCallArgs args) |
426 | 0 | { |
427 | 0 | AUTO_PROFILER_LABEL_FAST("get WorkerNavigator.userAgent", DOM, cx); |
428 | 0 |
|
429 | 0 | // Have to either root across the getter call or reget after. |
430 | 0 | JS::Rooted<JSObject*> slotStorage(cx, js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false)); |
431 | 0 | MOZ_ASSERT(IsDOMObject(slotStorage)); |
432 | 0 | const size_t slotIndex = (DOM_INSTANCE_RESERVED_SLOTS + 4); |
433 | 0 | MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex); |
434 | 0 | { |
435 | 0 | // Scope for cachedVal |
436 | 0 | JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex); |
437 | 0 | if (!cachedVal.isUndefined()) { |
438 | 0 | args.rval().set(cachedVal); |
439 | 0 | // The cached value is in the compartment of slotStorage, |
440 | 0 | // so wrap into the caller compartment as needed. |
441 | 0 | if (MaybeWrapValue(cx, args.rval())) { |
442 | 0 | return true; |
443 | 0 | } |
444 | 0 | return false; |
445 | 0 | } |
446 | 0 | } |
447 | 0 | |
448 | 0 | FastErrorResult rv; |
449 | 0 | DOMString result; |
450 | 0 | self->GetUserAgent(result, nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv); |
451 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
452 | 0 | return false; |
453 | 0 | } |
454 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
455 | 0 | { |
456 | 0 | JS::Rooted<JSObject*> conversionScope(cx, slotStorage); |
457 | 0 | JSAutoRealm ar(cx, conversionScope); |
458 | 0 | do { // block we break out of when done wrapping |
459 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
460 | 0 | return false; |
461 | 0 | } |
462 | 0 | break; |
463 | 0 | } while (false); |
464 | 0 | } |
465 | 0 | { // And now store things in the realm of our slotStorage. |
466 | 0 | JSAutoRealm ar(cx, slotStorage); |
467 | 0 | // Make a copy so that we don't do unnecessary wrapping on args.rval(). |
468 | 0 | JS::Rooted<JS::Value> storedVal(cx, args.rval()); |
469 | 0 | if (!MaybeWrapValue(cx, &storedVal)) { |
470 | 0 | return false; |
471 | 0 | } |
472 | 0 | js::SetReservedSlot(slotStorage, slotIndex, storedVal); |
473 | 0 | PreserveWrapper(self); |
474 | 0 | } |
475 | 0 | // And now make sure args.rval() is in the caller realm. |
476 | 0 | if (MaybeWrapValue(cx, args.rval())) { |
477 | 0 | return true; |
478 | 0 | } |
479 | 0 | return false; |
480 | 0 | } |
481 | | |
482 | | static const JSJitInfo userAgent_getterinfo = { |
483 | | { (JSJitGetterOp)get_userAgent }, |
484 | | { prototypes::id::WorkerNavigator }, |
485 | | { PrototypeTraits<prototypes::id::WorkerNavigator>::Depth }, |
486 | | JSJitInfo::Getter, |
487 | | JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */ |
488 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
489 | | false, /* isInfallible. False in setters. */ |
490 | | false, /* isMovable. Not relevant for setters. */ |
491 | | false, /* isEliminatable. Not relevant for setters. */ |
492 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
493 | | true, /* isLazilyCachedInSlot. Only relevant for getters. */ |
494 | | false, /* isTypedMethod. Only relevant for methods. */ |
495 | | (DOM_INSTANCE_RESERVED_SLOTS + 4) /* Reserved slot index, if we're stored in a slot, else 0. */ |
496 | | }; |
497 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 4) <= JSJitInfo::maxSlotIndex, "We won't fit"); |
498 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 4) < 9, "There is no slot for us"); |
499 | | |
500 | | MOZ_CAN_RUN_SCRIPT static bool |
501 | | get_product(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerNavigator* self, JSJitGetterCallArgs args) |
502 | 0 | { |
503 | 0 | AUTO_PROFILER_LABEL_FAST("get WorkerNavigator.product", DOM, cx); |
504 | 0 |
|
505 | 0 | // Have to either root across the getter call or reget after. |
506 | 0 | JS::Rooted<JSObject*> slotStorage(cx, js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false)); |
507 | 0 | MOZ_ASSERT(IsDOMObject(slotStorage)); |
508 | 0 | const size_t slotIndex = (DOM_INSTANCE_RESERVED_SLOTS + 5); |
509 | 0 | MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex); |
510 | 0 | { |
511 | 0 | // Scope for cachedVal |
512 | 0 | JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex); |
513 | 0 | if (!cachedVal.isUndefined()) { |
514 | 0 | args.rval().set(cachedVal); |
515 | 0 | // The cached value is in the compartment of slotStorage, |
516 | 0 | // so wrap into the caller compartment as needed. |
517 | 0 | if (MaybeWrapValue(cx, args.rval())) { |
518 | 0 | return true; |
519 | 0 | } |
520 | 0 | return false; |
521 | 0 | } |
522 | 0 | } |
523 | 0 | |
524 | 0 | DOMString result; |
525 | 0 | self->GetProduct(result); |
526 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
527 | 0 | { |
528 | 0 | JS::Rooted<JSObject*> conversionScope(cx, slotStorage); |
529 | 0 | JSAutoRealm ar(cx, conversionScope); |
530 | 0 | do { // block we break out of when done wrapping |
531 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
532 | 0 | return false; |
533 | 0 | } |
534 | 0 | break; |
535 | 0 | } while (false); |
536 | 0 | } |
537 | 0 | { // And now store things in the realm of our slotStorage. |
538 | 0 | JSAutoRealm ar(cx, slotStorage); |
539 | 0 | // Make a copy so that we don't do unnecessary wrapping on args.rval(). |
540 | 0 | JS::Rooted<JS::Value> storedVal(cx, args.rval()); |
541 | 0 | if (!MaybeWrapValue(cx, &storedVal)) { |
542 | 0 | return false; |
543 | 0 | } |
544 | 0 | js::SetReservedSlot(slotStorage, slotIndex, storedVal); |
545 | 0 | PreserveWrapper(self); |
546 | 0 | } |
547 | 0 | // And now make sure args.rval() is in the caller realm. |
548 | 0 | if (MaybeWrapValue(cx, args.rval())) { |
549 | 0 | return true; |
550 | 0 | } |
551 | 0 | return false; |
552 | 0 | } |
553 | | |
554 | | static const JSJitInfo product_getterinfo = { |
555 | | { (JSJitGetterOp)get_product }, |
556 | | { prototypes::id::WorkerNavigator }, |
557 | | { PrototypeTraits<prototypes::id::WorkerNavigator>::Depth }, |
558 | | JSJitInfo::Getter, |
559 | | JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */ |
560 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
561 | | false, /* isInfallible. False in setters. */ |
562 | | true, /* isMovable. Not relevant for setters. */ |
563 | | true, /* isEliminatable. Not relevant for setters. */ |
564 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
565 | | true, /* isLazilyCachedInSlot. Only relevant for getters. */ |
566 | | false, /* isTypedMethod. Only relevant for methods. */ |
567 | | (DOM_INSTANCE_RESERVED_SLOTS + 5) /* Reserved slot index, if we're stored in a slot, else 0. */ |
568 | | }; |
569 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 5) <= JSJitInfo::maxSlotIndex, "We won't fit"); |
570 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 5) < 9, "There is no slot for us"); |
571 | | |
572 | | MOZ_CAN_RUN_SCRIPT static bool |
573 | | taintEnabled(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerNavigator* self, const JSJitMethodCallArgs& args) |
574 | 0 | { |
575 | 0 | AUTO_PROFILER_LABEL_FAST("WorkerNavigator.taintEnabled", DOM, cx); |
576 | 0 |
|
577 | 0 | bool result(self->TaintEnabled()); |
578 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
579 | 0 | args.rval().setBoolean(result); |
580 | 0 | return true; |
581 | 0 | } |
582 | | |
583 | | static const JSJitInfo taintEnabled_methodinfo = { |
584 | | { (JSJitGetterOp)taintEnabled }, |
585 | | { prototypes::id::WorkerNavigator }, |
586 | | { PrototypeTraits<prototypes::id::WorkerNavigator>::Depth }, |
587 | | JSJitInfo::Method, |
588 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
589 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
590 | | true, /* isInfallible. False in setters. */ |
591 | | false, /* isMovable. Not relevant for setters. */ |
592 | | false, /* isEliminatable. Not relevant for setters. */ |
593 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
594 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
595 | | false, /* isTypedMethod. Only relevant for methods. */ |
596 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
597 | | }; |
598 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
599 | | static_assert(0 < 9, "There is no slot for us"); |
600 | | |
601 | | MOZ_CAN_RUN_SCRIPT static bool |
602 | | get_language(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerNavigator* self, JSJitGetterCallArgs args) |
603 | 0 | { |
604 | 0 | AUTO_PROFILER_LABEL_FAST("get WorkerNavigator.language", DOM, cx); |
605 | 0 |
|
606 | 0 | // Have to either root across the getter call or reget after. |
607 | 0 | JS::Rooted<JSObject*> slotStorage(cx, js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false)); |
608 | 0 | MOZ_ASSERT(IsDOMObject(slotStorage)); |
609 | 0 | const size_t slotIndex = (DOM_INSTANCE_RESERVED_SLOTS + 6); |
610 | 0 | MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex); |
611 | 0 | { |
612 | 0 | // Scope for cachedVal |
613 | 0 | JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex); |
614 | 0 | if (!cachedVal.isUndefined()) { |
615 | 0 | args.rval().set(cachedVal); |
616 | 0 | // The cached value is in the compartment of slotStorage, |
617 | 0 | // so wrap into the caller compartment as needed. |
618 | 0 | if (MaybeWrapValue(cx, args.rval())) { |
619 | 0 | return true; |
620 | 0 | } |
621 | 0 | return false; |
622 | 0 | } |
623 | 0 | } |
624 | 0 | |
625 | 0 | DOMString result; |
626 | 0 | self->GetLanguage(result); |
627 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
628 | 0 | { |
629 | 0 | JS::Rooted<JSObject*> conversionScope(cx, slotStorage); |
630 | 0 | JSAutoRealm ar(cx, conversionScope); |
631 | 0 | do { // block we break out of when done wrapping |
632 | 0 | if (!xpc::StringToJsval(cx, result, args.rval())) { |
633 | 0 | return false; |
634 | 0 | } |
635 | 0 | break; |
636 | 0 | } while (false); |
637 | 0 | } |
638 | 0 | { // And now store things in the realm of our slotStorage. |
639 | 0 | JSAutoRealm ar(cx, slotStorage); |
640 | 0 | // Make a copy so that we don't do unnecessary wrapping on args.rval(). |
641 | 0 | JS::Rooted<JS::Value> storedVal(cx, args.rval()); |
642 | 0 | if (!MaybeWrapValue(cx, &storedVal)) { |
643 | 0 | return false; |
644 | 0 | } |
645 | 0 | js::SetReservedSlot(slotStorage, slotIndex, storedVal); |
646 | 0 | PreserveWrapper(self); |
647 | 0 | } |
648 | 0 | // And now make sure args.rval() is in the caller realm. |
649 | 0 | if (MaybeWrapValue(cx, args.rval())) { |
650 | 0 | return true; |
651 | 0 | } |
652 | 0 | return false; |
653 | 0 | } |
654 | | |
655 | | static const JSJitInfo language_getterinfo = { |
656 | | { (JSJitGetterOp)get_language }, |
657 | | { prototypes::id::WorkerNavigator }, |
658 | | { PrototypeTraits<prototypes::id::WorkerNavigator>::Depth }, |
659 | | JSJitInfo::Getter, |
660 | | JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */ |
661 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
662 | | false, /* isInfallible. False in setters. */ |
663 | | true, /* isMovable. Not relevant for setters. */ |
664 | | true, /* isEliminatable. Not relevant for setters. */ |
665 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
666 | | true, /* isLazilyCachedInSlot. Only relevant for getters. */ |
667 | | false, /* isTypedMethod. Only relevant for methods. */ |
668 | | (DOM_INSTANCE_RESERVED_SLOTS + 6) /* Reserved slot index, if we're stored in a slot, else 0. */ |
669 | | }; |
670 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 6) <= JSJitInfo::maxSlotIndex, "We won't fit"); |
671 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 6) < 9, "There is no slot for us"); |
672 | | |
673 | | MOZ_CAN_RUN_SCRIPT static bool |
674 | | get_languages(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerNavigator* self, JSJitGetterCallArgs args) |
675 | 0 | { |
676 | 0 | AUTO_PROFILER_LABEL_FAST("get WorkerNavigator.languages", DOM, cx); |
677 | 0 |
|
678 | 0 | // Have to either root across the getter call or reget after. |
679 | 0 | JS::Rooted<JSObject*> slotStorage(cx, js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false)); |
680 | 0 | MOZ_ASSERT(IsDOMObject(slotStorage)); |
681 | 0 | const size_t slotIndex = (DOM_INSTANCE_RESERVED_SLOTS + 7); |
682 | 0 | MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex); |
683 | 0 | { |
684 | 0 | // Scope for cachedVal |
685 | 0 | JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex); |
686 | 0 | if (!cachedVal.isUndefined()) { |
687 | 0 | args.rval().set(cachedVal); |
688 | 0 | // The cached value is in the compartment of slotStorage, |
689 | 0 | // so wrap into the caller compartment as needed. |
690 | 0 | if (MaybeWrapNonDOMObjectValue(cx, args.rval())) { |
691 | 0 | return true; |
692 | 0 | } |
693 | 0 | return false; |
694 | 0 | } |
695 | 0 | } |
696 | 0 | |
697 | 0 | nsTArray<nsString> result; |
698 | 0 | self->GetLanguages(result); |
699 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
700 | 0 | { |
701 | 0 | JS::Rooted<JSObject*> conversionScope(cx, slotStorage); |
702 | 0 | JSAutoRealm ar(cx, conversionScope); |
703 | 0 | do { // block we break out of when done wrapping |
704 | 0 |
|
705 | 0 | uint32_t length = result.Length(); |
706 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
707 | 0 | if (!returnArray) { |
708 | 0 | return false; |
709 | 0 | } |
710 | 0 | // Scope for 'tmp' |
711 | 0 | { |
712 | 0 | JS::Rooted<JS::Value> tmp(cx); |
713 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
714 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
715 | 0 | // are different ways to succeed at wrapping the object. |
716 | 0 | do { |
717 | 0 | if (!xpc::NonVoidStringToJsval(cx, result[sequenceIdx0], &tmp)) { |
718 | 0 | return false; |
719 | 0 | } |
720 | 0 | break; |
721 | 0 | } while (false); |
722 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
723 | 0 | JSPROP_ENUMERATE)) { |
724 | 0 | return false; |
725 | 0 | } |
726 | 0 | } |
727 | 0 | } |
728 | 0 | args.rval().setObject(*returnArray); |
729 | 0 | break; |
730 | 0 | } while (false); |
731 | 0 | JS::Rooted<JSObject*> rvalObj(cx, &args.rval().toObject()); |
732 | 0 | if (!JS_FreezeObject(cx, rvalObj)) { |
733 | 0 | return false; |
734 | 0 | } |
735 | 0 | } |
736 | 0 | { // And now store things in the realm of our slotStorage. |
737 | 0 | JSAutoRealm ar(cx, slotStorage); |
738 | 0 | // Make a copy so that we don't do unnecessary wrapping on args.rval(). |
739 | 0 | JS::Rooted<JS::Value> storedVal(cx, args.rval()); |
740 | 0 | if (!MaybeWrapNonDOMObjectValue(cx, &storedVal)) { |
741 | 0 | return false; |
742 | 0 | } |
743 | 0 | js::SetReservedSlot(slotStorage, slotIndex, storedVal); |
744 | 0 | PreserveWrapper(self); |
745 | 0 | } |
746 | 0 | // And now make sure args.rval() is in the caller realm. |
747 | 0 | if (MaybeWrapNonDOMObjectValue(cx, args.rval())) { |
748 | 0 | return true; |
749 | 0 | } |
750 | 0 | return false; |
751 | 0 | } |
752 | | |
753 | | static const JSJitInfo languages_getterinfo = { |
754 | | { (JSJitGetterOp)get_languages }, |
755 | | { prototypes::id::WorkerNavigator }, |
756 | | { PrototypeTraits<prototypes::id::WorkerNavigator>::Depth }, |
757 | | JSJitInfo::Getter, |
758 | | JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */ |
759 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
760 | | false, /* isInfallible. False in setters. */ |
761 | | true, /* isMovable. Not relevant for setters. */ |
762 | | true, /* isEliminatable. Not relevant for setters. */ |
763 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
764 | | true, /* isLazilyCachedInSlot. Only relevant for getters. */ |
765 | | false, /* isTypedMethod. Only relevant for methods. */ |
766 | | (DOM_INSTANCE_RESERVED_SLOTS + 7) /* Reserved slot index, if we're stored in a slot, else 0. */ |
767 | | }; |
768 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 7) <= JSJitInfo::maxSlotIndex, "We won't fit"); |
769 | | static_assert((DOM_INSTANCE_RESERVED_SLOTS + 7) < 9, "There is no slot for us"); |
770 | | |
771 | | MOZ_CAN_RUN_SCRIPT static bool |
772 | | get_onLine(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerNavigator* self, JSJitGetterCallArgs args) |
773 | 0 | { |
774 | 0 | AUTO_PROFILER_LABEL_FAST("get WorkerNavigator.onLine", DOM, cx); |
775 | 0 |
|
776 | 0 | bool result(self->OnLine()); |
777 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
778 | 0 | args.rval().setBoolean(result); |
779 | 0 | return true; |
780 | 0 | } |
781 | | |
782 | | static const JSJitInfo onLine_getterinfo = { |
783 | | { (JSJitGetterOp)get_onLine }, |
784 | | { prototypes::id::WorkerNavigator }, |
785 | | { PrototypeTraits<prototypes::id::WorkerNavigator>::Depth }, |
786 | | JSJitInfo::Getter, |
787 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
788 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
789 | | true, /* isInfallible. False in setters. */ |
790 | | false, /* isMovable. Not relevant for setters. */ |
791 | | false, /* isEliminatable. Not relevant for setters. */ |
792 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
793 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
794 | | false, /* isTypedMethod. Only relevant for methods. */ |
795 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
796 | | }; |
797 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
798 | | static_assert(0 < 9, "There is no slot for us"); |
799 | | |
800 | | MOZ_CAN_RUN_SCRIPT static bool |
801 | | get_storage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerNavigator* self, JSJitGetterCallArgs args) |
802 | 0 | { |
803 | 0 | AUTO_PROFILER_LABEL_FAST("get WorkerNavigator.storage", DOM, cx); |
804 | 0 |
|
805 | 0 | auto result(StrongOrRawPtr<mozilla::dom::StorageManager>(self->Storage())); |
806 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
807 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
808 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
809 | 0 | return false; |
810 | 0 | } |
811 | 0 | return true; |
812 | 0 | } |
813 | | |
814 | | static const JSJitInfo storage_getterinfo = { |
815 | | { (JSJitGetterOp)get_storage }, |
816 | | { prototypes::id::WorkerNavigator }, |
817 | | { PrototypeTraits<prototypes::id::WorkerNavigator>::Depth }, |
818 | | JSJitInfo::Getter, |
819 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
820 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
821 | | false, /* isInfallible. False in setters. */ |
822 | | false, /* isMovable. Not relevant for setters. */ |
823 | | false, /* isEliminatable. Not relevant for setters. */ |
824 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
825 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
826 | | false, /* isTypedMethod. Only relevant for methods. */ |
827 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
828 | | }; |
829 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
830 | | static_assert(0 < 9, "There is no slot for us"); |
831 | | |
832 | | static bool |
833 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
834 | 0 | { |
835 | 0 | mozilla::dom::WorkerNavigator* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WorkerNavigator>(obj); |
836 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
837 | 0 | // obviously can't preserve if we're not initialized. |
838 | 0 | if (self && self->GetWrapperPreserveColor()) { |
839 | 0 | PreserveWrapper(self); |
840 | 0 | } |
841 | 0 | return true; |
842 | 0 | } |
843 | | |
844 | | static void |
845 | | _finalize(js::FreeOp* fop, JSObject* obj) |
846 | 0 | { |
847 | 0 | mozilla::dom::WorkerNavigator* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WorkerNavigator>(obj); |
848 | 0 | if (self) { |
849 | 0 | ClearWrapper(self, self, obj); |
850 | 0 | AddForDeferredFinalization<mozilla::dom::WorkerNavigator>(self); |
851 | 0 | } |
852 | 0 | } |
853 | | |
854 | | static size_t |
855 | | _objectMoved(JSObject* obj, JSObject* old) |
856 | 0 | { |
857 | 0 | mozilla::dom::WorkerNavigator* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WorkerNavigator>(obj); |
858 | 0 | if (self) { |
859 | 0 | UpdateWrapper(self, self, obj, old); |
860 | 0 | } |
861 | 0 |
|
862 | 0 | return 0; |
863 | 0 | } |
864 | | |
865 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
866 | | #if defined(__clang__) |
867 | | #pragma clang diagnostic push |
868 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
869 | | #endif |
870 | | static const JSFunctionSpec sMethods_specs[] = { |
871 | | JS_FNSPEC("taintEnabled", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&taintEnabled_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
872 | | JS_FS_END |
873 | | }; |
874 | | #if defined(__clang__) |
875 | | #pragma clang diagnostic pop |
876 | | #endif |
877 | | |
878 | | // Can't be const because the pref-enabled boolean needs to be writable |
879 | | static PrefableDisablers sMethods_disablers0 = { |
880 | | true, false, GlobalNames::DedicatedWorkerGlobalScope | GlobalNames::ServiceWorkerGlobalScope | GlobalNames::SharedWorkerGlobalScope, nullptr |
881 | | }; |
882 | | |
883 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
884 | | { &sMethods_disablers0, &sMethods_specs[0] }, |
885 | | { nullptr, nullptr } |
886 | | }; |
887 | | |
888 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
889 | | #if defined(__clang__) |
890 | | #pragma clang diagnostic push |
891 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
892 | | #endif |
893 | | static const JSPropertySpec sAttributes_specs[] = { |
894 | | { "connection", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &connection_getterinfo, nullptr, nullptr }, |
895 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr }, |
896 | | { "mediaCapabilities", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &mediaCapabilities_getterinfo, nullptr, nullptr }, |
897 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr }, |
898 | | { "hardwareConcurrency", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &hardwareConcurrency_getterinfo, nullptr, nullptr }, |
899 | | { "appCodeName", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &appCodeName_getterinfo, nullptr, nullptr }, |
900 | | { "appName", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &appName_getterinfo, nullptr, nullptr }, |
901 | | { "appVersion", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &appVersion_getterinfo, nullptr, nullptr }, |
902 | | { "platform", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &platform_getterinfo, nullptr, nullptr }, |
903 | | { "userAgent", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &userAgent_getterinfo, nullptr, nullptr }, |
904 | | { "product", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &product_getterinfo, nullptr, nullptr }, |
905 | | { "language", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &language_getterinfo, nullptr, nullptr }, |
906 | | { "languages", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &languages_getterinfo, nullptr, nullptr }, |
907 | | { "onLine", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onLine_getterinfo, nullptr, nullptr }, |
908 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr }, |
909 | | { "storage", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &storage_getterinfo, nullptr, nullptr }, |
910 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
911 | | }; |
912 | | #if defined(__clang__) |
913 | | #pragma clang diagnostic pop |
914 | | #endif |
915 | | |
916 | | // Can't be const because the pref-enabled boolean needs to be writable |
917 | | static PrefableDisablers sAttributes_disablers0 = { |
918 | | true, false, 0, &mozilla::dom::DOMPrefs::dom_netinfo_enabled |
919 | | }; |
920 | | |
921 | | // Can't be const because the pref-enabled boolean needs to be writable |
922 | | static PrefableDisablers sAttributes_disablers2 = { |
923 | | true, false, 0, &mozilla::dom::MediaCapabilities::Enabled |
924 | | }; |
925 | | |
926 | | // Can't be const because the pref-enabled boolean needs to be writable |
927 | | static PrefableDisablers sAttributes_disablers15 = { |
928 | | true, true, 0, &mozilla::dom::DOMPrefs::dom_storageManager_enabled |
929 | | }; |
930 | | |
931 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
932 | | { &sAttributes_disablers0, &sAttributes_specs[0] }, |
933 | | { &sAttributes_disablers2, &sAttributes_specs[2] }, |
934 | | { nullptr, &sAttributes_specs[4] }, |
935 | | { &sAttributes_disablers15, &sAttributes_specs[15] }, |
936 | | { nullptr, nullptr } |
937 | | }; |
938 | | |
939 | | |
940 | | static const NativePropertiesN<2> sNativeProperties = { |
941 | | false, 0, |
942 | | false, 0, |
943 | | true, 0 /* sMethods */, |
944 | | true, 1 /* sAttributes */, |
945 | | false, 0, |
946 | | false, 0, |
947 | | false, 0, |
948 | | -1, |
949 | | 0, |
950 | | nullptr, |
951 | | { |
952 | | { sMethods, nullptr }, |
953 | | { sAttributes, nullptr } |
954 | | } |
955 | | }; |
956 | | |
957 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
958 | | { |
959 | | "Function", |
960 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
961 | | &sBoringInterfaceObjectClassClassOps, |
962 | | JS_NULL_CLASS_SPEC, |
963 | | JS_NULL_CLASS_EXT, |
964 | | &sInterfaceObjectClassObjectOps |
965 | | }, |
966 | | eInterface, |
967 | | true, |
968 | | prototypes::id::WorkerNavigator, |
969 | | PrototypeTraits<prototypes::id::WorkerNavigator>::Depth, |
970 | | &sEmptyNativePropertyHooks, |
971 | | "function WorkerNavigator() {\n [native code]\n}", |
972 | | JS::GetRealmFunctionPrototype |
973 | | }; |
974 | | |
975 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
976 | | { |
977 | | "WorkerNavigatorPrototype", |
978 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
979 | | JS_NULL_CLASS_OPS, |
980 | | JS_NULL_CLASS_SPEC, |
981 | | JS_NULL_CLASS_EXT, |
982 | | JS_NULL_OBJECT_OPS |
983 | | }, |
984 | | eInterfacePrototype, |
985 | | false, |
986 | | prototypes::id::WorkerNavigator, |
987 | | PrototypeTraits<prototypes::id::WorkerNavigator>::Depth, |
988 | | &sEmptyNativePropertyHooks, |
989 | | "[object WorkerNavigatorPrototype]", |
990 | | JS::GetRealmObjectPrototype |
991 | | }; |
992 | | |
993 | | static const js::ClassOps sClassOps = { |
994 | | _addProperty, /* addProperty */ |
995 | | nullptr, /* delProperty */ |
996 | | nullptr, /* enumerate */ |
997 | | nullptr, /* newEnumerate */ |
998 | | nullptr, /* resolve */ |
999 | | nullptr, /* mayResolve */ |
1000 | | _finalize, /* finalize */ |
1001 | | nullptr, /* call */ |
1002 | | nullptr, /* hasInstance */ |
1003 | | nullptr, /* construct */ |
1004 | | nullptr, /* trace */ |
1005 | | }; |
1006 | | |
1007 | | static const js::ClassExtension sClassExtension = { |
1008 | | nullptr, /* weakmapKeyDelegateOp */ |
1009 | | _objectMoved /* objectMovedOp */ |
1010 | | }; |
1011 | | |
1012 | | static const DOMJSClass sClass = { |
1013 | | { "WorkerNavigator", |
1014 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(9), |
1015 | | &sClassOps, |
1016 | | JS_NULL_CLASS_SPEC, |
1017 | | &sClassExtension, |
1018 | | JS_NULL_OBJECT_OPS |
1019 | | }, |
1020 | | { prototypes::id::WorkerNavigator, 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 }, |
1021 | | IsBaseOf<nsISupports, mozilla::dom::WorkerNavigator >::value, |
1022 | | &sEmptyNativePropertyHooks, |
1023 | | FindAssociatedGlobalForNative<mozilla::dom::WorkerNavigator>::Get, |
1024 | | GetProtoObjectHandle, |
1025 | | GetCCParticipant<mozilla::dom::WorkerNavigator>::Get() |
1026 | | }; |
1027 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
1028 | | "Must have the right minimal number of reserved slots."); |
1029 | | static_assert(9 >= 9, |
1030 | | "Must have enough reserved slots."); |
1031 | | |
1032 | | const JSClass* |
1033 | | GetJSClass() |
1034 | 0 | { |
1035 | 0 | return sClass.ToJSClass(); |
1036 | 0 | } |
1037 | | |
1038 | | bool |
1039 | | Wrap(JSContext* aCx, mozilla::dom::WorkerNavigator* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
1040 | 0 | { |
1041 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::WorkerNavigator>::value, |
1042 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
1043 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::WorkerNavigator*>(aObject) == |
1044 | 0 | reinterpret_cast<mozilla::dom::WorkerNavigator*>(aObject), |
1045 | 0 | "Multiple inheritance for mozilla::dom::WorkerNavigator is broken."); |
1046 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
1047 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
1048 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
1049 | 0 | "You should probably not be using Wrap() directly; use " |
1050 | 0 | "GetOrCreateDOMReflector instead"); |
1051 | 0 |
|
1052 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
1053 | 0 | "nsISupports must be on our primary inheritance chain"); |
1054 | 0 |
|
1055 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
1056 | 0 | if (!global) { |
1057 | 0 | return false; |
1058 | 0 | } |
1059 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
1060 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
1061 | 0 |
|
1062 | 0 | // That might have ended up wrapping us already, due to the wonders |
1063 | 0 | // of XBL. Check for that, and bail out as needed. |
1064 | 0 | aReflector.set(aCache->GetWrapper()); |
1065 | 0 | if (aReflector) { |
1066 | | #ifdef DEBUG |
1067 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
1068 | | #endif // DEBUG |
1069 | | return true; |
1070 | 0 | } |
1071 | 0 |
|
1072 | 0 | JSAutoRealm ar(aCx, global); |
1073 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
1074 | 0 | if (!canonicalProto) { |
1075 | 0 | return false; |
1076 | 0 | } |
1077 | 0 | JS::Rooted<JSObject*> proto(aCx); |
1078 | 0 | if (aGivenProto) { |
1079 | 0 | proto = aGivenProto; |
1080 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
1081 | 0 | // coming in, we changed compartments to that of "parent" so may need |
1082 | 0 | // to wrap the proto here. |
1083 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
1084 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
1085 | 0 | return false; |
1086 | 0 | } |
1087 | 0 | } |
1088 | 0 | } else { |
1089 | 0 | proto = canonicalProto; |
1090 | 0 | } |
1091 | 0 |
|
1092 | 0 | BindingJSObjectCreator<mozilla::dom::WorkerNavigator> creator(aCx); |
1093 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
1094 | 0 | if (!aReflector) { |
1095 | 0 | return false; |
1096 | 0 | } |
1097 | 0 | |
1098 | 0 | aCache->SetWrapper(aReflector); |
1099 | 0 | creator.InitializationSucceeded(); |
1100 | 0 |
|
1101 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
1102 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
1103 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
1104 | 0 | // otherwise we won't be able to properly recreate it later, since |
1105 | 0 | // we won't know what proto to use. Note that we don't check |
1106 | 0 | // aGivenProto here, since it's entirely possible (and even |
1107 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
1108 | 0 | // same as canonicalProto. |
1109 | 0 | if (proto != canonicalProto) { |
1110 | 0 | PreserveWrapper(aObject); |
1111 | 0 | } |
1112 | 0 |
|
1113 | 0 | return true; |
1114 | 0 | } |
1115 | | |
1116 | | void |
1117 | | ClearCachedUserAgentValue(mozilla::dom::WorkerNavigator* aObject) |
1118 | 0 | { |
1119 | 0 | JSObject* obj; |
1120 | 0 | obj = aObject->GetWrapper(); |
1121 | 0 | if (!obj) { |
1122 | 0 | return; |
1123 | 0 | } |
1124 | 0 | js::SetReservedSlot(obj, (DOM_INSTANCE_RESERVED_SLOTS + 4), JS::UndefinedValue()); |
1125 | 0 | } |
1126 | | |
1127 | | void |
1128 | | ClearCachedLanguageValue(mozilla::dom::WorkerNavigator* aObject) |
1129 | 0 | { |
1130 | 0 | JSObject* obj; |
1131 | 0 | obj = aObject->GetWrapper(); |
1132 | 0 | if (!obj) { |
1133 | 0 | return; |
1134 | 0 | } |
1135 | 0 | js::SetReservedSlot(obj, (DOM_INSTANCE_RESERVED_SLOTS + 6), JS::UndefinedValue()); |
1136 | 0 | } |
1137 | | |
1138 | | void |
1139 | | ClearCachedLanguagesValue(mozilla::dom::WorkerNavigator* aObject) |
1140 | 0 | { |
1141 | 0 | JSObject* obj; |
1142 | 0 | obj = aObject->GetWrapper(); |
1143 | 0 | if (!obj) { |
1144 | 0 | return; |
1145 | 0 | } |
1146 | 0 | js::SetReservedSlot(obj, (DOM_INSTANCE_RESERVED_SLOTS + 7), JS::UndefinedValue()); |
1147 | 0 | } |
1148 | | |
1149 | | void |
1150 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
1151 | 0 | { |
1152 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
1153 | 0 | if (!parentProto) { |
1154 | 0 | return; |
1155 | 0 | } |
1156 | 0 | |
1157 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
1158 | 0 | if (!constructorProto) { |
1159 | 0 | return; |
1160 | 0 | } |
1161 | 0 | |
1162 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WorkerNavigator); |
1163 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WorkerNavigator); |
1164 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
1165 | 0 | &sPrototypeClass.mBase, protoCache, |
1166 | 0 | nullptr, |
1167 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
1168 | 0 | interfaceCache, |
1169 | 0 | sNativeProperties.Upcast(), |
1170 | 0 | nullptr, |
1171 | 0 | "WorkerNavigator", aDefineOnGlobal, |
1172 | 0 | nullptr, |
1173 | 0 | false); |
1174 | 0 | } |
1175 | | |
1176 | | JSObject* |
1177 | | GetConstructorObject(JSContext* aCx) |
1178 | 0 | { |
1179 | 0 | return GetConstructorObjectHandle(aCx); |
1180 | 0 | } |
1181 | | |
1182 | | } // namespace WorkerNavigator_Binding |
1183 | | |
1184 | | |
1185 | | |
1186 | | } // namespace dom |
1187 | | } // namespace mozilla |