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