michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * A common base class for representing WebIDL callback function types in C++. michael@0: * michael@0: * This class implements common functionality like lifetime michael@0: * management, initialization with the callable, and setup of the call michael@0: * environment. Subclasses corresponding to particular callback michael@0: * function types should provide a Call() method that actually does michael@0: * the call. michael@0: */ michael@0: michael@0: #ifndef mozilla_dom_CallbackFunction_h michael@0: #define mozilla_dom_CallbackFunction_h michael@0: michael@0: #include "mozilla/dom/CallbackObject.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class CallbackFunction : public CallbackObject michael@0: { michael@0: public: michael@0: explicit CallbackFunction(JS::Handle aCallable, michael@0: nsIGlobalObject* aIncumbentGlobal) michael@0: : CallbackObject(aCallable, aIncumbentGlobal) michael@0: { michael@0: } michael@0: michael@0: JS::Handle Callable() const michael@0: { michael@0: return Callback(); michael@0: } michael@0: michael@0: bool HasGrayCallable() const michael@0: { michael@0: // Play it safe in case this gets called after unlink. michael@0: return mCallback && xpc_IsGrayGCThing(mCallback); michael@0: } michael@0: michael@0: protected: michael@0: explicit CallbackFunction(CallbackFunction* aCallbackFunction) michael@0: : CallbackObject(aCallbackFunction) michael@0: { michael@0: } michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_dom_CallbackFunction_h