1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef __FilteringWrapper_h__
8 #define __FilteringWrapper_h__
9 
10 #include "XrayWrapper.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/Maybe.h"
13 #include "js/CallNonGenericMethod.h"
14 #include "js/Wrapper.h"
15 
16 namespace xpc {
17 
18 template <typename Base, typename Policy>
19 class FilteringWrapper : public Base {
20  public:
FilteringWrapper(unsigned flags)21   constexpr explicit FilteringWrapper(unsigned flags) : Base(flags) {}
22 
23   virtual bool enter(JSContext* cx, JS::Handle<JSObject*> wrapper,
24                      JS::Handle<jsid> id, js::Wrapper::Action act,
25                      bool mayThrow, bool* bp) const override;
26 
27   virtual bool getOwnPropertyDescriptor(
28       JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<jsid> id,
29       JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc)
30       const override;
31   virtual bool ownPropertyKeys(JSContext* cx, JS::Handle<JSObject*> wrapper,
32                                JS::MutableHandleIdVector props) const override;
33 
34   virtual bool getOwnEnumerablePropertyKeys(
35       JSContext* cx, JS::Handle<JSObject*> wrapper,
36       JS::MutableHandleIdVector props) const override;
37   virtual bool enumerate(JSContext* cx, JS::Handle<JSObject*> wrapper,
38                          JS::MutableHandleIdVector props) const override;
39 
40   virtual bool call(JSContext* cx, JS::Handle<JSObject*> wrapper,
41                     const JS::CallArgs& args) const override;
42   virtual bool construct(JSContext* cx, JS::Handle<JSObject*> wrapper,
43                          const JS::CallArgs& args) const override;
44 
45   virtual bool nativeCall(JSContext* cx, JS::IsAcceptableThis test,
46                           JS::NativeImpl impl,
47                           const JS::CallArgs& args) const override;
48 
49   virtual bool getPrototype(JSContext* cx, JS::HandleObject wrapper,
50                             JS::MutableHandleObject protop) const override;
51 
52   static const FilteringWrapper singleton;
53 };
54 
55 }  // namespace xpc
56 
57 #endif /* __FilteringWrapper_h__ */
58