Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/WorkerDebuggerGlobalScopeBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM WorkerDebuggerGlobalScope.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "EventHandlerBinding.h"
4
#include "EventTargetBinding.h"
5
#include "FunctionBinding.h"
6
#include "PromiseBinding.h"
7
#include "WorkerDebuggerGlobalScopeBinding.h"
8
#include "WrapperFactory.h"
9
#include "mozilla/OwningNonNull.h"
10
#include "mozilla/dom/BindingUtils.h"
11
#include "mozilla/dom/DOMJSClass.h"
12
#include "mozilla/dom/NonRefcountedDOMObject.h"
13
#include "mozilla/dom/Nullable.h"
14
#include "mozilla/dom/WorkerScope.h"
15
16
namespace mozilla {
17
namespace dom {
18
19
namespace binding_detail {}; // Just to make sure it's known as a namespace
20
using namespace mozilla::dom::binding_detail;
21
22
23
namespace WorkerDebuggerGlobalScope_Binding {
24
25
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value,
26
              "Can't inherit from an interface with a different ownership model.");
27
28
MOZ_CAN_RUN_SCRIPT static bool
29
get_global(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerDebuggerGlobalScope* self, JSJitGetterCallArgs args)
30
0
{
31
0
  AUTO_PROFILER_LABEL_FAST("get WorkerDebuggerGlobalScope.global", DOM, cx);
32
0
33
0
  FastErrorResult rv;
34
0
  JS::Rooted<JSObject*> result(cx);
35
0
  self->GetGlobal(cx, &result, rv);
36
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
37
0
    return false;
38
0
  }
39
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
40
0
  JS::ExposeObjectToActiveJS(result);
41
0
  args.rval().setObject(*result);
42
0
  if (!MaybeWrapObjectValue(cx, args.rval())) {
43
0
    return false;
44
0
  }
45
0
  return true;
46
0
}
47
48
static const JSJitInfo global_getterinfo = {
49
  { (JSJitGetterOp)get_global },
50
  { prototypes::id::WorkerDebuggerGlobalScope },
51
  { PrototypeTraits<prototypes::id::WorkerDebuggerGlobalScope>::Depth },
52
  JSJitInfo::Getter,
53
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
54
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
55
  false,  /* isInfallible. False in setters. */
56
  false,  /* isMovable.  Not relevant for setters. */
57
  false, /* isEliminatable.  Not relevant for setters. */
58
  false, /* isAlwaysInSlot.  Only relevant for getters. */
59
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
60
  false,  /* isTypedMethod.  Only relevant for methods. */
61
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
62
};
63
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
64
static_assert(0 < 1, "There is no slot for us");
65
66
MOZ_CAN_RUN_SCRIPT static bool
67
createSandbox(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerDebuggerGlobalScope* self, const JSJitMethodCallArgs& args)
68
0
{
69
0
  AUTO_PROFILER_LABEL_FAST("WorkerDebuggerGlobalScope.createSandbox", DOM, cx);
70
0
71
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
72
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WorkerDebuggerGlobalScope.createSandbox");
73
0
  }
74
0
  binding_detail::FakeString arg0;
75
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
76
0
    return false;
77
0
  }
78
0
  JS::Rooted<JSObject*> arg1(cx);
79
0
  if (args[1].isObject()) {
80
0
    arg1 = &args[1].toObject();
81
0
  } else {
82
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of WorkerDebuggerGlobalScope.createSandbox");
83
0
    return false;
84
0
  }
85
0
  FastErrorResult rv;
86
0
  JS::Rooted<JSObject*> result(cx);
87
0
  self->CreateSandbox(cx, NonNullHelper(Constify(arg0)), arg1, &result, rv);
88
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
89
0
    return false;
90
0
  }
91
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
92
0
  JS::ExposeObjectToActiveJS(result);
93
0
  args.rval().setObject(*result);
94
0
  if (!MaybeWrapObjectValue(cx, args.rval())) {
95
0
    return false;
96
0
  }
97
0
  return true;
