Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM Performance.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "EventHandlerBinding.h"
4 : #include "PerformanceBinding.h"
5 : #include "WrapperFactory.h"
6 : #include "mozilla/FloatingPoint.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/Preferences.h"
9 : #include "mozilla/dom/BindingUtils.h"
10 : #include "mozilla/dom/DOMJSClass.h"
11 : #include "mozilla/dom/NonRefcountedDOMObject.h"
12 : #include "mozilla/dom/Nullable.h"
13 : #include "mozilla/dom/Performance.h"
14 : #include "mozilla/dom/PerformanceEntry.h"
15 : #include "mozilla/dom/PerformanceNavigation.h"
16 : #include "mozilla/dom/PerformanceTiming.h"
17 : #include "mozilla/dom/PrimitiveConversions.h"
18 : #include "mozilla/dom/XrayExpandoClass.h"
19 : #include "nsISupports.h"
20 : #include "xpcjsid.h"
21 :
22 : namespace mozilla {
23 : namespace dom {
24 :
25 : namespace PerformanceBinding {
26 :
27 : static bool
28 0 : now(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, const JSJitMethodCallArgs& args)
29 : {
30 0 : double result(self->Now());
31 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
32 0 : args.rval().set(JS_NumberValue(double(result)));
33 0 : return true;
34 : }
35 :
36 : static const JSJitInfo::ArgType now_methodinfo_argTypes[] = { JSJitInfo::ArgTypeListEnd };
37 : static const JSTypedMethodJitInfo now_methodinfo = {
38 : {
39 : { (JSJitGetterOp)now },
40 : { prototypes::id::Performance },
41 : { PrototypeTraits<prototypes::id::Performance>::Depth },
42 : JSJitInfo::Method,
43 : JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
44 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
45 : true, /* isInfallible. False in setters. */
46 : false, /* isMovable. Not relevant for setters. */
47 : true, /* isEliminatable. Not relevant for setters. */
48 : false, /* isAlwaysInSlot. Only relevant for getters. */
49 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
50 : true, /* isTypedMethod. Only relevant for methods. */
51 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
52 : },
53 : now_methodinfo_argTypes
54 : };
55 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
56 : static_assert(0 < 1, "There is no slot for us");
57 :
58 : static bool
59 0 : get_timeOrigin(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, JSJitGetterCallArgs args)
60 : {
61 0 : double result(self->TimeOrigin());
62 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
63 0 : args.rval().set(JS_NumberValue(double(result)));
64 0 : return true;
65 : }
66 :
67 : static const JSJitInfo timeOrigin_getterinfo = {
68 : { (JSJitGetterOp)get_timeOrigin },
69 : { prototypes::id::Performance },
70 : { PrototypeTraits<prototypes::id::Performance>::Depth },
71 : JSJitInfo::Getter,
72 : JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
73 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
74 : true, /* isInfallible. False in setters. */
75 : true, /* isMovable. Not relevant for setters. */
76 : true, /* isEliminatable. Not relevant for setters. */
77 : false, /* isAlwaysInSlot. Only relevant for getters. */
78 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
79 : false, /* isTypedMethod. Only relevant for methods. */
80 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
81 : };
82 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
83 : static_assert(0 < 1, "There is no slot for us");
84 :
85 : static bool
86 0 : get_timing(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, JSJitGetterCallArgs args)
87 : {
88 0 : auto result(StrongOrRawPtr<mozilla::dom::PerformanceTiming>(self->Timing()));
89 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
90 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
91 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
92 0 : return false;
93 : }
94 0 : return true;
95 : }
96 :
97 : static const JSJitInfo timing_getterinfo = {
98 : { (JSJitGetterOp)get_timing },
99 : { prototypes::id::Performance },
100 : { PrototypeTraits<prototypes::id::Performance>::Depth },
101 : JSJitInfo::Getter,
102 : JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
103 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
104 : false, /* isInfallible. False in setters. */
105 : true, /* isMovable. Not relevant for setters. */
106 : true, /* isEliminatable. Not relevant for setters. */
107 : false, /* isAlwaysInSlot. Only relevant for getters. */
108 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
109 : false, /* isTypedMethod. Only relevant for methods. */
110 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
111 : };
112 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
113 : static_assert(0 < 1, "There is no slot for us");
114 :
115 : static bool
116 0 : get_navigation(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, JSJitGetterCallArgs args)
117 : {
118 0 : auto result(StrongOrRawPtr<mozilla::dom::PerformanceNavigation>(self->Navigation()));
119 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
120 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
121 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
122 0 : return false;
123 : }
124 0 : return true;
125 : }
126 :
127 : static const JSJitInfo navigation_getterinfo = {
128 : { (JSJitGetterOp)get_navigation },
129 : { prototypes::id::Performance },
130 : { PrototypeTraits<prototypes::id::Performance>::Depth },
131 : JSJitInfo::Getter,
132 : JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
133 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
134 : false, /* isInfallible. False in setters. */
135 : true, /* isMovable. Not relevant for setters. */
136 : true, /* isEliminatable. Not relevant for setters. */
137 : false, /* isAlwaysInSlot. Only relevant for getters. */
138 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
139 : false, /* isTypedMethod. Only relevant for methods. */
140 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
141 : };
142 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
143 : static_assert(0 < 1, "There is no slot for us");
144 :
145 : static bool
146 0 : getEntries(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, const JSJitMethodCallArgs& args)
147 : {
148 0 : nsTArray<StrongPtrForMember<mozilla::dom::PerformanceEntry>::Type> result;
149 0 : self->GetEntries(result);
150 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
151 :
152 0 : uint32_t length = result.Length();
153 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
154 0 : if (!returnArray) {
155 0 : return false;
156 : }
157 : // Scope for 'tmp'
158 : {
159 0 : JS::Rooted<JS::Value> tmp(cx);
160 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
161 : // Control block to let us common up the JS_DefineElement calls when there
162 : // are different ways to succeed at wrapping the object.
163 : do {
164 0 : if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
165 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
166 0 : return false;
167 : }
168 0 : break;
169 : } while (0);
170 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
171 : JSPROP_ENUMERATE)) {
172 0 : return false;
173 : }
174 : }
175 : }
176 0 : args.rval().setObject(*returnArray);
177 0 : return true;
178 : }
179 :
180 : static const JSJitInfo getEntries_methodinfo = {
181 : { (JSJitGetterOp)getEntries },
182 : { prototypes::id::Performance },
183 : { PrototypeTraits<prototypes::id::Performance>::Depth },
184 : JSJitInfo::Method,
185 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
186 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
187 : false, /* isInfallible. False in setters. */
188 : false, /* isMovable. Not relevant for setters. */
189 : false, /* isEliminatable. Not relevant for setters. */
190 : false, /* isAlwaysInSlot. Only relevant for getters. */
191 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
192 : false, /* isTypedMethod. Only relevant for methods. */
193 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
194 : };
195 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
196 : static_assert(0 < 1, "There is no slot for us");
197 :
198 : static bool
199 0 : getEntriesByType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, const JSJitMethodCallArgs& args)
200 : {
201 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
202 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Performance.getEntriesByType");
203 : }
204 0 : binding_detail::FakeString arg0;
205 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
206 0 : return false;
207 : }
208 0 : nsTArray<StrongPtrForMember<mozilla::dom::PerformanceEntry>::Type> result;
209 0 : self->GetEntriesByType(NonNullHelper(Constify(arg0)), result);
210 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
211 :
212 0 : uint32_t length = result.Length();
213 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
214 0 : if (!returnArray) {
215 0 : return false;
216 : }
217 : // Scope for 'tmp'
218 : {
219 0 : JS::Rooted<JS::Value> tmp(cx);
220 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
221 : // Control block to let us common up the JS_DefineElement calls when there
222 : // are different ways to succeed at wrapping the object.
223 : do {
224 0 : if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
225 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
226 0 : return false;
227 : }
228 0 : break;
229 : } while (0);
230 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
231 : JSPROP_ENUMERATE)) {
232 0 : return false;
233 : }
234 : }
235 : }
236 0 : args.rval().setObject(*returnArray);
237 0 : return true;
238 : }
239 :
240 : static const JSJitInfo getEntriesByType_methodinfo = {
241 : { (JSJitGetterOp)getEntriesByType },
242 : { prototypes::id::Performance },
243 : { PrototypeTraits<prototypes::id::Performance>::Depth },
244 : JSJitInfo::Method,
245 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
246 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
247 : false, /* isInfallible. False in setters. */
248 : false, /* isMovable. Not relevant for setters. */
249 : false, /* isEliminatable. Not relevant for setters. */
250 : false, /* isAlwaysInSlot. Only relevant for getters. */
251 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
252 : false, /* isTypedMethod. Only relevant for methods. */
253 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
254 : };
255 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
256 : static_assert(0 < 1, "There is no slot for us");
257 :
258 : static bool
259 0 : getEntriesByName(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, const JSJitMethodCallArgs& args)
260 : {
261 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
262 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Performance.getEntriesByName");
263 : }
264 0 : binding_detail::FakeString arg0;
265 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
266 0 : return false;
267 : }
268 0 : Optional<nsAString> arg1;
269 0 : binding_detail::FakeString arg1_holder;
270 0 : if (args.hasDefined(1)) {
271 0 : if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1_holder)) {
272 0 : return false;
273 : }
274 0 : arg1 = &arg1_holder;
275 : }
276 0 : nsTArray<StrongPtrForMember<mozilla::dom::PerformanceEntry>::Type> result;
277 0 : self->GetEntriesByName(NonNullHelper(Constify(arg0)), NonNullHelper(Constify(arg1)), result);
278 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
279 :
280 0 : uint32_t length = result.Length();
281 0 : JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
282 0 : if (!returnArray) {
283 0 : return false;
284 : }
285 : // Scope for 'tmp'
286 : {
287 0 : JS::Rooted<JS::Value> tmp(cx);
288 0 : for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
289 : // Control block to let us common up the JS_DefineElement calls when there
290 : // are different ways to succeed at wrapping the object.
291 : do {
292 0 : if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
293 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
294 0 : return false;
295 : }
296 0 : break;
297 : } while (0);
298 0 : if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
299 : JSPROP_ENUMERATE)) {
300 0 : return false;
301 : }
302 : }
303 : }
304 0 : args.rval().setObject(*returnArray);
305 0 : return true;
306 : }
307 :
308 : static const JSJitInfo getEntriesByName_methodinfo = {
309 : { (JSJitGetterOp)getEntriesByName },
310 : { prototypes::id::Performance },
311 : { PrototypeTraits<prototypes::id::Performance>::Depth },
312 : JSJitInfo::Method,
313 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
314 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
315 : false, /* isInfallible. False in setters. */
316 : false, /* isMovable. Not relevant for setters. */
317 : false, /* isEliminatable. Not relevant for setters. */
318 : false, /* isAlwaysInSlot. Only relevant for getters. */
319 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
320 : false, /* isTypedMethod. Only relevant for methods. */
321 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
322 : };
323 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
324 : static_assert(0 < 1, "There is no slot for us");
325 :
326 : static bool
327 0 : clearResourceTimings(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, const JSJitMethodCallArgs& args)
328 : {
329 0 : self->ClearResourceTimings();
330 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
331 0 : args.rval().setUndefined();
332 0 : return true;
333 : }
334 :
335 : static const JSJitInfo clearResourceTimings_methodinfo = {
336 : { (JSJitGetterOp)clearResourceTimings },
337 : { prototypes::id::Performance },
338 : { PrototypeTraits<prototypes::id::Performance>::Depth },
339 : JSJitInfo::Method,
340 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
341 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
342 : true, /* 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 : static bool
354 0 : setResourceTimingBufferSize(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, const JSJitMethodCallArgs& args)
355 : {
356 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
357 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Performance.setResourceTimingBufferSize");
358 : }
359 : uint32_t arg0;
360 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
361 0 : return false;
362 : }
363 0 : self->SetResourceTimingBufferSize(arg0);
364 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
365 0 : args.rval().setUndefined();
366 0 : return true;
367 : }
368 :
369 : static const JSJitInfo setResourceTimingBufferSize_methodinfo = {
370 : { (JSJitGetterOp)setResourceTimingBufferSize },
371 : { prototypes::id::Performance },
372 : { PrototypeTraits<prototypes::id::Performance>::Depth },
373 : JSJitInfo::Method,
374 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
375 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
376 : false, /* isInfallible. False in setters. */
377 : false, /* isMovable. Not relevant for setters. */
378 : false, /* isEliminatable. Not relevant for setters. */
379 : false, /* isAlwaysInSlot. Only relevant for getters. */
380 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
381 : false, /* isTypedMethod. Only relevant for methods. */
382 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
383 : };
384 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
385 : static_assert(0 < 1, "There is no slot for us");
386 :
387 : static bool
388 0 : get_onresourcetimingbufferfull(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, JSJitGetterCallArgs args)
389 : {
390 0 : RefPtr<EventHandlerNonNull> result(self->GetOnresourcetimingbufferfull());
391 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
392 0 : if (result) {
393 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
394 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
395 0 : return false;
396 : }
397 0 : return true;
398 : } else {
399 0 : args.rval().setNull();
400 0 : return true;
401 : }
402 : }
403 :
404 : static bool
405 0 : set_onresourcetimingbufferfull(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, JSJitSetterCallArgs args)
406 : {
407 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
408 0 : if (args[0].isObject()) {
409 : { // scope for tempRoot
410 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
411 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
412 : }
413 : } else {
414 0 : arg0 = nullptr;
415 : }
416 0 : self->SetOnresourcetimingbufferfull(Constify(arg0));
417 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
418 :
419 0 : return true;
420 : }
421 :
422 : static const JSJitInfo onresourcetimingbufferfull_getterinfo = {
423 : { (JSJitGetterOp)get_onresourcetimingbufferfull },
424 : { prototypes::id::Performance },
425 : { PrototypeTraits<prototypes::id::Performance>::Depth },
426 : JSJitInfo::Getter,
427 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
428 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
429 : false, /* isInfallible. False in setters. */
430 : false, /* isMovable. Not relevant for setters. */
431 : false, /* isEliminatable. Not relevant for setters. */
432 : false, /* isAlwaysInSlot. Only relevant for getters. */
433 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
434 : false, /* isTypedMethod. Only relevant for methods. */
435 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
436 : };
437 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
438 : static_assert(0 < 1, "There is no slot for us");
439 : static const JSJitInfo onresourcetimingbufferfull_setterinfo = {
440 : { (JSJitGetterOp)set_onresourcetimingbufferfull },
441 : { prototypes::id::Performance },
442 : { PrototypeTraits<prototypes::id::Performance>::Depth },
443 : JSJitInfo::Setter,
444 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
445 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
446 : false, /* isInfallible. False in setters. */
447 : false, /* isMovable. Not relevant for setters. */
448 : false, /* isEliminatable. Not relevant for setters. */
449 : false, /* isAlwaysInSlot. Only relevant for getters. */
450 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
451 : false, /* isTypedMethod. Only relevant for methods. */
452 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
453 : };
454 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
455 : static_assert(0 < 1, "There is no slot for us");
456 :
457 : static bool
458 0 : get_mozMemory(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, JSJitGetterCallArgs args)
459 : {
460 0 : JS::Rooted<JSObject*> result(cx);
461 0 : self->GetMozMemory(cx, &result);
462 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
463 0 : JS::ExposeObjectToActiveJS(result);
464 0 : args.rval().setObject(*result);
465 0 : if (!MaybeWrapObjectValue(cx, args.rval())) {
466 0 : return false;
467 : }
468 0 : return true;
469 : }
470 :
471 : static const JSJitInfo mozMemory_getterinfo = {
472 : { (JSJitGetterOp)get_mozMemory },
473 : { prototypes::id::Performance },
474 : { PrototypeTraits<prototypes::id::Performance>::Depth },
475 : JSJitInfo::Getter,
476 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
477 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
478 : false, /* isInfallible. False in setters. */
479 : false, /* isMovable. Not relevant for setters. */
480 : false, /* isEliminatable. Not relevant for setters. */
481 : false, /* isAlwaysInSlot. Only relevant for getters. */
482 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
483 : false, /* isTypedMethod. Only relevant for methods. */
484 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
485 : };
486 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
487 : static_assert(0 < 1, "There is no slot for us");
488 :
489 : static bool
490 0 : mark(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, const JSJitMethodCallArgs& args)
491 : {
492 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
493 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Performance.mark");
494 : }
495 0 : binding_detail::FakeString arg0;
496 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
497 0 : return false;
498 : }
499 0 : binding_detail::FastErrorResult rv;
500 0 : self->Mark(NonNullHelper(Constify(arg0)), rv);
501 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
502 0 : return false;
503 : }
504 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
505 0 : args.rval().setUndefined();
506 0 : return true;
507 : }
508 :
509 : static const JSJitInfo mark_methodinfo = {
510 : { (JSJitGetterOp)mark },
511 : { prototypes::id::Performance },
512 : { PrototypeTraits<prototypes::id::Performance>::Depth },
513 : JSJitInfo::Method,
514 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
515 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
516 : false, /* isInfallible. False in setters. */
517 : false, /* isMovable. Not relevant for setters. */
518 : false, /* isEliminatable. Not relevant for setters. */
519 : false, /* isAlwaysInSlot. Only relevant for getters. */
520 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
521 : false, /* isTypedMethod. Only relevant for methods. */
522 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
523 : };
524 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
525 : static_assert(0 < 1, "There is no slot for us");
526 :
527 : static bool
528 0 : clearMarks(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, const JSJitMethodCallArgs& args)
529 : {
530 0 : Optional<nsAString> arg0;
531 0 : binding_detail::FakeString arg0_holder;
532 0 : if (args.hasDefined(0)) {
533 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0_holder)) {
534 0 : return false;
535 : }
536 0 : arg0 = &arg0_holder;
537 : }
538 0 : self->ClearMarks(NonNullHelper(Constify(arg0)));
539 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
540 0 : args.rval().setUndefined();
541 0 : return true;
542 : }
543 :
544 : static const JSJitInfo clearMarks_methodinfo = {
545 : { (JSJitGetterOp)clearMarks },
546 : { prototypes::id::Performance },
547 : { PrototypeTraits<prototypes::id::Performance>::Depth },
548 : JSJitInfo::Method,
549 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
550 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
551 : false, /* isInfallible. False in setters. */
552 : false, /* isMovable. Not relevant for setters. */
553 : false, /* isEliminatable. Not relevant for setters. */
554 : false, /* isAlwaysInSlot. Only relevant for getters. */
555 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
556 : false, /* isTypedMethod. Only relevant for methods. */
557 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
558 : };
559 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
560 : static_assert(0 < 1, "There is no slot for us");
561 :
562 : static bool
563 0 : measure(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, const JSJitMethodCallArgs& args)
564 : {
565 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
566 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Performance.measure");
567 : }
568 0 : binding_detail::FakeString arg0;
569 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
570 0 : return false;
571 : }
572 0 : Optional<nsAString> arg1;
573 0 : binding_detail::FakeString arg1_holder;
574 0 : if (args.hasDefined(1)) {
575 0 : if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1_holder)) {
576 0 : return false;
577 : }
578 0 : arg1 = &arg1_holder;
579 : }
580 0 : Optional<nsAString> arg2;
581 0 : binding_detail::FakeString arg2_holder;
582 0 : if (args.hasDefined(2)) {
583 0 : if (!ConvertJSValueToString(cx, args[2], eStringify, eStringify, arg2_holder)) {
584 0 : return false;
585 : }
586 0 : arg2 = &arg2_holder;
587 : }
588 0 : binding_detail::FastErrorResult rv;
589 0 : self->Measure(NonNullHelper(Constify(arg0)), NonNullHelper(Constify(arg1)), NonNullHelper(Constify(arg2)), rv);
590 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
591 0 : return false;
592 : }
593 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
594 0 : args.rval().setUndefined();
595 0 : return true;
596 : }
597 :
598 : static const JSJitInfo measure_methodinfo = {
599 : { (JSJitGetterOp)measure },
600 : { prototypes::id::Performance },
601 : { PrototypeTraits<prototypes::id::Performance>::Depth },
602 : JSJitInfo::Method,
603 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
604 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
605 : false, /* isInfallible. False in setters. */
606 : false, /* isMovable. Not relevant for setters. */
607 : false, /* isEliminatable. Not relevant for setters. */
608 : false, /* isAlwaysInSlot. Only relevant for getters. */
609 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
610 : false, /* isTypedMethod. Only relevant for methods. */
611 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
612 : };
613 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
614 : static_assert(0 < 1, "There is no slot for us");
615 :
616 : static bool
617 0 : clearMeasures(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, const JSJitMethodCallArgs& args)
618 : {
619 0 : Optional<nsAString> arg0;
620 0 : binding_detail::FakeString arg0_holder;
621 0 : if (args.hasDefined(0)) {
622 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0_holder)) {
623 0 : return false;
624 : }
625 0 : arg0 = &arg0_holder;
626 : }
627 0 : self->ClearMeasures(NonNullHelper(Constify(arg0)));
628 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
629 0 : args.rval().setUndefined();
630 0 : return true;
631 : }
632 :
633 : static const JSJitInfo clearMeasures_methodinfo = {
634 : { (JSJitGetterOp)clearMeasures },
635 : { prototypes::id::Performance },
636 : { PrototypeTraits<prototypes::id::Performance>::Depth },
637 : JSJitInfo::Method,
638 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
639 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
640 : false, /* isInfallible. False in setters. */
641 : false, /* isMovable. Not relevant for setters. */
642 : false, /* isEliminatable. Not relevant for setters. */
643 : false, /* isAlwaysInSlot. Only relevant for getters. */
644 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
645 : false, /* isTypedMethod. Only relevant for methods. */
646 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
647 : };
648 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
649 : static_assert(0 < 1, "There is no slot for us");
650 :
651 : bool
652 0 : JsonifyAttributes(JSContext* aCx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, JS::Rooted<JSObject*>& aResult)
653 : {
654 : { // scope for "temp"
655 0 : JS::Rooted<JS::Value> temp(aCx);
656 0 : if (!get_timeOrigin(aCx, obj, self, JSJitGetterCallArgs(&temp))) {
657 0 : return false;
658 : }
659 0 : if (!JS_DefineProperty(aCx, aResult, "timeOrigin", temp, JSPROP_ENUMERATE)) {
660 0 : return false;
661 : }
662 : }
663 : { // scope for "temp"
664 0 : JS::Rooted<JS::Value> temp(aCx);
665 0 : if (!get_timing(aCx, obj, self, JSJitGetterCallArgs(&temp))) {
666 0 : return false;
667 : }
668 0 : if (!JS_DefineProperty(aCx, aResult, "timing", temp, JSPROP_ENUMERATE)) {
669 0 : return false;
670 : }
671 : }
672 : { // scope for "temp"
673 0 : JS::Rooted<JS::Value> temp(aCx);
674 0 : if (!get_navigation(aCx, obj, self, JSJitGetterCallArgs(&temp))) {
675 0 : return false;
676 : }
677 0 : if (!JS_DefineProperty(aCx, aResult, "navigation", temp, JSPROP_ENUMERATE)) {
678 0 : return false;
679 : }
680 : }
681 0 : return true;
682 : }
683 :
684 : static bool
685 0 : __jsonifier(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Performance* self, const JSJitMethodCallArgs& args)
686 : {
687 0 : JS::Rooted<JSObject*> result(cx, JS_NewPlainObject(cx));
688 0 : if (!result) {
689 0 : return false;
690 : }
691 0 : if (!PerformanceBinding::JsonifyAttributes(cx, obj, self, result)) {
692 0 : return false;
693 : }
694 0 : args.rval().setObject(*result);
695 0 : return true;
696 : }
697 :
698 : static const JSJitInfo __jsonifier_methodinfo = {
699 : { (JSJitGetterOp)__jsonifier },
700 : { prototypes::id::Performance },
701 : { PrototypeTraits<prototypes::id::Performance>::Depth },
702 : JSJitInfo::Method,
703 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
704 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
705 : false, /* isInfallible. False in setters. */
706 : false, /* isMovable. Not relevant for setters. */
707 : false, /* isEliminatable. Not relevant for setters. */
708 : false, /* isAlwaysInSlot. Only relevant for getters. */
709 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
710 : false, /* isTypedMethod. Only relevant for methods. */
711 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
712 : };
713 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
714 : static_assert(0 < 1, "There is no slot for us");
715 :
716 : static bool
717 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
718 : {
719 0 : mozilla::dom::Performance* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Performance>(obj);
720 : // We don't want to preserve if we don't have a wrapper, and we
721 : // obviously can't preserve if we're not initialized.
722 0 : if (self && self->GetWrapperPreserveColor()) {
723 0 : PreserveWrapper(self);
724 : }
725 0 : return true;
726 : }
727 :
728 : static void
729 0 : _finalize(js::FreeOp* fop, JSObject* obj)
730 : {
731 0 : mozilla::dom::Performance* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Performance>(obj);
732 0 : if (self) {
733 0 : ClearWrapper(self, self, obj);
734 0 : AddForDeferredFinalization<mozilla::dom::Performance>(self);
735 : }
736 0 : }
737 :
738 : static void
739 0 : _objectMoved(JSObject* obj, const JSObject* old)
740 : {
741 0 : mozilla::dom::Performance* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Performance>(obj);
742 0 : if (self) {
743 0 : UpdateWrapper(self, self, obj, old);
744 : }
745 0 : }
746 :
747 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
748 : #if defined(__clang__)
749 : #pragma clang diagnostic push
750 : #pragma clang diagnostic ignored "-Wmissing-braces"
751 : #endif
752 : static const JSFunctionSpec sMethods_specs[] = {
753 : JS_FNSPEC("now", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&now_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
754 : JS_FNSPEC("getEntries", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getEntries_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
755 : JS_FNSPEC("getEntriesByType", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getEntriesByType_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
756 : JS_FNSPEC("getEntriesByName", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getEntriesByName_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
757 : JS_FS_END,
758 : JS_FNSPEC("clearResourceTimings", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&clearResourceTimings_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
759 : JS_FNSPEC("setResourceTimingBufferSize", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&setResourceTimingBufferSize_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
760 : JS_FS_END,
761 : JS_FNSPEC("mark", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&mark_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
762 : JS_FNSPEC("clearMarks", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&clearMarks_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
763 : JS_FNSPEC("measure", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&measure_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
764 : JS_FNSPEC("clearMeasures", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&clearMeasures_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
765 : JS_FS_END,
766 : JS_FNSPEC("QueryInterface", QueryInterface, nullptr, 1, 0, nullptr),
767 : JS_FS_END,
768 : JS_FNSPEC("toJSON", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&__jsonifier_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
769 : JS_FS_END
770 : };
771 : #if defined(__clang__)
772 : #pragma clang diagnostic pop
773 : #endif
774 :
775 : static PrefableDisablers sMethods_disablers5 = {
776 : true, false, GlobalNames::DedicatedWorkerGlobalScope | GlobalNames::ServiceWorkerGlobalScope | GlobalNames::SharedWorkerGlobalScope, nullptr
777 : };
778 :
779 : static PrefableDisablers sMethods_disablers13 = {
780 : true, false, 0, &WantsQueryInterface<mozilla::dom::Performance>::Enabled
781 : };
782 :
783 : static PrefableDisablers sMethods_disablers15 = {
784 : true, false, GlobalNames::DedicatedWorkerGlobalScope | GlobalNames::ServiceWorkerGlobalScope | GlobalNames::SharedWorkerGlobalScope, nullptr
785 : };
786 :
787 : // Can't be const because the pref-enabled boolean needs to be writable
788 : static Prefable<const JSFunctionSpec> sMethods[] = {
789 : { nullptr, &sMethods_specs[0] },
790 : { &sMethods_disablers5, &sMethods_specs[5] },
791 : { nullptr, &sMethods_specs[8] },
792 : { &sMethods_disablers13, &sMethods_specs[13] },
793 : { &sMethods_disablers15, &sMethods_specs[15] },
794 : { nullptr, nullptr }
795 : };
796 :
797 : static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
798 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
799 : static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
800 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
801 :
802 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
803 : #if defined(__clang__)
804 : #pragma clang diagnostic push
805 : #pragma clang diagnostic ignored "-Wmissing-braces"
806 : #endif
807 : static const JSPropertySpec sAttributes_specs[] = {
808 : { "timeOrigin", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &timeOrigin_getterinfo, nullptr, nullptr },
809 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
810 : { "timing", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &timing_getterinfo, nullptr, nullptr },
811 : { "navigation", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &navigation_getterinfo, nullptr, nullptr },
812 : { "onresourcetimingbufferfull", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onresourcetimingbufferfull_getterinfo, GenericBindingSetter, &onresourcetimingbufferfull_setterinfo },
813 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
814 : { "mozMemory", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &mozMemory_getterinfo, nullptr, nullptr },
815 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
816 : };
817 : #if defined(__clang__)
818 : #pragma clang diagnostic pop
819 : #endif
820 :
821 : static PrefableDisablers sAttributes_disablers2 = {
822 : true, false, GlobalNames::DedicatedWorkerGlobalScope | GlobalNames::ServiceWorkerGlobalScope | GlobalNames::SharedWorkerGlobalScope, nullptr
823 : };
824 :
825 : static PrefableDisablers sAttributes_disablers6 = {
826 : true, false, GlobalNames::DedicatedWorkerGlobalScope | GlobalNames::ServiceWorkerGlobalScope | GlobalNames::SharedWorkerGlobalScope, nullptr
827 : };
828 :
829 : // Can't be const because the pref-enabled boolean needs to be writable
830 : static Prefable<const JSPropertySpec> sAttributes[] = {
831 : { nullptr, &sAttributes_specs[0] },
832 : { &sAttributes_disablers2, &sAttributes_specs[2] },
833 : { &sAttributes_disablers6, &sAttributes_specs[6] },
834 : { nullptr, nullptr }
835 : };
836 :
837 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
838 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
839 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
840 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
841 :
842 :
843 : static uint16_t sNativeProperties_sortedPropertyIndices[17];
844 : static PropertyInfo sNativeProperties_propertyInfos[17];
845 :
846 : static const NativePropertiesN<2> sNativeProperties = {
847 : false, 0,
848 : false, 0,
849 : true, 0 /* sMethods */,
850 : true, 1 /* sAttributes */,
851 : false, 0,
852 : false, 0,
853 : false, 0,
854 : -1,
855 : 17,
856 : sNativeProperties_sortedPropertyIndices,
857 : {
858 : { sMethods, &sNativeProperties_propertyInfos[0] },
859 : { sAttributes, &sNativeProperties_propertyInfos[12] }
860 : }
861 : };
862 : static_assert(17 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
863 : "We have a property info count that is oversized");
864 :
865 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
866 : {
867 : "Function",
868 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
869 : &sBoringInterfaceObjectClassClassOps,
870 : JS_NULL_CLASS_SPEC,
871 : JS_NULL_CLASS_EXT,
872 : &sInterfaceObjectClassObjectOps
873 : },
874 : eInterface,
875 : true,
876 : prototypes::id::Performance,
877 : PrototypeTraits<prototypes::id::Performance>::Depth,
878 : sNativePropertyHooks,
879 : "function Performance() {\n [native code]\n}",
880 : JS::GetRealmFunctionPrototype
881 : };
882 :
883 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
884 : {
885 : "PerformancePrototype",
886 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
887 : JS_NULL_CLASS_OPS,
888 : JS_NULL_CLASS_SPEC,
889 : JS_NULL_CLASS_EXT,
890 : JS_NULL_OBJECT_OPS
891 : },
892 : eInterfacePrototype,
893 : false,
894 : prototypes::id::Performance,
895 : PrototypeTraits<prototypes::id::Performance>::Depth,
896 : sNativePropertyHooks,
897 : "[object PerformancePrototype]",
898 : JS::GetRealmObjectPrototype
899 : };
900 :
901 : JSObject*
902 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
903 : {
904 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
905 : }
906 :
907 : static const js::ClassOps sClassOps = {
908 : _addProperty, /* addProperty */
909 : nullptr, /* delProperty */
910 : nullptr, /* getProperty */
911 : nullptr, /* setProperty */
912 : nullptr, /* enumerate */
913 : nullptr, /* newEnumerate */
914 : nullptr, /* resolve */
915 : nullptr, /* mayResolve */
916 : _finalize, /* finalize */
917 : nullptr, /* call */
918 : nullptr, /* hasInstance */
919 : nullptr, /* construct */
920 : nullptr, /* trace */
921 : };
922 :
923 : static const js::ClassExtension sClassExtension = {
924 : nullptr, /* weakmapKeyDelegateOp */
925 : _objectMoved /* objectMovedOp */
926 : };
927 :
928 : static const DOMJSClass sClass = {
929 : { "Performance",
930 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
931 : &sClassOps,
932 : JS_NULL_CLASS_SPEC,
933 : &sClassExtension,
934 : JS_NULL_OBJECT_OPS
935 : },
936 : { prototypes::id::Performance, 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 },
937 : IsBaseOf<nsISupports, mozilla::dom::Performance >::value,
938 : sNativePropertyHooks,
939 : FindAssociatedGlobalForNative<mozilla::dom::Performance>::Get,
940 : GetProtoObjectHandle,
941 : GetCCParticipant<mozilla::dom::Performance>::Get()
942 : };
943 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
944 : "Must have the right minimal number of reserved slots.");
945 : static_assert(1 >= 1,
946 : "Must have enough reserved slots.");
947 :
948 : const JSClass*
949 0 : GetJSClass()
950 : {
951 0 : return sClass.ToJSClass();
952 : }
953 :
954 : bool
955 7 : Wrap(JSContext* aCx, mozilla::dom::Performance* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
956 : {
957 : MOZ_ASSERT(static_cast<mozilla::dom::Performance*>(aObject) ==
958 : reinterpret_cast<mozilla::dom::Performance*>(aObject),
959 : "Multiple inheritance for mozilla::dom::Performance is broken.");
960 7 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
961 7 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
962 7 : MOZ_ASSERT(!aCache->GetWrapper(),
963 : "You should probably not be using Wrap() directly; use "
964 : "GetOrCreateDOMReflector instead");
965 :
966 7 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
967 : "nsISupports must be on our primary inheritance chain");
968 :
969 14 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
970 7 : if (!global) {
971 0 : return false;
972 : }
973 7 : MOZ_ASSERT(JS_IsGlobalObject(global));
974 7 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
975 :
976 : // That might have ended up wrapping us already, due to the wonders
977 : // of XBL. Check for that, and bail out as needed.
978 7 : aReflector.set(aCache->GetWrapper());
979 7 : if (aReflector) {
980 : #ifdef DEBUG
981 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
982 : #endif // DEBUG
983 0 : return true;
984 : }
985 :
986 14 : JSAutoCompartment ac(aCx, global);
987 7 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
988 7 : if (!canonicalProto) {
989 0 : return false;
990 : }
991 14 : JS::Rooted<JSObject*> proto(aCx);
992 7 : if (aGivenProto) {
993 0 : proto = aGivenProto;
994 : // Unfortunately, while aGivenProto was in the compartment of aCx
995 : // coming in, we changed compartments to that of "parent" so may need
996 : // to wrap the proto here.
997 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
998 0 : if (!JS_WrapObject(aCx, &proto)) {
999 0 : return false;
1000 : }
1001 : }
1002 : } else {
1003 7 : proto = canonicalProto;
1004 : }
1005 :
1006 14 : BindingJSObjectCreator<mozilla::dom::Performance> creator(aCx);
1007 7 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1008 7 : if (!aReflector) {
1009 0 : return false;
1010 : }
1011 :
1012 7 : aCache->SetWrapper(aReflector);
1013 7 : creator.InitializationSucceeded();
1014 :
1015 7 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1016 : aCache->GetWrapperPreserveColor() == aReflector);
1017 : // If proto != canonicalProto, we have to preserve our wrapper;
1018 : // otherwise we won't be able to properly recreate it later, since
1019 : // we won't know what proto to use. Note that we don't check
1020 : // aGivenProto here, since it's entirely possible (and even
1021 : // somewhat common) to have a non-null aGivenProto which is the
1022 : // same as canonicalProto.
1023 7 : if (proto != canonicalProto) {
1024 0 : PreserveWrapper(aObject);
1025 : }
1026 :
1027 7 : return true;
1028 : }
1029 :
1030 : const NativePropertyHooks sNativePropertyHooks[] = { {
1031 : nullptr,
1032 : nullptr,
1033 : nullptr,
1034 : { sNativeProperties.Upcast(), nullptr },
1035 : prototypes::id::Performance,
1036 : constructors::id::Performance,
1037 : nullptr,
1038 : &DefaultXrayExpandoObjectClass
1039 : } };
1040 :
1041 : void
1042 8 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1043 : {
1044 16 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
1045 8 : if (!parentProto) {
1046 0 : return;
1047 : }
1048 :
1049 16 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
1050 8 : if (!constructorProto) {
1051 0 : return;
1052 : }
1053 :
1054 : static bool sIdsInited = false;
1055 8 : if (!sIdsInited && NS_IsMainThread()) {
1056 2 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
1057 0 : return;
1058 : }
1059 2 : sIdsInited = true;
1060 : }
1061 :
1062 : static bool sPrefCachesInited = false;
1063 8 : if (!sPrefCachesInited && NS_IsMainThread()) {
1064 2 : sPrefCachesInited = true;
1065 2 : Preferences::AddBoolVarCache(&sAttributes[2].disablers->enabled, "dom.enable_memory_stats");
1066 : }
1067 :
1068 8 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Performance);
1069 8 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Performance);
1070 16 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1071 : &sPrototypeClass.mBase, protoCache,
1072 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1073 : interfaceCache,
1074 : sNativeProperties.Upcast(),
1075 : nullptr,
1076 : "Performance", aDefineOnGlobal,
1077 : nullptr,
1078 8 : false);
1079 : }
1080 :
1081 : JS::Handle<JSObject*>
1082 7 : GetProtoObjectHandle(JSContext* aCx)
1083 : {
1084 : /* Get the interface prototype object for this class. This will create the
1085 : object as needed. */
1086 7 : bool aDefineOnGlobal = true;
1087 :
1088 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1089 7 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1090 7 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1091 0 : return nullptr;
1092 : }
1093 :
1094 : /* Check to see whether the interface objects are already installed */
1095 7 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1096 7 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::Performance)) {
1097 14 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1098 7 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1099 : }
1100 :
1101 : /*
1102 : * The object might _still_ be null, but that's OK.
1103 : *
1104 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1105 : * traced by TraceProtoAndIfaceCache() and its contents are never
1106 : * changed after they have been set.
1107 : *
1108 : * Calling address() avoids the read read barrier that does gray
1109 : * unmarking, but it's not possible for the object to be gray here.
1110 : */
1111 :
1112 7 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::Performance);
1113 7 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1114 7 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1115 : }
1116 :
1117 : JS::Handle<JSObject*>
1118 1 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
1119 : {
1120 : /* Get the interface object for this class. This will create the object as
1121 : needed. */
1122 :
1123 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1124 1 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1125 1 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1126 0 : return nullptr;
1127 : }
1128 :
1129 : /* Check to see whether the interface objects are already installed */
1130 1 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1131 1 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::Performance)) {
1132 2 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1133 1 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1134 : }
1135 :
1136 : /*
1137 : * The object might _still_ be null, but that's OK.
1138 : *
1139 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1140 : * traced by TraceProtoAndIfaceCache() and its contents are never
1141 : * changed after they have been set.
1142 : *
1143 : * Calling address() avoids the read read barrier that does gray
1144 : * unmarking, but it's not possible for the object to be gray here.
1145 : */
1146 :
1147 1 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::Performance);
1148 1 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1149 1 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1150 : }
1151 :
1152 : JSObject*
1153 1 : GetConstructorObject(JSContext* aCx)
1154 : {
1155 1 : return GetConstructorObjectHandle(aCx);
1156 : }
1157 :
1158 : } // namespace PerformanceBinding
1159 :
1160 :
1161 :
1162 : } // namespace dom
1163 : } // namespace mozilla
|