CallbackFunction.h (2208B)
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 /** 8 * A common base class for representing WebIDL callback function types in C++. 9 * 10 * This class implements common functionality like lifetime 11 * management, initialization with the callable, and setup of the call 12 * environment. Subclasses corresponding to particular callback 13 * function types should provide a Call() method that actually does 14 * the call. 15 */ 16 17 #ifndef mozilla_dom_CallbackFunction_h 18 #define mozilla_dom_CallbackFunction_h 19 20 #include "mozilla/dom/CallbackObject.h" 21 22 namespace mozilla::dom { 23 24 class CallbackFunction : public CallbackObject { 25 public: 26 // See CallbackObject for an explanation of the arguments. 27 explicit CallbackFunction(JSContext* aCx, JS::Handle<JSObject*> aCallable, 28 JS::Handle<JSObject*> aCallableGlobal, 29 nsIGlobalObject* aIncumbentGlobal) 30 : CallbackObject(aCx, aCallable, aCallableGlobal, aIncumbentGlobal) {} 31 32 // See CallbackObject for an explanation of the arguments. 33 explicit CallbackFunction(JSObject* aCallable, JSObject* aCallableGlobal, 34 JSObject* aAsyncStack, 35 nsIGlobalObject* aIncumbentGlobal) 36 : CallbackObject(aCallable, aCallableGlobal, aAsyncStack, 37 aIncumbentGlobal) {} 38 39 JSObject* CallableOrNull() const { return CallbackOrNull(); } 40 41 JSObject* CallablePreserveColor() const { return CallbackPreserveColor(); } 42 43 protected: 44 explicit CallbackFunction(CallbackFunction* aCallbackFunction) 45 : CallbackObject(aCallbackFunction) {} 46 47 // See CallbackObject for an explanation of the arguments. 48 CallbackFunction(JSObject* aCallable, JSObject* aCallableGlobal, 49 const FastCallbackConstructor&) 50 : CallbackObject(aCallable, aCallableGlobal, FastCallbackConstructor()) {} 51 }; 52 53 } // namespace mozilla::dom 54 55 #endif // mozilla_dom_CallbackFunction_h