Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/HistoryBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM History.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "HistoryBinding.h"
4
#include "WrapperFactory.h"
5
#include "jsapi.h"
6
#include "mozilla/OwningNonNull.h"
7
#include "mozilla/dom/BindingUtils.h"
8
#include "mozilla/dom/DOMJSClass.h"
9
#include "mozilla/dom/NonRefcountedDOMObject.h"
10
#include "mozilla/dom/Nullable.h"
11
#include "mozilla/dom/PrimitiveConversions.h"
12
#include "mozilla/dom/XrayExpandoClass.h"
13
#include "nsHistory.h"
14
15
namespace mozilla {
16
namespace dom {
17
18
namespace binding_detail {}; // Just to make sure it's known as a namespace
19
using namespace mozilla::dom::binding_detail;
20
21
22
namespace ScrollRestorationValues {
23
extern const EnumEntry strings[3] = {
24
  {"auto", 4},
25
  {"manual", 6},
26
  { nullptr, 0 }
27
};
28
} // namespace ScrollRestorationValues
29
30
bool
31
ToJSValue(JSContext* aCx, ScrollRestoration aArgument, JS::MutableHandle<JS::Value> aValue)
32
0
{
33
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(ScrollRestorationValues::strings));
34
0
  JSString* resultStr =
35
0
    JS_NewStringCopyN(aCx, ScrollRestorationValues::strings[uint32_t(aArgument)].value,
36
0
                      ScrollRestorationValues::strings[uint32_t(aArgument)].length);
37
0
  if (!resultStr) {
38
0
    return false;
39
0
  }
40
0
  aValue.setString(resultStr);
41
0
  return true;
42
0
}
43
44
45
namespace History_Binding {
46
47
MOZ_CAN_RUN_SCRIPT static bool
48
get_length(JSContext* cx, JS::Handle<JSObject*> obj, nsHistory* self, JSJitGetterCallArgs args)
49
0
{
50
0
  AUTO_PROFILER_LABEL_FAST("get History.length", DOM, cx);
51
0
52
0
  FastErrorResult rv;
53
0
  uint32_t result(self->GetLength(rv));
54
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
55
0
    return false;
56
0
  }
57
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
58
0
  args.rval().setNumber(result);
59
0
  return true;
60
0
}
61
62
static const JSJitInfo length_getterinfo = {
63
  { (JSJitGetterOp)get_length },
64
  { prototypes::id::History },
65
  { PrototypeTraits<prototypes::id::History>::Depth },
66
  JSJitInfo::Getter,
67
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
68
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
69
  false,  /* isInfallible. False in setters. */
70
  false,  /* isMovable.  Not relevant for setters. */
71
  false, /* isEliminatable.  Not relevant for setters. */
72
  false, /* isAlwaysInSlot.  Only relevant for getters. */
73
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
74
  false,  /* isTypedMethod.  Only relevant for methods. */
75
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
76
};
77
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
78
static_assert(0 < 1, "There is no slot for us");
79
80
MOZ_CAN_RUN_SCRIPT static bool
81
get_scrollRestoration(JSContext* cx, JS::Handle<JSObject*> obj, nsHistory* self, JSJitGetterCallArgs args)
82
0
{
83
0
  AUTO_PROFILER_LABEL_FAST("get History.scrollRestoration", DOM, cx);
84
0
85
0
  FastErrorResult rv;
86
0
  ScrollRestoration result(self->GetScrollRestoration(rv));
87
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
88
0
    return false;
89
0
  }
90
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
91
0
  if (!ToJSValue(cx, result, args.rval())) {
92
0
    return false;
93
0
  }
94
0
  return true;
95
0
}
96
97
MOZ_CAN_RUN_SCRIPT static bool
98
set_scrollRestoration(JSContext* cx, JS::Handle<JSObject*> obj, nsHistory* self, JSJitSetterCallArgs args)
99
0
{
100
0
  AUTO_PROFILER_LABEL_FAST("set History.scrollRestoration", DOM, cx);
101
0
102
0
  ScrollRestoration arg0;
103
0
  {
104
0
    int index;
105
0
    if (!FindEnumStringIndex<false>(cx, args[0], ScrollRestorationValues::strings, "ScrollRestoration", "Value being assigned to History.scrollRestoration", &index)) {
106
0
      return false;
107
0
    }
108
0
    if (index < 0) {
109
0
      return true;
110
0
    }
111
0
    arg0 = static_cast<ScrollRestoration>(index);
112
0
  }
113
0
  FastErrorResult rv;
114
0
  self->SetScrollRestoration(arg0, rv);
115
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
116
0
    return false;
117
0
  }