98
0
}
99
100
static const JSJitInfo createSandbox_methodinfo = {
101
  { (JSJitGetterOp)createSandbox },
102
  { prototypes::id::WorkerDebuggerGlobalScope },
103
  { PrototypeTraits<prototypes::id::WorkerDebuggerGlobalScope>::Depth },
104
  JSJitInfo::Method,
105
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
106
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
107
  false,  /* isInfallible. False in setters. */
108
  false,  /* isMovable.  Not relevant for setters. */
109
  false, /* isEliminatable.  Not relevant for setters. */
110
  false, /* isAlwaysInSlot.  Only relevant for getters. */
111
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
112
  false,  /* isTypedMethod.  Only relevant for methods. */
113
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
114
};
115
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
116
static_assert(0 < 1, "There is no slot for us");
117
118
MOZ_CAN_RUN_SCRIPT static bool
119
loadSubScript(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerDebuggerGlobalScope* self, const JSJitMethodCallArgs& args)
120
0
{
121
0
  AUTO_PROFILER_LABEL_FAST("WorkerDebuggerGlobalScope.loadSubScript", DOM, cx);
122
0
123
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
124
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WorkerDebuggerGlobalScope.loadSubScript");
125
0
  }
126
0
  binding_detail::FakeString arg0;
127
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
128
0
    return false;
129
0
  }
130
0
  Optional<JS::Handle<JSObject*>> arg1;
131
0
  if (args.hasDefined(1)) {
132
0
    arg1.Construct(cx);
133
0
    if (args[1].isObject()) {
134
0
      arg1.Value() = &args[1].toObject();
135
0
    } else {
136
0
      ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of WorkerDebuggerGlobalScope.loadSubScript");
137
0
      return false;
138
0
    }
139
0
  }
140
0
  FastErrorResult rv;
141
0
  self->LoadSubScript(cx, NonNullHelper(Constify(arg0)), Constify(arg1), rv);
142
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
143
0
    return false;
144
0
  }
145
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
146
0
  args.rval().setUndefined();
147
0
  return true;
148
0
}
149
150
static const JSJitInfo loadSubScript_methodinfo = {
151
  { (JSJitGetterOp)loadSubScript },
152
  { prototypes::id::WorkerDebuggerGlobalScope },
153
  { PrototypeTraits<prototypes::id::WorkerDebuggerGlobalScope>::Depth },
154
  JSJitInfo::Method,
155
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
156
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
157
  false,  /* isInfallible. False in setters. */
158
  false,  /* isMovable.  Not relevant for setters. */
159
  false, /* isEliminatable.  Not relevant for setters. */
160
  false, /* isAlwaysInSlot.  Only relevant for getters. */
161
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
162
  false,  /* isTypedMethod.  Only relevant for methods. */
163
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
164
};
165
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
166
static_assert(0 < 1, "There is no slot for us");
167
168
MOZ_CAN_RUN_SCRIPT static bool
169
enterEventLoop(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerDebuggerGlobalScope* self, const JSJitMethodCallArgs& args)
170
0
{
171
0
  AUTO_PROFILER_LABEL_FAST("WorkerDebuggerGlobalScope.enterEventLoop", DOM, cx);
172
0
173
0
  self->EnterEventLoop();
174
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
175
0
  args.rval().setUndefined();
176
0
  return true;
177
0
}
178
179
static const JSJitInfo enterEventLoop_methodinfo = {
180
  { (JSJitGetterOp)enterEventLoop },
181
  { prototypes::id::WorkerDebuggerGlobalScope },
182
  { PrototypeTraits<prototypes::id::WorkerDebuggerGlobalScope>::Depth },
183
  JSJitInfo::Method,
184
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
185
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
186
  true,  /* isInfallible. False in setters. */
187
  false,  /* isMovable.  Not relevant for setters. */
188
  false, /* isEliminatable.  Not relevant for setters. */
189
  false, /* isAlwaysInSlot.  Only relevant for getters. */
190
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
191
  false,  /* isTypedMethod.  Only relevant for methods. */
192
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
193
};
194
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
195
static_assert(0 < 1, "There is no slot for us");
196
197
MOZ_CAN_RUN_SCRIPT static bool
198
leaveEventLoop(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerDebuggerGlobalScope* self, const JSJitMethodCallArgs& args)
199
0
{
200
0
  AUTO_PROFILER_LABEL_FAST("WorkerDebuggerGlobalScope.leaveEventLoop", DOM, cx);
201
0
202
0
  self->LeaveEventLoop();
203
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
204
0
  args.rval().setUndefined();
205
0
  return true;
206
0
}
207
208
static const JSJitInfo leaveEventLoop_methodinfo = {
209
  { (JSJitGetterOp)leaveEventLoop },
210
  { prototypes::id::WorkerDebuggerGlobalScope },
211
  { PrototypeTraits<prototypes::id::WorkerDebuggerGlobalScope>::Depth },
212
  JSJitInfo::Method,
213
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
214
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
215
  true,  /* isInfallible. False in setters. */
216
  false,  /* isMovable.  Not relevant for setters. */
217
  false, /* isEliminatable.  Not relevant for setters. */
218
  false, /* isAlwaysInSlot.  Only relevant for getters. */
219
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
220
  false,  /* isTypedMethod.  Only relevant for methods. */
221
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
222
};
223
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
224
static_assert(0 < 1, "There is no slot for us");
225
226
MOZ_CAN_RUN_SCRIPT static bool
227
postMessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerDebuggerGlobalScope* self, const JSJitMethodCallArgs& args)
228
0
{
229
0
  AUTO_PROFILER_LABEL_FAST("WorkerDebuggerGlobalScope.postMessage", DOM, cx);
230
0
231
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
232
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WorkerDebuggerGlobalScope.postMessage");
233
0
  }
