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