Bug 1842773 - Part 5: Add ArrayBuffer.prototype.{maxByteLength,resizable} getters...
[gecko.git] / dom / base / MozQueryInterface.h
blob1dd3d9bfff6e7596d695f77293c31590672b1bda
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
10 /**
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
16 * passed.
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"
24 #include "nsID.h"
26 namespace mozilla {
27 class ErrorResult;
29 namespace dom {
31 class MozQueryInterface final : public NonRefcountedDOMObject {
32 public:
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);
47 private:
48 nsTArray<nsIID> mInterfaces;
51 } // namespace dom
52 } // namespace mozilla
54 #endif // mozilla_dom_MozQueryInterface