234
0
  binding_detail::FakeString arg0;
235
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
236
0
    return false;
237
0
  }
238
0
  self->PostMessage(NonNullHelper(Constify(arg0)));
239
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
240
0
  args.rval().setUndefined();
241
0
  return true;
242
0
}
243
244
static const JSJitInfo postMessage_methodinfo = {
245
  { (JSJitGetterOp)postMessage },
246
  { prototypes::id::WorkerDebuggerGlobalScope },
247
  { PrototypeTraits<prototypes::id::WorkerDebuggerGlobalScope>::Depth },
248
  JSJitInfo::Method,
249
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
250
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
251
  false,  /* isInfallible. False in setters. */
252
  false,  /* isMovable.  Not relevant for setters. */
253
  false, /* isEliminatable.  Not relevant for setters. */
254
  false, /* isAlwaysInSlot.  Only relevant for getters. */
255
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
256
  false,  /* isTypedMethod.  Only relevant for methods. */
257
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
258
};
259
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
260
static_assert(0 < 1, "There is no slot for us");
261
262
MOZ_CAN_RUN_SCRIPT static bool
263
get_onmessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerDebuggerGlobalScope* self, JSJitGetterCallArgs args)
264
0
{
265
0
  AUTO_PROFILER_LABEL_FAST("get WorkerDebuggerGlobalScope.onmessage", DOM, cx);
266
0
267
0
  RefPtr<EventHandlerNonNull> result(self->GetOnmessage());
268
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
269
0
  if (result) {
270
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
271
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
272
0
      return false;
273
0
    }
274
0
    return true;
275
0
  } else {
276
0
    args.rval().setNull();
277
0
    return true;
278
0
  }
279
0
}
280
281
MOZ_CAN_RUN_SCRIPT static bool
282
set_onmessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerDebuggerGlobalScope* self, JSJitSetterCallArgs args)
283
0
{
284
0
  AUTO_PROFILER_LABEL_FAST("set WorkerDebuggerGlobalScope.onmessage", DOM, cx);
285
0
286
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
287
0
  if (args[0].isObject()) {
288
0
    { // scope for tempRoot and tempGlobalRoot if needed
289
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
290
0
    }
291
0
  } else {
292
0
    arg0 = nullptr;
293
0
  }
294
0
  self->SetOnmessage(Constify(arg0));
295
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
296
0
297
0
  return true;
298
0
}
299
300
static const JSJitInfo onmessage_getterinfo = {
301
  { (JSJitGetterOp)get_onmessage },
302
  { prototypes::id::WorkerDebuggerGlobalScope },
303
  { PrototypeTraits<prototypes::id::WorkerDebuggerGlobalScope>::Depth },
304
  JSJitInfo::Getter,
305
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
306
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
307
  false,  /* isInfallible. False in setters. */
308
  false,  /* isMovable.  Not relevant for setters. */
309
  false, /* isEliminatable.  Not relevant for setters. */
310
  false, /* isAlwaysInSlot.  Only relevant for getters. */
311
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
312
  false,  /* isTypedMethod.  Only relevant for methods. */
313
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
314
};
315
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
316
static_assert(0 < 1, "There is no slot for us");
317
static const JSJitInfo onmessage_setterinfo = {
318
  { (JSJitGetterOp)set_onmessage },
319
  { prototypes::id::WorkerDebuggerGlobalScope },
320
  { PrototypeTraits<prototypes::id::WorkerDebuggerGlobalScope>::Depth },
321
  JSJitInfo::Setter,
322
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
323
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
324
  false,  /* isInfallible. False in setters. */
325
  false,  /* isMovable.  Not relevant for setters. */
326
  false, /* isEliminatable.  Not relevant for setters. */
327
  false, /* isAlwaysInSlot.  Only relevant for getters. */
328
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
329
  false,  /* isTypedMethod.  Only relevant for methods. */
330
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
331
};
332
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
333
static_assert(0 < 1, "There is no slot for us");
334
335
MOZ_CAN_RUN_SCRIPT static bool
336
setImmediate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerDebuggerGlobalScope* self, const JSJitMethodCallArgs& args)
337
0
{
338
0
  AUTO_PROFILER_LABEL_FAST("WorkerDebuggerGlobalScope.setImmediate", DOM, cx);
339
0
340
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
341
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WorkerDebuggerGlobalScope.setImmediate");
342
0
  }
