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/src/proxy/SecurityWrapper.cpp | |
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 'js/src/proxy/SecurityWrapper.cpp')
-rw-r--r-- | js/src/proxy/SecurityWrapper.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/js/src/proxy/SecurityWrapper.cpp b/js/src/proxy/SecurityWrapper.cpp new file mode 100644 index 0000000000..1b8ce9677c --- /dev/null +++ b/js/src/proxy/SecurityWrapper.cpp @@ -0,0 +1,110 @@ +/* -*- 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/. */ + +#include "jsapi.h" +#include "jsfriendapi.h" +#include "NamespaceImports.h" + +#include "js/friend/ErrorMessages.h" // JSMSG_* +#include "js/Wrapper.h" +#include "vm/JSObject.h" +#include "vm/StringType.h" + +using namespace js; + +template <class Base> +bool SecurityWrapper<Base>::enter(JSContext* cx, HandleObject wrapper, + HandleId id, Wrapper::Action act, + bool mayThrow, bool* bp) const { + ReportAccessDenied(cx); + *bp = false; + return false; +} + +template <class Base> +bool SecurityWrapper<Base>::nativeCall(JSContext* cx, IsAcceptableThis test, + NativeImpl impl, + const CallArgs& args) const { + ReportAccessDenied(cx); + return false; +} + +template <class Base> +bool SecurityWrapper<Base>::setPrototype(JSContext* cx, HandleObject wrapper, + HandleObject proto, + ObjectOpResult& result) const { + ReportAccessDenied(cx); + return false; +} + +template <class Base> +bool SecurityWrapper<Base>::setImmutablePrototype(JSContext* cx, + HandleObject wrapper, + bool* succeeded) const { + ReportAccessDenied(cx); + return false; +} + +template <class Base> +bool SecurityWrapper<Base>::preventExtensions(JSContext* cx, + HandleObject wrapper, + ObjectOpResult& result) const { + // Just like BaseProxyHandler, SecurityWrappers claim by default to always + // be extensible, so as not to leak information about the state of the + // underlying wrapped thing. + return result.fail(JSMSG_CANT_CHANGE_EXTENSIBILITY); +} + +template <class Base> +bool SecurityWrapper<Base>::isExtensible(JSContext* cx, HandleObject wrapper, + bool* extensible) const { + // See above. + *extensible = true; + return true; +} + +template <class Base> +bool SecurityWrapper<Base>::getBuiltinClass(JSContext* cx, HandleObject wrapper, + ESClass* cls) const { + *cls = ESClass::Other; + return true; +} + +template <class Base> +bool SecurityWrapper<Base>::isArray(JSContext* cx, HandleObject obj, + JS::IsArrayAnswer* answer) const { + // This should ReportAccessDenied(cx), but bug 849730 disagrees. :-( + *answer = JS::IsArrayAnswer::NotArray; + return true; +} + +template <class Base> +RegExpShared* SecurityWrapper<Base>::regexp_toShared(JSContext* cx, + HandleObject obj) const { + return Base::regexp_toShared(cx, obj); +} + +template <class Base> +bool SecurityWrapper<Base>::boxedValue_unbox(JSContext* cx, HandleObject obj, + MutableHandleValue vp) const { + vp.setUndefined(); + return true; +} + +template <class Base> +bool SecurityWrapper<Base>::defineProperty(JSContext* cx, HandleObject wrapper, + HandleId id, + Handle<PropertyDescriptor> desc, + ObjectOpResult& result) const { + if (desc.getter() || desc.setter()) { + return Throw(cx, id, JSMSG_ACCESSOR_DEF_DENIED); + } + + return Base::defineProperty(cx, wrapper, id, desc, result); +} + +template class js::SecurityWrapper<Wrapper>; +template class js::SecurityWrapper<CrossCompartmentWrapper>; |