Bug 1856663 - Add more chunks for Android mochitest-plain. r=jmaher,taskgraph-reviewe...
[gecko.git] / dom / bindings / ObservableArrayProxyHandler.h
blobd0a9bdfaf4db42cdbbe0143e5d865095daf0a018
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_ObservableArrayProxyHandler_h
8 #define mozilla_dom_ObservableArrayProxyHandler_h
10 #include "js/TypeDecls.h"
11 #include "js/Wrapper.h"
13 namespace mozilla::dom {
15 /**
16 * Proxy handler for observable array exotic object.
18 * The indexed properties are stored in the backing list object in reserved slot
19 * of the proxy object with special treatment intact.
21 * The additional properties are stored in the proxy target object.
24 class ObservableArrayProxyHandler : public js::ForwardingProxyHandler {
25 public:
26 explicit constexpr ObservableArrayProxyHandler()
27 : js::ForwardingProxyHandler(&family) {}
29 // Implementations of methods that can be implemented in terms of
30 // other lower-level methods.
31 bool defineProperty(JSContext* aCx, JS::Handle<JSObject*> aProxy,
32 JS::Handle<JS::PropertyKey> aId,
33 JS::Handle<JS::PropertyDescriptor> aDesc,
34 JS::ObjectOpResult& aResult) const override;
36 bool delete_(JSContext* aCx, JS::Handle<JSObject*> aProxy,
37 JS::Handle<JS::PropertyKey> aId,
38 JS::ObjectOpResult& aResult) const override;
40 bool get(JSContext* aCx, JS::Handle<JSObject*> aProxy,
41 JS::Handle<JS::Value> aReceiver, JS::Handle<JS::PropertyKey> aId,
42 JS::MutableHandle<JS::Value> aVp) const override;
44 bool getOwnPropertyDescriptor(
45 JSContext* aCx, JS::Handle<JSObject*> aProxy,
46 JS::Handle<JS::PropertyKey> aId,
47 JS::MutableHandle<Maybe<JS::PropertyDescriptor>> aDesc) const override;
49 bool has(JSContext* aCx, JS::Handle<JSObject*> aProxy,
50 JS::Handle<JS::PropertyKey> aId, bool* aBp) const override;
52 bool ownPropertyKeys(JSContext* aCx, JS::Handle<JSObject*> aProxy,
53 JS::MutableHandleVector<jsid> aProps) const override;
55 bool preventExtensions(JSContext* aCx, JS::Handle<JSObject*> aProxy,
56 JS::ObjectOpResult& aResult) const override;
58 bool set(JSContext* aCx, JS::Handle<JSObject*> aProxy,
59 JS::Handle<JS::PropertyKey> aId, JS::Handle<JS::Value> aV,
60 JS::Handle<JS::Value> aReceiver,
61 JS::ObjectOpResult& aResult) const override;
63 bool SetLength(JSContext* aCx, JS::Handle<JSObject*> aProxy,
64 uint32_t aLength) const;
66 static const char family;
68 protected:
69 bool GetBackingListObject(
70 JSContext* aCx, JS::Handle<JSObject*> aProxy,
71 JS::MutableHandle<JSObject*> aBackingListObject) const;
73 bool GetBackingListLength(JSContext* aCx, JS::Handle<JSObject*> aProxy,
74 uint32_t* aLength) const;
76 bool SetLength(JSContext* aCx, JS::Handle<JSObject*> aProxy,
77 JS::Handle<JSObject*> aBackingList, uint32_t aLength,
78 JS::ObjectOpResult& aResult) const;
80 bool SetLength(JSContext* aCx, JS::Handle<JSObject*> aProxy,
81 JS::Handle<JSObject*> aBackingList,
82 JS::Handle<JS::Value> aValue,
83 JS::ObjectOpResult& aResult) const;
85 // Hook for subclasses to invoke the setting the indexed value steps which
86 // would invoke DeleteAlgorithm/SetAlgorithm defined and implemented per
87 // interface. Returns false and throw exception on failure.
88 virtual bool SetIndexedValue(JSContext* aCx, JS::Handle<JSObject*> aProxy,
89 JS::Handle<JSObject*> aBackingList,
90 uint32_t aIndex, JS::Handle<JS::Value> aValue,
91 JS::ObjectOpResult& aResult) const = 0;
93 // Hook for subclasses to invoke the DeleteAlgorithm defined and implemented
94 // per interface. Returns false and throw exception on failure.
95 virtual bool OnDeleteItem(JSContext* aCx, JS::Handle<JSObject*> aProxy,
96 JS::Handle<JS::Value> aValue,
97 uint32_t aIndex) const = 0;
100 inline bool IsObservableArrayProxy(JSObject* obj) {
101 return js::IsProxy(obj) && js::GetProxyHandler(obj)->family() ==
102 &ObservableArrayProxyHandler::family;
105 inline const ObservableArrayProxyHandler* GetObservableArrayProxyHandler(
106 JSObject* obj) {
107 MOZ_ASSERT(IsObservableArrayProxy(obj));
108 return static_cast<const ObservableArrayProxyHandler*>(
109 js::GetProxyHandler(obj));
112 } // namespace mozilla::dom
114 #endif /* mozilla_dom_ObservableArrayProxyHandler_h */