343
0
  RootedCallback<OwningNonNull<binding_detail::FastFunction>> arg0(cx);
344
0
  if (args[0].isObject()) {
345
0
    if (JS::IsCallable(&args[0].toObject())) {
346
0
    { // scope for tempRoot and tempGlobalRoot if needed
347
0
      arg0 = new binding_detail::FastFunction(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
348
0
    }
349
0
    } else {
350
0
      ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 1 of WorkerDebuggerGlobalScope.setImmediate");
351
0
      return false;
352
0
    }
353
0
  } else {
354
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of WorkerDebuggerGlobalScope.setImmediate");
355
0
    return false;
356
0
  }
357
0
  FastErrorResult rv;
358
0
  self->SetImmediate(NonNullHelper(arg0), rv);
359
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
360
0
    return false;
361
0
  }
362
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
363
0
  args.rval().setUndefined();
364
0
  return true;
365
0
}
366
367
static const JSJitInfo setImmediate_methodinfo = {
368
  { (JSJitGetterOp)setImmediate },
369
  { prototypes::id::WorkerDebuggerGlobalScope },
370
  { PrototypeTraits<prototypes::id::WorkerDebuggerGlobalScope>::Depth },
371
  JSJitInfo::Method,
372
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
373
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
374
  false,  /* isInfallible. False in setters. */
375
  false,  /* isMovable.  Not relevant for setters. */
376
  false, /* isEliminatable.  Not relevant for setters. */
377
  false, /* isAlwaysInSlot.  Only relevant for getters. */
378
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
379
  false,  /* isTypedMethod.  Only relevant for methods. */
380
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
381
};
382
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
383
static_assert(0 < 1, "There is no slot for us");
384
385
MOZ_CAN_RUN_SCRIPT static bool
386
reportError(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerDebuggerGlobalScope* self, const JSJitMethodCallArgs& args)
387
0
{
388
0
  AUTO_PROFILER_LABEL_FAST("WorkerDebuggerGlobalScope.reportError", DOM, cx);
389
0
390
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
391
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WorkerDebuggerGlobalScope.reportError");
392
0
  }
393
0
  binding_detail::FakeString arg0;
394
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
395
0
    return false;
396
0
  }
397
0
  self->ReportError(cx, NonNullHelper(Constify(arg0)));
398
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
399
0
  args.rval().setUndefined();
400
0
  return true;
401
0
}
402
403
static const JSJitInfo reportError_methodinfo = {
404
  { (JSJitGetterOp)reportError },
405
  { prototypes::id::WorkerDebuggerGlobalScope },
406
  { PrototypeTraits<prototypes::id::WorkerDebuggerGlobalScope>::Depth },
407
  JSJitInfo::Method,
408
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
409
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
410
  false,  /* isInfallible. False in setters. */
411
  false,  /* isMovable.  Not relevant for setters. */
412
  false, /* isEliminatable.  Not relevant for setters. */
413
  false, /* isAlwaysInSlot.  Only relevant for getters. */
414
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
415
  false,  /* isTypedMethod.  Only relevant for methods. */
416
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
417
};
418
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
419
static_assert(0 < 1, "There is no slot for us");
420
421
MOZ_CAN_RUN_SCRIPT static bool
422
retrieveConsoleEvents(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerDebuggerGlobalScope* self, const JSJitMethodCallArgs& args)
423
0
{
424
0
  AUTO_PROFILER_LABEL_FAST("WorkerDebuggerGlobalScope.retrieveConsoleEvents", DOM, cx);
425
0
426
0
  FastErrorResult rv;
427
0
  nsTArray<JS::Value> result;
428
0
  SequenceRooter<JS::Value > resultRooter(cx, &result);
429
0
  self->RetrieveConsoleEvents(cx, result, rv);
430
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
431
0
    return false;
432
0
  }
