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/. */
7 #ifndef mozilla_dom_MozQueryInterface
8 #define mozilla_dom_MozQueryInterface
11 * This class implements an optimized QueryInterface method for
12 * XPConnect-wrapped JS objects.
14 * For JavaScript callers, it behaves as an ordinary QueryInterface method,
15 * returning its `this` object or throwing depending on the interface it was
18 * For native XPConnect callers, we bypass JSAPI entirely, and directly check
19 * whether the queried interface is in the interfaces list.
22 #include "mozilla/dom/BindingDeclarations.h"
23 #include "mozilla/dom/NonRefcountedDOMObject.h"
31 class MozQueryInterface final
: public NonRefcountedDOMObject
{
33 explicit MozQueryInterface(nsTArray
<nsIID
>&& aInterfaces
)
34 : mInterfaces(std::move(aInterfaces
)) {}
36 bool QueriesTo(const nsIID
& aIID
) const;
38 void LegacyCall(JSContext
* cx
, JS::Handle
<JS::Value
> thisv
,
39 JS::Handle
<JS::Value
> aIID
,
40 JS::MutableHandle
<JS::Value
> aResult
, ErrorResult
& aRv
) const;
42 nsISupports
* GetParentObject() const { return nullptr; }
44 bool WrapObject(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
,
45 JS::MutableHandle
<JSObject
*> aReflector
);
48 nsTArray
<nsIID
> mInterfaces
;
52 } // namespace mozilla
54 #endif // mozilla_dom_MozQueryInterface