118
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
119
0
120
0
  return true;
121
0
}
122
123
static const JSJitInfo scrollRestoration_getterinfo = {
124
  { (JSJitGetterOp)get_scrollRestoration },
125
  { prototypes::id::History },
126
  { PrototypeTraits<prototypes::id::History>::Depth },
127
  JSJitInfo::Getter,
128
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
129
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
130
  false,  /* isInfallible. False in setters. */
131
  false,  /* isMovable.  Not relevant for setters. */
132
  false, /* isEliminatable.  Not relevant for setters. */
133
  false, /* isAlwaysInSlot.  Only relevant for getters. */
134
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
135
  false,  /* isTypedMethod.  Only relevant for methods. */
136
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
137
};
138
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
139
static_assert(0 < 1, "There is no slot for us");
140
static const JSJitInfo scrollRestoration_setterinfo = {
141
  { (JSJitGetterOp)set_scrollRestoration },
142
  { prototypes::id::History },
143
  { PrototypeTraits<prototypes::id::History>::Depth },
144
  JSJitInfo::Setter,
145
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
146
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
147
  false,  /* isInfallible. False in setters. */
148
  false,  /* isMovable.  Not relevant for setters. */
149
  false, /* isEliminatable.  Not relevant for setters. */
150
  false, /* isAlwaysInSlot.  Only relevant for getters. */
151
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
152
  false,  /* isTypedMethod.  Only relevant for methods. */
153
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
154
};
155
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
156
static_assert(0 < 1, "There is no slot for us");
157
158
MOZ_CAN_RUN_SCRIPT static bool
159
get_state(JSContext* cx, JS::Handle<JSObject*> obj, nsHistory* self, JSJitGetterCallArgs args)
160
0
{
161
0
  AUTO_PROFILER_LABEL_FAST("get History.state", DOM, cx);
162
0
163
0
  FastErrorResult rv;
164
0
  JS::Rooted<JS::Value> result(cx);
165
0
  self->GetState(cx, &result, rv);
166
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
167
0
    return false;
168
0
  }
169
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
170
0
  JS::ExposeValueToActiveJS(result);
171
0
  args.rval().set(result);
172
0
  if (!MaybeWrapValue(cx, args.rval())) {
173
0
    return false;
174
0
  }
175
0
  return true;
176
0
}
177
178
static const JSJitInfo state_getterinfo = {
179
  { (JSJitGetterOp)get_state },
180
  { prototypes::id::History },
181
  { PrototypeTraits<prototypes::id::History>::Depth },
182
  JSJitInfo::Getter,
183
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
184
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
185
  false,  /* isInfallible. False in setters. */
186
  false,  /* isMovable.  Not relevant for setters. */
187
  false, /* isEliminatable.  Not relevant for setters. */
188
  false, /* isAlwaysInSlot.  Only relevant for getters. */
189
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
190
  false,  /* isTypedMethod.  Only relevant for methods. */
191
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
192
};
193
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
194
static_assert(0 < 1, "There is no slot for us");
195
196
MOZ_CAN_RUN_SCRIPT static bool
197
go(JSContext* cx, JS::Handle<JSObject*> obj, nsHistory* self, const JSJitMethodCallArgs& args)
198
0
{
199
0
  AUTO_PROFILER_LABEL_FAST("History.go", DOM, cx);
200
0
201
0
  int32_t arg0;
202
0
  if (args.hasDefined(0)) {
203
0
    if (!ValueToPrimitive<int32_t, eDefault>(cx, args[0], &arg0)) {
204
0
      return false;
205
0
    }
206
0
  } else {
207
0
    arg0 = 0;
208
0
  }
209
0
  FastErrorResult rv;
210
0
  self->Go(arg0, rv);
211
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
212
0
    return false;
213
0
  }
214
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
215
0
  args.rval().setUndefined();
216
0
  return true;
