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