/* THIS FILE IS AUTOGENERATED FROM ImageDocument.webidl BY Codegen.py - DO NOT EDIT */ #include #include "HTMLDocumentBinding.h" #include "ImageDocumentBinding.h" #include "MainThreadUtils.h" #include "WrapperFactory.h" #include "XrayWrapper.h" #include "js/CallAndConstruct.h" #include "js/Exception.h" #include "js/MapAndSet.h" #include "js/Object.h" #include "js/PropertyAndElement.h" #include "js/PropertyDescriptor.h" #include "js/String.h" #include "js/experimental/JitInfo.h" #include "mozilla/Atomics.h" #include "mozilla/OwningNonNull.h" #include "mozilla/ProfilerLabels.h" #include "mozilla/StaticPrefs_dom.h" #include "mozilla/dom/BindingCallContext.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/DOMJSClass.h" #include "mozilla/dom/DOMJSProxyHandler.h" #include "mozilla/dom/ImageDocument.h" #include "mozilla/dom/Location.h" #include "mozilla/dom/NonRefcountedDOMObject.h" #include "mozilla/dom/Nullable.h" #include "mozilla/dom/PrimitiveConversions.h" #include "mozilla/dom/ProxyHandlerUtils.h" #include "mozilla/dom/XrayExpandoClass.h" #include "nsContentUtils.h" namespace mozilla::dom { namespace binding_detail {}; // Just to make sure it's known as a namespace using namespace mozilla::dom::binding_detail; namespace ImageDocument_Binding { static_assert(IsRefcounted::value == IsRefcounted::value, "Can't inherit from an interface with a different ownership model."); MOZ_CAN_RUN_SCRIPT static bool get_imageIsOverflowing(JSContext* cx, JS::Handle obj, void* void_self, JSJitGetterCallArgs args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "ImageDocument", "imageIsOverflowing", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); bool result(MOZ_KnownLive(self)->ImageIsOverflowing()); MOZ_ASSERT(!JS_IsExceptionPending(cx)); args.rval().setBoolean(result); return true; } static const JSJitInfo imageIsOverflowing_getterinfo = { { get_imageIsOverflowing }, { prototypes::id::ImageDocument }, { PrototypeTraits::Depth }, JSJitInfo::Getter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ true, /* isInfallible. False in setters. */ false, /* isMovable. Not relevant for setters. */ false, /* isEliminatable. Not relevant for setters. */ false, /* isAlwaysInSlot. Only relevant for getters. */ false, /* isLazilyCachedInSlot. Only relevant for getters. */ false, /* isTypedMethod. Only relevant for methods. */ 0 /* Reserved slot index, if we're stored in a slot, else 0. */ }; MOZ_CAN_RUN_SCRIPT static bool get_imageIsResized(JSContext* cx, JS::Handle obj, void* void_self, JSJitGetterCallArgs args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "ImageDocument", "imageIsResized", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); bool result(MOZ_KnownLive(self)->ImageIsResized()); MOZ_ASSERT(!JS_IsExceptionPending(cx)); args.rval().setBoolean(result); return true; } static const JSJitInfo imageIsResized_getterinfo = { { get_imageIsResized }, { prototypes::id::ImageDocument }, { PrototypeTraits::Depth }, JSJitInfo::Getter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ true, /* isInfallible. False in setters. */ false, /* isMovable. Not relevant for setters. */ false, /* isEliminatable. Not relevant for setters. */ false, /* isAlwaysInSlot. Only relevant for getters. */ false, /* isLazilyCachedInSlot. Only relevant for getters. */ false, /* isTypedMethod. Only relevant for methods. */ 0 /* Reserved slot index, if we're stored in a slot, else 0. */ }; MOZ_CAN_RUN_SCRIPT static bool shrinkToFit(JSContext* cx, JS::Handle obj, void* void_self, const JSJitMethodCallArgs& args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "ImageDocument", "shrinkToFit", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); // NOTE: This assert does NOT call the function. static_assert(std::is_void_vShrinkToFit())>, "Should be returning void here"); MOZ_KnownLive(self)->ShrinkToFit(); MOZ_ASSERT(!JS_IsExceptionPending(cx)); args.rval().setUndefined(); return true; } static const JSJitInfo shrinkToFit_methodinfo = { { (JSJitGetterOp)shrinkToFit }, { prototypes::id::ImageDocument }, { PrototypeTraits::Depth }, JSJitInfo::Method, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ true, /* isInfallible. False in setters. */ false, /* isMovable. Not relevant for setters. */ false, /* isEliminatable. Not relevant for setters. */ false, /* isAlwaysInSlot. Only relevant for getters. */ false, /* isLazilyCachedInSlot. Only relevant for getters. */ false, /* isTypedMethod. Only relevant for methods. */ 0 /* Reserved slot index, if we're stored in a slot, else 0. */ }; MOZ_CAN_RUN_SCRIPT static bool restoreImage(JSContext* cx, JS::Handle obj, void* void_self, const JSJitMethodCallArgs& args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "ImageDocument", "restoreImage", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); // NOTE: This assert does NOT call the function. static_assert(std::is_void_vRestoreImage())>, "Should be returning void here"); MOZ_KnownLive(self)->RestoreImage(); MOZ_ASSERT(!JS_IsExceptionPending(cx)); args.rval().setUndefined(); return true; } static const JSJitInfo restoreImage_methodinfo = { { (JSJitGetterOp)restoreImage }, { prototypes::id::ImageDocument }, { PrototypeTraits::Depth }, JSJitInfo::Method, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ true, /* isInfallible. False in setters. */ false, /* isMovable. Not relevant for setters. */ false, /* isEliminatable. Not relevant for setters. */ false, /* isAlwaysInSlot. Only relevant for getters. */ false, /* isLazilyCachedInSlot. Only relevant for getters. */ false, /* isTypedMethod. Only relevant for methods. */ 0 /* Reserved slot index, if we're stored in a slot, else 0. */ }; MOZ_CAN_RUN_SCRIPT static bool get_location(JSContext* cx, JS::Handle obj, void* void_self, JSJitGetterCallArgs args) { AUTO_PROFILER_LABEL_DYNAMIC_FAST( "ImageDocument", "location", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); auto* self = static_cast(void_self); auto result(StrongOrRawPtr(MOZ_KnownLive(self)->GetLocation())); MOZ_ASSERT(!JS_IsExceptionPending(cx)); if (!result) { args.rval().setNull(); return true; } if (!GetOrCreateDOMReflector(cx, result, args.rval())) { MOZ_ASSERT(JS_IsExceptionPending(cx)); return false; } return true; } MOZ_CAN_RUN_SCRIPT static bool set_location(JSContext* cx_, JS::Handle obj, void* void_self, JSJitSetterCallArgs args) { BindingCallContext cx(cx_, "ImageDocument.location setter"); AUTO_PROFILER_LABEL_DYNAMIC_FAST( "ImageDocument", "location", DOM, cx, uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_SETTER) | uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS)); JS::Rooted v(cx); if (!JS_GetProperty(cx, obj, "location", &v)) { return false; } if (!v.isObject()) { return cx.ThrowErrorMessage("ImageDocument.location"); } JS::Rooted targetObj(cx, &v.toObject()); return JS_SetProperty(cx, targetObj, "href", args[0]); } static const JSJitInfo location_getterinfo = { { get_location }, { prototypes::id::ImageDocument }, { PrototypeTraits::Depth }, JSJitInfo::Getter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ false, /* isInfallible. False in setters. */ false, /* isMovable. Not relevant for setters. */ false, /* isEliminatable. Not relevant for setters. */ false, /* isAlwaysInSlot. Only relevant for getters. */ false, /* isLazilyCachedInSlot. Only relevant for getters. */ false, /* isTypedMethod. Only relevant for methods. */ 0 /* Reserved slot index, if we're stored in a slot, else 0. */ }; static const JSJitInfo location_setterinfo = { { (JSJitGetterOp)set_location }, { prototypes::id::ImageDocument }, { PrototypeTraits::Depth }, JSJitInfo::Setter, JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ false, /* isInfallible. False in setters. */ false, /* isMovable. Not relevant for setters. */ false, /* isEliminatable. Not relevant for setters. */ false, /* isAlwaysInSlot. Only relevant for getters. */ false, /* isLazilyCachedInSlot. Only relevant for getters. */ false, /* isTypedMethod. Only relevant for methods. */ 0 /* Reserved slot index, if we're stored in a slot, else 0. */ }; MOZ_GLOBINIT static const JSFunctionSpec sMethods_specs[] = { JS_FNSPEC("shrinkToFit", (GenericMethod), reinterpret_cast(&shrinkToFit_methodinfo), 0, JSPROP_ENUMERATE, nullptr), JS_FNSPEC("restoreImage", (GenericMethod), reinterpret_cast(&restoreImage_methodinfo), 0, JSPROP_ENUMERATE, nullptr), JS_FS_END }; static const Prefable sMethods[] = { { nullptr, &sMethods_specs[0] }, { nullptr, nullptr } }; static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); MOZ_GLOBINIT static const JSPropertySpec sAttributes_specs[] = { JSPropertySpec::nativeAccessors("imageIsOverflowing", JSPROP_ENUMERATE, GenericGetter, &imageIsOverflowing_getterinfo, nullptr, nullptr), JSPropertySpec::nativeAccessors("imageIsResized", JSPROP_ENUMERATE, GenericGetter, &imageIsResized_getterinfo, nullptr, nullptr), JS_PS_END }; static const Prefable sAttributes[] = { { nullptr, &sAttributes_specs[0] }, { nullptr, nullptr } }; static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); MOZ_GLOBINIT static const JSPropertySpec sUnforgeableAttributes_specs[] = { JSPropertySpec::nativeAccessors("location", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter, &location_getterinfo, GenericSetter, &location_setterinfo), JS_PS_END }; static const Prefable sUnforgeableAttributes[] = { { nullptr, &sUnforgeableAttributes_specs[0] }, { nullptr, nullptr } }; static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); static uint16_t sNativeProperties_sortedPropertyIndices[5]; static PropertyInfo sNativeProperties_propertyInfos[5]; static const NativePropertiesN<3> sNativeProperties = { false, 0, false, 0, true, 0 /* sMethods */, true, 1 /* sAttributes */, false, 0, true, 2 /* sUnforgeableAttributes */, false, 0, -1, 5, sNativeProperties_sortedPropertyIndices, { { sMethods, &sNativeProperties_propertyInfos[0] }, { sAttributes, &sNativeProperties_propertyInfos[2] }, { sUnforgeableAttributes, &sNativeProperties_propertyInfos[4] } } }; static_assert(5 < 1ull << (CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount)), "We have a property info count that is oversized"); static_assert(std::is_base_of_v, "We don't support non-nsISupports native classes for " "proxy-based bindings yet"); class MOZ_EMPTY_BASES DOMProxyHandler : public ShadowingDOMProxyHandler { public: using Base = ShadowingDOMProxyHandler; explicit constexpr DOMProxyHandler() { } bool getOwnPropDescriptor(JSContext* cx, JS::Handle proxy, JS::Handle id, bool ignoreNamedProps, JS::MutableHandle> desc) const override; bool defineProperty(JSContext* cx_, JS::Handle proxy, JS::Handle id, JS::Handle desc, JS::ObjectOpResult& opresult, bool* done) const override; using mozilla::dom::DOMProxyHandler::defineProperty; bool ownPropNames(JSContext* cx, JS::Handle proxy, unsigned flags, JS::MutableHandleVector props) const override; bool hasOwn(JSContext* cx, JS::Handle proxy, JS::Handle id, bool* bp) const override; bool get(JSContext* cx, JS::Handle proxy, JS::Handle receiver, JS::Handle id, JS::MutableHandle vp) const override; const char* className(JSContext* cx, JS::Handle proxy) const override; bool finalizeInBackground(const JS::Value& priv) const override; void finalize(JS::GCContext* gcx, JSObject* proxy) const override; static const DOMProxyHandler* getInstance(); bool delete_(JSContext* cx, JS::Handle proxy, JS::Handle id, JS::ObjectOpResult& opresult) const override; size_t objectMoved(JSObject* obj, JSObject* old) const override; }; MOZ_ALWAYS_INLINE bool IsProxy(JSObject* obj) { return js::IsProxy(obj) && js::GetProxyHandler(obj) == DOMProxyHandler::getInstance(); } MOZ_ALWAYS_INLINE mozilla::dom::ImageDocument* UnwrapProxy(JSObject* obj) { MOZ_ASSERT(js::IsProxy(obj)); if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) { MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj)); obj = js::UncheckedUnwrap(obj); } MOZ_ASSERT(IsProxy(obj)); return static_cast(js::GetProxyReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate()); } // This may allocate too many slots, because we only really need // slots for our non-interface-typed members that we cache. But // allocating slots only for those would make the slot index // computations much more complicated, so let's do this the simple // way for now. DEFINE_XRAY_EXPANDO_CLASS_WITH_OPS(static, sXrayExpandoObjectClass, 1, &xpc::XrayExpandoObjectClassOps); const NativeNamedOrIndexedPropertyHooks sNativeNamedOrIndexedPropertyHooks = { binding_detail::ResolveOwnProperty, binding_detail::EnumerateOwnProperties, nullptr }; bool sNativePropertiesInited = false; const NativePropertyHooks sNativePropertyHooks = { &sNativeNamedOrIndexedPropertyHooks, { sNativeProperties.Upcast(), nullptr, &sNativePropertiesInited }, prototypes::id::ImageDocument, constructors::id::ImageDocument, &sXrayExpandoObjectClass }; static const DOMInterfaceInfo sInterfaceObjectInfo = { { ThrowingConstructor, &sNativePropertyHooks }, HTMLDocument_Binding::GetConstructorObjectHandle, PrototypeTraits::Depth, prototypes::id::ImageDocument, true, 0, "ImageDocument", }; static const DOMIfaceAndProtoJSClass sPrototypeClass = { { "ImageDocumentPrototype", JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */), JS_NULL_CLASS_OPS, JS_NULL_CLASS_SPEC, JS_NULL_CLASS_EXT, JS_NULL_OBJECT_OPS }, eInterfacePrototype, prototypes::id::ImageDocument, PrototypeTraits::Depth, &sNativePropertyHooks, HTMLDocument_Binding::GetProtoObject }; bool ConstructorEnabled(JSContext* aCx, JS::Handle aObj) { return nsContentUtils::ThreadsafeIsSystemCaller(aCx); } bool CountMaybeMissingProperty(JS::Handle proxy, JS::Handle id) { if (HTMLDocument_Binding::CountMaybeMissingProperty(proxy, id)) { return true; } return false; } static JS::Handle GetProtoObjectHandle(JSContext* aCx); bool DOMProxyHandler::getOwnPropDescriptor(JSContext* cx, JS::Handle proxy, JS::Handle id, bool ignoreNamedProps, JS::MutableHandle> desc) const { bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy); if (StaticPrefs::dom_missing_prop_counters_enabled() && id.isAtom()) { CountMaybeMissingProperty(proxy, id); } JS::Rooted expando(cx); if (!isXray &&(expando = GetExpandoObject(proxy))) { if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) { return false; } if (desc.isSome()) { return true; } } bool callNamedGetter = false; if (!ignoreNamedProps) { if (!isXray) { callNamedGetter = true; } else { bool hasOnProto; if (!HasPropertyOnPrototype(cx, proxy, id, &hasOnProto)) { return false; } callNamedGetter = !hasOnProto; } } if (callNamedGetter) { JS::Rooted value(cx); nsAutoString name; bool isSymbol; if (!ConvertIdToString(cx, id, name, isSymbol)) { return false; } if (!isSymbol) { mozilla::dom::ImageDocument* self = UnwrapProxy(proxy); bool found = false; FastErrorResult rv; JS::Rooted result(cx); // NOTE: This assert does NOT call the function. static_assert(std::is_void_vNamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv))>, "Should be returning void here"); MOZ_KnownLive(self)->NamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv); if (rv.MaybeSetPendingException(cx, "ImageDocument named getter")) [[unlikely]] { return false; } MOZ_ASSERT(!JS_IsExceptionPending(cx)); if (found) { JS::ExposeObjectToActiveJS(result); value.setObject(*result); if (!MaybeWrapObjectValue(cx, &value)) { return false; } desc.set(mozilla::Some(JS::PropertyDescriptor::Data(value, { JS::PropertyAttribute::Configurable, JS::PropertyAttribute::Enumerable }))); return true; } } } desc.reset(); return true; } bool DOMProxyHandler::defineProperty(JSContext* cx_, JS::Handle proxy, JS::Handle id, JS::Handle desc, JS::ObjectOpResult& opresult, bool* done) const { JSContext* cx = cx_; bool found = false; nsAutoString name; bool isSymbol; if (!ConvertIdToString(cx, id, name, isSymbol)) { return false; } if (!isSymbol) { mozilla::dom::ImageDocument* self = UnwrapProxy(proxy); FastErrorResult rv; JS::Rooted result(cx); // NOTE: This assert does NOT call the function. static_assert(std::is_void_vNamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv))>, "Should be returning void here"); MOZ_KnownLive(self)->NamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv); if (rv.MaybeSetPendingException(cx, "ImageDocument named getter")) [[unlikely]] { return false; } MOZ_ASSERT(!JS_IsExceptionPending(cx)); (void)result; } if (found) { *done = true; return opresult.failNoNamedSetter(); } return mozilla::dom::DOMProxyHandler::defineProperty(cx_, proxy, id, desc, opresult, done); } bool DOMProxyHandler::ownPropNames(JSContext* cx, JS::Handle proxy, unsigned flags, JS::MutableHandleVector props) const { bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy); nsTArray names; UnwrapProxy(proxy)->GetSupportedNames(names); if (!AppendNamedPropertyIds(cx, proxy, names, !isXray, props)) { return false; } JS::Rooted expando(cx); if (!isXray &&(expando = DOMProxyHandler::GetExpandoObject(proxy)) && !js::GetPropertyKeys(cx, expando, flags, props)) { return false; } return true; } bool DOMProxyHandler::hasOwn(JSContext* cx, JS::Handle proxy, JS::Handle id, bool* bp) const { MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), "Should not have a XrayWrapper here"); if (StaticPrefs::dom_missing_prop_counters_enabled() && id.isAtom()) { CountMaybeMissingProperty(proxy, id); } JS::Rooted expando(cx, GetExpandoObject(proxy)); if (expando) { bool b = true; bool ok = JS_HasPropertyById(cx, expando, id, &b); *bp = !!b; if (!ok || *bp) { return ok; } } bool found = false; nsAutoString name; bool isSymbol; if (!ConvertIdToString(cx, id, name, isSymbol)) { return false; } if (!isSymbol) { mozilla::dom::ImageDocument* self = UnwrapProxy(proxy); FastErrorResult rv; JS::Rooted result(cx); // NOTE: This assert does NOT call the function. static_assert(std::is_void_vNamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv))>, "Should be returning void here"); MOZ_KnownLive(self)->NamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv); if (rv.MaybeSetPendingException(cx, "ImageDocument named getter")) [[unlikely]] { return false; } MOZ_ASSERT(!JS_IsExceptionPending(cx)); (void)result; } *bp = found; return true; } bool DOMProxyHandler::get(JSContext* cx, JS::Handle proxy, JS::Handle receiver, JS::Handle id, JS::MutableHandle vp) const { MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), "Should not have a XrayWrapper here"); if (StaticPrefs::dom_missing_prop_counters_enabled() && id.isAtom()) { CountMaybeMissingProperty(proxy, id); } bool expandoHasProp = false; { // Scope for expando JS::Rooted expando(cx, DOMProxyHandler::GetExpandoObject(proxy)); if (expando) { if (!JS_HasPropertyById(cx, expando, id, &expandoHasProp)) { return false; } if (expandoHasProp) { // Forward the get to the expando object, but our receiver is whatever our // receiver is. if (!JS_ForwardGetPropertyTo(cx, expando, id, receiver, vp)) { return false; } } } } if (expandoHasProp) { return true; } nsAutoString name; bool isSymbol; if (!ConvertIdToString(cx, id, name, isSymbol)) { return false; } if (!isSymbol) { mozilla::dom::ImageDocument* self = UnwrapProxy(proxy); bool found = false; FastErrorResult rv; JS::Rooted result(cx); // NOTE: This assert does NOT call the function. static_assert(std::is_void_vNamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv))>, "Should be returning void here"); MOZ_KnownLive(self)->NamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv); if (rv.MaybeSetPendingException(cx, "ImageDocument named getter")) [[unlikely]] { return false; } MOZ_ASSERT(!JS_IsExceptionPending(cx)); if (found) { JS::ExposeObjectToActiveJS(result); vp.setObject(*result); if (!MaybeWrapObjectValue(cx, vp)) { return false; } return true; } } bool foundOnPrototype; if (!GetPropertyOnPrototype(cx, proxy, receiver, id, &foundOnPrototype, vp)) { return false; } if (foundOnPrototype) { return true; } MOZ_ASSERT(vp.isUndefined()); return true; } const char* DOMProxyHandler::className(JSContext* cx, JS::Handle proxy) const { return "ImageDocument"; } bool DOMProxyHandler::finalizeInBackground(const JS::Value& priv) const { return false; } void DOMProxyHandler::finalize(JS::GCContext* gcx, JSObject* proxy) const { mozilla::dom::ImageDocument* self = UnwrapPossiblyNotInitializedDOMObject(proxy); if (self) { js::SetProxyReservedSlot(proxy, DOM_OBJECT_SLOT, JS::UndefinedValue()); { JS::Value val = js::GetProxyReservedSlot(proxy, (DOM_INSTANCE_RESERVED_SLOTS + 0)); if (!val.isUndefined()) { JSObject* proxyObj = &val.toObject(); js::SetProxyReservedSlot(proxyObj, OBSERVABLE_ARRAY_DOM_INTERFACE_SLOT, JS::UndefinedValue()); } } // Either our proxy created an expando object or not. If it did, // then we would have preserved ourselves, and hence if we're going // away so is our C++ object and we should reset its expando value. // It's possible that in this situation the C++ object's reflector // pointer has been nulled out, but if not it's pointing to us. If // our proxy did _not_ create an expando object then it's possible // that we're no longer the reflector for our C++ object (and // incremental finalization is finally getting to us), and that in // the meantime the new reflector has created an expando object. // In that case we do NOT want to clear the expando pointer in the // C++ object. // // It's important to do this before we ClearWrapper, of course. JSObject* reflector = self->GetWrapperMaybeDead(); if (!reflector || reflector == proxy) { self->mExpandoAndGeneration.expando = JS::UndefinedValue(); } ClearWrapper(self, self, proxy); if (size_t mallocBytes = BindingJSObjectMallocBytes(self)) { JS::RemoveAssociatedMemory(proxy, mallocBytes, JS::MemoryUse::DOMBinding); } AddForDeferredFinalization(self); } } const DOMProxyHandler* DOMProxyHandler::getInstance() { static const DOMProxyHandler instance; return &instance; } bool DOMProxyHandler::delete_(JSContext* cx, JS::Handle proxy, JS::Handle id, JS::ObjectOpResult& opresult) const { MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), "Should not have a XrayWrapper here"); // Try named delete only if the named property visibility // algorithm says the property is visible. bool tryNamedDelete = true; { // Scope for expando JS::Rooted expando(cx, DOMProxyHandler::GetExpandoObject(proxy)); if (expando) { bool hasProp; if (!JS_HasPropertyById(cx, expando, id, &hasProp)) { return false; } tryNamedDelete = !hasProp; } } if (tryNamedDelete) { bool found = false; bool deleteSucceeded; nsAutoString name; bool isSymbol; if (!ConvertIdToString(cx, id, name, isSymbol)) { return false; } if (!isSymbol) { mozilla::dom::ImageDocument* self = UnwrapProxy(proxy); FastErrorResult rv; JS::Rooted result(cx); // NOTE: This assert does NOT call the function. static_assert(std::is_void_vNamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv))>, "Should be returning void here"); MOZ_KnownLive(self)->NamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv); if (rv.MaybeSetPendingException(cx, "ImageDocument named getter")) [[unlikely]] { return false; } MOZ_ASSERT(!JS_IsExceptionPending(cx)); (void)result; } deleteSucceeded = !found; if (found) { return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete(); } } return dom::DOMProxyHandler::delete_(cx, proxy, id, opresult); } size_t DOMProxyHandler::objectMoved(JSObject* obj, JSObject* old) const { return NativeTypeHelpers::ObjectMoved(obj, old); } static const DOMJSClass sClass = { PROXY_CLASS_DEF("ImageDocument", JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(2)), { prototypes::id::EventTarget, prototypes::id::Node, prototypes::id::Document, prototypes::id::HTMLDocument, prototypes::id::ImageDocument, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, std::is_base_of_v, &sNativePropertyHooks, GetProtoObjectHandle, GetCCParticipant::Get(), nullptr, nullptr }; bool Wrap(JSContext* aCx, mozilla::dom::ImageDocument* aObject, nsWrapperCache* aCache, JS::Handle aGivenProto, JS::MutableHandle aReflector) { static_assert(!std::is_base_of_v, "Shouldn't have wrappercached things that are not refcounted."); static_assert(std::is_same_v); MOZ_ASSERT(static_cast(aObject) == reinterpret_cast(aObject), "Multiple inheritance for nsHTMLDocument is broken."); MOZ_ASSERT(static_cast(aObject) == reinterpret_cast(aObject), "Multiple inheritance for mozilla::dom::Document is broken."); MOZ_ASSERT(static_cast(aObject) == reinterpret_cast(aObject), "Multiple inheritance for nsINode is broken."); MOZ_ASSERT(static_cast(aObject) == reinterpret_cast(aObject), "Multiple inheritance for mozilla::dom::EventTarget is broken."); MOZ_ASSERT(ToSupportsIsCorrect(aObject)); MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); MOZ_ASSERT(!aCache->GetWrapper(), "You should probably not be using Wrap() directly; use " "GetOrCreateDOMReflector instead"); MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), "nsISupports must be on our primary inheritance chain"); // If the wrapper cache contains a dead reflector then finalize that // now, ensuring that the finalizer for the old reflector always // runs before the new reflector is created and attached. This // avoids the awkward situation where there are multiple reflector // objects that contain pointers to the same native. if (JSObject* oldReflector = aCache->GetWrapperMaybeDead()) { DOMProxyHandler::getInstance()->finalize(nullptr /* unused */, oldReflector); MOZ_ASSERT(!aCache->GetWrapperMaybeDead()); } JS::Rooted global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); if (!global) { return false; } MOZ_ASSERT(JS_IsGlobalObject(global)); JS::AssertObjectIsNotGray(global); // That might have ended up wrapping us already, due to the wonders // of XBL. Check for that, and bail out as needed. aReflector.set(aCache->GetWrapper()); if (aReflector) { #ifdef DEBUG AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); #endif // DEBUG return true; } JSAutoRealm ar(aCx, global); JS::Handle canonicalProto = GetProtoObjectHandle(aCx); if (!canonicalProto) { return false; } JS::Rooted proto(aCx); if (aGivenProto) { proto = aGivenProto; // Unfortunately, while aGivenProto was in the compartment of aCx // coming in, we changed compartments to that of "parent" so may need // to wrap the proto here. if (js::GetContextCompartment(aCx) != JS::GetCompartment(proto)) { if (!JS_WrapObject(aCx, &proto)) { return false; } } } else { proto = canonicalProto; } BindingJSObjectCreator creator(aCx); aObject->mExpandoAndGeneration.expando.setUndefined(); JS::Rooted expandoValue(aCx, JS::PrivateValue(&aObject->mExpandoAndGeneration)); creator.CreateProxyObject(aCx, &sClass.mBase, DOMProxyHandler::getInstance(), proto, /* aLazyProto = */ false, aObject, expandoValue, aReflector); if (!aReflector) { return false; } aCache->SetWrapper(aReflector); // Important: do unforgeable property setup after we have handed // over ownership of the C++ object to obj as needed, so that if // we fail and it ends up GCed it won't have problems in the // finalizer trying to drop its ownership of the C++ object. JS::Rooted expando(aCx, DOMProxyHandler::EnsureExpandoObject(aCx, aReflector)); if (!expando) { aCache->ReleaseWrapper(aObject); aCache->ClearWrapperOnWrapFailure(); return false; } JS::Rooted unforgeableHolder(aCx, &JS::GetNativeObjectReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject()); if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, expando, unforgeableHolder)) { aCache->ReleaseWrapper(aObject); aCache->ClearWrapperOnWrapFailure(); return false; } creator.InitializationSucceeded(); MOZ_ASSERT(aCache->GetWrapperPreserveColor() && aCache->GetWrapperPreserveColor() == aReflector); // If proto != canonicalProto, we have to preserve our wrapper; // otherwise we won't be able to properly recreate it later, since // we won't know what proto to use. Note that we don't check // aGivenProto here, since it's entirely possible (and even // somewhat common) to have a non-null aGivenProto which is the // same as canonicalProto. if (proto != canonicalProto) { PreserveWrapper(aObject); } return true; } void CreateInterfaceObjects(JSContext* aCx, JS::Handle aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, DefineInterfaceProperty aDefineOnGlobal) { JS::Heap* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ImageDocument); JS::Heap* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ImageDocument); JS::Handle parentProto(HTMLDocument_Binding::GetProtoObjectHandle(aCx)); if (!parentProto) { return; } JS::Handle constructorProto(HTMLDocument_Binding::GetConstructorObjectHandle(aCx)); if (!constructorProto) { return; } dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, &sPrototypeClass, protoCache, constructorProto, &sInterfaceObjectInfo, 0, false, Span{}, interfaceCache, sNativeProperties.Upcast(), nullptr, "ImageDocument", ShouldExpose(aCx, aGlobal, aDefineOnGlobal), nullptr, false, nullptr); JS::Rooted unforgeableHolder( aCx, JS_NewObjectWithoutMetadata(aCx, nullptr, nullptr)); if (!unforgeableHolder) { *protoCache = nullptr; if (interfaceCache) { *interfaceCache = nullptr; } return; } if (!DefineLegacyUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) { *protoCache = nullptr; if (interfaceCache) { *interfaceCache = nullptr; } return; } if (*protoCache) { JS::SetNativeObjectReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE, JS::ObjectValue(*unforgeableHolder)); } } static JS::Handle GetProtoObjectHandle(JSContext* aCx) { /* Get the interface prototype object for this class. This will create the object as needed. */ return GetPerInterfaceObjectHandle(aCx, prototypes::id::ImageDocument, &CreateInterfaceObjects, DefineInterfaceProperty::CheckExposure); } JS::Handle GetConstructorObjectHandle(JSContext* aCx) { /* Get the interface object for this class. This will create the object as needed. */ return GetPerInterfaceObjectHandle(aCx, constructors::id::ImageDocument, &CreateInterfaceObjects, DefineInterfaceProperty::CheckExposure); } } // namespace ImageDocument_Binding } // namespace mozilla::dom