diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/xpconnect/public | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/xpconnect/public/moz.build | 10 | ||||
-rw-r--r-- | js/xpconnect/public/xpc_make_class.h | 127 | ||||
-rw-r--r-- | js/xpconnect/public/xpc_map_end.h | 114 |
3 files changed, 251 insertions, 0 deletions
diff --git a/js/xpconnect/public/moz.build b/js/xpconnect/public/moz.build new file mode 100644 index 0000000000..29e24495b2 --- /dev/null +++ b/js/xpconnect/public/moz.build @@ -0,0 +1,10 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +EXPORTS += [ + "xpc_make_class.h", + "xpc_map_end.h", +] diff --git a/js/xpconnect/public/xpc_make_class.h b/js/xpconnect/public/xpc_make_class.h new file mode 100644 index 0000000000..8137142197 --- /dev/null +++ b/js/xpconnect/public/xpc_make_class.h @@ -0,0 +1,127 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef xpc_make_class_h +#define xpc_make_class_h + +// This file should be used to create JSClass instances for nsIXPCScriptable +// instances. This includes any file that uses xpc_map_end.h. + +#include "xpcpublic.h" +#include "mozilla/dom/DOMJSClass.h" + +bool XPC_WN_MaybeResolvingPropertyStub(JSContext* cx, JS::HandleObject obj, + JS::HandleId id, JS::HandleValue v); +bool XPC_WN_CannotModifyPropertyStub(JSContext* cx, JS::HandleObject obj, + JS::HandleId id, JS::HandleValue v); + +bool XPC_WN_MaybeResolvingDeletePropertyStub(JSContext* cx, + JS::HandleObject obj, + JS::HandleId id, + JS::ObjectOpResult& result); +bool XPC_WN_CannotDeletePropertyStub(JSContext* cx, JS::HandleObject obj, + JS::HandleId id, + JS::ObjectOpResult& result); + +bool XPC_WN_Shared_Enumerate(JSContext* cx, JS::HandleObject obj); + +bool XPC_WN_NewEnumerate(JSContext* cx, JS::HandleObject obj, + JS::MutableHandleIdVector properties, + bool enumerableOnly); + +bool XPC_WN_Helper_Resolve(JSContext* cx, JS::HandleObject obj, JS::HandleId id, + bool* resolvedp); + +void XPC_WN_Helper_Finalize(JSFreeOp* fop, JSObject* obj); +void XPC_WN_NoHelper_Finalize(JSFreeOp* fop, JSObject* obj); + +bool XPC_WN_Helper_Call(JSContext* cx, unsigned argc, JS::Value* vp); + +bool XPC_WN_Helper_HasInstance(JSContext* cx, JS::HandleObject obj, + JS::MutableHandleValue valp, bool* bp); + +bool XPC_WN_Helper_Construct(JSContext* cx, unsigned argc, JS::Value* vp); + +void XPCWrappedNative_Trace(JSTracer* trc, JSObject* obj); + +extern const js::ClassExtension XPC_WN_JSClassExtension; + +#define XPC_MAKE_CLASS_OPS(_flags) \ + { \ + /* addProperty */ \ + ((_flags)&XPC_SCRIPTABLE_USE_JSSTUB_FOR_ADDPROPERTY) ? nullptr \ + : ((_flags)&XPC_SCRIPTABLE_ALLOW_PROP_MODS_DURING_RESOLVE) \ + ? XPC_WN_MaybeResolvingPropertyStub \ + : XPC_WN_CannotModifyPropertyStub, \ + \ + /* delProperty */ \ + ((_flags)&XPC_SCRIPTABLE_USE_JSSTUB_FOR_DELPROPERTY) ? nullptr \ + : ((_flags)&XPC_SCRIPTABLE_ALLOW_PROP_MODS_DURING_RESOLVE) \ + ? XPC_WN_MaybeResolvingDeletePropertyStub \ + : XPC_WN_CannotDeletePropertyStub, \ + \ + /* enumerate */ \ + ((_flags)&XPC_SCRIPTABLE_WANT_NEWENUMERATE) \ + ? nullptr /* We will use newEnumerate set below in this case */ \ + : XPC_WN_Shared_Enumerate, \ + \ + /* newEnumerate */ \ + ((_flags)&XPC_SCRIPTABLE_WANT_NEWENUMERATE) ? XPC_WN_NewEnumerate \ + : nullptr, \ + \ + /* resolve */ /* We have to figure out resolve strategy at call time \ + */ \ + XPC_WN_Helper_Resolve, \ + \ + /* mayResolve */ \ + nullptr, \ + \ + /* finalize */ \ + ((_flags)&XPC_SCRIPTABLE_WANT_FINALIZE) ? XPC_WN_Helper_Finalize \ + : XPC_WN_NoHelper_Finalize, \ + \ + /* call */ \ + ((_flags)&XPC_SCRIPTABLE_WANT_CALL) ? XPC_WN_Helper_Call : nullptr, \ + \ + /* hasInstance */ \ + ((_flags)&XPC_SCRIPTABLE_WANT_HASINSTANCE) ? XPC_WN_Helper_HasInstance \ + : nullptr, \ + \ + /* construct */ \ + ((_flags)&XPC_SCRIPTABLE_WANT_CONSTRUCT) ? XPC_WN_Helper_Construct \ + : nullptr, \ + \ + /* trace */ \ + ((_flags)&XPC_SCRIPTABLE_IS_GLOBAL_OBJECT) ? JS_GlobalObjectTraceHook \ + : XPCWrappedNative_Trace, \ + } + +#define XPC_MAKE_CLASS(_name, _flags, _classOps) \ + { \ + /* name */ \ + _name, \ + \ + /* flags */ \ + XPC_WRAPPER_FLAGS | JSCLASS_PRIVATE_IS_NSISUPPORTS | \ + JSCLASS_IS_WRAPPED_NATIVE | \ + (((_flags)&XPC_SCRIPTABLE_IS_GLOBAL_OBJECT) \ + ? XPCONNECT_GLOBAL_FLAGS \ + : 0), \ + \ + /* cOps */ \ + _classOps, \ + \ + /* spec */ \ + nullptr, \ + \ + /* ext */ \ + &XPC_WN_JSClassExtension, \ + \ + /* oOps */ \ + nullptr, \ + } + +#endif diff --git a/js/xpconnect/public/xpc_map_end.h b/js/xpconnect/public/xpc_map_end.h new file mode 100644 index 0000000000..07f0f0b707 --- /dev/null +++ b/js/xpconnect/public/xpc_map_end.h @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// If you include this file you must also include xpc_make_class.h at the top +// of the file doing the including. + +#ifndef XPC_MAP_CLASSNAME +# error "Must #define XPC_MAP_CLASSNAME before #including xpc_map_end.h" +#endif + +#ifndef XPC_MAP_QUOTED_CLASSNAME +# error "Must #define XPC_MAP_QUOTED_CLASSNAME before #including xpc_map_end.h" +#endif + +#ifndef XPC_MAP_FLAGS +# error "Must #define XPC_MAP_FLAGS before #including xpc_map_end.h" +#endif + +#include "js/Id.h" + +/**************************************************************/ + +NS_IMETHODIMP XPC_MAP_CLASSNAME::GetClassName(nsACString& aClassName) { + aClassName.AssignLiteral(XPC_MAP_QUOTED_CLASSNAME); + return NS_OK; +} + +/**************************************************************/ + +// virtual +uint32_t XPC_MAP_CLASSNAME::GetScriptableFlags() { return (XPC_MAP_FLAGS); } + +// virtual +const JSClass* XPC_MAP_CLASSNAME::GetJSClass() { + static const JSClassOps classOps = XPC_MAKE_CLASS_OPS(GetScriptableFlags()); + static const JSClass klass = + XPC_MAKE_CLASS(XPC_MAP_QUOTED_CLASSNAME, GetScriptableFlags(), &classOps); + return &klass; +} + +/**************************************************************/ + +#if !((XPC_MAP_FLAGS)&XPC_SCRIPTABLE_WANT_PRECREATE) +NS_IMETHODIMP XPC_MAP_CLASSNAME::PreCreate(nsISupports* nativeObj, + JSContext* cx, JSObject* globalObj, + JSObject** parentObj) { + NS_ERROR("never called"); + return NS_ERROR_NOT_IMPLEMENTED; +} +#endif + +#if !((XPC_MAP_FLAGS)&XPC_SCRIPTABLE_WANT_NEWENUMERATE) +NS_IMETHODIMP XPC_MAP_CLASSNAME::NewEnumerate( + nsIXPConnectWrappedNative* wrapper, JSContext* cx, JSObject* obj, + JS::MutableHandleIdVector properties, bool enumerableOnly, bool* _retval) { + NS_ERROR("never called"); + return NS_ERROR_NOT_IMPLEMENTED; +} +#endif + +#if !((XPC_MAP_FLAGS)&XPC_SCRIPTABLE_WANT_RESOLVE) +NS_IMETHODIMP XPC_MAP_CLASSNAME::Resolve(nsIXPConnectWrappedNative* wrapper, + JSContext* cx, JSObject* obj, jsid id, + bool* resolvedp, bool* _retval) { + NS_ERROR("never called"); + return NS_ERROR_NOT_IMPLEMENTED; +} +#endif + +#if !((XPC_MAP_FLAGS)&XPC_SCRIPTABLE_WANT_FINALIZE) +NS_IMETHODIMP XPC_MAP_CLASSNAME::Finalize(nsIXPConnectWrappedNative* wrapper, + JSFreeOp* fop, JSObject* obj) { + NS_ERROR("never called"); + return NS_ERROR_NOT_IMPLEMENTED; +} +#endif + +#if !((XPC_MAP_FLAGS)&XPC_SCRIPTABLE_WANT_CALL) +NS_IMETHODIMP XPC_MAP_CLASSNAME::Call(nsIXPConnectWrappedNative* wrapper, + JSContext* cx, JSObject* obj, + const JS::CallArgs& args, bool* _retval) { + NS_ERROR("never called"); + return NS_ERROR_NOT_IMPLEMENTED; +} +#endif + +#if !((XPC_MAP_FLAGS)&XPC_SCRIPTABLE_WANT_CONSTRUCT) +NS_IMETHODIMP XPC_MAP_CLASSNAME::Construct(nsIXPConnectWrappedNative* wrapper, + JSContext* cx, JSObject* obj, + const JS::CallArgs& args, + bool* _retval) { + NS_ERROR("never called"); + return NS_ERROR_NOT_IMPLEMENTED; +} +#endif + +#if !((XPC_MAP_FLAGS)&XPC_SCRIPTABLE_WANT_HASINSTANCE) +NS_IMETHODIMP XPC_MAP_CLASSNAME::HasInstance(nsIXPConnectWrappedNative* wrapper, + JSContext* cx, JSObject* obj, + JS::HandleValue val, bool* bp, + bool* _retval) { + NS_ERROR("never called"); + return NS_ERROR_NOT_IMPLEMENTED; +} +#endif + +/**************************************************************/ + +#undef XPC_MAP_CLASSNAME +#undef XPC_MAP_QUOTED_CLASSNAME +#undef XPC_MAP_FLAGS |