js/xpconnect/wrappers/AddonWrapper.h
author Jason Orendorff <jorendorff@mozilla.com>
Wed, 21 Feb 2018 10:30:19 -0600
changeset 405100 0ceb91c42b0ff876a61ed23f5e587ba3a2083bcf
parent 304308 96875d7ae6f2f4cb0f56cd872eaae90345933563
permissions -rw-r--r--
Bug 1439063 - Part 1: Move several public headers from js/src to js/public. r=jandem. js/src/jsalloc.h -> js/public/AllocPolicy.h jsalloc.cpp -> js/src/util/AllocPolicy.cpp jsbytecode.h -> merge into js/public/TypeDecls.h jsprf.h -> js/public/Printf.h jsprf.cpp -> js/src/util/Printf.cpp jsprototypes.h -> public/ProtoKey.h jswrapper.h -> js/Wrapper.h

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set ts=8 sts=4 et sw=4 tw=99: */
/* 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 AddonWrapper_h
#define AddonWrapper_h

#include "mozilla/Attributes.h"

#include "nsID.h"

#include "js/Wrapper.h"

namespace xpc {

bool
InterposeProperty(JSContext* cx, JS::HandleObject target, const nsIID* iid, JS::HandleId id,
                  JS::MutableHandle<JS::PropertyDescriptor> descriptor);

bool
InterposeCall(JSContext* cx, JS::HandleObject wrapper,
              const JS::CallArgs& args, bool& done);

template<typename Base>
class AddonWrapper : public Base {
  public:
    explicit constexpr AddonWrapper(unsigned flags) : Base(flags) { }

    virtual bool getOwnPropertyDescriptor(JSContext* cx, JS::Handle<JSObject*> wrapper,
                                          JS::Handle<jsid> id,
                                          JS::MutableHandle<JS::PropertyDescriptor> desc) const override;
    virtual bool defineProperty(JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
                                JS::Handle<JS::PropertyDescriptor> desc,
                                JS::ObjectOpResult& result) const override;
    virtual bool delete_(JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
                         JS::ObjectOpResult& result) const override;
    virtual bool get(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JS::Value> receiver,
                     JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const override;
    virtual bool set(JSContext* cx, JS::HandleObject wrapper, JS::HandleId id, JS::HandleValue v,
                     JS::HandleValue receiver, JS::ObjectOpResult& result) const override;
    virtual bool call(JSContext* cx, JS::Handle<JSObject*> wrapper,
                      const JS::CallArgs& args) const override;

    virtual bool getPropertyDescriptor(JSContext* cx, JS::Handle<JSObject*> wrapper,
                                       JS::Handle<jsid> id,
                                       JS::MutableHandle<JS::PropertyDescriptor> desc) const override;

    static const AddonWrapper singleton;
};

} // namespace xpc

#endif // AddonWrapper_h