217
0
}
218
219
static const JSJitInfo go_methodinfo = {
220
  { (JSJitGetterOp)go },
221
  { prototypes::id::History },
222
  { PrototypeTraits<prototypes::id::History>::Depth },
223
  JSJitInfo::Method,
224
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
225
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
226
  false,  /* isInfallible. False in setters. */
227
  false,  /* isMovable.  Not relevant for setters. */
228
  false, /* isEliminatable.  Not relevant for setters. */
229
  false, /* isAlwaysInSlot.  Only relevant for getters. */
230
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
231
  false,  /* isTypedMethod.  Only relevant for methods. */
232
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
233
};
234
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
235
static_assert(0 < 1, "There is no slot for us");
236
237
MOZ_CAN_RUN_SCRIPT static bool
238
back(JSContext* cx, JS::Handle<JSObject*> obj, nsHistory* self, const JSJitMethodCallArgs& args)
239
0
{
240
0
  AUTO_PROFILER_LABEL_FAST("History.back", DOM, cx);
241
0
242
0
  FastErrorResult rv;
243
0
  self->Back(rv);
244
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
245
0
    return false;
246
0
  }
247
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
248
0
  args.rval().setUndefined();
249
0
  return true;
250
0
}
251
252
static const JSJitInfo back_methodinfo = {
253
  { (JSJitGetterOp)back },
254
  { prototypes::id::History },
255
  { PrototypeTraits<prototypes::id::History>::Depth },
256
  JSJitInfo::Method,
257
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
258
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
259
  false,  /* isInfallible. False in setters. */
260
  false,  /* isMovable.  Not relevant for setters. */
261
  false, /* isEliminatable.  Not relevant for setters. */
262
  false, /* isAlwaysInSlot.  Only relevant for getters. */
263
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
264
  false,  /* isTypedMethod.  Only relevant for methods. */
265
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
266
};
267
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
268
static_assert(0 < 1, "There is no slot for us");
269
270
MOZ_CAN_RUN_SCRIPT static bool
271
forward(JSContext* cx, JS::Handle<JSObject*> obj, nsHistory* self, const JSJitMethodCallArgs& args)
272
0
{
273
0
  AUTO_PROFILER_LABEL_FAST("History.forward", DOM, cx);
274
0
275
0
  FastErrorResult rv;
276
0
  self->Forward(rv);
277
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
278
0
    return false;
279
0
  }
280
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
281
0
  args.rval().setUndefined();
282
0
  return true;
283
0
}
284
285
static const JSJitInfo forward_methodinfo = {
286
  { (JSJitGetterOp)forward },
287
  { prototypes::id::History },
288
  { PrototypeTraits<prototypes::id::History>::Depth },
289
  JSJitInfo::Method,
290
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
291
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
292
  false,  /* isInfallible. False in setters. */
293
  false,  /* isMovable.  Not relevant for setters. */
294
  false, /* isEliminatable.  Not relevant for setters. */
295
  false, /* isAlwaysInSlot.  Only relevant for getters. */
296
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
297
  false,  /* isTypedMethod.  Only relevant for methods. */
298
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
299
};
300
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
301
static_assert(0 < 1, "There is no slot for us");
302
303
MOZ_CAN_RUN_SCRIPT static bool
304
pushState(JSContext* cx, JS::Handle<JSObject*> obj, nsHistory* self, const JSJitMethodCallArgs& args)
305
0
{
306
0
  AUTO_PROFILER_LABEL_FAST("History.pushState", DOM, cx);
307
0
308
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
309
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "History.pushState");
310
0
  }
311
0
  JS::Rooted<JS::Value> arg0(cx);
312
0
  arg0 = args[0];
313
0
  binding_detail::FakeString arg1;
314
0
  if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
315
0
    return false;
316
0
  }
317
0
  binding_detail::FakeString arg2;
318
0
  if (args.hasDefined(2)) {
319
0
    if (!ConvertJSValueToString(cx, args[2], eNull, eNull, arg2)) {
320
0
      return false;
321
0
    }
322
0
  } else {
323
0
    arg2.SetIsVoid(true);
324
0
  }
325
0
  FastErrorResult rv;
326
0
  self->PushState(cx, arg0, NonNullHelper(Constify(arg1)), NonNullHelper(Constify(arg2)), rv);
327
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
328
0
    return false;
329
0
  }
330
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
331
0
  args.rval().setUndefined();
332
0
  return true;
