Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM WorkerGlobalScope.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "Crypto.h"
4 : #include "EventHandlerBinding.h"
5 : #include "EventTargetBinding.h"
6 : #include "FunctionBinding.h"
7 : #include "ImageBitmapBinding.h"
8 : #include "RequestBinding.h"
9 : #include "WorkerGlobalScopeBinding.h"
10 : #include "WrapperFactory.h"
11 : #include "mozilla/OwningNonNull.h"
12 : #include "mozilla/dom/BindingUtils.h"
13 : #include "mozilla/dom/DOMJSClass.h"
14 : #include "mozilla/dom/IDBFactory.h"
15 : #include "mozilla/dom/NonRefcountedDOMObject.h"
16 : #include "mozilla/dom/Nullable.h"
17 : #include "mozilla/dom/Performance.h"
18 : #include "mozilla/dom/PrimitiveConversions.h"
19 : #include "mozilla/dom/Promise.h"
20 : #include "mozilla/dom/ToJSValue.h"
21 : #include "mozilla/dom/UnionConversions.h"
22 : #include "mozilla/dom/WorkerLocation.h"
23 : #include "mozilla/dom/WorkerNavigator.h"
24 : #include "mozilla/dom/WorkerScope.h"
25 : #include "mozilla/dom/cache/CacheStorage.h"
26 : #include "nsContentUtils.h"
27 :
28 : namespace mozilla {
29 : namespace dom {
30 :
31 : namespace WorkerGlobalScopeBinding {
32 :
33 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTargetBinding::NativeType>::value,
34 : "Can't inherit from an interface with a different ownership model.");
35 :
36 : static bool
37 0 : get_self(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, JSJitGetterCallArgs args)
38 : {
39 : // Have to either root across the getter call or reget after.
40 0 : JS::Rooted<JSObject*> slotStorage(cx, js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false));
41 0 : MOZ_ASSERT(IsDOMObject(slotStorage));
42 0 : const size_t slotIndex = (DOM_INSTANCE_RESERVED_SLOTS + 0);
43 0 : MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex);
44 : {
45 : // Scope for cachedVal
46 0 : JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex);
47 0 : if (!cachedVal.isUndefined()) {
48 0 : args.rval().set(cachedVal);
49 : // The cached value is in the compartment of slotStorage,
50 : // so wrap into the caller compartment as needed.
51 0 : return MaybeWrapValue(cx, args.rval());
52 : }
53 : }
54 :
55 0 : auto result(StrongOrRawPtr<mozilla::dom::WorkerGlobalScope>(self->Self()));
56 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
57 : {
58 0 : JS::Rooted<JSObject*> conversionScope(cx, slotStorage);
59 0 : JSAutoCompartment ac(cx, conversionScope);
60 : do { // block we break out of when done wrapping
61 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
62 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
63 0 : return false;
64 : }
65 0 : break;
66 : } while (0);
67 : }
68 : { // And now store things in the compartment of our slotStorage.
69 0 : JSAutoCompartment ac(cx, slotStorage);
70 : // Make a copy so that we don't do unnecessary wrapping on args.rval().
71 0 : JS::Rooted<JS::Value> storedVal(cx, args.rval());
72 0 : if (!MaybeWrapValue(cx, &storedVal)) {
73 0 : return false;
74 : }
75 0 : js::SetReservedSlot(slotStorage, slotIndex, storedVal);
76 0 : PreserveWrapper(self);
77 : }
78 : // And now make sure args.rval() is in the caller compartment
79 0 : return MaybeWrapValue(cx, args.rval());
80 : }
81 :
82 : static const JSJitInfo self_getterinfo = {
83 : { (JSJitGetterOp)get_self },
84 : { prototypes::id::WorkerGlobalScope },
85 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
86 : JSJitInfo::Getter,
87 : JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
88 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
89 : false, /* isInfallible. False in setters. */
90 : true, /* isMovable. Not relevant for setters. */
91 : true, /* isEliminatable. Not relevant for setters. */
92 : false, /* isAlwaysInSlot. Only relevant for getters. */
93 : true, /* isLazilyCachedInSlot. Only relevant for getters. */
94 : false, /* isTypedMethod. Only relevant for methods. */
95 : (DOM_INSTANCE_RESERVED_SLOTS + 0) /* Reserved slot index, if we're stored in a slot, else 0. */
96 : };
97 : static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) <= JSJitInfo::maxSlotIndex, "We won't fit");
98 : static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) < 3, "There is no slot for us");
99 :
100 : static bool
101 0 : get_location(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, JSJitGetterCallArgs args)
102 : {
103 0 : auto result(StrongOrRawPtr<mozilla::dom::WorkerLocation>(self->Location()));
104 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
105 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
106 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
107 0 : return false;
108 : }
109 0 : return true;
110 : }
111 :
112 : static const JSJitInfo location_getterinfo = {
113 : { (JSJitGetterOp)get_location },
114 : { prototypes::id::WorkerGlobalScope },
115 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
116 : JSJitInfo::Getter,
117 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
118 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
119 : false, /* isInfallible. False in setters. */
120 : false, /* isMovable. Not relevant for setters. */
121 : false, /* isEliminatable. Not relevant for setters. */
122 : false, /* isAlwaysInSlot. Only relevant for getters. */
123 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
124 : false, /* isTypedMethod. Only relevant for methods. */
125 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
126 : };
127 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
128 : static_assert(0 < 3, "There is no slot for us");
129 :
130 : static bool
131 0 : get_navigator(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, JSJitGetterCallArgs args)
132 : {
133 0 : auto result(StrongOrRawPtr<mozilla::dom::WorkerNavigator>(self->Navigator()));
134 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
135 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
136 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
137 0 : return false;
138 : }
139 0 : return true;
140 : }
141 :
142 : static const JSJitInfo navigator_getterinfo = {
143 : { (JSJitGetterOp)get_navigator },
144 : { prototypes::id::WorkerGlobalScope },
145 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
146 : JSJitInfo::Getter,
147 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
148 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
149 : false, /* isInfallible. False in setters. */
150 : false, /* isMovable. Not relevant for setters. */
151 : false, /* isEliminatable. Not relevant for setters. */
152 : false, /* isAlwaysInSlot. Only relevant for getters. */
153 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
154 : false, /* isTypedMethod. Only relevant for methods. */
155 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
156 : };
157 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
158 : static_assert(0 < 3, "There is no slot for us");
159 :
160 : static bool
161 4 : importScripts(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, const JSJitMethodCallArgs& args)
162 : {
163 6 : binding_detail::AutoSequence<nsString> arg0;
164 4 : if (args.length() > 0) {
165 4 : if (!arg0.SetCapacity(args.length() - 0, mozilla::fallible)) {
166 0 : JS_ReportOutOfMemory(cx);
167 0 : return false;
168 : }
169 11 : for (uint32_t variadicArg = 0; variadicArg < args.length(); ++variadicArg) {
170 7 : nsString& slot = *arg0.AppendElement(mozilla::fallible);
171 7 : if (!ConvertJSValueToString(cx, args[variadicArg], eStringify, eStringify, slot)) {
172 0 : return false;
173 : }
174 : }
175 : }
176 6 : binding_detail::FastErrorResult rv;
177 4 : self->ImportScripts(NonNullHelper(Constify(arg0)), rv);
178 2 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
179 0 : return false;
180 : }
181 2 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
182 2 : args.rval().setUndefined();
183 2 : return true;
184 : }
185 :
186 : static const JSJitInfo importScripts_methodinfo = {
187 : { (JSJitGetterOp)importScripts },
188 : { prototypes::id::WorkerGlobalScope },
189 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
190 : JSJitInfo::Method,
191 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
192 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
193 : false, /* isInfallible. False in setters. */
194 : false, /* isMovable. Not relevant for setters. */
195 : false, /* isEliminatable. Not relevant for setters. */
196 : false, /* isAlwaysInSlot. Only relevant for getters. */
197 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
198 : false, /* isTypedMethod. Only relevant for methods. */
199 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
200 : };
201 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
202 : static_assert(0 < 3, "There is no slot for us");
203 :
204 : static bool
205 0 : get_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, JSJitGetterCallArgs args)
206 : {
207 0 : RefPtr<OnErrorEventHandlerNonNull> result(self->GetOnerror());
208 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
209 0 : if (result) {
210 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
211 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
212 0 : return false;
213 : }
214 0 : return true;
215 : } else {
216 0 : args.rval().setNull();
217 0 : return true;
218 : }
219 : }
220 :
221 : static bool
222 0 : set_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, JSJitSetterCallArgs args)
223 : {
224 0 : RootedCallback<RefPtr<binding_detail::FastOnErrorEventHandlerNonNull>> arg0(cx);
225 0 : if (args[0].isObject()) {
226 : { // scope for tempRoot
227 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
228 0 : arg0 = new binding_detail::FastOnErrorEventHandlerNonNull(tempRoot);
229 : }
230 : } else {
231 0 : arg0 = nullptr;
232 : }
233 0 : self->SetOnerror(Constify(arg0));
234 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
235 :
236 0 : return true;
237 : }
238 :
239 : static const JSJitInfo onerror_getterinfo = {
240 : { (JSJitGetterOp)get_onerror },
241 : { prototypes::id::WorkerGlobalScope },
242 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
243 : JSJitInfo::Getter,
244 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
245 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
246 : false, /* isInfallible. False in setters. */
247 : false, /* isMovable. Not relevant for setters. */
248 : false, /* isEliminatable. Not relevant for setters. */
249 : false, /* isAlwaysInSlot. Only relevant for getters. */
250 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
251 : false, /* isTypedMethod. Only relevant for methods. */
252 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
253 : };
254 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
255 : static_assert(0 < 3, "There is no slot for us");
256 : static const JSJitInfo onerror_setterinfo = {
257 : { (JSJitGetterOp)set_onerror },
258 : { prototypes::id::WorkerGlobalScope },
259 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
260 : JSJitInfo::Setter,
261 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
262 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
263 : false, /* isInfallible. False in setters. */
264 : false, /* isMovable. Not relevant for setters. */
265 : false, /* isEliminatable. Not relevant for setters. */
266 : false, /* isAlwaysInSlot. Only relevant for getters. */
267 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
268 : false, /* isTypedMethod. Only relevant for methods. */
269 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
270 : };
271 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
272 : static_assert(0 < 3, "There is no slot for us");
273 :
274 : static bool
275 0 : get_onoffline(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, JSJitGetterCallArgs args)
276 : {
277 0 : RefPtr<EventHandlerNonNull> result(self->GetOnoffline());
278 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
279 0 : if (result) {
280 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
281 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
282 0 : return false;
283 : }
284 0 : return true;
285 : } else {
286 0 : args.rval().setNull();
287 0 : return true;
288 : }
289 : }
290 :
291 : static bool
292 0 : set_onoffline(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, JSJitSetterCallArgs args)
293 : {
294 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
295 0 : if (args[0].isObject()) {
296 : { // scope for tempRoot
297 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
298 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
299 : }
300 : } else {
301 0 : arg0 = nullptr;
302 : }
303 0 : self->SetOnoffline(Constify(arg0));
304 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
305 :
306 0 : return true;
307 : }
308 :
309 : static const JSJitInfo onoffline_getterinfo = {
310 : { (JSJitGetterOp)get_onoffline },
311 : { prototypes::id::WorkerGlobalScope },
312 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
313 : JSJitInfo::Getter,
314 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
315 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
316 : false, /* isInfallible. False in setters. */
317 : false, /* isMovable. Not relevant for setters. */
318 : false, /* isEliminatable. Not relevant for setters. */
319 : false, /* isAlwaysInSlot. Only relevant for getters. */
320 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
321 : false, /* isTypedMethod. Only relevant for methods. */
322 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
323 : };
324 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
325 : static_assert(0 < 3, "There is no slot for us");
326 : static const JSJitInfo onoffline_setterinfo = {
327 : { (JSJitGetterOp)set_onoffline },
328 : { prototypes::id::WorkerGlobalScope },
329 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
330 : JSJitInfo::Setter,
331 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
332 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
333 : false, /* isInfallible. False in setters. */
334 : false, /* isMovable. Not relevant for setters. */
335 : false, /* isEliminatable. Not relevant for setters. */
336 : false, /* isAlwaysInSlot. Only relevant for getters. */
337 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
338 : false, /* isTypedMethod. Only relevant for methods. */
339 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
340 : };
341 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
342 : static_assert(0 < 3, "There is no slot for us");
343 :
344 : static bool
345 0 : get_ononline(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, JSJitGetterCallArgs args)
346 : {
347 0 : RefPtr<EventHandlerNonNull> result(self->GetOnonline());
348 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
349 0 : if (result) {
350 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
351 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
352 0 : return false;
353 : }
354 0 : return true;
355 : } else {
356 0 : args.rval().setNull();
357 0 : return true;
358 : }
359 : }
360 :
361 : static bool
362 0 : set_ononline(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, JSJitSetterCallArgs args)
363 : {
364 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
365 0 : if (args[0].isObject()) {
366 : { // scope for tempRoot
367 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
368 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
369 : }
370 : } else {
371 0 : arg0 = nullptr;
372 : }
373 0 : self->SetOnonline(Constify(arg0));
374 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
375 :
376 0 : return true;
377 : }
378 :
379 : static const JSJitInfo ononline_getterinfo = {
380 : { (JSJitGetterOp)get_ononline },
381 : { prototypes::id::WorkerGlobalScope },
382 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
383 : JSJitInfo::Getter,
384 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
385 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
386 : false, /* isInfallible. False in setters. */
387 : false, /* isMovable. Not relevant for setters. */
388 : false, /* isEliminatable. Not relevant for setters. */
389 : false, /* isAlwaysInSlot. Only relevant for getters. */
390 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
391 : false, /* isTypedMethod. Only relevant for methods. */
392 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
393 : };
394 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
395 : static_assert(0 < 3, "There is no slot for us");
396 : static const JSJitInfo ononline_setterinfo = {
397 : { (JSJitGetterOp)set_ononline },
398 : { prototypes::id::WorkerGlobalScope },
399 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
400 : JSJitInfo::Setter,
401 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
402 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
403 : false, /* isInfallible. False in setters. */
404 : false, /* isMovable. Not relevant for setters. */
405 : false, /* isEliminatable. Not relevant for setters. */
406 : false, /* isAlwaysInSlot. Only relevant for getters. */
407 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
408 : false, /* isTypedMethod. Only relevant for methods. */
409 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
410 : };
411 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
412 : static_assert(0 < 3, "There is no slot for us");
413 :
414 : static bool
415 0 : dump(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, const JSJitMethodCallArgs& args)
416 : {
417 0 : Optional<nsAString> arg0;
418 0 : binding_detail::FakeString arg0_holder;
419 0 : if (args.hasDefined(0)) {
420 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0_holder)) {
421 0 : return false;
422 : }
423 0 : arg0 = &arg0_holder;
424 : }
425 0 : self->Dump(NonNullHelper(Constify(arg0)));
426 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
427 0 : args.rval().setUndefined();
428 0 : return true;
429 : }
430 :
431 : static const JSJitInfo dump_methodinfo = {
432 : { (JSJitGetterOp)dump },
433 : { prototypes::id::WorkerGlobalScope },
434 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
435 : JSJitInfo::Method,
436 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
437 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
438 : false, /* isInfallible. False in setters. */
439 : false, /* isMovable. Not relevant for setters. */
440 : false, /* isEliminatable. Not relevant for setters. */
441 : false, /* isAlwaysInSlot. Only relevant for getters. */
442 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
443 : false, /* isTypedMethod. Only relevant for methods. */
444 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
445 : };
446 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
447 : static_assert(0 < 3, "There is no slot for us");
448 :
449 : static bool
450 0 : get_performance(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, JSJitGetterCallArgs args)
451 : {
452 : // Have to either root across the getter call or reget after.
453 0 : JS::Rooted<JSObject*> slotStorage(cx, js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false));
454 0 : MOZ_ASSERT(IsDOMObject(slotStorage));
455 0 : const size_t slotIndex = (DOM_INSTANCE_RESERVED_SLOTS + 1);
456 0 : MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex);
457 : {
458 : // Scope for cachedVal
459 0 : JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex);
460 0 : if (!cachedVal.isUndefined()) {
461 0 : args.rval().set(cachedVal);
462 : // The cached value is in the compartment of slotStorage,
463 : // so wrap into the caller compartment as needed.
464 0 : return MaybeWrapValue(cx, args.rval());
465 : }
466 : }
467 :
468 0 : auto result(StrongOrRawPtr<mozilla::dom::Performance>(self->GetPerformance()));
469 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
470 : {
471 0 : JS::Rooted<JSObject*> conversionScope(cx, slotStorage);
472 0 : JSAutoCompartment ac(cx, conversionScope);
473 : do { // block we break out of when done wrapping
474 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
475 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
476 0 : return false;
477 : }
478 0 : break;
479 : } while (0);
480 : }
481 : { // And now store things in the compartment of our slotStorage.
482 0 : JSAutoCompartment ac(cx, slotStorage);
483 : // Make a copy so that we don't do unnecessary wrapping on args.rval().
484 0 : JS::Rooted<JS::Value> storedVal(cx, args.rval());
485 0 : if (!MaybeWrapValue(cx, &storedVal)) {
486 0 : return false;
487 : }
488 0 : js::SetReservedSlot(slotStorage, slotIndex, storedVal);
489 0 : PreserveWrapper(self);
490 : }
491 : // And now make sure args.rval() is in the caller compartment
492 0 : return MaybeWrapValue(cx, args.rval());
493 : }
494 :
495 : static const JSJitInfo performance_getterinfo = {
496 : { (JSJitGetterOp)get_performance },
497 : { prototypes::id::WorkerGlobalScope },
498 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
499 : JSJitInfo::Getter,
500 : JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
501 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
502 : false, /* isInfallible. False in setters. */
503 : true, /* isMovable. Not relevant for setters. */
504 : true, /* isEliminatable. Not relevant for setters. */
505 : false, /* isAlwaysInSlot. Only relevant for getters. */
506 : true, /* isLazilyCachedInSlot. Only relevant for getters. */
507 : false, /* isTypedMethod. Only relevant for methods. */
508 : (DOM_INSTANCE_RESERVED_SLOTS + 1) /* Reserved slot index, if we're stored in a slot, else 0. */
509 : };
510 : static_assert((DOM_INSTANCE_RESERVED_SLOTS + 1) <= JSJitInfo::maxSlotIndex, "We won't fit");
511 : static_assert((DOM_INSTANCE_RESERVED_SLOTS + 1) < 3, "There is no slot for us");
512 :
513 : static bool
514 0 : get_crypto(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, JSJitGetterCallArgs args)
515 : {
516 0 : binding_detail::FastErrorResult rv;
517 0 : auto result(StrongOrRawPtr<mozilla::dom::Crypto>(self->GetCrypto(rv)));
518 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
519 0 : return false;
520 : }
521 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
522 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
523 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
524 0 : return false;
525 : }
526 0 : return true;
527 : }
528 :
529 : static const JSJitInfo crypto_getterinfo = {
530 : { (JSJitGetterOp)get_crypto },
531 : { prototypes::id::WorkerGlobalScope },
532 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
533 : JSJitInfo::Getter,
534 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
535 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
536 : false, /* isInfallible. False in setters. */
537 : false, /* isMovable. Not relevant for setters. */
538 : false, /* isEliminatable. Not relevant for setters. */
539 : false, /* isAlwaysInSlot. Only relevant for getters. */
540 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
541 : false, /* isTypedMethod. Only relevant for methods. */
542 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
543 : };
544 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
545 : static_assert(0 < 3, "There is no slot for us");
546 :
547 : static bool
548 0 : get_origin(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, JSJitGetterCallArgs args)
549 : {
550 0 : DOMString result;
551 0 : self->GetOrigin(result);
552 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
553 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
554 0 : return false;
555 : }
556 0 : return true;
557 : }
558 :
559 : static bool
560 0 : set_origin(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, JSJitSetterCallArgs args)
561 : {
562 0 : return JS_DefineProperty(cx, obj, "origin", args[0], JSPROP_ENUMERATE);
563 : }
564 :
565 : static const JSJitInfo origin_getterinfo = {
566 : { (JSJitGetterOp)get_origin },
567 : { prototypes::id::WorkerGlobalScope },
568 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
569 : JSJitInfo::Getter,
570 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
571 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
572 : false, /* isInfallible. False in setters. */
573 : false, /* isMovable. Not relevant for setters. */
574 : false, /* isEliminatable. Not relevant for setters. */
575 : false, /* isAlwaysInSlot. Only relevant for getters. */
576 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
577 : false, /* isTypedMethod. Only relevant for methods. */
578 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
579 : };
580 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
581 : static_assert(0 < 3, "There is no slot for us");
582 : static const JSJitInfo origin_setterinfo = {
583 : { (JSJitGetterOp)set_origin },
584 : { prototypes::id::WorkerGlobalScope },
585 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
586 : JSJitInfo::Setter,
587 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
588 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
589 : false, /* isInfallible. False in setters. */
590 : false, /* isMovable. Not relevant for setters. */
591 : false, /* isEliminatable. Not relevant for setters. */
592 : false, /* isAlwaysInSlot. Only relevant for getters. */
593 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
594 : false, /* isTypedMethod. Only relevant for methods. */
595 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
596 : };
597 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
598 : static_assert(0 < 3, "There is no slot for us");
599 :
600 : static bool
601 0 : btoa(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, const JSJitMethodCallArgs& args)
602 : {
603 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
604 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WorkerGlobalScope.btoa");
605 : }
606 0 : binding_detail::FakeString arg0;
607 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
608 0 : return false;
609 : }
610 0 : binding_detail::FastErrorResult rv;
611 0 : DOMString result;
612 0 : self->Btoa(NonNullHelper(Constify(arg0)), result, rv);
613 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
614 0 : return false;
615 : }
616 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
617 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
618 0 : return false;
619 : }
620 0 : return true;
621 : }
622 :
623 : static const JSJitInfo btoa_methodinfo = {
624 : { (JSJitGetterOp)btoa },
625 : { prototypes::id::WorkerGlobalScope },
626 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
627 : JSJitInfo::Method,
628 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
629 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
630 : false, /* isInfallible. False in setters. */
631 : false, /* isMovable. Not relevant for setters. */
632 : false, /* isEliminatable. Not relevant for setters. */
633 : false, /* isAlwaysInSlot. Only relevant for getters. */
634 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
635 : false, /* isTypedMethod. Only relevant for methods. */
636 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
637 : };
638 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
639 : static_assert(0 < 3, "There is no slot for us");
640 :
641 : static bool
642 0 : atob(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, const JSJitMethodCallArgs& args)
643 : {
644 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
645 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WorkerGlobalScope.atob");
646 : }
647 0 : binding_detail::FakeString arg0;
648 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
649 0 : return false;
650 : }
651 0 : binding_detail::FastErrorResult rv;
652 0 : DOMString result;
653 0 : self->Atob(NonNullHelper(Constify(arg0)), result, rv);
654 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
655 0 : return false;
656 : }
657 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
658 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
659 0 : return false;
660 : }
661 0 : return true;
662 : }
663 :
664 : static const JSJitInfo atob_methodinfo = {
665 : { (JSJitGetterOp)atob },
666 : { prototypes::id::WorkerGlobalScope },
667 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
668 : JSJitInfo::Method,
669 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
670 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
671 : false, /* isInfallible. False in setters. */
672 : false, /* isMovable. Not relevant for setters. */
673 : false, /* isEliminatable. Not relevant for setters. */
674 : false, /* isAlwaysInSlot. Only relevant for getters. */
675 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
676 : false, /* isTypedMethod. Only relevant for methods. */
677 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
678 : };
679 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
680 : static_assert(0 < 3, "There is no slot for us");
681 :
682 : static bool
683 0 : setTimeout(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, const JSJitMethodCallArgs& args)
684 : {
685 0 : unsigned argcount = std::min(args.length(), 3u);
686 0 : switch (argcount) {
687 : case 1: {
688 : MOZ_FALLTHROUGH;
689 : }
690 : case 2: {
691 : MOZ_FALLTHROUGH;
692 : }
693 : case 3: {
694 0 : if (args[0].isObject()) {
695 : do {
696 0 : RootedCallback<OwningNonNull<binding_detail::FastFunction>> arg0(cx);
697 0 : if (JS::IsCallable(&args[0].toObject())) {
698 : { // scope for tempRoot
699 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
700 0 : arg0 = new binding_detail::FastFunction(tempRoot);
701 : }
702 : } else {
703 0 : break;
704 : }
705 : int32_t arg1;
706 0 : if (args.hasDefined(1)) {
707 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, args[1], &arg1)) {
708 0 : return false;
709 : }
710 : } else {
711 0 : arg1 = 0;
712 : }
713 0 : binding_detail::AutoSequence<JS::Value> arg2;
714 0 : SequenceRooter<JS::Value> arg2_holder(cx, &arg2);
715 0 : if (args.length() > 2) {
716 0 : if (!arg2.SetCapacity(args.length() - 2, mozilla::fallible)) {
717 0 : JS_ReportOutOfMemory(cx);
718 0 : return false;
719 : }
720 0 : for (uint32_t variadicArg = 2; variadicArg < args.length(); ++variadicArg) {
721 0 : JS::Value& slot = *arg2.AppendElement(mozilla::fallible);
722 0 : slot = args[variadicArg];
723 : }
724 : }
725 0 : binding_detail::FastErrorResult rv;
726 0 : int32_t result(self->SetTimeout(cx, NonNullHelper(arg0), arg1, Constify(arg2), rv));
727 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
728 0 : return false;
729 : }
730 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
731 0 : args.rval().setInt32(int32_t(result));
732 0 : return true;
733 : } while (0);
734 : }
735 0 : binding_detail::FakeString arg0;
736 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
737 0 : return false;
738 : }
739 : int32_t arg1;
740 0 : if (args.hasDefined(1)) {
741 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, args[1], &arg1)) {
742 0 : return false;
743 : }
744 : } else {
745 0 : arg1 = 0;
746 : }
747 0 : binding_detail::AutoSequence<JS::Value> arg2;
748 0 : SequenceRooter<JS::Value> arg2_holder(cx, &arg2);
749 0 : if (args.length() > 2) {
750 0 : if (!arg2.SetCapacity(args.length() - 2, mozilla::fallible)) {
751 0 : JS_ReportOutOfMemory(cx);
752 0 : return false;
753 : }
754 0 : for (uint32_t variadicArg = 2; variadicArg < args.length(); ++variadicArg) {
755 0 : JS::Value& slot = *arg2.AppendElement(mozilla::fallible);
756 0 : slot = args[variadicArg];
757 : }
758 : }
759 0 : binding_detail::FastErrorResult rv;
760 0 : int32_t result(self->SetTimeout(cx, NonNullHelper(Constify(arg0)), arg1, Constify(arg2), rv));
761 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
762 0 : return false;
763 : }
764 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
765 0 : args.rval().setInt32(int32_t(result));
766 0 : return true;
767 : break;
768 : }
769 : default: {
770 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WorkerGlobalScope.setTimeout");
771 : break;
772 : }
773 : }
774 : MOZ_CRASH("We have an always-returning default case");
775 : return false;
776 : }
777 :
778 : static const JSJitInfo setTimeout_methodinfo = {
779 : { (JSJitGetterOp)setTimeout },
780 : { prototypes::id::WorkerGlobalScope },
781 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
782 : JSJitInfo::Method,
783 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
784 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
785 : false, /* isInfallible. False in setters. */
786 : false, /* isMovable. Not relevant for setters. */
787 : false, /* isEliminatable. Not relevant for setters. */
788 : false, /* isAlwaysInSlot. Only relevant for getters. */
789 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
790 : false, /* isTypedMethod. Only relevant for methods. */
791 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
792 : };
793 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
794 : static_assert(0 < 3, "There is no slot for us");
795 :
796 : static bool
797 0 : clearTimeout(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, const JSJitMethodCallArgs& args)
798 : {
799 : int32_t arg0;
800 0 : if (args.hasDefined(0)) {
801 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, args[0], &arg0)) {
802 0 : return false;
803 : }
804 : } else {
805 0 : arg0 = 0;
806 : }
807 0 : self->ClearTimeout(arg0);
808 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
809 0 : args.rval().setUndefined();
810 0 : return true;
811 : }
812 :
813 : static const JSJitInfo clearTimeout_methodinfo = {
814 : { (JSJitGetterOp)clearTimeout },
815 : { prototypes::id::WorkerGlobalScope },
816 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
817 : JSJitInfo::Method,
818 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
819 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
820 : false, /* isInfallible. False in setters. */
821 : false, /* isMovable. Not relevant for setters. */
822 : false, /* isEliminatable. Not relevant for setters. */
823 : false, /* isAlwaysInSlot. Only relevant for getters. */
824 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
825 : false, /* isTypedMethod. Only relevant for methods. */
826 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
827 : };
828 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
829 : static_assert(0 < 3, "There is no slot for us");
830 :
831 : static bool
832 0 : setInterval(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, const JSJitMethodCallArgs& args)
833 : {
834 0 : unsigned argcount = std::min(args.length(), 3u);
835 0 : switch (argcount) {
836 : case 1: {
837 : MOZ_FALLTHROUGH;
838 : }
839 : case 2: {
840 : MOZ_FALLTHROUGH;
841 : }
842 : case 3: {
843 0 : if (args[0].isObject()) {
844 : do {
845 0 : RootedCallback<OwningNonNull<binding_detail::FastFunction>> arg0(cx);
846 0 : if (JS::IsCallable(&args[0].toObject())) {
847 : { // scope for tempRoot
848 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
849 0 : arg0 = new binding_detail::FastFunction(tempRoot);
850 : }
851 : } else {
852 0 : break;
853 : }
854 0 : Optional<int32_t> arg1;
855 0 : if (args.hasDefined(1)) {
856 0 : arg1.Construct();
857 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, args[1], &arg1.Value())) {
858 0 : return false;
859 : }
860 : }
861 0 : binding_detail::AutoSequence<JS::Value> arg2;
862 0 : SequenceRooter<JS::Value> arg2_holder(cx, &arg2);
863 0 : if (args.length() > 2) {
864 0 : if (!arg2.SetCapacity(args.length() - 2, mozilla::fallible)) {
865 0 : JS_ReportOutOfMemory(cx);
866 0 : return false;
867 : }
868 0 : for (uint32_t variadicArg = 2; variadicArg < args.length(); ++variadicArg) {
869 0 : JS::Value& slot = *arg2.AppendElement(mozilla::fallible);
870 0 : slot = args[variadicArg];
871 : }
872 : }
873 0 : binding_detail::FastErrorResult rv;
874 0 : int32_t result(self->SetInterval(cx, NonNullHelper(arg0), Constify(arg1), Constify(arg2), rv));
875 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
876 0 : return false;
877 : }
878 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
879 0 : args.rval().setInt32(int32_t(result));
880 0 : return true;
881 : } while (0);
882 : }
883 0 : binding_detail::FakeString arg0;
884 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
885 0 : return false;
886 : }
887 0 : Optional<int32_t> arg1;
888 0 : if (args.hasDefined(1)) {
889 0 : arg1.Construct();
890 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, args[1], &arg1.Value())) {
891 0 : return false;
892 : }
893 : }
894 0 : binding_detail::AutoSequence<JS::Value> arg2;
895 0 : SequenceRooter<JS::Value> arg2_holder(cx, &arg2);
896 0 : if (args.length() > 2) {
897 0 : if (!arg2.SetCapacity(args.length() - 2, mozilla::fallible)) {
898 0 : JS_ReportOutOfMemory(cx);
899 0 : return false;
900 : }
901 0 : for (uint32_t variadicArg = 2; variadicArg < args.length(); ++variadicArg) {
902 0 : JS::Value& slot = *arg2.AppendElement(mozilla::fallible);
903 0 : slot = args[variadicArg];
904 : }
905 : }
906 0 : binding_detail::FastErrorResult rv;
907 0 : int32_t result(self->SetInterval(cx, NonNullHelper(Constify(arg0)), Constify(arg1), Constify(arg2), rv));
908 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
909 0 : return false;
910 : }
911 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
912 0 : args.rval().setInt32(int32_t(result));
913 0 : return true;
914 : break;
915 : }
916 : default: {
917 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WorkerGlobalScope.setInterval");
918 : break;
919 : }
920 : }
921 : MOZ_CRASH("We have an always-returning default case");
922 : return false;
923 : }
924 :
925 : static const JSJitInfo setInterval_methodinfo = {
926 : { (JSJitGetterOp)setInterval },
927 : { prototypes::id::WorkerGlobalScope },
928 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
929 : JSJitInfo::Method,
930 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
931 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
932 : false, /* isInfallible. False in setters. */
933 : false, /* isMovable. Not relevant for setters. */
934 : false, /* isEliminatable. Not relevant for setters. */
935 : false, /* isAlwaysInSlot. Only relevant for getters. */
936 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
937 : false, /* isTypedMethod. Only relevant for methods. */
938 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
939 : };
940 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
941 : static_assert(0 < 3, "There is no slot for us");
942 :
943 : static bool
944 0 : clearInterval(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, const JSJitMethodCallArgs& args)
945 : {
946 : int32_t arg0;
947 0 : if (args.hasDefined(0)) {
948 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, args[0], &arg0)) {
949 0 : return false;
950 : }
951 : } else {
952 0 : arg0 = 0;
953 : }
954 0 : self->ClearInterval(arg0);
955 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
956 0 : args.rval().setUndefined();
957 0 : return true;
958 : }
959 :
960 : static const JSJitInfo clearInterval_methodinfo = {
961 : { (JSJitGetterOp)clearInterval },
962 : { prototypes::id::WorkerGlobalScope },
963 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
964 : JSJitInfo::Method,
965 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
966 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
967 : false, /* isInfallible. False in setters. */
968 : false, /* isMovable. Not relevant for setters. */
969 : false, /* isEliminatable. Not relevant for setters. */
970 : false, /* isAlwaysInSlot. Only relevant for getters. */
971 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
972 : false, /* isTypedMethod. Only relevant for methods. */
973 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
974 : };
975 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
976 : static_assert(0 < 3, "There is no slot for us");
977 :
978 : static bool
979 0 : createImageBitmap(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, const JSJitMethodCallArgs& args)
980 : {
981 0 : unsigned argcount = std::min(args.length(), 5u);
982 0 : switch (argcount) {
983 : case 1: {
984 0 : HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer arg0;
985 0 : HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBufferArgument arg0_holder(arg0);
986 : {
987 0 : bool done = false, failed = false, tryNext;
988 0 : if (args[0].isObject()) {
989 0 : done = (failed = !arg0_holder.TrySetToHTMLImageElement(cx, args[0], tryNext, false)) || !tryNext ||
990 0 : (failed = !arg0_holder.TrySetToHTMLVideoElement(cx, args[0], tryNext, false)) || !tryNext ||
991 0 : (failed = !arg0_holder.TrySetToHTMLCanvasElement(cx, args[0], tryNext, false)) || !tryNext ||
992 0 : (failed = !arg0_holder.TrySetToBlob(cx, args[0], tryNext, false)) || !tryNext ||
993 0 : (failed = !arg0_holder.TrySetToImageData(cx, args[0], tryNext, false)) || !tryNext ||
994 0 : (failed = !arg0_holder.TrySetToCanvasRenderingContext2D(cx, args[0], tryNext, false)) || !tryNext ||
995 0 : (failed = !arg0_holder.TrySetToImageBitmap(cx, args[0], tryNext, false)) || !tryNext ||
996 0 : (failed = !arg0_holder.TrySetToArrayBufferView(cx, args[0], tryNext, false)) || !tryNext ||
997 0 : (failed = !arg0_holder.TrySetToArrayBuffer(cx, args[0], tryNext, false)) || !tryNext;
998 :
999 : }
1000 0 : if (failed) {
1001 0 : return false;
1002 : }
1003 0 : if (!done) {
1004 0 : ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of WorkerGlobalScope.createImageBitmap", "HTMLImageElement, HTMLVideoElement, HTMLCanvasElement, Blob, ImageData, CanvasRenderingContext2D, ImageBitmap, ArrayBufferView, ArrayBuffer");
1005 0 : return false;
1006 : }
1007 : }
1008 0 : binding_detail::FastErrorResult rv;
1009 0 : auto result(StrongOrRawPtr<Promise>(self->CreateImageBitmap(cx, Constify(arg0), rv)));
1010 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1011 0 : return false;
1012 : }
1013 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1014 0 : if (!ToJSValue(cx, result, args.rval())) {
1015 0 : return false;
1016 : }
1017 0 : return true;
1018 : break;
1019 : }
1020 : case 5: {
1021 0 : HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer arg0;
1022 0 : HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBufferArgument arg0_holder(arg0);
1023 : {
1024 0 : bool done = false, failed = false, tryNext;
1025 0 : if (args[0].isObject()) {
1026 0 : done = (failed = !arg0_holder.TrySetToHTMLImageElement(cx, args[0], tryNext, false)) || !tryNext ||
1027 0 : (failed = !arg0_holder.TrySetToHTMLVideoElement(cx, args[0], tryNext, false)) || !tryNext ||
1028 0 : (failed = !arg0_holder.TrySetToHTMLCanvasElement(cx, args[0], tryNext, false)) || !tryNext ||
1029 0 : (failed = !arg0_holder.TrySetToBlob(cx, args[0], tryNext, false)) || !tryNext ||
1030 0 : (failed = !arg0_holder.TrySetToImageData(cx, args[0], tryNext, false)) || !tryNext ||
1031 0 : (failed = !arg0_holder.TrySetToCanvasRenderingContext2D(cx, args[0], tryNext, false)) || !tryNext ||
1032 0 : (failed = !arg0_holder.TrySetToImageBitmap(cx, args[0], tryNext, false)) || !tryNext ||
1033 0 : (failed = !arg0_holder.TrySetToArrayBufferView(cx, args[0], tryNext, false)) || !tryNext ||
1034 0 : (failed = !arg0_holder.TrySetToArrayBuffer(cx, args[0], tryNext, false)) || !tryNext;
1035 :
1036 : }
1037 0 : if (failed) {
1038 0 : return false;
1039 : }
1040 0 : if (!done) {
1041 0 : ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of WorkerGlobalScope.createImageBitmap", "HTMLImageElement, HTMLVideoElement, HTMLCanvasElement, Blob, ImageData, CanvasRenderingContext2D, ImageBitmap, ArrayBufferView, ArrayBuffer");
1042 0 : return false;
1043 : }
1044 : }
1045 : int32_t arg1;
1046 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, args[1], &arg1)) {
1047 0 : return false;
1048 : }
1049 : int32_t arg2;
1050 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, args[2], &arg2)) {
1051 0 : return false;
1052 : }
1053 0 : if (args[3].isNumber()) {
1054 : int32_t arg3;
1055 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, args[3], &arg3)) {
1056 0 : return false;
1057 : }
1058 : int32_t arg4;
1059 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, args[4], &arg4)) {
1060 0 : return false;
1061 : }
1062 0 : binding_detail::FastErrorResult rv;
1063 0 : auto result(StrongOrRawPtr<Promise>(self->CreateImageBitmap(cx, Constify(arg0), arg1, arg2, arg3, arg4, rv)));
1064 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1065 0 : return false;
1066 : }
1067 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1068 0 : if (!ToJSValue(cx, result, args.rval())) {
1069 0 : return false;
1070 : }
1071 0 : return true;
1072 : }
1073 : ImageBitmapFormat arg3;
1074 : {
1075 : int index;
1076 0 : if (!FindEnumStringIndex<true>(cx, args[3], ImageBitmapFormatValues::strings, "ImageBitmapFormat", "Argument 4 of WorkerGlobalScope.createImageBitmap", &index)) {
1077 0 : return false;
1078 : }
1079 0 : MOZ_ASSERT(index >= 0);
1080 0 : arg3 = static_cast<ImageBitmapFormat>(index);
1081 : }
1082 0 : binding_detail::AutoSequence<ChannelPixelLayout> arg4;
1083 0 : if (args[4].isObject()) {
1084 0 : JS::ForOfIterator iter(cx);
1085 0 : if (!iter.init(args[4], JS::ForOfIterator::AllowNonIterable)) {
1086 0 : return false;
1087 : }
1088 0 : if (!iter.valueIsIterable()) {
1089 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 5 of WorkerGlobalScope.createImageBitmap");
1090 0 : return false;
1091 : }
1092 0 : binding_detail::AutoSequence<ChannelPixelLayout> &arr = arg4;
1093 0 : JS::Rooted<JS::Value> temp(cx);
1094 : while (true) {
1095 : bool done;
1096 0 : if (!iter.next(&temp, &done)) {
1097 0 : return false;
1098 : }
1099 0 : if (done) {
1100 0 : break;
1101 : }
1102 0 : ChannelPixelLayout* slotPtr = arr.AppendElement(mozilla::fallible);
1103 0 : if (!slotPtr) {
1104 0 : JS_ReportOutOfMemory(cx);
1105 0 : return false;
1106 : }
1107 0 : ChannelPixelLayout& slot = *slotPtr;
1108 0 : if (!slot.Init(cx, temp, "Element of argument 5 of WorkerGlobalScope.createImageBitmap", false)) {
1109 0 : return false;
1110 : }
1111 0 : }
1112 : } else {
1113 0 : ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 5 of WorkerGlobalScope.createImageBitmap");
1114 0 : return false;
1115 : }
1116 0 : binding_detail::FastErrorResult rv;
1117 0 : auto result(StrongOrRawPtr<Promise>(self->CreateImageBitmap(cx, Constify(arg0), arg1, arg2, arg3, Constify(arg4), rv)));
1118 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1119 0 : return false;
1120 : }
1121 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1122 0 : if (!ToJSValue(cx, result, args.rval())) {
1123 0 : return false;
1124 : }
1125 0 : return true;
1126 : break;
1127 : }
1128 : default: {
1129 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WorkerGlobalScope.createImageBitmap");
1130 : break;
1131 : }
1132 : }
1133 : MOZ_CRASH("We have an always-returning default case");
1134 : return false;
1135 : }
1136 :
1137 : static bool
1138 0 : createImageBitmap_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, const JSJitMethodCallArgs& args)
1139 : {
1140 : // Make sure to save the callee before someone maybe messes
1141 : // with rval().
1142 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
1143 0 : bool ok = createImageBitmap(cx, obj, self, args);
1144 0 : if (ok) {
1145 0 : return true;
1146 : }
1147 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
1148 0 : args.rval());
1149 : }
1150 :
1151 : static const JSJitInfo createImageBitmap_methodinfo = {
1152 : { (JSJitGetterOp)createImageBitmap_promiseWrapper },
1153 : { prototypes::id::WorkerGlobalScope },
1154 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
1155 : JSJitInfo::Method,
1156 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
1157 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
1158 : false, /* isInfallible. False in setters. */
1159 : false, /* isMovable. Not relevant for setters. */
1160 : false, /* isEliminatable. Not relevant for setters. */
1161 : false, /* isAlwaysInSlot. Only relevant for getters. */
1162 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
1163 : false, /* isTypedMethod. Only relevant for methods. */
1164 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
1165 : };
1166 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1167 : static_assert(0 < 3, "There is no slot for us");
1168 :
1169 : static bool
1170 0 : fetch(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, const JSJitMethodCallArgs& args)
1171 : {
1172 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
1173 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WorkerGlobalScope.fetch");
1174 : }
1175 0 : RequestOrUSVString arg0;
1176 0 : RequestOrUSVStringArgument arg0_holder(arg0);
1177 : {
1178 0 : bool done = false, failed = false, tryNext;
1179 0 : if (args[0].isObject()) {
1180 0 : done = (failed = !arg0_holder.TrySetToRequest(cx, args[0], tryNext, false)) || !tryNext;
1181 :
1182 : }
1183 0 : if (!done) {
1184 : do {
1185 0 : done = (failed = !arg0_holder.TrySetToUSVString(cx, args[0], tryNext)) || !tryNext;
1186 0 : break;
1187 : } while (0);
1188 : }
1189 0 : if (failed) {
1190 0 : return false;
1191 : }
1192 0 : if (!done) {
1193 0 : ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of WorkerGlobalScope.fetch", "Request");
1194 0 : return false;
1195 : }
1196 : }
1197 0 : RootedDictionary<binding_detail::FastRequestInit> arg1(cx);
1198 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of WorkerGlobalScope.fetch", false)) {
1199 0 : return false;
1200 : }
1201 0 : binding_detail::FastErrorResult rv;
1202 0 : auto result(StrongOrRawPtr<Promise>(self->Fetch(Constify(arg0), Constify(arg1), nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv)));
1203 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1204 0 : return false;
1205 : }
1206 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1207 : static_assert(!IsPointer<decltype(result)>::value,
1208 : "NewObject implies that we need to keep the object alive with a strong reference.");
1209 0 : if (!ToJSValue(cx, result, args.rval())) {
1210 0 : return false;
1211 : }
1212 0 : return true;
1213 : }
1214 :
1215 : static bool
1216 0 : fetch_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, const JSJitMethodCallArgs& args)
1217 : {
1218 : // Make sure to save the callee before someone maybe messes
1219 : // with rval().
1220 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
1221 0 : bool ok = fetch(cx, obj, self, args);
1222 0 : if (ok) {
1223 0 : return true;
1224 : }
1225 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
1226 0 : args.rval());
1227 : }
1228 :
1229 : static const JSJitInfo fetch_methodinfo = {
1230 : { (JSJitGetterOp)fetch_promiseWrapper },
1231 : { prototypes::id::WorkerGlobalScope },
1232 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
1233 : JSJitInfo::Method,
1234 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
1235 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
1236 : false, /* isInfallible. False in setters. */
1237 : false, /* isMovable. Not relevant for setters. */
1238 : false, /* isEliminatable. Not relevant for setters. */
1239 : false, /* isAlwaysInSlot. Only relevant for getters. */
1240 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
1241 : false, /* isTypedMethod. Only relevant for methods. */
1242 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
1243 : };
1244 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1245 : static_assert(0 < 3, "There is no slot for us");
1246 :
1247 : static bool
1248 0 : get_isSecureContext(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, JSJitGetterCallArgs args)
1249 : {
1250 0 : bool result(self->IsSecureContext());
1251 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1252 0 : args.rval().setBoolean(result);
1253 0 : return true;
1254 : }
1255 :
1256 : static const JSJitInfo isSecureContext_getterinfo = {
1257 : { (JSJitGetterOp)get_isSecureContext },
1258 : { prototypes::id::WorkerGlobalScope },
1259 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
1260 : JSJitInfo::Getter,
1261 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
1262 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
1263 : true, /* isInfallible. False in setters. */
1264 : false, /* isMovable. Not relevant for setters. */
1265 : false, /* isEliminatable. Not relevant for setters. */
1266 : false, /* isAlwaysInSlot. Only relevant for getters. */
1267 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
1268 : false, /* isTypedMethod. Only relevant for methods. */
1269 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
1270 : };
1271 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1272 : static_assert(0 < 3, "There is no slot for us");
1273 :
1274 : static bool
1275 0 : get_indexedDB(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, JSJitGetterCallArgs args)
1276 : {
1277 0 : binding_detail::FastErrorResult rv;
1278 0 : auto result(StrongOrRawPtr<mozilla::dom::IDBFactory>(self->GetIndexedDB(rv)));
1279 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1280 0 : return false;
1281 : }
1282 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1283 0 : if (!result) {
1284 0 : args.rval().setNull();
1285 0 : return true;
1286 : }
1287 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
1288 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
1289 0 : return false;
1290 : }
1291 0 : return true;
1292 : }
1293 :
1294 : static const JSJitInfo indexedDB_getterinfo = {
1295 : { (JSJitGetterOp)get_indexedDB },
1296 : { prototypes::id::WorkerGlobalScope },
1297 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
1298 : JSJitInfo::Getter,
1299 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
1300 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
1301 : false, /* isInfallible. False in setters. */
1302 : false, /* isMovable. Not relevant for setters. */
1303 : false, /* isEliminatable. Not relevant for setters. */
1304 : false, /* isAlwaysInSlot. Only relevant for getters. */
1305 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
1306 : false, /* isTypedMethod. Only relevant for methods. */
1307 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
1308 : };
1309 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1310 : static_assert(0 < 3, "There is no slot for us");
1311 :
1312 : static bool
1313 0 : get_caches(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerGlobalScope* self, JSJitGetterCallArgs args)
1314 : {
1315 0 : binding_detail::FastErrorResult rv;
1316 0 : auto result(StrongOrRawPtr<mozilla::dom::cache::CacheStorage>(self->GetCaches(rv)));
1317 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1318 0 : return false;
1319 : }
1320 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1321 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
1322 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
1323 0 : return false;
1324 : }
1325 0 : return true;
1326 : }
1327 :
1328 : static const JSJitInfo caches_getterinfo = {
1329 : { (JSJitGetterOp)get_caches },
1330 : { prototypes::id::WorkerGlobalScope },
1331 : { PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth },
1332 : JSJitInfo::Getter,
1333 : JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
1334 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
1335 : false, /* isInfallible. False in setters. */
1336 : false, /* isMovable. Not relevant for setters. */
1337 : false, /* isEliminatable. Not relevant for setters. */
1338 : false, /* isAlwaysInSlot. Only relevant for getters. */
1339 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
1340 : false, /* isTypedMethod. Only relevant for methods. */
1341 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
1342 : };
1343 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1344 : static_assert(0 < 3, "There is no slot for us");
1345 :
1346 : static bool
1347 4 : genericMethod(JSContext* cx, unsigned argc, JS::Value* vp)
1348 : {
1349 4 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1350 4 : if (!args.thisv().isNullOrUndefined() && !args.thisv().isObject()) {
1351 0 : return ThrowInvalidThis(cx, args, false, "WorkerGlobalScope");
1352 : }
1353 6 : JS::Rooted<JSObject*> obj(cx, args.thisv().isObject() ? &args.thisv().toObject() : js::GetGlobalForObjectCrossCompartment(&args.callee()));
1354 :
1355 : mozilla::dom::WorkerGlobalScope* self;
1356 6 : JS::Rooted<JS::Value> rootSelf(cx, JS::ObjectValue(*obj));
1357 : {
1358 4 : nsresult rv = UnwrapObject<prototypes::id::WorkerGlobalScope, mozilla::dom::WorkerGlobalScope>(&rootSelf, self);
1359 4 : if (NS_FAILED(rv)) {
1360 0 : return ThrowInvalidThis(cx, args, rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO, "WorkerGlobalScope");
1361 : }
1362 : }
1363 4 : const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(args.calleev());
1364 4 : MOZ_ASSERT(info->type() == JSJitInfo::Method);
1365 4 : JSJitMethodOp method = info->method;
1366 4 : bool ok = method(cx, obj, self, JSJitMethodCallArgs(args));
1367 : #ifdef DEBUG
1368 2 : if (ok) {
1369 2 : AssertReturnTypeMatchesJitinfo(info, args.rval());
1370 : }
1371 : #endif
1372 2 : return ok;
1373 : }
1374 :
1375 : static bool
1376 0 : genericPromiseReturningMethod(JSContext* cx, unsigned argc, JS::Value* vp)
1377 : {
1378 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1379 : // Make sure to save the callee before someone maybe messes with rval().
1380 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
1381 0 : if (!args.thisv().isNullOrUndefined() && !args.thisv().isObject()) {
1382 0 : ThrowInvalidThis(cx, args, false, "WorkerGlobalScope");
1383 :
1384 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
1385 0 : args.rval());
1386 : }
1387 0 : JS::Rooted<JSObject*> obj(cx, args.thisv().isObject() ? &args.thisv().toObject() : js::GetGlobalForObjectCrossCompartment(&args.callee()));
1388 :
1389 : mozilla::dom::WorkerGlobalScope* self;
1390 0 : JS::Rooted<JS::Value> rootSelf(cx, JS::ObjectValue(*obj));
1391 : {
1392 0 : nsresult rv = UnwrapObject<prototypes::id::WorkerGlobalScope, mozilla::dom::WorkerGlobalScope>(&rootSelf, self);
1393 0 : if (NS_FAILED(rv)) {
1394 0 : ThrowInvalidThis(cx, args, rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO, "WorkerGlobalScope");
1395 :
1396 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
1397 0 : args.rval());
1398 : }
1399 : }
1400 0 : const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(args.calleev());
1401 0 : MOZ_ASSERT(info->type() == JSJitInfo::Method);
1402 0 : JSJitMethodOp method = info->method;
1403 0 : bool ok = method(cx, obj, self, JSJitMethodCallArgs(args));
1404 0 : if (ok) {
1405 : #ifdef DEBUG
1406 0 : AssertReturnTypeMatchesJitinfo(info, args.rval());
1407 : #endif
1408 0 : return true;
1409 : }
1410 :
1411 0 : MOZ_ASSERT(info->returnType() == JSVAL_TYPE_OBJECT);
1412 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
1413 0 : args.rval());
1414 : }
1415 :
1416 : static bool
1417 0 : genericGetter(JSContext* cx, unsigned argc, JS::Value* vp)
1418 : {
1419 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1420 0 : if (!args.thisv().isNullOrUndefined() && !args.thisv().isObject()) {
1421 0 : return ThrowInvalidThis(cx, args, false, "WorkerGlobalScope");
1422 : }
1423 0 : JS::Rooted<JSObject*> obj(cx, args.thisv().isObject() ? &args.thisv().toObject() : js::GetGlobalForObjectCrossCompartment(&args.callee()));
1424 :
1425 : mozilla::dom::WorkerGlobalScope* self;
1426 0 : JS::Rooted<JS::Value> rootSelf(cx, JS::ObjectValue(*obj));
1427 : {
1428 0 : nsresult rv = UnwrapObject<prototypes::id::WorkerGlobalScope, mozilla::dom::WorkerGlobalScope>(&rootSelf, self);
1429 0 : if (NS_FAILED(rv)) {
1430 0 : return ThrowInvalidThis(cx, args, rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO, "WorkerGlobalScope");
1431 : }
1432 : }
1433 0 : const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(args.calleev());
1434 0 : MOZ_ASSERT(info->type() == JSJitInfo::Getter);
1435 0 : JSJitGetterOp getter = info->getter;
1436 0 : bool ok = getter(cx, obj, self, JSJitGetterCallArgs(args));
1437 : #ifdef DEBUG
1438 0 : if (ok) {
1439 0 : AssertReturnTypeMatchesJitinfo(info, args.rval());
1440 : }
1441 : #endif
1442 0 : return ok;
1443 : }
1444 :
1445 : static bool
1446 0 : genericSetter(JSContext* cx, unsigned argc, JS::Value* vp)
1447 : {
1448 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1449 0 : if (!args.thisv().isNullOrUndefined() && !args.thisv().isObject()) {
1450 0 : return ThrowInvalidThis(cx, args, false, "WorkerGlobalScope");
1451 : }
1452 0 : JS::Rooted<JSObject*> obj(cx, args.thisv().isObject() ? &args.thisv().toObject() : js::GetGlobalForObjectCrossCompartment(&args.callee()));
1453 :
1454 : mozilla::dom::WorkerGlobalScope* self;
1455 0 : JS::Rooted<JS::Value> rootSelf(cx, JS::ObjectValue(*obj));
1456 : {
1457 0 : nsresult rv = UnwrapObject<prototypes::id::WorkerGlobalScope, mozilla::dom::WorkerGlobalScope>(&rootSelf, self);
1458 0 : if (NS_FAILED(rv)) {
1459 0 : return ThrowInvalidThis(cx, args, rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO, "WorkerGlobalScope");
1460 : }
1461 : }
1462 0 : if (args.length() == 0) {
1463 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WorkerGlobalScope attribute setter");
1464 : }
1465 0 : const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(args.calleev());
1466 0 : MOZ_ASSERT(info->type() == JSJitInfo::Setter);
1467 0 : JSJitSetterOp setter = info->setter;
1468 0 : if (!setter(cx, obj, self, JSJitSetterCallArgs(args))) {
1469 0 : return false;
1470 : }
1471 0 : args.rval().setUndefined();
1472 : #ifdef DEBUG
1473 0 : AssertReturnTypeMatchesJitinfo(info, args.rval());
1474 : #endif
1475 0 : return true;
1476 : }
1477 :
1478 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
1479 : #if defined(__clang__)
1480 : #pragma clang diagnostic push
1481 : #pragma clang diagnostic ignored "-Wmissing-braces"
1482 : #endif
1483 : static const JSFunctionSpec sMethods_specs[] = {
1484 : JS_FNSPEC("importScripts", genericMethod, reinterpret_cast<const JSJitInfo*>(&importScripts_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1485 : JS_FNSPEC("dump", genericMethod, reinterpret_cast<const JSJitInfo*>(&dump_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1486 : JS_FNSPEC("btoa", genericMethod, reinterpret_cast<const JSJitInfo*>(&btoa_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1487 : JS_FNSPEC("atob", genericMethod, reinterpret_cast<const JSJitInfo*>(&atob_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1488 : JS_FNSPEC("setTimeout", genericMethod, reinterpret_cast<const JSJitInfo*>(&setTimeout_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1489 : JS_FNSPEC("clearTimeout", genericMethod, reinterpret_cast<const JSJitInfo*>(&clearTimeout_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1490 : JS_FNSPEC("setInterval", genericMethod, reinterpret_cast<const JSJitInfo*>(&setInterval_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1491 : JS_FNSPEC("clearInterval", genericMethod, reinterpret_cast<const JSJitInfo*>(&clearInterval_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1492 : JS_FNSPEC("createImageBitmap", genericPromiseReturningMethod, reinterpret_cast<const JSJitInfo*>(&createImageBitmap_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1493 : JS_FNSPEC("fetch", genericPromiseReturningMethod, reinterpret_cast<const JSJitInfo*>(&fetch_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1494 : JS_FS_END
1495 : };
1496 : #if defined(__clang__)
1497 : #pragma clang diagnostic pop
1498 : #endif
1499 :
1500 :
1501 : // Can't be const because the pref-enabled boolean needs to be writable
1502 : static Prefable<const JSFunctionSpec> sMethods[] = {
1503 : { nullptr, &sMethods_specs[0] },
1504 : { nullptr, nullptr }
1505 : };
1506 :
1507 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
1508 : #if defined(__clang__)
1509 : #pragma clang diagnostic push
1510 : #pragma clang diagnostic ignored "-Wmissing-braces"
1511 : #endif
1512 : static const JSPropertySpec sAttributes_specs[] = {
1513 : { "self", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &self_getterinfo, nullptr, nullptr },
1514 : { "location", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &location_getterinfo, nullptr, nullptr },
1515 : { "navigator", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &navigator_getterinfo, nullptr, nullptr },
1516 : { "onerror", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &onerror_getterinfo, genericSetter, &onerror_setterinfo },
1517 : { "onoffline", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &onoffline_getterinfo, genericSetter, &onoffline_setterinfo },
1518 : { "ononline", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &ononline_getterinfo, genericSetter, &ononline_setterinfo },
1519 : { "performance", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &performance_getterinfo, nullptr, nullptr },
1520 : { "crypto", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &crypto_getterinfo, nullptr, nullptr },
1521 : { "origin", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &origin_getterinfo, genericSetter, &origin_setterinfo },
1522 : { "isSecureContext", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &isSecureContext_getterinfo, nullptr, nullptr },
1523 : { "indexedDB", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &indexedDB_getterinfo, nullptr, nullptr },
1524 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
1525 : { "caches", JSPROP_SHARED | JSPROP_ENUMERATE, genericGetter, &caches_getterinfo, nullptr, nullptr },
1526 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1527 : };
1528 : #if defined(__clang__)
1529 : #pragma clang diagnostic pop
1530 : #endif
1531 :
1532 : static PrefableDisablers sAttributes_disablers12 = {
1533 : true, false, 0, &mozilla::dom::cache::CacheStorage::PrefEnabled
1534 : };
1535 :
1536 : // Can't be const because the pref-enabled boolean needs to be writable
1537 : static Prefable<const JSPropertySpec> sAttributes[] = {
1538 : { nullptr, &sAttributes_specs[0] },
1539 : { &sAttributes_disablers12, &sAttributes_specs[12] },
1540 : { nullptr, nullptr }
1541 : };
1542 :
1543 :
1544 : static const NativePropertiesN<2> sNativeProperties = {
1545 : false, 0,
1546 : false, 0,
1547 : true, 0 /* sMethods */,
1548 : true, 1 /* sAttributes */,
1549 : false, 0,
1550 : false, 0,
1551 : false, 0,
1552 : -1,
1553 : 0,
1554 : nullptr,
1555 : {
1556 : { sMethods, nullptr },
1557 : { sAttributes, nullptr }
1558 : }
1559 : };
1560 :
1561 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1562 : {
1563 : "Function",
1564 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1565 : &sBoringInterfaceObjectClassClassOps,
1566 : JS_NULL_CLASS_SPEC,
1567 : JS_NULL_CLASS_EXT,
1568 : &sInterfaceObjectClassObjectOps
1569 : },
1570 : eInterface,
1571 : true,
1572 : prototypes::id::WorkerGlobalScope,
1573 : PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth,
1574 : &sEmptyNativePropertyHooks,
1575 : "function WorkerGlobalScope() {\n [native code]\n}",
1576 : EventTargetBinding::GetConstructorObject
1577 : };
1578 :
1579 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1580 : {
1581 : "WorkerGlobalScopePrototype",
1582 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
1583 : JS_NULL_CLASS_OPS,
1584 : JS_NULL_CLASS_SPEC,
1585 : JS_NULL_CLASS_EXT,
1586 : JS_NULL_OBJECT_OPS
1587 : },
1588 : eInterfacePrototype,
1589 : false,
1590 : prototypes::id::WorkerGlobalScope,
1591 : PrototypeTraits<prototypes::id::WorkerGlobalScope>::Depth,
1592 : &sEmptyNativePropertyHooks,
1593 : "[object WorkerGlobalScopePrototype]",
1594 : EventTargetBinding::GetProtoObject
1595 : };
1596 :
1597 : void
1598 1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1599 : {
1600 1 : JS::Handle<JSObject*> parentProto(EventTargetBinding::GetProtoObjectHandle(aCx));
1601 1 : if (!parentProto) {
1602 0 : return;
1603 : }
1604 :
1605 1 : JS::Handle<JSObject*> constructorProto(EventTargetBinding::GetConstructorObjectHandle(aCx));
1606 1 : if (!constructorProto) {
1607 0 : return;
1608 : }
1609 :
1610 1 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WorkerGlobalScope);
1611 1 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WorkerGlobalScope);
1612 1 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1613 : &sPrototypeClass.mBase, protoCache,
1614 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1615 : interfaceCache,
1616 : sNativeProperties.Upcast(),
1617 : nullptr,
1618 : "WorkerGlobalScope", aDefineOnGlobal,
1619 : nullptr,
1620 1 : false);
1621 :
1622 1 : if (*&aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WorkerGlobalScope)) {
1623 : bool succeeded;
1624 1 : JS::Handle<JSObject*> prot = GetProtoObjectHandle(aCx);
1625 1 : if (!JS_SetImmutablePrototype(aCx, prot, &succeeded)) {
1626 0 : *protoCache = nullptr;
1627 0 : if (interfaceCache) {
1628 0 : *interfaceCache = nullptr;
1629 : }
1630 0 : return;
1631 : }
1632 :
1633 1 : MOZ_ASSERT(succeeded,
1634 : "making a fresh prototype object's [[Prototype]] "
1635 : "immutable can internally fail, but it should "
1636 : "never be unsuccessful");
1637 : }
1638 : }
1639 :
1640 : JS::Handle<JSObject*>
1641 2 : GetProtoObjectHandle(JSContext* aCx)
1642 : {
1643 : /* Get the interface prototype object for this class. This will create the
1644 : object as needed. */
1645 2 : bool aDefineOnGlobal = true;
1646 :
1647 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1648 2 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1649 2 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1650 0 : return nullptr;
1651 : }
1652 :
1653 : /* Check to see whether the interface objects are already installed */
1654 2 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1655 2 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::WorkerGlobalScope)) {
1656 2 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1657 1 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1658 : }
1659 :
1660 : /*
1661 : * The object might _still_ be null, but that's OK.
1662 : *
1663 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1664 : * traced by TraceProtoAndIfaceCache() and its contents are never
1665 : * changed after they have been set.
1666 : *
1667 : * Calling address() avoids the read read barrier that does gray
1668 : * unmarking, but it's not possible for the object to be gray here.
1669 : */
1670 :
1671 2 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::WorkerGlobalScope);
1672 2 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1673 2 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1674 : }
1675 :
1676 : JSObject*
1677 0 : GetProtoObject(JSContext* aCx)
1678 : {
1679 0 : return GetProtoObjectHandle(aCx);
1680 : }
1681 :
1682 : JS::Handle<JSObject*>
1683 2 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
1684 : {
1685 : /* Get the interface object for this class. This will create the object as
1686 : needed. */
1687 :
1688 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1689 2 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1690 2 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1691 0 : return nullptr;
1692 : }
1693 :
1694 : /* Check to see whether the interface objects are already installed */
1695 2 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1696 2 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::WorkerGlobalScope)) {
1697 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1698 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1699 : }
1700 :
1701 : /*
1702 : * The object might _still_ be null, but that's OK.
1703 : *
1704 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1705 : * traced by TraceProtoAndIfaceCache() and its contents are never
1706 : * changed after they have been set.
1707 : *
1708 : * Calling address() avoids the read read barrier that does gray
1709 : * unmarking, but it's not possible for the object to be gray here.
1710 : */
1711 :
1712 2 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::WorkerGlobalScope);
1713 2 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1714 2 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1715 : }
1716 :
1717 : JSObject*
1718 1 : GetConstructorObject(JSContext* aCx)
1719 : {
1720 1 : return GetConstructorObjectHandle(aCx);
1721 : }
1722 :
1723 : } // namespace WorkerGlobalScopeBinding
1724 :
1725 :
1726 :
1727 : } // namespace dom
1728 : } // namespace mozilla
|