Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM PerformanceObserverEntryList.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "Performance.h"
5 : #include "PerformanceObserverEntryListBinding.h"
6 : #include "WrapperFactory.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/dom/BindingUtils.h"
9 : #include "mozilla/dom/DOMJSClass.h"
10 : #include "mozilla/dom/NonRefcountedDOMObject.h"
11 : #include "mozilla/dom/PerformanceEntry.h"
12 : #include "mozilla/dom/PerformanceObserverEntryList.h"
13 : #include "mozilla/dom/ScriptSettings.h"
14 : #include "mozilla/dom/SimpleGlobalObject.h"
15 : #include "mozilla/dom/XrayExpandoClass.h"
16 :
17 : namespace mozilla {
18 : namespace dom {
19 :
20 :
21 0 : PerformanceEntryFilterOptions::PerformanceEntryFilterOptions()
22 : {
23 : // Safe to pass a null context if we pass a null value
24 0 : Init(nullptr, JS::NullHandleValue);
25 0 : }
26 :
27 :
28 :
29 : bool
30 0 : PerformanceEntryFilterOptions::InitIds(JSContext* cx, PerformanceEntryFilterOptionsAtoms* atomsCache)
31 : {
32 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
33 :
34 : // Initialize these in reverse order so that any failure leaves the first one
35 : // uninitialized.
36 0 : if (!atomsCache->name_id.init(cx, "name") ||
37 0 : !atomsCache->initiatorType_id.init(cx, "initiatorType") ||
38 0 : !atomsCache->entryType_id.init(cx, "entryType")) {
39 0 : return false;
40 : }
41 0 : return true;
42 : }
43 :
44 : bool
45 0 : PerformanceEntryFilterOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
46 : {
47 : // Passing a null JSContext is OK only if we're initing from null,
48 : // Since in that case we will not have to do any property gets
49 : // Also evaluate isNullOrUndefined in order to avoid false-positive
50 : // checkers by static analysis tools
51 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
52 0 : PerformanceEntryFilterOptionsAtoms* atomsCache = nullptr;
53 0 : if (cx) {
54 0 : atomsCache = GetAtomCache<PerformanceEntryFilterOptionsAtoms>(cx);
55 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
56 0 : return false;
57 : }
58 : }
59 :
60 0 : if (!IsConvertibleToDictionary(val)) {
61 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
62 : }
63 :
64 0 : bool isNull = val.isNullOrUndefined();
65 : // We only need these if !isNull, in which case we have |cx|.
66 0 : Maybe<JS::Rooted<JSObject *> > object;
67 0 : Maybe<JS::Rooted<JS::Value> > temp;
68 0 : if (!isNull) {
69 0 : MOZ_ASSERT(cx);
70 0 : object.emplace(cx, &val.toObject());
71 0 : temp.emplace(cx);
72 : }
73 0 : if (!isNull) {
74 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->entryType_id, temp.ptr())) {
75 0 : return false;
76 : }
77 : }
78 0 : if (!isNull && !temp->isUndefined()) {
79 0 : mEntryType.Construct();
80 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mEntryType.Value()))) {
81 0 : return false;
82 : }
83 0 : mIsAnyMemberPresent = true;
84 : }
85 :
86 0 : if (!isNull) {
87 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->initiatorType_id, temp.ptr())) {
88 0 : return false;
89 : }
90 : }
91 0 : if (!isNull && !temp->isUndefined()) {
92 0 : mInitiatorType.Construct();
93 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mInitiatorType.Value()))) {
94 0 : return false;
95 : }
96 0 : mIsAnyMemberPresent = true;
97 : }
98 :
99 0 : if (!isNull) {
100 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) {
101 0 : return false;
102 : }
103 : }
104 0 : if (!isNull && !temp->isUndefined()) {
105 0 : mName.Construct();
106 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mName.Value()))) {
107 0 : return false;
108 : }
109 0 : mIsAnyMemberPresent = true;
110 : }
111 0 : return true;
112 : }
113 :
114 : bool
115 0 : PerformanceEntryFilterOptions::Init(const nsAString& aJSON)
116 : {
117 0 : AutoJSAPI jsapi;
118 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
119 0 : if (!cleanGlobal) {
120 0 : return false;
121 : }
122 0 : if (!jsapi.Init(cleanGlobal)) {
123 0 : return false;
124 : }
125 0 : JSContext* cx = jsapi.cx();
126 0 : JS::Rooted<JS::Value> json(cx);
127 0 : bool ok = ParseJSON(cx, aJSON, &json);
128 0 : NS_ENSURE_TRUE(ok, false);
129 0 : return Init(cx, json);
130 : }
131 :
132 : bool
133 0 : PerformanceEntryFilterOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
134 : {
135 0 : PerformanceEntryFilterOptionsAtoms* atomsCache = GetAtomCache<PerformanceEntryFilterOptionsAtoms>(cx);
136 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
137 0 : return false;
138 : }
139 :
140 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
141 0 : if (!obj) {
142 0 : return false;
143 : }
144 0 : rval.set(JS::ObjectValue(*obj));
145 :
146 0 : if (mEntryType.WasPassed()) {
147 : do {
148 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
149 0 : JS::Rooted<JS::Value> temp(cx);
150 0 : nsString const & currentValue = mEntryType.InternalValue();
151 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
152 0 : return false;
153 : }
154 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->entryType_id, temp, JSPROP_ENUMERATE)) {
155 0 : return false;
156 : }
157 0 : break;
158 : } while(0);
159 : }
160 :
161 0 : if (mInitiatorType.WasPassed()) {
162 : do {
163 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
164 0 : JS::Rooted<JS::Value> temp(cx);
165 0 : nsString const & currentValue = mInitiatorType.InternalValue();
166 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
167 0 : return false;
168 : }
169 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->initiatorType_id, temp, JSPROP_ENUMERATE)) {
170 0 : return false;
171 : }
172 0 : break;
173 : } while(0);
174 : }
175 :
176 0 : if (mName.WasPassed()) {
177 : do {
178 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
179 0 : JS::Rooted<JS::Value> temp(cx);
180 0 : nsString const & currentValue = mName.InternalValue();
181 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
182 0 : return false;
183 : }
184 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) {
185 0 : return false;
186 : }
187 0 : break;
188 : } while(0);
189 : }
190 :
191 0 : return true;
192 : }
193 :
194 : bool
195 0 : PerformanceEntryFilterOptions::ToJSON(nsAString& aJSON) const
196 : {
197 0 : AutoJSAPI jsapi;
198 0 : jsapi.Init();
199 0 : JSContext *cx = jsapi.cx();
200 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
201 : // because we'll only be creating objects, in ways that have no
202 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
203 : // which likewise guarantees no side-effects for the sorts of
204 : // things we will pass it.
205 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
206 0 : JS::Rooted<JS::Value> val(cx);
207 0 : if (!ToObjectInternal(cx, &val)) {
208 0 : return false;
209 : }
210 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
211 0 : return StringifyToJSON(cx, obj, aJSON);
212 : }
213 :
214 : void
215 0 : PerformanceEntryFilterOptions::TraceDictionary(JSTracer* trc)
216 : {
217 0 : }
218 :
219 : PerformanceEntryFilterOptions&
220 0 : PerformanceEntryFilterOptions::operator=(const PerformanceEntryFilterOptions& aOther)
221 : {
222 0 : mEntryType.Reset();
223 0 : if (aOther.mEntryType.WasPassed()) {
224 0 : mEntryType.Construct(aOther.mEntryType.Value());
225 : }
226 0 : mInitiatorType.Reset();
227 0 : if (aOther.mInitiatorType.WasPassed()) {
228 0 : mInitiatorType.Construct(aOther.mInitiatorType.Value());
229 : }
230 0 : mName.Reset();
231 0 : if (aOther.mName.WasPassed()) {
232 0 : mName.Construct(aOther.mName.Value());
233 : }
234 0 : return *this;
235 : }
236 :
237 : namespace binding_detail {
238 : } // namespace binding_detail
239 :
240 :
241 : namespace PerformanceObserverEntryListBinding {
242 :
243 : static bool
244 0 : getEntries(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceObserverEntryList* self, const JSJitMethodCallArgs& args)
245 : {
246 0 : binding_detail::FastPerformanceEntryFilterOptions arg0;
247 0 : if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of PerformanceObserverEntryList.getEntries", false)) {
248 0 : return false;
249 : }
250 0 : nsTArray<StrongPtrForMember<mozilla::dom::PerformanceEntry>::Type> result;
251 0 : self->GetEntries(Constify(arg0), result);
252 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
253 :
254 0 : uint32_t length = result.Length();
255 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
256 0 : if (!returnArray) {
257 0 : return false;
258 : }
259 : // Scope for 'tmp'
260 : {
261 0 : JS::Rooted<JS::Value> tmp(cx);
262 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
263 : // Control block to let us common up the JS_DefineElement calls when there
264 : // are different ways to succeed at wrapping the object.
265 : do {
266 0 : if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
267 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
268 0 : return false;
269 : }
270 0 : break;
271 : } while (0);
272 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
273 : JSPROP_ENUMERATE)) {
274 0 : return false;
275 : }
276 : }
277 : }
278 0 : args.rval().setObject(*returnArray);
279 0 : return true;
280 : }
281 :
282 : static const JSJitInfo getEntries_methodinfo = {
283 : { (JSJitGetterOp)getEntries },
284 : { prototypes::id::PerformanceObserverEntryList },
285 : { PrototypeTraits<prototypes::id::PerformanceObserverEntryList>::Depth },
286 : JSJitInfo::Method,
287 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
288 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
289 : false, /* isInfallible. False in setters. */
290 : false, /* isMovable. Not relevant for setters. */
291 : false, /* isEliminatable. Not relevant for setters. */
292 : false, /* isAlwaysInSlot. Only relevant for getters. */
293 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
294 : false, /* isTypedMethod. Only relevant for methods. */
295 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
296 : };
297 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
298 : static_assert(0 < 1, "There is no slot for us");
299 :
300 : static bool
301 0 : getEntriesByType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceObserverEntryList* self, const JSJitMethodCallArgs& args)
302 : {
303 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
304 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PerformanceObserverEntryList.getEntriesByType");
305 : }
306 0 : binding_detail::FakeString arg0;
307 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
308 0 : return false;
309 : }
310 0 : nsTArray<StrongPtrForMember<mozilla::dom::PerformanceEntry>::Type> result;
311 0 : self->GetEntriesByType(NonNullHelper(Constify(arg0)), result);
312 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
313 :
314 0 : uint32_t length = result.Length();
315 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
316 0 : if (!returnArray) {
317 0 : return false;
318 : }
319 : // Scope for 'tmp'
320 : {
321 0 : JS::Rooted<JS::Value> tmp(cx);
322 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
323 : // Control block to let us common up the JS_DefineElement calls when there
324 : // are different ways to succeed at wrapping the object.
325 : do {
326 0 : if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
327 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
328 0 : return false;
329 : }
330 0 : break;
331 : } while (0);
332 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
333 : JSPROP_ENUMERATE)) {
334 0 : return false;
335 : }
336 : }
337 : }
338 0 : args.rval().setObject(*returnArray);
339 0 : return true;
340 : }
341 :
342 : static const JSJitInfo getEntriesByType_methodinfo = {
343 : { (JSJitGetterOp)getEntriesByType },
344 : { prototypes::id::PerformanceObserverEntryList },
345 : { PrototypeTraits<prototypes::id::PerformanceObserverEntryList>::Depth },
346 : JSJitInfo::Method,
347 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
348 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
349 : false, /* isInfallible. False in setters. */
350 : false, /* isMovable. Not relevant for setters. */
351 : false, /* isEliminatable. Not relevant for setters. */
352 : false, /* isAlwaysInSlot. Only relevant for getters. */
353 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
354 : false, /* isTypedMethod. Only relevant for methods. */
355 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
356 : };
357 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
358 : static_assert(0 < 1, "There is no slot for us");
359 :
360 : static bool
361 0 : getEntriesByName(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceObserverEntryList* self, const JSJitMethodCallArgs& args)
362 : {
363 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
364 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PerformanceObserverEntryList.getEntriesByName");
365 : }
366 0 : binding_detail::FakeString arg0;
367 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
368 0 : return false;
369 : }
370 0 : Optional<nsAString> arg1;
371 0 : binding_detail::FakeString arg1_holder;
372 0 : if (args.hasDefined(1)) {
373 0 : if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1_holder)) {
374 0 : return false;
375 : }
376 0 : arg1 = &arg1_holder;
377 : }
378 0 : nsTArray<StrongPtrForMember<mozilla::dom::PerformanceEntry>::Type> result;
379 0 : self->GetEntriesByName(NonNullHelper(Constify(arg0)), NonNullHelper(Constify(arg1)), result);
380 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
381 :
382 0 : uint32_t length = result.Length();
383 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
384 0 : if (!returnArray) {
385 0 : return false;
386 : }
387 : // Scope for 'tmp'
388 : {
389 0 : JS::Rooted<JS::Value> tmp(cx);
390 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
391 : // Control block to let us common up the JS_DefineElement calls when there
392 : // are different ways to succeed at wrapping the object.
393 : do {
394 0 : if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
395 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
396 0 : return false;
397 : }
398 0 : break;
399 : } while (0);
400 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
401 : JSPROP_ENUMERATE)) {
402 0 : return false;
403 : }
404 : }
405 : }
406 0 : args.rval().setObject(*returnArray);
407 0 : return true;
408 : }
409 :
410 : static const JSJitInfo getEntriesByName_methodinfo = {
411 : { (JSJitGetterOp)getEntriesByName },
412 : { prototypes::id::PerformanceObserverEntryList },
413 : { PrototypeTraits<prototypes::id::PerformanceObserverEntryList>::Depth },
414 : JSJitInfo::Method,
415 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
416 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
417 : false, /* isInfallible. False in setters. */
418 : false, /* isMovable. Not relevant for setters. */
419 : false, /* isEliminatable. Not relevant for setters. */
420 : false, /* isAlwaysInSlot. Only relevant for getters. */
421 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
422 : false, /* isTypedMethod. Only relevant for methods. */
423 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
424 : };
425 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
426 : static_assert(0 < 1, "There is no slot for us");
427 :
428 : static bool
429 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
430 : {
431 0 : mozilla::dom::PerformanceObserverEntryList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PerformanceObserverEntryList>(obj);
432 : // We don't want to preserve if we don't have a wrapper, and we
433 : // obviously can't preserve if we're not initialized.
434 0 : if (self && self->GetWrapperPreserveColor()) {
435 0 : PreserveWrapper(self);
436 : }
437 0 : return true;
438 : }
439 :
440 : static void
441 0 : _finalize(js::FreeOp* fop, JSObject* obj)
442 : {
443 0 : mozilla::dom::PerformanceObserverEntryList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PerformanceObserverEntryList>(obj);
444 0 : if (self) {
445 0 : ClearWrapper(self, self, obj);
446 0 : AddForDeferredFinalization<mozilla::dom::PerformanceObserverEntryList>(self);
447 : }
448 0 : }
449 :
450 : static void
451 0 : _objectMoved(JSObject* obj, const JSObject* old)
452 : {
453 0 : mozilla::dom::PerformanceObserverEntryList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PerformanceObserverEntryList>(obj);
454 0 : if (self) {
455 0 : UpdateWrapper(self, self, obj, old);
456 : }
457 0 : }
458 :
459 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
460 : #if defined(__clang__)
461 : #pragma clang diagnostic push
462 : #pragma clang diagnostic ignored "-Wmissing-braces"
463 : #endif
464 : static const JSFunctionSpec sMethods_specs[] = {
465 : JS_FNSPEC("getEntries", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getEntries_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
466 : JS_FNSPEC("getEntriesByType", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getEntriesByType_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
467 : JS_FNSPEC("getEntriesByName", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getEntriesByName_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
468 : JS_FS_END
469 : };
470 : #if defined(__clang__)
471 : #pragma clang diagnostic pop
472 : #endif
473 :
474 :
475 : // Can't be const because the pref-enabled boolean needs to be writable
476 : static Prefable<const JSFunctionSpec> sMethods[] = {
477 : { nullptr, &sMethods_specs[0] },
478 : { nullptr, nullptr }
479 : };
480 :
481 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
482 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
483 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
484 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
485 :
486 :
487 : static uint16_t sNativeProperties_sortedPropertyIndices[3];
488 : static PropertyInfo sNativeProperties_propertyInfos[3];
489 :
490 : static const NativePropertiesN<1> sNativeProperties = {
491 : false, 0,
492 : false, 0,
493 : true, 0 /* sMethods */,
494 : false, 0,
495 : false, 0,
496 : false, 0,
497 : false, 0,
498 : -1,
499 : 3,
500 : sNativeProperties_sortedPropertyIndices,
501 : {
502 : { sMethods, &sNativeProperties_propertyInfos[0] }
503 : }
504 : };
505 : static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
506 : "We have a property info count that is oversized");
507 :
508 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
509 : {
510 : "Function",
511 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
512 : &sBoringInterfaceObjectClassClassOps,
513 : JS_NULL_CLASS_SPEC,
514 : JS_NULL_CLASS_EXT,
515 : &sInterfaceObjectClassObjectOps
516 : },
517 : eInterface,
518 : true,
519 : prototypes::id::PerformanceObserverEntryList,
520 : PrototypeTraits<prototypes::id::PerformanceObserverEntryList>::Depth,
521 : sNativePropertyHooks,
522 : "function PerformanceObserverEntryList() {\n [native code]\n}",
523 : JS::GetRealmFunctionPrototype
524 : };
525 :
526 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
527 : {
528 : "PerformanceObserverEntryListPrototype",
529 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
530 : JS_NULL_CLASS_OPS,
531 : JS_NULL_CLASS_SPEC,
532 : JS_NULL_CLASS_EXT,
533 : JS_NULL_OBJECT_OPS
534 : },
535 : eInterfacePrototype,
536 : false,
537 : prototypes::id::PerformanceObserverEntryList,
538 : PrototypeTraits<prototypes::id::PerformanceObserverEntryList>::Depth,
539 : sNativePropertyHooks,
540 : "[object PerformanceObserverEntryListPrototype]",
541 : JS::GetRealmObjectPrototype
542 : };
543 :
544 : bool
545 1 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
546 : {
547 1 : return Performance::IsObserverEnabled(aCx, aObj);
548 : }
549 :
550 : JSObject*
551 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
552 : {
553 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
554 : }
555 :
556 : static const js::ClassOps sClassOps = {
557 : _addProperty, /* addProperty */
558 : nullptr, /* delProperty */
559 : nullptr, /* getProperty */
560 : nullptr, /* setProperty */
561 : nullptr, /* enumerate */
562 : nullptr, /* newEnumerate */
563 : nullptr, /* resolve */
564 : nullptr, /* mayResolve */
565 : _finalize, /* finalize */
566 : nullptr, /* call */
567 : nullptr, /* hasInstance */
568 : nullptr, /* construct */
569 : nullptr, /* trace */
570 : };
571 :
572 : static const js::ClassExtension sClassExtension = {
573 : nullptr, /* weakmapKeyDelegateOp */
574 : _objectMoved /* objectMovedOp */
575 : };
576 :
577 : static const DOMJSClass sClass = {
578 : { "PerformanceObserverEntryList",
579 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
580 : &sClassOps,
581 : JS_NULL_CLASS_SPEC,
582 : &sClassExtension,
583 : JS_NULL_OBJECT_OPS
584 : },
585 : { prototypes::id::PerformanceObserverEntryList, 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 },
586 : IsBaseOf<nsISupports, mozilla::dom::PerformanceObserverEntryList >::value,
587 : sNativePropertyHooks,
588 : FindAssociatedGlobalForNative<mozilla::dom::PerformanceObserverEntryList>::Get,
589 : GetProtoObjectHandle,
590 : GetCCParticipant<mozilla::dom::PerformanceObserverEntryList>::Get()
591 : };
592 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
593 : "Must have the right minimal number of reserved slots.");
594 : static_assert(1 >= 1,
595 : "Must have enough reserved slots.");
596 :
597 : const JSClass*
598 0 : GetJSClass()
599 : {
600 0 : return sClass.ToJSClass();
601 : }
602 :
603 : bool
604 0 : Wrap(JSContext* aCx, mozilla::dom::PerformanceObserverEntryList* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
605 : {
606 : MOZ_ASSERT(static_cast<mozilla::dom::PerformanceObserverEntryList*>(aObject) ==
607 : reinterpret_cast<mozilla::dom::PerformanceObserverEntryList*>(aObject),
608 : "Multiple inheritance for mozilla::dom::PerformanceObserverEntryList is broken.");
609 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
610 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
611 0 : MOZ_ASSERT(!aCache->GetWrapper(),
612 : "You should probably not be using Wrap() directly; use "
613 : "GetOrCreateDOMReflector instead");
614 :
615 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
616 : "nsISupports must be on our primary inheritance chain");
617 :
618 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
619 0 : if (!global) {
620 0 : return false;
621 : }
622 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
623 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
624 :
625 : // That might have ended up wrapping us already, due to the wonders
626 : // of XBL. Check for that, and bail out as needed.
627 0 : aReflector.set(aCache->GetWrapper());
628 0 : if (aReflector) {
629 : #ifdef DEBUG
630 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
631 : #endif // DEBUG
632 0 : return true;
633 : }
634 :
635 0 : JSAutoCompartment ac(aCx, global);
636 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
637 0 : if (!canonicalProto) {
638 0 : return false;
639 : }
640 0 : JS::Rooted<JSObject*> proto(aCx);
641 0 : if (aGivenProto) {
642 0 : proto = aGivenProto;
643 : // Unfortunately, while aGivenProto was in the compartment of aCx
644 : // coming in, we changed compartments to that of "parent" so may need
645 : // to wrap the proto here.
646 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
647 0 : if (!JS_WrapObject(aCx, &proto)) {
648 0 : return false;
649 : }
650 : }
651 : } else {
652 0 : proto = canonicalProto;
653 : }
654 :
655 0 : BindingJSObjectCreator<mozilla::dom::PerformanceObserverEntryList> creator(aCx);
656 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
657 0 : if (!aReflector) {
658 0 : return false;
659 : }
660 :
661 0 : aCache->SetWrapper(aReflector);
662 0 : creator.InitializationSucceeded();
663 :
664 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
665 : aCache->GetWrapperPreserveColor() == aReflector);
666 : // If proto != canonicalProto, we have to preserve our wrapper;
667 : // otherwise we won't be able to properly recreate it later, since
668 : // we won't know what proto to use. Note that we don't check
669 : // aGivenProto here, since it's entirely possible (and even
670 : // somewhat common) to have a non-null aGivenProto which is the
671 : // same as canonicalProto.
672 0 : if (proto != canonicalProto) {
673 0 : PreserveWrapper(aObject);
674 : }
675 :
676 0 : return true;
677 : }
678 :
679 : const NativePropertyHooks sNativePropertyHooks[] = { {
680 : nullptr,
681 : nullptr,
682 : nullptr,
683 : { sNativeProperties.Upcast(), nullptr },
684 : prototypes::id::PerformanceObserverEntryList,
685 : constructors::id::PerformanceObserverEntryList,
686 : nullptr,
687 : &DefaultXrayExpandoObjectClass
688 : } };
689 :
690 : void
691 1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
692 : {
693 2 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
694 1 : if (!parentProto) {
695 0 : return;
696 : }
697 :
698 2 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
699 1 : if (!constructorProto) {
700 0 : return;
701 : }
702 :
703 : static bool sIdsInited = false;
704 1 : if (!sIdsInited && NS_IsMainThread()) {
705 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
706 0 : return;
707 : }
708 0 : sIdsInited = true;
709 : }
710 :
711 1 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::PerformanceObserverEntryList);
712 1 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::PerformanceObserverEntryList);
713 2 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
714 : &sPrototypeClass.mBase, protoCache,
715 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
716 : interfaceCache,
717 : sNativeProperties.Upcast(),
718 : nullptr,
719 : "PerformanceObserverEntryList", aDefineOnGlobal,
720 : nullptr,
721 1 : false);
722 : }
723 :
724 : JS::Handle<JSObject*>
725 0 : GetProtoObjectHandle(JSContext* aCx)
726 : {
727 : /* Get the interface prototype object for this class. This will create the
728 : object as needed. */
729 0 : bool aDefineOnGlobal = true;
730 :
731 : /* Make sure our global is sane. Hopefully we can remove this sometime */
732 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
733 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
734 0 : return nullptr;
735 : }
736 :
737 : /* Check to see whether the interface objects are already installed */
738 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
739 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::PerformanceObserverEntryList)) {
740 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
741 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
742 : }
743 :
744 : /*
745 : * The object might _still_ be null, but that's OK.
746 : *
747 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
748 : * traced by TraceProtoAndIfaceCache() and its contents are never
749 : * changed after they have been set.
750 : *
751 : * Calling address() avoids the read read barrier that does gray
752 : * unmarking, but it's not possible for the object to be gray here.
753 : */
754 :
755 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::PerformanceObserverEntryList);
756 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
757 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
758 : }
759 :
760 : JS::Handle<JSObject*>
761 1 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
762 : {
763 : /* Get the interface object for this class. This will create the object as
764 : needed. */
765 :
766 : /* Make sure our global is sane. Hopefully we can remove this sometime */
767 1 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
768 1 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
769 0 : return nullptr;
770 : }
771 :
772 : /* Check to see whether the interface objects are already installed */
773 1 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
774 1 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::PerformanceObserverEntryList)) {
775 2 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
776 1 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
777 : }
778 :
779 : /*
780 : * The object might _still_ be null, but that's OK.
781 : *
782 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
783 : * traced by TraceProtoAndIfaceCache() and its contents are never
784 : * changed after they have been set.
785 : *
786 : * Calling address() avoids the read read barrier that does gray
787 : * unmarking, but it's not possible for the object to be gray here.
788 : */
789 :
790 1 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::PerformanceObserverEntryList);
791 1 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
792 1 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
793 : }
794 :
795 : JSObject*
796 1 : GetConstructorObject(JSContext* aCx)
797 : {
798 1 : return GetConstructorObjectHandle(aCx);
799 : }
800 :
801 : } // namespace PerformanceObserverEntryListBinding
802 :
803 :
804 :
805 : } // namespace dom
806 : } // namespace mozilla
|