333
0
}
334
335
static const JSJitInfo pushState_methodinfo = {
336
  { (JSJitGetterOp)pushState },
337
  { prototypes::id::History },
338
  { PrototypeTraits<prototypes::id::History>::Depth },
339
  JSJitInfo::Method,
340
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
341
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
342
  false,  /* isInfallible. False in setters. */
343
  false,  /* isMovable.  Not relevant for setters. */
344
  false, /* isEliminatable.  Not relevant for setters. */
345
  false, /* isAlwaysInSlot.  Only relevant for getters. */
346
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
347
  false,  /* isTypedMethod.  Only relevant for methods. */
348
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
349
};
350
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
351
static_assert(0 < 1, "There is no slot for us");
352
353
MOZ_CAN_RUN_SCRIPT static bool
354
replaceState(JSContext* cx, JS::Handle<JSObject*> obj, nsHistory* self, const JSJitMethodCallArgs& args)
355
0
{
356
0
  AUTO_PROFILER_LABEL_FAST("History.replaceState", DOM, cx);
357
0
358
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
359
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "History.replaceState");
360
0
  }
361
0
  JS::Rooted<JS::Value> arg0(cx);
362
0
  arg0 = args[0];
363
0
  binding_detail::FakeString arg1;
364
0
  if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
365
0
    return false;
366
0
  }
367
0
  binding_detail::FakeString arg2;
368
0
  if (args.hasDefined(2)) {
369
0
    if (!ConvertJSValueToString(cx, args[2], eNull, eNull, arg2)) {
370
0
      return false;
371
0
    }
372
0
  } else {
373
0
    arg2.SetIsVoid(true);
374
0
  }
375
0
  FastErrorResult rv;
376
0
  self->ReplaceState(cx, arg0, NonNullHelper(Constify(arg1)), NonNullHelper(Constify(arg2)), rv);
377
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
378
0
    return false;
379
0
  }
380
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
381
0
  args.rval().setUndefined();
382
0
  return true;