433
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
434
0
435
0
  uint32_t length = result.Length();
436
0
  JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
437
0
  if (!returnArray) {
438
0
    return false;
439
0
  }
440
0
  // Scope for 'tmp'
441
0
  {
442
0
    JS::Rooted<JS::Value> tmp(cx);
443
0
    for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
444
0
      // Control block to let us common up the JS_DefineElement calls when there
445
0
      // are different ways to succeed at wrapping the object.
446
0
      do {
447
0
        JS::ExposeValueToActiveJS(result[sequenceIdx0]);
448
0
        tmp.set(result[sequenceIdx0]);
449
0
        if (!MaybeWrapValue(cx, &tmp)) {
450
0
          return false;
451
0
        }
452
0
        break;
453
0
      } while (false);
454
0
      if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
455
0
                            JSPROP_ENUMERATE)) {
456
0
        return false;
457
0
      }
458
0
    }
459
0
  }
460
0
  args.rval().setObject(*returnArray);
461
0
  return true;
462
0
}
463
464
static const JSJitInfo retrieveConsoleEvents_methodinfo = {
465
  { (JSJitGetterOp)retrieveConsoleEvents },
466
  { prototypes::id::WorkerDebuggerGlobalScope },
467
  { PrototypeTraits<prototypes::id::WorkerDebuggerGlobalScope>::Depth },
468
  JSJitInfo::Method,
469
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
470
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
471
  false,  /* isInfallible. False in setters. */
472
  false,  /* isMovable.  Not relevant for setters. */
473
  false, /* isEliminatable.  Not relevant for setters. */
474
  false, /* isAlwaysInSlot.  Only relevant for getters. */
475
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
476
  false,  /* isTypedMethod.  Only relevant for methods. */
477
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
478
};
479
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
480
static_assert(0 < 1, "There is no slot for us");
481
482
MOZ_CAN_RUN_SCRIPT static bool
483
setConsoleEventHandler(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerDebuggerGlobalScope* self, const JSJitMethodCallArgs& args)
484
0
{
485
0
  AUTO_PROFILER_LABEL_FAST("WorkerDebuggerGlobalScope.setConsoleEventHandler", DOM, cx);
486
0
487
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
488
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WorkerDebuggerGlobalScope.setConsoleEventHandler");
489
0
  }
490
0
  RootedCallback<RefPtr<binding_detail::FastAnyCallback>> arg0(cx);
491
0
  if (args[0].isObject()) {
492
0
    if (JS::IsCallable(&args[0].toObject())) {
493
0
    { // scope for tempRoot and tempGlobalRoot if needed
494
0
      arg0 = new binding_detail::FastAnyCallback(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
495
0
    }
496
0
    } else {
497
0
      ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 1 of WorkerDebuggerGlobalScope.setConsoleEventHandler");
498
0
      return false;
499
0
    }
500
0
  } else if (args[0].isNullOrUndefined()) {
501
0
    arg0 = nullptr;
502
0
  } else {
503
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of WorkerDebuggerGlobalScope.setConsoleEventHandler");
504
0
    return false;
505
0
  }
506
0
  FastErrorResult rv;
507
0
  self->SetConsoleEventHandler(cx, Constify(arg0), rv);
508
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
509
0
    return false;
510
0
  }
511
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
512
0
  args.rval().setUndefined();
513
0
  return true;
