no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / toolkit / components / uniffi-js / UniFFIPointer.h
blob24a7b80eedf21dffb1559f9d83260f85d3ec3f82
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_UniFFIPointer_h
8 #define mozilla_dom_UniFFIPointer_h
10 #include "nsISupports.h"
11 #include "nsWrapperCache.h"
12 #include "nsString.h"
13 #include "mozilla/ErrorResult.h"
14 #include "mozilla/dom/TypedArray.h"
15 #include "mozilla/dom/UniFFIPointerType.h"
17 namespace mozilla::dom {
19 class UniFFIPointer final : public nsISupports, public nsWrapperCache {
20 public:
21 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
22 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(UniFFIPointer)
24 static already_AddRefed<UniFFIPointer> Create(
25 void* aPtr, const uniffi::UniFFIPointerType* aType);
26 static already_AddRefed<UniFFIPointer> Read(
27 const ArrayBuffer& aArrayBuff, uint32_t aPosition,
28 const uniffi::UniFFIPointerType* aType, ErrorResult& aError);
29 void Write(const ArrayBuffer& aArrayBuff, uint32_t aPosition,
30 const uniffi::UniFFIPointerType* aType, ErrorResult& aError) const;
32 UniFFIPointer(void* aPtr, const uniffi::UniFFIPointerType* aType);
34 JSObject* WrapObject(JSContext* aCx,
35 JS::Handle<JSObject*> aGivenProto) override;
36 nsISupports* GetParentObject() {
37 return xpc::NativeGlobal(xpc::PrivilegedJunkScope());
40 /**
41 * Clone the raw pointer that `UniFFIPointer` holds
43 * Use this when lowering the pointer to pass it across the FFI, for example:
44 * - When calling a method
45 * - When passing the object as an argument to a function
47 void* ClonePtr() const;
49 /**
50 * Returns true if the pointer type `this` holds is the same as the argument
51 * it does so using pointer comparison, as there is **exactly** one static
52 * `UniFFIPointerType` per type exposed in the UniFFI interface
54 bool IsSamePtrType(const uniffi::UniFFIPointerType* type) const;
56 private:
57 const uniffi::UniFFIPointerType* mType;
58 void* mPtr;
60 protected:
61 /**
62 * Destructs the `UniFFIPointer`, making sure to give back ownership of the
63 * raw pointer back to Rust, which deallocates the pointer
65 ~UniFFIPointer();
67 } // namespace mozilla::dom
69 #endif /* mozilla_dom_UniFFIPointer_h */