Coverage Report

Created: 2018-09-25 14:53

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