Line data Source code
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 {
23 : namespace dom {
24 :
25 229 : class CallbackFunction : public CallbackObject
26 : {
27 : public:
28 : // See CallbackObject for an explanation of the arguments.
29 13 : explicit CallbackFunction(JSContext* aCx, JS::Handle<JSObject*> aCallable,
30 : nsIGlobalObject* aIncumbentGlobal)
31 13 : : CallbackObject(aCx, aCallable, aIncumbentGlobal)
32 : {
33 13 : }
34 :
35 : // See CallbackObject for an explanation of the arguments.
36 235 : explicit CallbackFunction(JS::Handle<JSObject*> aCallable,
37 : JS::Handle<JSObject*> aAsyncStack,
38 : nsIGlobalObject* aIncumbentGlobal)
39 235 : : CallbackObject(aCallable, aAsyncStack, aIncumbentGlobal)
40 : {
41 235 : }
42 :
43 0 : JS::Handle<JSObject*> CallableOrNull() const
44 : {
45 0 : return CallbackOrNull();
46 : }
47 :
48 0 : JS::Handle<JSObject*> CallablePreserveColor() const
49 : {
50 0 : return CallbackPreserveColor();
51 : }
52 :
53 0 : bool HasGrayCallable() const
54 : {
55 : // Play it safe in case this gets called after unlink.
56 0 : return mCallback && JS::ObjectIsMarkedGray(mCallback);
57 : }
58 :
59 : protected:
60 0 : explicit CallbackFunction(CallbackFunction* aCallbackFunction)
61 0 : : CallbackObject(aCallbackFunction)
62 : {
63 0 : }
64 :
65 : // See CallbackObject for an explanation of the arguments.
66 21 : CallbackFunction(JS::Handle<JSObject*> aCallable,
67 : const FastCallbackConstructor&)
68 21 : : CallbackObject(aCallable, FastCallbackConstructor())
69 : {
70 21 : }
71 : };
72 :
73 : } // namespace dom
74 : } // namespace mozilla
75 :
76 : #endif // mozilla_dom_CallbackFunction_h
|