/work/obj-fuzz/dom/bindings/PerformanceEntryEventBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM PerformanceEntryEvent.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "EventBinding.h" |
5 | | #include "PerformanceEntryEventBinding.h" |
6 | | #include "WrapperFactory.h" |
7 | | #include "mozilla/FloatingPoint.h" |
8 | | #include "mozilla/OwningNonNull.h" |
9 | | #include "mozilla/dom/BindingUtils.h" |
10 | | #include "mozilla/dom/DOMJSClass.h" |
11 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
12 | | #include "mozilla/dom/PerformanceEntryEvent.h" |
13 | | #include "mozilla/dom/PrimitiveConversions.h" |
14 | | #include "mozilla/dom/ScriptSettings.h" |
15 | | #include "mozilla/dom/SimpleGlobalObject.h" |
16 | | #include "mozilla/dom/XrayExpandoClass.h" |
17 | | #include "nsContentUtils.h" |
18 | | |
19 | | namespace mozilla { |
20 | | namespace dom { |
21 | | |
22 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
23 | | using namespace mozilla::dom::binding_detail; |
24 | | |
25 | | |
26 | | |
27 | | PerformanceEntryEventInit::PerformanceEntryEventInit() |
28 | | : EventInit(FastDictionaryInitializer()) |
29 | 0 | { |
30 | 0 | // Safe to pass a null context if we pass a null value |
31 | 0 | Init(nullptr, JS::NullHandleValue); |
32 | 0 | } |
33 | | |
34 | | |
35 | | |
36 | | bool |
37 | | PerformanceEntryEventInit::InitIds(JSContext* cx, PerformanceEntryEventInitAtoms* atomsCache) |
38 | 0 | { |
39 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
40 | 0 |
|
41 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
42 | 0 | // uninitialized. |
43 | 0 | if (!atomsCache->startTime_id.init(cx, "startTime") || |
44 | 0 | !atomsCache->origin_id.init(cx, "origin") || |
45 | 0 | !atomsCache->name_id.init(cx, "name") || |
46 | 0 | !atomsCache->epoch_id.init(cx, "epoch") || |
47 | 0 | !atomsCache->entryType_id.init(cx, "entryType") || |
48 | 0 | !atomsCache->duration_id.init(cx, "duration")) { |
49 | 0 | return false; |
50 | 0 | } |
51 | 0 | return true; |
52 | 0 | } |
53 | | |
54 | | bool |
55 | | PerformanceEntryEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
56 | 0 | { |
57 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
58 | 0 | // Since in that case we will not have to do any property gets |
59 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
60 | 0 | // checkers by static analysis tools |
61 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
62 | 0 | PerformanceEntryEventInitAtoms* atomsCache = nullptr; |
63 | 0 | if (cx) { |
64 | 0 | atomsCache = GetAtomCache<PerformanceEntryEventInitAtoms>(cx); |
65 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
66 | 0 | return false; |
67 | 0 | } |
68 | 0 | } |
69 | 0 | |
70 | 0 | // Per spec, we init the parent's members first |
71 | 0 | if (!EventInit::Init(cx, val)) { |
72 | 0 | return false; |
73 | 0 | } |
74 | 0 | |
75 | 0 | bool isNull = val.isNullOrUndefined(); |
76 | 0 | // We only need these if !isNull, in which case we have |cx|. |
77 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
78 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
79 | 0 | if (!isNull) { |
80 | 0 | MOZ_ASSERT(cx); |
81 | 0 | object.emplace(cx, &val.toObject()); |
82 | 0 | temp.emplace(cx); |
83 | 0 | } |
84 | 0 | if (!isNull) { |
85 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->duration_id, temp.ptr())) { |
86 | 0 | return false; |
87 | 0 | } |
88 | 0 | } |
89 | 0 | if (!isNull && !temp->isUndefined()) { |
90 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mDuration)) { |
91 | 0 | return false; |
92 | 0 | } else if (!mozilla::IsFinite(mDuration)) { |
93 | 0 | ThrowErrorMessage(cx, MSG_NOT_FINITE, "'duration' member of PerformanceEntryEventInit"); |
94 | 0 | return false; |
95 | 0 | } |
96 | 0 | } else { |
97 | 0 | mDuration = 0.0; |
98 | 0 | } |
99 | 0 | mIsAnyMemberPresent = true; |
100 | 0 |
|
101 | 0 | if (!isNull) { |
102 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->entryType_id, temp.ptr())) { |
103 | 0 | return false; |
104 | 0 | } |
105 | 0 | } |
106 | 0 | if (!isNull && !temp->isUndefined()) { |
107 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mEntryType)) { |
108 | 0 | return false; |
109 | 0 | } |
110 | 0 | } else { |
111 | 0 | static const char16_t data[] = { 0 }; |
112 | 0 | mEntryType.Rebind(data, ArrayLength(data) - 1); |
113 | 0 | } |
114 | 0 | mIsAnyMemberPresent = true; |
115 | 0 |
|
116 | 0 | if (!isNull) { |
117 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->epoch_id, temp.ptr())) { |
118 | 0 | return false; |
119 | 0 | } |
120 | 0 | } |
121 | 0 | if (!isNull && !temp->isUndefined()) { |
122 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mEpoch)) { |
123 | 0 | return false; |
124 | 0 | } else if (!mozilla::IsFinite(mEpoch)) { |
125 | 0 | ThrowErrorMessage(cx, MSG_NOT_FINITE, "'epoch' member of PerformanceEntryEventInit"); |
126 | 0 | return false; |
127 | 0 | } |
128 | 0 | } else { |
129 | 0 | mEpoch = 0.0; |
130 | 0 | } |
131 | 0 | mIsAnyMemberPresent = true; |
132 | 0 |
|
133 | 0 | if (!isNull) { |
134 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) { |
135 | 0 | return false; |
136 | 0 | } |
137 | 0 | } |
138 | 0 | if (!isNull && !temp->isUndefined()) { |
139 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) { |
140 | 0 | return false; |
141 | 0 | } |
142 | 0 | } else { |
143 | 0 | static const char16_t data[] = { 0 }; |
144 | 0 | mName.Rebind(data, ArrayLength(data) - 1); |
145 | 0 | } |
146 | 0 | mIsAnyMemberPresent = true; |
147 | 0 |
|
148 | 0 | if (!isNull) { |
149 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->origin_id, temp.ptr())) { |
150 | 0 | return false; |
151 | 0 | } |
152 | 0 | } |
153 | 0 | if (!isNull && !temp->isUndefined()) { |
154 | 0 | if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mOrigin)) { |
155 | 0 | return false; |
156 | 0 | } |
157 | 0 | } else { |
158 | 0 | static const char16_t data[] = { 0 }; |
159 | 0 | mOrigin.Rebind(data, ArrayLength(data) - 1); |
160 | 0 | } |
161 | 0 | mIsAnyMemberPresent = true; |
162 | 0 |
|
163 | 0 | if (!isNull) { |
164 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->startTime_id, temp.ptr())) { |
165 | 0 | return false; |
166 | 0 | } |
167 | 0 | } |
168 | 0 | if (!isNull && !temp->isUndefined()) { |
169 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mStartTime)) { |
170 | 0 | return false; |
171 | 0 | } else if (!mozilla::IsFinite(mStartTime)) { |
172 | 0 | ThrowErrorMessage(cx, MSG_NOT_FINITE, "'startTime' member of PerformanceEntryEventInit"); |
173 | 0 | return false; |
174 | 0 | } |
175 | 0 | } else { |
176 | 0 | mStartTime = 0.0; |
177 | 0 | } |
178 | 0 | mIsAnyMemberPresent = true; |
179 | 0 | return true; |
180 | 0 | } |
181 | | |
182 | | bool |
183 | | PerformanceEntryEventInit::Init(const nsAString& aJSON) |
184 | 0 | { |
185 | 0 | AutoJSAPI jsapi; |
186 | 0 | JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail); |
187 | 0 | if (!cleanGlobal) { |
188 | 0 | return false; |
189 | 0 | } |
190 | 0 | if (!jsapi.Init(cleanGlobal)) { |
191 | 0 | return false; |
192 | 0 | } |
193 | 0 | JSContext* cx = jsapi.cx(); |
194 | 0 | JS::Rooted<JS::Value> json(cx); |
195 | 0 | bool ok = ParseJSON(cx, aJSON, &json); |
196 | 0 | NS_ENSURE_TRUE(ok, false); |
197 | 0 | return Init(cx, json); |
198 | 0 | } |
199 | | |
200 | | bool |
201 | | PerformanceEntryEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
202 | 0 | { |
203 | 0 | PerformanceEntryEventInitAtoms* atomsCache = GetAtomCache<PerformanceEntryEventInitAtoms>(cx); |
204 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
205 | 0 | return false; |
206 | 0 | } |
207 | 0 | |
208 | 0 | // Per spec, we define the parent's members first |
209 | 0 | if (!EventInit::ToObjectInternal(cx, rval)) { |
210 | 0 | return false; |
211 | 0 | } |
212 | 0 | JS::Rooted<JSObject*> obj(cx, &rval.toObject()); |
213 | 0 |
|
214 | 0 | do { |
215 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
216 | 0 | JS::Rooted<JS::Value> temp(cx); |
217 | 0 | double const & currentValue = mDuration; |
218 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
219 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->duration_id, temp, JSPROP_ENUMERATE)) { |
220 | 0 | return false; |
221 | 0 | } |
222 | 0 | break; |
223 | 0 | } while(false); |
224 | 0 |
|
225 | 0 | do { |
226 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
227 | 0 | JS::Rooted<JS::Value> temp(cx); |
228 | 0 | nsString const & currentValue = mEntryType; |
229 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
230 | 0 | return false; |
231 | 0 | } |
232 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->entryType_id, temp, JSPROP_ENUMERATE)) { |
233 | 0 | return false; |
234 | 0 | } |
235 | 0 | break; |
236 | 0 | } while(false); |
237 | 0 |
|
238 | 0 | do { |
239 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
240 | 0 | JS::Rooted<JS::Value> temp(cx); |
241 | 0 | double const & currentValue = mEpoch; |
242 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
243 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->epoch_id, temp, JSPROP_ENUMERATE)) { |
244 | 0 | return false; |
245 | 0 | } |
246 | 0 | break; |
247 | 0 | } while(false); |
248 | 0 |
|
249 | 0 | do { |
250 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
251 | 0 | JS::Rooted<JS::Value> temp(cx); |
252 | 0 | nsString const & currentValue = mName; |
253 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
254 | 0 | return false; |
255 | 0 | } |
256 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) { |
257 | 0 | return false; |
258 | 0 | } |
259 | 0 | break; |
260 | 0 | } while(false); |
261 | 0 |
|
262 | 0 | do { |
263 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
264 | 0 | JS::Rooted<JS::Value> temp(cx); |
265 | 0 | nsString const & currentValue = mOrigin; |
266 | 0 | if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) { |
267 | 0 | return false; |
268 | 0 | } |
269 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->origin_id, temp, JSPROP_ENUMERATE)) { |
270 | 0 | return false; |
271 | 0 | } |
272 | 0 | break; |
273 | 0 | } while(false); |
274 | 0 |
|
275 | 0 | do { |
276 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
277 | 0 | JS::Rooted<JS::Value> temp(cx); |
278 | 0 | double const & currentValue = mStartTime; |
279 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
280 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->startTime_id, temp, JSPROP_ENUMERATE)) { |
281 | 0 | return false; |
282 | 0 | } |
283 | 0 | break; |
284 | 0 | } while(false); |
285 | 0 |
|
286 | 0 | return true; |
287 | 0 | } |
288 | | |
289 | | bool |
290 | | PerformanceEntryEventInit::ToJSON(nsAString& aJSON) const |
291 | 0 | { |
292 | 0 | AutoJSAPI jsapi; |
293 | 0 | jsapi.Init(); |
294 | 0 | JSContext *cx = jsapi.cx(); |
295 | 0 | // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here |
296 | 0 | // because we'll only be creating objects, in ways that have no |
297 | 0 | // side-effects, followed by a call to JS::ToJSONMaybeSafely, |
298 | 0 | // which likewise guarantees no side-effects for the sorts of |
299 | 0 | // things we will pass it. |
300 | 0 | JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal()); |
301 | 0 | JS::Rooted<JS::Value> val(cx); |
302 | 0 | if (!ToObjectInternal(cx, &val)) { |
303 | 0 | return false; |
304 | 0 | } |
305 | 0 | JS::Rooted<JSObject*> obj(cx, &val.toObject()); |
306 | 0 | return StringifyToJSON(cx, obj, aJSON); |
307 | 0 | } |
308 | | |
309 | | void |
310 | | PerformanceEntryEventInit::TraceDictionary(JSTracer* trc) |
311 | 0 | { |
312 | 0 | EventInit::TraceDictionary(trc); |
313 | 0 | } |
314 | | |
315 | | PerformanceEntryEventInit& |
316 | | PerformanceEntryEventInit::operator=(const PerformanceEntryEventInit& aOther) |
317 | 0 | { |
318 | 0 | EventInit::operator=(aOther); |
319 | 0 | mDuration = aOther.mDuration; |
320 | 0 | mEntryType = aOther.mEntryType; |
321 | 0 | mEpoch = aOther.mEpoch; |
322 | 0 | mName = aOther.mName; |
323 | 0 | mOrigin = aOther.mOrigin; |
324 | 0 | mStartTime = aOther.mStartTime; |
325 | 0 | return *this; |
326 | 0 | } |
327 | | |
328 | | namespace binding_detail { |
329 | | } // namespace binding_detail |
330 | | |
331 | | |
332 | | namespace PerformanceEntryEvent_Binding { |
333 | | |
334 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<Event_Binding::NativeType>::value, |
335 | | "Can't inherit from an interface with a different ownership model."); |
336 | | |
337 | | MOZ_CAN_RUN_SCRIPT static bool |
338 | | get_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceEntryEvent* self, JSJitGetterCallArgs args) |
339 | 0 | { |
340 | 0 | AUTO_PROFILER_LABEL_FAST("get PerformanceEntryEvent.name", DOM, cx); |
341 | 0 |
|
342 | 0 | DOMString result; |
343 | 0 | self->GetName(result); |
344 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
345 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
346 | 0 | return false; |
347 | 0 | } |
348 | 0 | return true; |
349 | 0 | } |
350 | | |
351 | | static const JSJitInfo name_getterinfo = { |
352 | | { (JSJitGetterOp)get_name }, |
353 | | { prototypes::id::PerformanceEntryEvent }, |
354 | | { PrototypeTraits<prototypes::id::PerformanceEntryEvent>::Depth }, |
355 | | JSJitInfo::Getter, |
356 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
357 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
358 | | false, /* isInfallible. False in setters. */ |
359 | | false, /* isMovable. Not relevant for setters. */ |
360 | | false, /* isEliminatable. Not relevant for setters. */ |
361 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
362 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
363 | | false, /* isTypedMethod. Only relevant for methods. */ |
364 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
365 | | }; |
366 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
367 | | static_assert(0 < 1, "There is no slot for us"); |
368 | | |
369 | | MOZ_CAN_RUN_SCRIPT static bool |
370 | | get_entryType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceEntryEvent* self, JSJitGetterCallArgs args) |
371 | 0 | { |
372 | 0 | AUTO_PROFILER_LABEL_FAST("get PerformanceEntryEvent.entryType", DOM, cx); |
373 | 0 |
|
374 | 0 | DOMString result; |
375 | 0 | self->GetEntryType(result); |
376 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
377 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
378 | 0 | return false; |
379 | 0 | } |
380 | 0 | return true; |
381 | 0 | } |
382 | | |
383 | | static const JSJitInfo entryType_getterinfo = { |
384 | | { (JSJitGetterOp)get_entryType }, |
385 | | { prototypes::id::PerformanceEntryEvent }, |
386 | | { PrototypeTraits<prototypes::id::PerformanceEntryEvent>::Depth }, |
387 | | JSJitInfo::Getter, |
388 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
389 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
390 | | false, /* isInfallible. False in setters. */ |
391 | | false, /* isMovable. Not relevant for setters. */ |
392 | | false, /* isEliminatable. Not relevant for setters. */ |
393 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
394 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
395 | | false, /* isTypedMethod. Only relevant for methods. */ |
396 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
397 | | }; |
398 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
399 | | static_assert(0 < 1, "There is no slot for us"); |
400 | | |
401 | | MOZ_CAN_RUN_SCRIPT static bool |
402 | | get_startTime(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceEntryEvent* self, JSJitGetterCallArgs args) |
403 | 0 | { |
404 | 0 | AUTO_PROFILER_LABEL_FAST("get PerformanceEntryEvent.startTime", DOM, cx); |
405 | 0 |
|
406 | 0 | double result(self->StartTime()); |
407 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
408 | 0 | args.rval().set(JS_NumberValue(double(result))); |
409 | 0 | return true; |
410 | 0 | } |
411 | | |
412 | | static const JSJitInfo startTime_getterinfo = { |
413 | | { (JSJitGetterOp)get_startTime }, |
414 | | { prototypes::id::PerformanceEntryEvent }, |
415 | | { PrototypeTraits<prototypes::id::PerformanceEntryEvent>::Depth }, |
416 | | JSJitInfo::Getter, |
417 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
418 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
419 | | true, /* isInfallible. False in setters. */ |
420 | | false, /* isMovable. Not relevant for setters. */ |
421 | | false, /* isEliminatable. Not relevant for setters. */ |
422 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
423 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
424 | | false, /* isTypedMethod. Only relevant for methods. */ |
425 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
426 | | }; |
427 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
428 | | static_assert(0 < 1, "There is no slot for us"); |
429 | | |
430 | | MOZ_CAN_RUN_SCRIPT static bool |
431 | | get_duration(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceEntryEvent* self, JSJitGetterCallArgs args) |
432 | 0 | { |
433 | 0 | AUTO_PROFILER_LABEL_FAST("get PerformanceEntryEvent.duration", DOM, cx); |
434 | 0 |
|
435 | 0 | double result(self->Duration()); |
436 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
437 | 0 | args.rval().set(JS_NumberValue(double(result))); |
438 | 0 | return true; |
439 | 0 | } |
440 | | |
441 | | static const JSJitInfo duration_getterinfo = { |
442 | | { (JSJitGetterOp)get_duration }, |
443 | | { prototypes::id::PerformanceEntryEvent }, |
444 | | { PrototypeTraits<prototypes::id::PerformanceEntryEvent>::Depth }, |
445 | | JSJitInfo::Getter, |
446 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
447 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
448 | | true, /* isInfallible. False in setters. */ |
449 | | false, /* isMovable. Not relevant for setters. */ |
450 | | false, /* isEliminatable. Not relevant for setters. */ |
451 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
452 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
453 | | false, /* isTypedMethod. Only relevant for methods. */ |
454 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
455 | | }; |
456 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
457 | | static_assert(0 < 1, "There is no slot for us"); |
458 | | |
459 | | MOZ_CAN_RUN_SCRIPT static bool |
460 | | get_epoch(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceEntryEvent* self, JSJitGetterCallArgs args) |
461 | 0 | { |
462 | 0 | AUTO_PROFILER_LABEL_FAST("get PerformanceEntryEvent.epoch", DOM, cx); |
463 | 0 |
|
464 | 0 | double result(self->Epoch()); |
465 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
466 | 0 | args.rval().set(JS_NumberValue(double(result))); |
467 | 0 | return true; |
468 | 0 | } |
469 | | |
470 | | static const JSJitInfo epoch_getterinfo = { |
471 | | { (JSJitGetterOp)get_epoch }, |
472 | | { prototypes::id::PerformanceEntryEvent }, |
473 | | { PrototypeTraits<prototypes::id::PerformanceEntryEvent>::Depth }, |
474 | | JSJitInfo::Getter, |
475 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
476 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
477 | | true, /* isInfallible. False in setters. */ |
478 | | false, /* isMovable. Not relevant for setters. */ |
479 | | false, /* isEliminatable. Not relevant for setters. */ |
480 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
481 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
482 | | false, /* isTypedMethod. Only relevant for methods. */ |
483 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
484 | | }; |
485 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
486 | | static_assert(0 < 1, "There is no slot for us"); |
487 | | |
488 | | MOZ_CAN_RUN_SCRIPT static bool |
489 | | get_origin(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceEntryEvent* self, JSJitGetterCallArgs args) |
490 | 0 | { |
491 | 0 | AUTO_PROFILER_LABEL_FAST("get PerformanceEntryEvent.origin", DOM, cx); |
492 | 0 |
|
493 | 0 | DOMString result; |
494 | 0 | self->GetOrigin(result); |
495 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
496 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
497 | 0 | return false; |
498 | 0 | } |
499 | 0 | return true; |
500 | 0 | } |
501 | | |
502 | | static const JSJitInfo origin_getterinfo = { |
503 | | { (JSJitGetterOp)get_origin }, |
504 | | { prototypes::id::PerformanceEntryEvent }, |
505 | | { PrototypeTraits<prototypes::id::PerformanceEntryEvent>::Depth }, |
506 | | JSJitInfo::Getter, |
507 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
508 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
509 | | false, /* isInfallible. False in setters. */ |
510 | | false, /* isMovable. Not relevant for setters. */ |
511 | | false, /* isEliminatable. Not relevant for setters. */ |
512 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
513 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
514 | | false, /* isTypedMethod. Only relevant for methods. */ |
515 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
516 | | }; |
517 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
518 | | static_assert(0 < 1, "There is no slot for us"); |
519 | | |
520 | | MOZ_CAN_RUN_SCRIPT static bool |
521 | | get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PerformanceEntryEvent* self, JSJitGetterCallArgs args) |
522 | 0 | { |
523 | 0 | AUTO_PROFILER_LABEL_FAST("get PerformanceEntryEvent.isTrusted", DOM, cx); |
524 | 0 |
|
525 | 0 | bool result(self->IsTrusted()); |
526 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
527 | 0 | args.rval().setBoolean(result); |
528 | 0 | return true; |
529 | 0 | } |
530 | | |
531 | | static const JSJitInfo isTrusted_getterinfo = { |
532 | | { (JSJitGetterOp)get_isTrusted }, |
533 | | { prototypes::id::PerformanceEntryEvent }, |
534 | | { PrototypeTraits<prototypes::id::PerformanceEntryEvent>::Depth }, |
535 | | JSJitInfo::Getter, |
536 | | JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */ |
537 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
538 | | true, /* isInfallible. False in setters. */ |
539 | | true, /* isMovable. Not relevant for setters. */ |
540 | | true, /* isEliminatable. Not relevant for setters. */ |
541 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
542 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
543 | | false, /* isTypedMethod. Only relevant for methods. */ |
544 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
545 | | }; |
546 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
547 | | static_assert(0 < 1, "There is no slot for us"); |
548 | | |
549 | | static bool |
550 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
551 | 0 | { |
552 | 0 | mozilla::dom::PerformanceEntryEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PerformanceEntryEvent>(obj); |
553 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
554 | 0 | // obviously can't preserve if we're not initialized. |
555 | 0 | if (self && self->GetWrapperPreserveColor()) { |
556 | 0 | PreserveWrapper(self); |
557 | 0 | } |
558 | 0 | return true; |
559 | 0 | } |
560 | | |
561 | | static void |
562 | | _finalize(js::FreeOp* fop, JSObject* obj) |
563 | 0 | { |
564 | 0 | mozilla::dom::PerformanceEntryEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PerformanceEntryEvent>(obj); |
565 | 0 | if (self) { |
566 | 0 | ClearWrapper(self, self, obj); |
567 | 0 | AddForDeferredFinalization<mozilla::dom::PerformanceEntryEvent>(self); |
568 | 0 | } |
569 | 0 | } |
570 | | |
571 | | static size_t |
572 | | _objectMoved(JSObject* obj, JSObject* old) |
573 | 0 | { |
574 | 0 | mozilla::dom::PerformanceEntryEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PerformanceEntryEvent>(obj); |
575 | 0 | if (self) { |
576 | 0 | UpdateWrapper(self, self, obj, old); |
577 | 0 | } |
578 | 0 |
|
579 | 0 | return 0; |
580 | 0 | } |
581 | | |
582 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
583 | | #if defined(__clang__) |
584 | | #pragma clang diagnostic push |
585 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
586 | | #endif |
587 | | static const JSPropertySpec sAttributes_specs[] = { |
588 | | { "name", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &name_getterinfo, nullptr, nullptr }, |
589 | | { "entryType", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &entryType_getterinfo, nullptr, nullptr }, |
590 | | { "startTime", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &startTime_getterinfo, nullptr, nullptr }, |
591 | | { "duration", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &duration_getterinfo, nullptr, nullptr }, |
592 | | { "epoch", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &epoch_getterinfo, nullptr, nullptr }, |
593 | | { "origin", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &origin_getterinfo, nullptr, nullptr }, |
594 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
595 | | }; |
596 | | #if defined(__clang__) |
597 | | #pragma clang diagnostic pop |
598 | | #endif |
599 | | |
600 | | |
601 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
602 | | { nullptr, &sAttributes_specs[0] }, |
603 | | { nullptr, nullptr } |
604 | | }; |
605 | | |
606 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
607 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
608 | | static_assert(6 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
609 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
610 | | |
611 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
612 | | #if defined(__clang__) |
613 | | #pragma clang diagnostic push |
614 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
615 | | #endif |
616 | | static const JSPropertySpec sUnforgeableAttributes_specs[] = { |
617 | | { "isTrusted", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isTrusted_getterinfo, nullptr, nullptr }, |
618 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
619 | | }; |
620 | | #if defined(__clang__) |
621 | | #pragma clang diagnostic pop |
622 | | #endif |
623 | | |
624 | | |
625 | | static const Prefable<const JSPropertySpec> sUnforgeableAttributes[] = { |
626 | | { nullptr, &sUnforgeableAttributes_specs[0] }, |
627 | | { nullptr, nullptr } |
628 | | }; |
629 | | |
630 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
631 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
632 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
633 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
634 | | |
635 | | |
636 | | static uint16_t sNativeProperties_sortedPropertyIndices[7]; |
637 | | static PropertyInfo sNativeProperties_propertyInfos[7]; |
638 | | |
639 | | static const NativePropertiesN<2> sNativeProperties = { |
640 | | false, 0, |
641 | | false, 0, |
642 | | false, 0, |
643 | | true, 0 /* sAttributes */, |
644 | | false, 0, |
645 | | true, 1 /* sUnforgeableAttributes */, |
646 | | false, 0, |
647 | | -1, |
648 | | 7, |
649 | | sNativeProperties_sortedPropertyIndices, |
650 | | { |
651 | | { sAttributes, &sNativeProperties_propertyInfos[0] }, |
652 | | { sUnforgeableAttributes, &sNativeProperties_propertyInfos[6] } |
653 | | } |
654 | | }; |
655 | | static_assert(7 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
656 | | "We have a property info count that is oversized"); |
657 | | |
658 | | static bool |
659 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
660 | 0 | { |
661 | 0 | AUTO_PROFILER_LABEL_FAST("PerformanceEntryEvent constructor", DOM, cx); |
662 | 0 |
|
663 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
664 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
665 | 0 | if (!args.isConstructing()) { |
666 | 0 | // XXXbz wish I could get the name from the callee instead of |
667 | 0 | // Adding more relocations |
668 | 0 | return ThrowConstructorWithoutNew(cx, "PerformanceEntryEvent"); |
669 | 0 | } |
670 | 0 | |
671 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
672 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
673 | 0 | return false; |
674 | 0 | } |
675 | 0 | |
676 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
677 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PerformanceEntryEvent"); |
678 | 0 | } |
679 | 0 | GlobalObject global(cx, obj); |
680 | 0 | if (global.Failed()) { |
681 | 0 | return false; |
682 | 0 | } |
683 | 0 | |
684 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
685 | 0 | binding_detail::FakeString arg0; |
686 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
687 | 0 | return false; |
688 | 0 | } |
689 | 0 | binding_detail::FastPerformanceEntryEventInit arg1; |
690 | 0 | if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of PerformanceEntryEvent.constructor", false)) { |
691 | 0 | return false; |
692 | 0 | } |
693 | 0 | Maybe<JSAutoRealm> ar; |
694 | 0 | if (objIsXray) { |
695 | 0 | obj = js::CheckedUnwrap(obj); |
696 | 0 | if (!obj) { |
697 | 0 | return false; |
698 | 0 | } |
699 | 0 | ar.emplace(cx, obj); |
700 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
701 | 0 | return false; |
702 | 0 | } |
703 | 0 | } |
704 | 0 | FastErrorResult rv; |
705 | 0 | auto result(StrongOrRawPtr<mozilla::dom::PerformanceEntryEvent>(mozilla::dom::PerformanceEntryEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv))); |
706 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
707 | 0 | return false; |
708 | 0 | } |
709 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
710 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
711 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
712 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
713 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
714 | 0 | return false; |
715 | 0 | } |
716 | 0 | return true; |
717 | 0 | } |
718 | | |
719 | | static const js::ClassOps sInterfaceObjectClassOps = { |
720 | | nullptr, /* addProperty */ |
721 | | nullptr, /* delProperty */ |
722 | | nullptr, /* enumerate */ |
723 | | nullptr, /* newEnumerate */ |
724 | | nullptr, /* resolve */ |
725 | | nullptr, /* mayResolve */ |
726 | | nullptr, /* finalize */ |
727 | | _constructor, /* call */ |
728 | | nullptr, /* hasInstance */ |
729 | | _constructor, /* construct */ |
730 | | nullptr, /* trace */ |
731 | | }; |
732 | | |
733 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
734 | | { |
735 | | "Function", |
736 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
737 | | &sInterfaceObjectClassOps, |
738 | | JS_NULL_CLASS_SPEC, |
739 | | JS_NULL_CLASS_EXT, |
740 | | &sInterfaceObjectClassObjectOps |
741 | | }, |
742 | | eInterface, |
743 | | true, |
744 | | prototypes::id::PerformanceEntryEvent, |
745 | | PrototypeTraits<prototypes::id::PerformanceEntryEvent>::Depth, |
746 | | sNativePropertyHooks, |
747 | | "function PerformanceEntryEvent() {\n [native code]\n}", |
748 | | Event_Binding::GetConstructorObject |
749 | | }; |
750 | | |
751 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
752 | | { |
753 | | "PerformanceEntryEventPrototype", |
754 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */), |
755 | | JS_NULL_CLASS_OPS, |
756 | | JS_NULL_CLASS_SPEC, |
757 | | JS_NULL_CLASS_EXT, |
758 | | JS_NULL_OBJECT_OPS |
759 | | }, |
760 | | eInterfacePrototype, |
761 | | false, |
762 | | prototypes::id::PerformanceEntryEvent, |
763 | | PrototypeTraits<prototypes::id::PerformanceEntryEvent>::Depth, |
764 | | sNativePropertyHooks, |
765 | | "[object PerformanceEntryEventPrototype]", |
766 | | Event_Binding::GetProtoObject |
767 | | }; |
768 | | |
769 | | bool |
770 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
771 | 0 | { |
772 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
773 | 0 | } |
774 | | |
775 | | static const js::ClassOps sClassOps = { |
776 | | _addProperty, /* addProperty */ |
777 | | nullptr, /* delProperty */ |
778 | | nullptr, /* enumerate */ |
779 | | nullptr, /* newEnumerate */ |
780 | | nullptr, /* resolve */ |
781 | | nullptr, /* mayResolve */ |
782 | | _finalize, /* finalize */ |
783 | | nullptr, /* call */ |
784 | | nullptr, /* hasInstance */ |
785 | | nullptr, /* construct */ |
786 | | nullptr, /* trace */ |
787 | | }; |
788 | | |
789 | | static const js::ClassExtension sClassExtension = { |
790 | | nullptr, /* weakmapKeyDelegateOp */ |
791 | | _objectMoved /* objectMovedOp */ |
792 | | }; |
793 | | |
794 | | static const DOMJSClass sClass = { |
795 | | { "PerformanceEntryEvent", |
796 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE, |
797 | | &sClassOps, |
798 | | JS_NULL_CLASS_SPEC, |
799 | | &sClassExtension, |
800 | | JS_NULL_OBJECT_OPS |
801 | | }, |
802 | | { prototypes::id::Event, prototypes::id::PerformanceEntryEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
803 | | IsBaseOf<nsISupports, mozilla::dom::PerformanceEntryEvent >::value, |
804 | | sNativePropertyHooks, |
805 | | FindAssociatedGlobalForNative<mozilla::dom::PerformanceEntryEvent>::Get, |
806 | | GetProtoObjectHandle, |
807 | | GetCCParticipant<mozilla::dom::PerformanceEntryEvent>::Get() |
808 | | }; |
809 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
810 | | "Must have the right minimal number of reserved slots."); |
811 | | static_assert(1 >= 1, |
812 | | "Must have enough reserved slots."); |
813 | | |
814 | | const JSClass* |
815 | | GetJSClass() |
816 | 0 | { |
817 | 0 | return sClass.ToJSClass(); |
818 | 0 | } |
819 | | |
820 | | bool |
821 | | Wrap(JSContext* aCx, mozilla::dom::PerformanceEntryEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
822 | 0 | { |
823 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::PerformanceEntryEvent>::value, |
824 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
825 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::PerformanceEntryEvent*>(aObject) == |
826 | 0 | reinterpret_cast<mozilla::dom::PerformanceEntryEvent*>(aObject), |
827 | 0 | "Multiple inheritance for mozilla::dom::PerformanceEntryEvent is broken."); |
828 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) == |
829 | 0 | reinterpret_cast<mozilla::dom::Event*>(aObject), |
830 | 0 | "Multiple inheritance for mozilla::dom::Event is broken."); |
831 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
832 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
833 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
834 | 0 | "You should probably not be using Wrap() directly; use " |
835 | 0 | "GetOrCreateDOMReflector instead"); |
836 | 0 |
|
837 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
838 | 0 | "nsISupports must be on our primary inheritance chain"); |
839 | 0 |
|
840 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
841 | 0 | if (!global) { |
842 | 0 | return false; |
843 | 0 | } |
844 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
845 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
846 | 0 |
|
847 | 0 | // That might have ended up wrapping us already, due to the wonders |
848 | 0 | // of XBL. Check for that, and bail out as needed. |
849 | 0 | aReflector.set(aCache->GetWrapper()); |
850 | 0 | if (aReflector) { |
851 | | #ifdef DEBUG |
852 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
853 | | #endif // DEBUG |
854 | | return true; |
855 | 0 | } |
856 | 0 |
|
857 | 0 | JSAutoRealm ar(aCx, global); |
858 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
859 | 0 | if (!canonicalProto) { |
860 | 0 | return false; |
861 | 0 | } |
862 | 0 | JS::Rooted<JSObject*> proto(aCx); |
863 | 0 | if (aGivenProto) { |
864 | 0 | proto = aGivenProto; |
865 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
866 | 0 | // coming in, we changed compartments to that of "parent" so may need |
867 | 0 | // to wrap the proto here. |
868 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
869 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
870 | 0 | return false; |
871 | 0 | } |
872 | 0 | } |
873 | 0 | } else { |
874 | 0 | proto = canonicalProto; |
875 | 0 | } |
876 | 0 |
|
877 | 0 | BindingJSObjectCreator<mozilla::dom::PerformanceEntryEvent> creator(aCx); |
878 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
879 | 0 | if (!aReflector) { |
880 | 0 | return false; |
881 | 0 | } |
882 | 0 | |
883 | 0 | aCache->SetWrapper(aReflector); |
884 | 0 |
|
885 | 0 | // Important: do unforgeable property setup after we have handed |
886 | 0 | // over ownership of the C++ object to obj as needed, so that if |
887 | 0 | // we fail and it ends up GCed it won't have problems in the |
888 | 0 | // finalizer trying to drop its ownership of the C++ object. |
889 | 0 | JS::Rooted<JSObject*> unforgeableHolder(aCx, |
890 | 0 | &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject()); |
891 | 0 | if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) { |
892 | 0 | aCache->ReleaseWrapper(aObject); |
893 | 0 | aCache->ClearWrapper(); |
894 | 0 | return false; |
895 | 0 | } |
896 | 0 | creator.InitializationSucceeded(); |
897 | 0 |
|
898 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
899 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
900 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
901 | 0 | // otherwise we won't be able to properly recreate it later, since |
902 | 0 | // we won't know what proto to use. Note that we don't check |
903 | 0 | // aGivenProto here, since it's entirely possible (and even |
904 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
905 | 0 | // same as canonicalProto. |
906 | 0 | if (proto != canonicalProto) { |
907 | 0 | PreserveWrapper(aObject); |
908 | 0 | } |
909 | 0 |
|
910 | 0 | return true; |
911 | 0 | } |
912 | | |
913 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
914 | | nullptr, |
915 | | nullptr, |
916 | | nullptr, |
917 | | { sNativeProperties.Upcast(), nullptr }, |
918 | | prototypes::id::PerformanceEntryEvent, |
919 | | constructors::id::PerformanceEntryEvent, |
920 | | Event_Binding::sNativePropertyHooks, |
921 | | &DefaultXrayExpandoObjectClass |
922 | | } }; |
923 | | |
924 | | void |
925 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
926 | 0 | { |
927 | 0 | JS::Handle<JSObject*> parentProto(Event_Binding::GetProtoObjectHandle(aCx)); |
928 | 0 | if (!parentProto) { |
929 | 0 | return; |
930 | 0 | } |
931 | 0 | |
932 | 0 | JS::Handle<JSObject*> constructorProto(Event_Binding::GetConstructorObjectHandle(aCx)); |
933 | 0 | if (!constructorProto) { |
934 | 0 | return; |
935 | 0 | } |
936 | 0 | |
937 | 0 | static bool sIdsInited = false; |
938 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
939 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
940 | 0 | return; |
941 | 0 | } |
942 | 0 | sIdsInited = true; |
943 | 0 | } |
944 | 0 |
|
945 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::PerformanceEntryEvent); |
946 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::PerformanceEntryEvent); |
947 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
948 | 0 | &sPrototypeClass.mBase, protoCache, |
949 | 0 | nullptr, |
950 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr, |
951 | 0 | interfaceCache, |
952 | 0 | sNativeProperties.Upcast(), |
953 | 0 | nullptr, |
954 | 0 | "PerformanceEntryEvent", aDefineOnGlobal, |
955 | 0 | nullptr, |
956 | 0 | false); |
957 | 0 |
|
958 | 0 | JS::Rooted<JSObject*> unforgeableHolder(aCx); |
959 | 0 | { |
960 | 0 | JS::Rooted<JSObject*> holderProto(aCx, *protoCache); |
961 | 0 | unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto); |
962 | 0 | if (!unforgeableHolder) { |
963 | 0 | *protoCache = nullptr; |
964 | 0 | if (interfaceCache) { |
965 | 0 | *interfaceCache = nullptr; |
966 | 0 | } |
967 | 0 | return; |
968 | 0 | } |
969 | 0 | } |
970 | 0 |
|
971 | 0 | if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) { |
972 | 0 | *protoCache = nullptr; |
973 | 0 | if (interfaceCache) { |
974 | 0 | *interfaceCache = nullptr; |
975 | 0 | } |
976 | 0 | return; |
977 | 0 | } |
978 | 0 |
|
979 | 0 | if (*protoCache) { |
980 | 0 | js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE, |
981 | 0 | JS::ObjectValue(*unforgeableHolder)); |
982 | 0 | } |
983 | 0 | } |
984 | | |
985 | | JSObject* |
986 | | GetConstructorObject(JSContext* aCx) |
987 | 0 | { |
988 | 0 | return GetConstructorObjectHandle(aCx); |
989 | 0 | } |
990 | | |
991 | | } // namespace PerformanceEntryEvent_Binding |
992 | | |
993 | | |
994 | | |
995 | | } // namespace dom |
996 | | } // namespace mozilla |