514
0
}
515
516
static const JSJitInfo setConsoleEventHandler_methodinfo = {
517
  { (JSJitGetterOp)setConsoleEventHandler },
518
  { prototypes::id::WorkerDebuggerGlobalScope },
519
  { PrototypeTraits<prototypes::id::WorkerDebuggerGlobalScope>::Depth },
520
  JSJitInfo::Method,
521
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
522
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
523
  false,  /* isInfallible. False in setters. */
524
  false,  /* isMovable.  Not relevant for setters. */
525
  false, /* isEliminatable.  Not relevant for setters. */
526
  false, /* isAlwaysInSlot.  Only relevant for getters. */
527
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
528
  false,  /* isTypedMethod.  Only relevant for methods. */
529
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
530
};
531
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
532
static_assert(0 < 1, "There is no slot for us");
533
534
MOZ_CAN_RUN_SCRIPT static bool
535
dump(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WorkerDebuggerGlobalScope* self, const JSJitMethodCallArgs& args)
536
0
{
537
0
  AUTO_PROFILER_LABEL_FAST("WorkerDebuggerGlobalScope.dump", DOM, cx);
538
0
539
0
  Optional<nsAString> arg0;
540
0
  binding_detail::FakeString arg0_holder;
541
0
  if (args.hasDefined(0)) {
542
0
    if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0_holder)) {
543
0
      return false;
544
0
    }
545
0
    arg0 = &arg0_holder;
546
0
  }
547
0
  self->Dump(cx, NonNullHelper(Constify(arg0)));
548
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
549
0
  args.rval().setUndefined();
550
0
  return true;