383
0
}
384
385
static const JSJitInfo replaceState_methodinfo = {
386
  { (JSJitGetterOp)replaceState },
387
  { prototypes::id::History },
388
  { PrototypeTraits<prototypes::id::History>::Depth },
389
  JSJitInfo::Method,
390
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
391
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
392
  false,  /* isInfallible. False in setters. */
393
  false,  /* isMovable.  Not relevant for setters. */
394
  false, /* isEliminatable.  Not relevant for setters. */
395
  false, /* isAlwaysInSlot.  Only relevant for getters. */
396
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
397
  false,  /* isTypedMethod.  Only relevant for methods. */
398
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
399
};
400
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
401
static_assert(0 < 1, "There is no slot for us");
402
403
static bool
404
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
405
0
{
406
0
  nsHistory* self = UnwrapPossiblyNotInitializedDOMObject<nsHistory>(obj);
407
0
  // We don't want to preserve if we don't have a wrapper, and we
408
0
  // obviously can't preserve if we're not initialized.
409
0
  if (self && self->GetWrapperPreserveColor()) {
410
0
    PreserveWrapper(self);
411
0
  }
412
0
  return true;
413
0
}
414
415
static void
416
_finalize(js::FreeOp* fop, JSObject* obj)
417
0
{
418
0
  nsHistory* self = UnwrapPossiblyNotInitializedDOMObject<nsHistory>(obj);
419
0
  if (self) {
420
0
    ClearWrapper(self, self, obj);
421
0
    AddForDeferredFinalization<nsHistory>(self);
422
0
  }
423
0
}
424
425
static size_t
426
_objectMoved(JSObject* obj, JSObject* old)
427
0
{
428
0
  nsHistory* self = UnwrapPossiblyNotInitializedDOMObject<nsHistory>(obj);
429
0
  if (self) {
430
0
    UpdateWrapper(self, self, obj, old);
431
0
  }
432
0
433
0
  return 0;
434
0
}
435
436
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
437
#if defined(__clang__)
438
#pragma clang diagnostic push
439
#pragma clang diagnostic ignored "-Wmissing-braces"
440
#endif
441
static const JSFunctionSpec sMethods_specs[] = {
442
  JS_FNSPEC("go", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&go_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
443
  JS_FNSPEC("back", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&back_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
444
  JS_FNSPEC("forward", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&forward_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
445
  JS_FNSPEC("pushState", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&pushState_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
446
  JS_FNSPEC("replaceState", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&replaceState_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
447
  JS_FS_END
448
};
449
#if defined(__clang__)
450
#pragma clang diagnostic pop
451
#endif
452
453
454
static const Prefable<const JSFunctionSpec> sMethods[] = {
455
  { nullptr, &sMethods_specs[0] },
456
  { nullptr, nullptr }
457
};
458
459
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
460
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
461
static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
462
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
463
464
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
465
#if defined(__clang__)
466
#pragma clang diagnostic push
467
#pragma clang diagnostic ignored "-Wmissing-braces"
468
#endif
469
static const JSPropertySpec sAttributes_specs[] = {
470
  { "length", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &length_getterinfo, nullptr, nullptr },
471
  { "scrollRestoration", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &scrollRestoration_getterinfo, GenericSetter<NormalThisPolicy>, &scrollRestoration_setterinfo },
472
  { "state", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &state_getterinfo, nullptr, nullptr },
473
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
474
};
475
#if defined(__clang__)
476
#pragma clang diagnostic pop
477
#endif
478
479
480
static const Prefable<const JSPropertySpec> sAttributes[] = {
481
  { nullptr, &sAttributes_specs[0] },
482
  { nullptr, nullptr }
483
};
484
485
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
486
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
487
static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
488
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
489
490
491
static uint16_t sNativeProperties_sortedPropertyIndices[8];
492
static PropertyInfo sNativeProperties_propertyInfos[8];
493
494
static const NativePropertiesN<2> sNativeProperties = {
495
  false, 0,
496
  false, 0,
497
  true,  0 /* sMethods */,
498
  true,  1 /* sAttributes */,
499
  false, 0,
500
  false, 0,
501
  false, 0,
502
  -1,
503
  8,
504
  sNativeProperties_sortedPropertyIndices,
505
  {
506
    { sMethods, &sNativeProperties_propertyInfos[0] },
507
    { sAttributes, &sNativeProperties_propertyInfos[5] }
508
  }
509
};
510
static_assert(8 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
511
    "We have a property info count that is oversized");
512
513
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
514
  {
515
    "Function",
516
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
517
    &sBoringInterfaceObjectClassClassOps,
518
    JS_NULL_CLASS_SPEC,
519
    JS_NULL_CLASS_EXT,
520
    &sInterfaceObjectClassObjectOps
521
  },
522
  eInterface,
523
  true,
524
  prototypes::id::History,
525
  PrototypeTraits<prototypes::id::History>::Depth,
526
  sNativePropertyHooks,
527
  "function History() {\n    [native code]\n}",
528
  JS::GetRealmFunctionPrototype
529
};
530
531
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
532
  {
533
    "HistoryPrototype",
534
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
535
    JS_NULL_CLASS_OPS,
536
    JS_NULL_CLASS_SPEC,
537
    JS_NULL_CLASS_EXT,
538
    JS_NULL_OBJECT_OPS
539
  },
540
  eInterfacePrototype,
541
  false,
542
  prototypes::id::History,
543
  PrototypeTraits<prototypes::id::History>::Depth,
544
  sNativePropertyHooks,
545
  "[object HistoryPrototype]",
546
  JS::GetRealmObjectPrototype
547
};
548
549
static const js::ClassOps sClassOps = {
550
  _addProperty, /* addProperty */
551
  nullptr,               /* delProperty */
552
  nullptr,               /* enumerate */
553
  nullptr, /* newEnumerate */
554
  nullptr, /* resolve */
555
  nullptr, /* mayResolve */
556
  _finalize, /* finalize */
557
  nullptr, /* call */
558
  nullptr,               /* hasInstance */
559
  nullptr,               /* construct */
560
  nullptr, /* trace */
561
};
562
563
static const js::ClassExtension sClassExtension = {
564
  nullptr, /* weakmapKeyDelegateOp */
565
  _objectMoved /* objectMovedOp */
566
};
567
568
static const DOMJSClass sClass = {
569
  { "History",
570
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
571
    &sClassOps,
572
    JS_NULL_CLASS_SPEC,
573
    &sClassExtension,
574
    JS_NULL_OBJECT_OPS
575
  },
576
  { prototypes::id::History, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
577
  IsBaseOf<nsISupports, nsHistory >::value,
578
  sNativePropertyHooks,
579
  FindAssociatedGlobalForNative<nsHistory>::Get,
580
  GetProtoObjectHandle,
581
  GetCCParticipant<nsHistory>::Get()
582
};
583
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
584
              "Must have the right minimal number of reserved slots.");
585
static_assert(1 >= 1,
586
              "Must have enough reserved slots.");
587
588
const JSClass*
589
GetJSClass()
590
0
{
591
0
  return sClass.ToJSClass();
592
0
}
593
594
bool
595
Wrap(JSContext* aCx, nsHistory* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
596
0
{
597
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, nsHistory>::value,
598
0
                "Shouldn't have wrappercached things that are not refcounted.");
599
0
  MOZ_ASSERT(static_cast<nsHistory*>(aObject) ==
600
0
             reinterpret_cast<nsHistory*>(aObject),
601
0
             "Multiple inheritance for nsHistory is broken.");
602
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
603
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
604
0
  MOZ_ASSERT(!aCache->GetWrapper(),
605
0
             "You should probably not be using Wrap() directly; use "
606
0
             "GetOrCreateDOMReflector instead");
607
0
608
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
609
0
             "nsISupports must be on our primary inheritance chain");
610
0
611
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
612
0
  if (!global) {
613
0
    return false;
614
0
  }
615
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
616
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
617
0
618
0
  // That might have ended up wrapping us already, due to the wonders
619
0
  // of XBL.  Check for that, and bail out as needed.
620
0
  aReflector.set(aCache->GetWrapper());
621
0
  if (aReflector) {
622
#ifdef DEBUG
623
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
624
#endif // DEBUG
625
    return true;
626
0
  }
627
0
628
0
  JSAutoRealm ar(aCx, global);
629
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
630
0
  if (!canonicalProto) {
631
0
    return false;
632
0
  }
633
0
  JS::Rooted<JSObject*> proto(aCx);
634
0
  if (aGivenProto) {
635
0
    proto = aGivenProto;
636
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
637
0
    // coming in, we changed compartments to that of "parent" so may need
638
0
    // to wrap the proto here.
639
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
640
0
      if (!JS_WrapObject(aCx, &proto)) {
641
0
        return false;
642
0
      }
643
0
    }
644
0
  } else {
645
0
    proto = canonicalProto;
646
0
  }
647
0
648
0
  BindingJSObjectCreator<nsHistory> creator(aCx);
649
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
650
0
  if (!aReflector) {
651
0
    return false;
652
0
  }
653
0
654
0
  aCache->SetWrapper(aReflector);
655
0
  creator.InitializationSucceeded();
656
0
657
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
658
0
             aCache->GetWrapperPreserveColor() == aReflector);
659
0
  // If proto != canonicalProto, we have to preserve our wrapper;
660
0
  // otherwise we won't be able to properly recreate it later, since
661
0
  // we won't know what proto to use.  Note that we don't check
662
0
  // aGivenProto here, since it's entirely possible (and even
663
0
  // somewhat common) to have a non-null aGivenProto which is the
664
0
  // same as canonicalProto.
665
0
  if (proto != canonicalProto) {
666
0
    PreserveWrapper(aObject);
667
0
  }
668
0
669
0
  return true;
670
0
}
671
672
const NativePropertyHooks sNativePropertyHooks[] = { {
673
  nullptr,
674
  nullptr,
675
  nullptr,
676
  { sNativeProperties.Upcast(), nullptr },
677
  prototypes::id::History,
678
  constructors::id::History,
679
  nullptr,
680
  &DefaultXrayExpandoObjectClass
681
} };
682
683
void
684
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
685
0
{
686
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
687
0
  if (!parentProto) {
688
0
    return;
689
0
  }
690
0
691
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
692
0
  if (!constructorProto) {
693
0
    return;
694
0
  }
695
0
696
0
  static bool sIdsInited = false;
697
0
  if (!sIdsInited && NS_IsMainThread()) {
698
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
699
0
      return;
700
0
    }
701
0
    sIdsInited = true;
702
0
  }
703
0
704
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::History);
705
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::History);
706
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
707
0
                              &sPrototypeClass.mBase, protoCache,
708
0
                              nullptr,
709
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
710
0
                              interfaceCache,
711
0
                              sNativeProperties.Upcast(),
712
0
                              nullptr,
713
0
                              "History", aDefineOnGlobal,
714
0
                              nullptr,
715
0
                              false);
716
0
}
717
718
JSObject*
719
GetConstructorObject(JSContext* aCx)
720
0
{
721
0
  return GetConstructorObjectHandle(aCx);
722
0
}
723
724
} // namespace History_Binding
725
726
727
728
} // namespace dom
729
} // namespace mozilla