Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM PerformanceEntry.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "PerformanceEntryBinding.h"
4 : #include "WrapperFactory.h"
5 : #include "mozilla/FloatingPoint.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/PerformanceEntry.h"
11 : #include "mozilla/dom/PrimitiveConversions.h"
12 : #include "mozilla/dom/XrayExpandoClass.h"
13 :
14 : namespace mozilla {
15 : namespace dom {
16 :
17 : namespace PerformanceEntryBinding {
18 :
19 : static bool
20 0 : get_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceEntry* self, JSJitGetterCallArgs args)
21 : {
22 0 : DOMString result;
23 0 : self->GetName(result);
24 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
25 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
26 0 : return false;
27 : }
28 0 : return true;
29 : }
30 :
31 : static const JSJitInfo name_getterinfo = {
32 : { (JSJitGetterOp)get_name },
33 : { prototypes::id::PerformanceEntry },
34 : { PrototypeTraits<prototypes::id::PerformanceEntry>::Depth },
35 : JSJitInfo::Getter,
36 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
37 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
38 : false, /* isInfallible. False in setters. */
39 : false, /* isMovable. Not relevant for setters. */
40 : false, /* isEliminatable. Not relevant for setters. */
41 : false, /* isAlwaysInSlot. Only relevant for getters. */
42 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
43 : false, /* isTypedMethod. Only relevant for methods. */
44 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
45 : };
46 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
47 : static_assert(0 < 1, "There is no slot for us");
48 :
49 : static bool
50 0 : get_entryType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceEntry* self, JSJitGetterCallArgs args)
51 : {
52 0 : DOMString result;
53 0 : self->GetEntryType(result);
54 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
55 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
56 0 : return false;
57 : }
58 0 : return true;
59 : }
60 :
61 : static const JSJitInfo entryType_getterinfo = {
62 : { (JSJitGetterOp)get_entryType },
63 : { prototypes::id::PerformanceEntry },
64 : { PrototypeTraits<prototypes::id::PerformanceEntry>::Depth },
65 : JSJitInfo::Getter,
66 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
67 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
68 : false, /* isInfallible. False in setters. */
69 : false, /* isMovable. Not relevant for setters. */
70 : false, /* isEliminatable. Not relevant for setters. */
71 : false, /* isAlwaysInSlot. Only relevant for getters. */
72 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
73 : false, /* isTypedMethod. Only relevant for methods. */
74 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
75 : };
76 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
77 : static_assert(0 < 1, "There is no slot for us");
78 :
79 : static bool
80 0 : get_startTime(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceEntry* self, JSJitGetterCallArgs args)
81 : {
82 0 : double result(self->StartTime());
83 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
84 0 : args.rval().set(JS_NumberValue(double(result)));
85 0 : return true;
86 : }
87 :
88 : static const JSJitInfo startTime_getterinfo = {
89 : { (JSJitGetterOp)get_startTime },
90 : { prototypes::id::PerformanceEntry },
91 : { PrototypeTraits<prototypes::id::PerformanceEntry>::Depth },
92 : JSJitInfo::Getter,
93 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
94 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
95 : true, /* isInfallible. False in setters. */
96 : false, /* isMovable. Not relevant for setters. */
97 : false, /* isEliminatable. Not relevant for setters. */
98 : false, /* isAlwaysInSlot. Only relevant for getters. */
99 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
100 : false, /* isTypedMethod. Only relevant for methods. */
101 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
102 : };
103 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
104 : static_assert(0 < 1, "There is no slot for us");
105 :
106 : static bool
107 0 : get_duration(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceEntry* self, JSJitGetterCallArgs args)
108 : {
109 0 : double result(self->Duration());
110 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
111 0 : args.rval().set(JS_NumberValue(double(result)));
112 0 : return true;
113 : }
114 :
115 : static const JSJitInfo duration_getterinfo = {
116 : { (JSJitGetterOp)get_duration },
117 : { prototypes::id::PerformanceEntry },
118 : { PrototypeTraits<prototypes::id::PerformanceEntry>::Depth },
119 : JSJitInfo::Getter,
120 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
121 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
122 : true, /* isInfallible. False in setters. */
123 : false, /* isMovable. Not relevant for setters. */
124 : false, /* isEliminatable. Not relevant for setters. */
125 : false, /* isAlwaysInSlot. Only relevant for getters. */
126 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
127 : false, /* isTypedMethod. Only relevant for methods. */
128 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
129 : };
130 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
131 : static_assert(0 < 1, "There is no slot for us");
132 :
133 : bool
134 0 : JsonifyAttributes(JSContext* aCx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceEntry* self, JS::Rooted<JSObject*>& aResult)
135 : {
136 : { // scope for "temp"
137 0 : JS::Rooted<JS::Value> temp(aCx);
138 0 : if (!get_name(aCx, obj, self, JSJitGetterCallArgs(&temp))) {
139 0 : return false;
140 : }
141 0 : if (!JS_DefineProperty(aCx, aResult, "name", temp, JSPROP_ENUMERATE)) {
142 0 : return false;
143 : }
144 : }
145 : { // scope for "temp"
146 0 : JS::Rooted<JS::Value> temp(aCx);
147 0 : if (!get_entryType(aCx, obj, self, JSJitGetterCallArgs(&temp))) {
148 0 : return false;
149 : }
150 0 : if (!JS_DefineProperty(aCx, aResult, "entryType", temp, JSPROP_ENUMERATE)) {
151 0 : return false;
152 : }
153 : }
154 : { // scope for "temp"
155 0 : JS::Rooted<JS::Value> temp(aCx);
156 0 : if (!get_startTime(aCx, obj, self, JSJitGetterCallArgs(&temp))) {
157 0 : return false;
158 : }
159 0 : if (!JS_DefineProperty(aCx, aResult, "startTime", temp, JSPROP_ENUMERATE)) {
160 0 : return false;
161 : }
162 : }
163 : { // scope for "temp"
164 0 : JS::Rooted<JS::Value> temp(aCx);
165 0 : if (!get_duration(aCx, obj, self, JSJitGetterCallArgs(&temp))) {
166 0 : return false;
167 : }
168 0 : if (!JS_DefineProperty(aCx, aResult, "duration", temp, JSPROP_ENUMERATE)) {
169 0 : return false;
170 : }
171 : }
172 0 : return true;
173 : }
174 :
175 : static bool
176 0 : __jsonifier(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceEntry* self, const JSJitMethodCallArgs& args)
177 : {
178 0 : JS::Rooted<JSObject*> result(cx, JS_NewPlainObject(cx));
179 0 : if (!result) {
180 0 : return false;
181 : }
182 0 : if (!PerformanceEntryBinding::JsonifyAttributes(cx, obj, self, result)) {
183 0 : return false;
184 : }
185 0 : args.rval().setObject(*result);
186 0 : return true;
187 : }
188 :
189 : static const JSJitInfo __jsonifier_methodinfo = {
190 : { (JSJitGetterOp)__jsonifier },
191 : { prototypes::id::PerformanceEntry },
192 : { PrototypeTraits<prototypes::id::PerformanceEntry>::Depth },
193 : JSJitInfo::Method,
194 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
195 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
196 : false, /* isInfallible. False in setters. */
197 : false, /* isMovable. Not relevant for setters. */
198 : false, /* isEliminatable. Not relevant for setters. */
199 : false, /* isAlwaysInSlot. Only relevant for getters. */
200 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
201 : false, /* isTypedMethod. Only relevant for methods. */
202 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
203 : };
204 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
205 : static_assert(0 < 1, "There is no slot for us");
206 :
207 : static bool
208 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
209 : {
210 0 : mozilla::dom::PerformanceEntry* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PerformanceEntry>(obj);
211 : // We don't want to preserve if we don't have a wrapper, and we
212 : // obviously can't preserve if we're not initialized.
213 0 : if (self && self->GetWrapperPreserveColor()) {
214 0 : PreserveWrapper(self);
215 : }
216 0 : return true;
217 : }
218 :
219 : static void
220 0 : _finalize(js::FreeOp* fop, JSObject* obj)
221 : {
222 0 : mozilla::dom::PerformanceEntry* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PerformanceEntry>(obj);
223 0 : if (self) {
224 0 : ClearWrapper(self, self, obj);
225 0 : AddForDeferredFinalization<mozilla::dom::PerformanceEntry>(self);
226 : }
227 0 : }
228 :
229 : static void
230 0 : _objectMoved(JSObject* obj, const JSObject* old)
231 : {
232 0 : mozilla::dom::PerformanceEntry* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PerformanceEntry>(obj);
233 0 : if (self) {
234 0 : UpdateWrapper(self, self, obj, old);
235 : }
236 0 : }
237 :
238 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
239 : #if defined(__clang__)
240 : #pragma clang diagnostic push
241 : #pragma clang diagnostic ignored "-Wmissing-braces"
242 : #endif
243 : static const JSFunctionSpec sMethods_specs[] = {
244 : JS_FNSPEC("toJSON", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&__jsonifier_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
245 : JS_FS_END
246 : };
247 : #if defined(__clang__)
248 : #pragma clang diagnostic pop
249 : #endif
250 :
251 :
252 : // Can't be const because the pref-enabled boolean needs to be writable
253 : static Prefable<const JSFunctionSpec> sMethods[] = {
254 : { nullptr, &sMethods_specs[0] },
255 : { nullptr, nullptr }
256 : };
257 :
258 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
259 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
260 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
261 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
262 :
263 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
264 : #if defined(__clang__)
265 : #pragma clang diagnostic push
266 : #pragma clang diagnostic ignored "-Wmissing-braces"
267 : #endif
268 : static const JSPropertySpec sAttributes_specs[] = {
269 : { "name", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &name_getterinfo, nullptr, nullptr },
270 : { "entryType", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &entryType_getterinfo, nullptr, nullptr },
271 : { "startTime", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &startTime_getterinfo, nullptr, nullptr },
272 : { "duration", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &duration_getterinfo, nullptr, nullptr },
273 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
274 : };
275 : #if defined(__clang__)
276 : #pragma clang diagnostic pop
277 : #endif
278 :
279 :
280 : // Can't be const because the pref-enabled boolean needs to be writable
281 : static Prefable<const JSPropertySpec> sAttributes[] = {
282 : { nullptr, &sAttributes_specs[0] },
283 : { nullptr, nullptr }
284 : };
285 :
286 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
287 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
288 : static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
289 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
290 :
291 :
292 : static uint16_t sNativeProperties_sortedPropertyIndices[5];
293 : static PropertyInfo sNativeProperties_propertyInfos[5];
294 :
295 : static const NativePropertiesN<2> sNativeProperties = {
296 : false, 0,
297 : false, 0,
298 : true, 0 /* sMethods */,
299 : true, 1 /* sAttributes */,
300 : false, 0,
301 : false, 0,
302 : false, 0,
303 : -1,
304 : 5,
305 : sNativeProperties_sortedPropertyIndices,
306 : {
307 : { sMethods, &sNativeProperties_propertyInfos[0] },
308 : { sAttributes, &sNativeProperties_propertyInfos[1] }
309 : }
310 : };
311 : static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
312 : "We have a property info count that is oversized");
313 :
314 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
315 : {
316 : "Function",
317 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
318 : &sBoringInterfaceObjectClassClassOps,
319 : JS_NULL_CLASS_SPEC,
320 : JS_NULL_CLASS_EXT,
321 : &sInterfaceObjectClassObjectOps
322 : },
323 : eInterface,
324 : true,
325 : prototypes::id::PerformanceEntry,
326 : PrototypeTraits<prototypes::id::PerformanceEntry>::Depth,
327 : sNativePropertyHooks,
328 : "function PerformanceEntry() {\n [native code]\n}",
329 : JS::GetRealmFunctionPrototype
330 : };
331 :
332 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
333 : {
334 : "PerformanceEntryPrototype",
335 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
336 : JS_NULL_CLASS_OPS,
337 : JS_NULL_CLASS_SPEC,
338 : JS_NULL_CLASS_EXT,
339 : JS_NULL_OBJECT_OPS
340 : },
341 : eInterfacePrototype,
342 : false,
343 : prototypes::id::PerformanceEntry,
344 : PrototypeTraits<prototypes::id::PerformanceEntry>::Depth,
345 : sNativePropertyHooks,
346 : "[object PerformanceEntryPrototype]",
347 : JS::GetRealmObjectPrototype
348 : };
349 :
350 : JSObject*
351 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
352 : {
353 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
354 : }
355 :
356 : static const js::ClassOps sClassOps = {
357 : _addProperty, /* addProperty */
358 : nullptr, /* delProperty */
359 : nullptr, /* getProperty */
360 : nullptr, /* setProperty */
361 : nullptr, /* enumerate */
362 : nullptr, /* newEnumerate */
363 : nullptr, /* resolve */
364 : nullptr, /* mayResolve */
365 : _finalize, /* finalize */
366 : nullptr, /* call */
367 : nullptr, /* hasInstance */
368 : nullptr, /* construct */
369 : nullptr, /* trace */
370 : };
371 :
372 : static const js::ClassExtension sClassExtension = {
373 : nullptr, /* weakmapKeyDelegateOp */
374 : _objectMoved /* objectMovedOp */
375 : };
376 :
377 : static const DOMJSClass sClass = {
378 : { "PerformanceEntry",
379 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
380 : &sClassOps,
381 : JS_NULL_CLASS_SPEC,
382 : &sClassExtension,
383 : JS_NULL_OBJECT_OPS
384 : },
385 : { prototypes::id::PerformanceEntry, 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 },
386 : IsBaseOf<nsISupports, mozilla::dom::PerformanceEntry >::value,
387 : sNativePropertyHooks,
388 : FindAssociatedGlobalForNative<mozilla::dom::PerformanceEntry>::Get,
389 : GetProtoObjectHandle,
390 : GetCCParticipant<mozilla::dom::PerformanceEntry>::Get()
391 : };
392 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
393 : "Must have the right minimal number of reserved slots.");
394 : static_assert(1 >= 1,
395 : "Must have enough reserved slots.");
396 :
397 : const JSClass*
398 0 : GetJSClass()
399 : {
400 0 : return sClass.ToJSClass();
401 : }
402 :
403 : bool
404 0 : Wrap(JSContext* aCx, mozilla::dom::PerformanceEntry* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
405 : {
406 : MOZ_ASSERT(static_cast<mozilla::dom::PerformanceEntry*>(aObject) ==
407 : reinterpret_cast<mozilla::dom::PerformanceEntry*>(aObject),
408 : "Multiple inheritance for mozilla::dom::PerformanceEntry is broken.");
409 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
410 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
411 0 : MOZ_ASSERT(!aCache->GetWrapper(),
412 : "You should probably not be using Wrap() directly; use "
413 : "GetOrCreateDOMReflector instead");
414 :
415 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
416 : "nsISupports must be on our primary inheritance chain");
417 :
418 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
419 0 : if (!global) {
420 0 : return false;
421 : }
422 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
423 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
424 :
425 : // That might have ended up wrapping us already, due to the wonders
426 : // of XBL. Check for that, and bail out as needed.
427 0 : aReflector.set(aCache->GetWrapper());
428 0 : if (aReflector) {
429 : #ifdef DEBUG
430 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
431 : #endif // DEBUG
432 0 : return true;
433 : }
434 :
435 0 : JSAutoCompartment ac(aCx, global);
436 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
437 0 : if (!canonicalProto) {
438 0 : return false;
439 : }
440 0 : JS::Rooted<JSObject*> proto(aCx);
441 0 : if (aGivenProto) {
442 0 : proto = aGivenProto;
443 : // Unfortunately, while aGivenProto was in the compartment of aCx
444 : // coming in, we changed compartments to that of "parent" so may need
445 : // to wrap the proto here.
446 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
447 0 : if (!JS_WrapObject(aCx, &proto)) {
448 0 : return false;
449 : }
450 : }
451 : } else {
452 0 : proto = canonicalProto;
453 : }
454 :
455 0 : BindingJSObjectCreator<mozilla::dom::PerformanceEntry> creator(aCx);
456 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
457 0 : if (!aReflector) {
458 0 : return false;
459 : }
460 :
461 0 : aCache->SetWrapper(aReflector);
462 0 : creator.InitializationSucceeded();
463 :
464 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
465 : aCache->GetWrapperPreserveColor() == aReflector);
466 : // If proto != canonicalProto, we have to preserve our wrapper;
467 : // otherwise we won't be able to properly recreate it later, since
468 : // we won't know what proto to use. Note that we don't check
469 : // aGivenProto here, since it's entirely possible (and even
470 : // somewhat common) to have a non-null aGivenProto which is the
471 : // same as canonicalProto.
472 0 : if (proto != canonicalProto) {
473 0 : PreserveWrapper(aObject);
474 : }
475 :
476 0 : return true;
477 : }
478 :
479 : const NativePropertyHooks sNativePropertyHooks[] = { {
480 : nullptr,
481 : nullptr,
482 : nullptr,
483 : { sNativeProperties.Upcast(), nullptr },
484 : prototypes::id::PerformanceEntry,
485 : constructors::id::PerformanceEntry,
486 : nullptr,
487 : &DefaultXrayExpandoObjectClass
488 : } };
489 :
490 : void
491 1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
492 : {
493 2 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
494 1 : if (!parentProto) {
495 0 : return;
496 : }
497 :
498 2 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
499 1 : if (!constructorProto) {
500 0 : return;
501 : }
502 :
503 : static bool sIdsInited = false;
504 1 : if (!sIdsInited && NS_IsMainThread()) {
505 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
506 0 : return;
507 : }
508 0 : sIdsInited = true;
509 : }
510 :
511 1 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::PerformanceEntry);
512 1 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::PerformanceEntry);
513 2 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
514 : &sPrototypeClass.mBase, protoCache,
515 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
516 : interfaceCache,
517 : sNativeProperties.Upcast(),
518 : nullptr,
519 : "PerformanceEntry", aDefineOnGlobal,
520 : nullptr,
521 1 : false);
522 : }
523 :
524 : JS::Handle<JSObject*>
525 2 : GetProtoObjectHandle(JSContext* aCx)
526 : {
527 : /* Get the interface prototype object for this class. This will create the
528 : object as needed. */
529 2 : bool aDefineOnGlobal = true;
530 :
531 : /* Make sure our global is sane. Hopefully we can remove this sometime */
532 2 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
533 2 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
534 0 : return nullptr;
535 : }
536 :
537 : /* Check to see whether the interface objects are already installed */
538 2 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
539 2 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::PerformanceEntry)) {
540 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
541 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
542 : }
543 :
544 : /*
545 : * The object might _still_ be null, but that's OK.
546 : *
547 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
548 : * traced by TraceProtoAndIfaceCache() and its contents are never
549 : * changed after they have been set.
550 : *
551 : * Calling address() avoids the read read barrier that does gray
552 : * unmarking, but it's not possible for the object to be gray here.
553 : */
554 :
555 2 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::PerformanceEntry);
556 2 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
557 2 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
558 : }
559 :
560 : JSObject*
561 0 : GetProtoObject(JSContext* aCx)
562 : {
563 0 : return GetProtoObjectHandle(aCx);
564 : }
565 :
566 : JS::Handle<JSObject*>
567 3 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
568 : {
569 : /* Get the interface object for this class. This will create the object as
570 : needed. */
571 :
572 : /* Make sure our global is sane. Hopefully we can remove this sometime */
573 3 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
574 3 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
575 0 : return nullptr;
576 : }
577 :
578 : /* Check to see whether the interface objects are already installed */
579 3 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
580 3 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::PerformanceEntry)) {
581 2 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
582 1 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
583 : }
584 :
585 : /*
586 : * The object might _still_ be null, but that's OK.
587 : *
588 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
589 : * traced by TraceProtoAndIfaceCache() and its contents are never
590 : * changed after they have been set.
591 : *
592 : * Calling address() avoids the read read barrier that does gray
593 : * unmarking, but it's not possible for the object to be gray here.
594 : */
595 :
596 3 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::PerformanceEntry);
597 3 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
598 3 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
599 : }
600 :
601 : JSObject*
602 1 : GetConstructorObject(JSContext* aCx)
603 : {
604 1 : return GetConstructorObjectHandle(aCx);
605 : }
606 :
607 : } // namespace PerformanceEntryBinding
608 :
609 :
610 :
611 : } // namespace dom
612 : } // namespace mozilla
|