551
0
}
552
553
static const JSJitInfo dump_methodinfo = {
554
  { (JSJitGetterOp)dump },
555
  { prototypes::id::WorkerDebuggerGlobalScope },
556
  { PrototypeTraits<prototypes::id::WorkerDebuggerGlobalScope>::Depth },
557
  JSJitInfo::Method,
558
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
559
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
560
  false,  /* isInfallible. False in setters. */
561
  false,  /* isMovable.  Not relevant for setters. */
562
  false, /* isEliminatable.  Not relevant for setters. */
563
  false, /* isAlwaysInSlot.  Only relevant for getters. */
564
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
565
  false,  /* isTypedMethod.  Only relevant for methods. */
566
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
567
};
568
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
569
static_assert(0 < 1, "There is no slot for us");
570
571
static void
572
_finalize(js::FreeOp* fop, JSObject* obj)
573
0
{
574
0
  mozilla::dom::WorkerDebuggerGlobalScope* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WorkerDebuggerGlobalScope>(obj);
575
0
  if (self) {
576
0
    ClearWrapper(self, self, obj);
577
0
    mozilla::dom::FinalizeGlobal(CastToJSFreeOp(fop), obj);
578
0
    AddForDeferredFinalization<mozilla::dom::WorkerDebuggerGlobalScope>(self);
579
0
  }
580
0
}
581
582
static size_t
583
_objectMoved(JSObject* obj, JSObject* old)
584
0
{
585
0
  mozilla::dom::WorkerDebuggerGlobalScope* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WorkerDebuggerGlobalScope>(obj);
586
0
  if (self) {
587
0
    UpdateWrapper(self, self, obj, old);
588
0
  }
589
0
590
0
  return 0;
591
0
}
592
593
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
594
#if defined(__clang__)
595
#pragma clang diagnostic push
596
#pragma clang diagnostic ignored "-Wmissing-braces"
597
#endif
598
static const JSFunctionSpec sMethods_specs[] = {
599
  JS_FNSPEC("createSandbox", (GenericMethod<MaybeGlobalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&createSandbox_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
600
  JS_FNSPEC("loadSubScript", (GenericMethod<MaybeGlobalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&loadSubScript_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
601
  JS_FNSPEC("enterEventLoop", (GenericMethod<MaybeGlobalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&enterEventLoop_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
602
  JS_FNSPEC("leaveEventLoop", (GenericMethod<MaybeGlobalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&leaveEventLoop_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
603
  JS_FNSPEC("postMessage", (GenericMethod<MaybeGlobalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&postMessage_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
604
  JS_FNSPEC("setImmediate", (GenericMethod<MaybeGlobalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&setImmediate_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
605
  JS_FNSPEC("reportError", (GenericMethod<MaybeGlobalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&reportError_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
606
  JS_FNSPEC("retrieveConsoleEvents", (GenericMethod<MaybeGlobalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&retrieveConsoleEvents_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
607
  JS_FNSPEC("setConsoleEventHandler", (GenericMethod<MaybeGlobalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&setConsoleEventHandler_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
608
  JS_FNSPEC("dump", (GenericMethod<MaybeGlobalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&dump_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
609
  JS_FS_END
610
};
611
#if defined(__clang__)
612
#pragma clang diagnostic pop
613
#endif
614
615
616
static const Prefable<const JSFunctionSpec> sMethods[] = {
617
  { nullptr, &sMethods_specs[0] },
618
  { nullptr, nullptr }
619
};
620
621
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
622
#if defined(__clang__)
623
#pragma clang diagnostic push
624
#pragma clang diagnostic ignored "-Wmissing-braces"
625
#endif
626
static const JSPropertySpec sAttributes_specs[] = {
627
  { "global", JSPROP_ENUMERATE, GenericGetter<MaybeGlobalThisPolicy, ThrowExceptions>, &global_getterinfo, nullptr, nullptr },
628
  { "onmessage", JSPROP_ENUMERATE, GenericGetter<MaybeGlobalThisPolicy, ThrowExceptions>, &onmessage_getterinfo, GenericSetter<MaybeGlobalThisPolicy>, &onmessage_setterinfo },
629
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
630
};
631
#if defined(__clang__)
632
#pragma clang diagnostic pop
633
#endif
634
635
636
static const Prefable<const JSPropertySpec> sAttributes[] = {
637
  { nullptr, &sAttributes_specs[0] },
638
  { nullptr, nullptr }
639
};
640
641
642
static const NativePropertiesN<2> sNativeProperties = {
643
  false, 0,
644
  false, 0,
645
  true,  0 /* sMethods */,
646
  true,  1 /* sAttributes */,
647
  false, 0,
648
  false, 0,
649
  false, 0,
650
  -1,
651
  0,
652
  nullptr,
653
  {
654
    { sMethods, nullptr },
655
    { sAttributes, nullptr }
656
  }
657
};
658
659
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
660
  {
661
    "Function",
662
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
663
    &sBoringInterfaceObjectClassClassOps,
664
    JS_NULL_CLASS_SPEC,
665
    JS_NULL_CLASS_EXT,
666
    &sInterfaceObjectClassObjectOps
667
  },
668
  eInterface,
669
  true,
670
  prototypes::id::WorkerDebuggerGlobalScope,
671
  PrototypeTraits<prototypes::id::WorkerDebuggerGlobalScope>::Depth,
672
  &sEmptyNativePropertyHooks,
673
  "function WorkerDebuggerGlobalScope() {\n    [native code]\n}",
674
  EventTarget_Binding::GetConstructorObject
675
};
676
677
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
678
  {
679
    "WorkerDebuggerGlobalScopePrototype",
680
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
681
    JS_NULL_CLASS_OPS,
682
    JS_NULL_CLASS_SPEC,
683
    JS_NULL_CLASS_EXT,
684
    JS_NULL_OBJECT_OPS
685
  },
686
  eGlobalInterfacePrototype,
687
  false,
688
  prototypes::id::WorkerDebuggerGlobalScope,
689
  PrototypeTraits<prototypes::id::WorkerDebuggerGlobalScope>::Depth,
690
  &sEmptyNativePropertyHooks,
691
  "[object WorkerDebuggerGlobalScopePrototype]",
692
  EventTarget_Binding::GetProtoObject
693
};
694
695
static const js::ClassOps sClassOps = {
696
  nullptr, /* addProperty */
697
  nullptr,               /* delProperty */
698
  nullptr,               /* enumerate */
699
  mozilla::dom::EnumerateGlobal, /* newEnumerate */
700
  mozilla::dom::ResolveGlobal, /* resolve */
701
  mozilla::dom::MayResolveGlobal, /* mayResolve */
702
  _finalize, /* finalize */
703
  nullptr, /* call */
704
  nullptr,               /* hasInstance */
705
  nullptr,               /* construct */
706
  JS_GlobalObjectTraceHook, /* trace */
707
};
708
709
static const js::ClassExtension sClassExtension = {
710
  nullptr, /* weakmapKeyDelegateOp */
711
  _objectMoved /* objectMovedOp */
712
};
713
714
static const DOMJSClass sClass = {
715
  { "WorkerDebuggerGlobalScope",
716
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_DOM_GLOBAL | JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(DOM_GLOBAL_SLOTS),
717
    &sClassOps,
718
    JS_NULL_CLASS_SPEC,
719
    &sClassExtension,
720
    JS_NULL_OBJECT_OPS
721
  },
722
  { prototypes::id::EventTarget, prototypes::id::WorkerDebuggerGlobalScope, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
723
  IsBaseOf<nsISupports, mozilla::dom::WorkerDebuggerGlobalScope >::value,
724
  &sEmptyNativePropertyHooks,
725
  FindAssociatedGlobalForNative<mozilla::dom::WorkerDebuggerGlobalScope>::Get,
726
  GetProtoObjectHandle,
727
  GetCCParticipant<mozilla::dom::WorkerDebuggerGlobalScope>::Get()
728
};
729
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
730
              "Must have the right minimal number of reserved slots.");
731
static_assert(JSCLASS_GLOBAL_APPLICATION_SLOTS >= 1,
732
              "Must have enough reserved slots.");
733
734
const JSClass*
735
GetJSClass()
736
0
{
737
0
  return sClass.ToJSClass();
738
0
}
739
740
bool
741
Wrap(JSContext* aCx, mozilla::dom::WorkerDebuggerGlobalScope* aObject, nsWrapperCache* aCache, JS::RealmOptions& aOptions, JSPrincipals* aPrincipal, bool aInitStandardClasses, JS::MutableHandle<JSObject*> aReflector)
742
0
{
743
0
  MOZ_ASSERT(static_cast<mozilla::dom::WorkerDebuggerGlobalScope*>(aObject) ==
744
0
             reinterpret_cast<mozilla::dom::WorkerDebuggerGlobalScope*>(aObject),
745
0
             "Multiple inheritance for mozilla::dom::WorkerDebuggerGlobalScope is broken.");
746
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
747
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
748
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
749
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
750
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
751
0
             "nsISupports must be on our primary inheritance chain");
752
0
753
0
  if (!CreateGlobal<mozilla::dom::WorkerDebuggerGlobalScope, GetProtoObjectHandle>(aCx,
754
0
                                   aObject,
755
0
                                   aCache,
756
0
                                   sClass.ToJSClass(),
757
0
                                   aOptions,
758
0
                                   aPrincipal,
759
0
                                   aInitStandardClasses,
760
0
                                   aReflector)) {
761
0
    aCache->ReleaseWrapper(aObject);
762
0
    aCache->ClearWrapper();
763
0
    return false;
764
0
  }
765
0
766
0
  // aReflector is a new global, so has a new realm.  Enter it
767
0
  // before doing anything with it.
768
0
  JSAutoRealm ar(aCx, aReflector);
769
0
770
0
  if (!DefineProperties(aCx, aReflector, sNativeProperties.Upcast(), nullptr)) {
771
0
    aCache->ReleaseWrapper(aObject);
772
0
    aCache->ClearWrapper();
773
0
    return false;
774
0
  }
775
0
776
0
777
0
  return true;
778
0
}
779
780
void
781
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
782
0
{
783
0
  JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx));
784
0
  if (!parentProto) {
785
0
    return;
786
0
  }
787
0
788
0
  JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx));
789
0
  if (!constructorProto) {
790
0
    return;
791
0
  }
792
0
793
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WorkerDebuggerGlobalScope);
794
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WorkerDebuggerGlobalScope);
795
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
796
0
                              &sPrototypeClass.mBase, protoCache,
797
0
                              nullptr,
798
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
799
0
                              interfaceCache,
800
0
                              sNativeProperties.Upcast(),
801
0
                              nullptr,
802
0
                              "WorkerDebuggerGlobalScope", aDefineOnGlobal,
803
0
                              nullptr,
804
0
                              true);
805
0
806
0
  if (*&aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WorkerDebuggerGlobalScope)) {
807
0
    bool succeeded;
808
0
    JS::Handle<JSObject*> prot = GetProtoObjectHandle(aCx);
809
0
    if (!JS_SetImmutablePrototype(aCx, prot, &succeeded)) {
810
0
      *protoCache = nullptr;
811
0
      if (interfaceCache) {
812
0
        *interfaceCache = nullptr;
813
0
      }
814
0
      return;
815
0
    }
816
0
817
0
    MOZ_ASSERT(succeeded,
818
0
               "making a fresh prototype object's [[Prototype]] "
819
0
               "immutable can internally fail, but it should "
820
0
               "never be unsuccessful");
821
0
  }
822
0
}
823
824
JSObject*
825
GetConstructorObject(JSContext* aCx)
826
0
{
827
0
  return GetConstructorObjectHandle(aCx);
828
0
}
829
830
} // namespace WorkerDebuggerGlobalScope_Binding
831
832
833
834
} // namespace dom
835
} // namespace mozilla