2022-03-11 01:44:27 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_ObservableArrayProxyHandler_h
|
|
|
|
#define mozilla_dom_ObservableArrayProxyHandler_h
|
|
|
|
|
|
|
|
#include "js/TypeDecls.h"
|
|
|
|
#include "js/Wrapper.h"
|
|
|
|
|
2022-05-09 23:41:05 +03:00
|
|
|
namespace mozilla::dom {
|
2022-03-11 01:44:27 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Proxy handler for observable array exotic object.
|
|
|
|
*
|
|
|
|
* The indexed properties are stored in the backing list object in reserved slot
|
|
|
|
* of the proxy object with special treatment intact.
|
|
|
|
*
|
|
|
|
* The additional properties are stored in the proxy target object.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class ObservableArrayProxyHandler : public js::ForwardingProxyHandler {
|
|
|
|
public:
|
|
|
|
explicit constexpr ObservableArrayProxyHandler()
|
|
|
|
: js::ForwardingProxyHandler(&family) {}
|
|
|
|
|
|
|
|
// Implementations of methods that can be implemented in terms of
|
|
|
|
// other lower-level methods.
|
2022-05-18 11:43:09 +03:00
|
|
|
bool defineProperty(JSContext* aCx, JS::Handle<JSObject*> aProxy,
|
|
|
|
JS::Handle<JS::PropertyKey> aId,
|
2022-03-11 01:44:27 +03:00
|
|
|
JS::Handle<JS::PropertyDescriptor> aDesc,
|
|
|
|
JS::ObjectOpResult& aResult) const override;
|
|
|
|
|
2022-05-18 11:43:09 +03:00
|
|
|
bool delete_(JSContext* aCx, JS::Handle<JSObject*> aProxy,
|
|
|
|
JS::Handle<JS::PropertyKey> aId,
|
2022-03-11 01:44:27 +03:00
|
|
|
JS::ObjectOpResult& aResult) const override;
|
|
|
|
|
2022-05-18 11:43:09 +03:00
|
|
|
bool get(JSContext* aCx, JS::Handle<JSObject*> aProxy,
|
|
|
|
JS::Handle<JS::Value> aReceiver, JS::Handle<JS::PropertyKey> aId,
|
|
|
|
JS::MutableHandle<JS::Value> aVp) const override;
|
2022-03-11 01:44:27 +03:00
|
|
|
|
|
|
|
bool getOwnPropertyDescriptor(
|
2022-05-18 11:43:09 +03:00
|
|
|
JSContext* aCx, JS::Handle<JSObject*> aProxy,
|
|
|
|
JS::Handle<JS::PropertyKey> aId,
|
2022-03-11 01:44:27 +03:00
|
|
|
JS::MutableHandle<Maybe<JS::PropertyDescriptor>> aDesc) const override;
|
|
|
|
|
2022-05-18 11:43:09 +03:00
|
|
|
bool has(JSContext* aCx, JS::Handle<JSObject*> aProxy,
|
|
|
|
JS::Handle<JS::PropertyKey> aId, bool* aBp) const override;
|
2022-03-11 01:44:27 +03:00
|
|
|
|
2022-05-18 11:43:09 +03:00
|
|
|
bool ownPropertyKeys(JSContext* aCx, JS::Handle<JSObject*> aProxy,
|
2022-03-11 01:44:27 +03:00
|
|
|
JS::MutableHandleVector<jsid> aProps) const override;
|
|
|
|
|
2022-05-18 11:43:09 +03:00
|
|
|
bool preventExtensions(JSContext* aCx, JS::Handle<JSObject*> aProxy,
|
2022-03-11 01:44:27 +03:00
|
|
|
JS::ObjectOpResult& aResult) const override;
|
|
|
|
|
2022-05-18 11:43:09 +03:00
|
|
|
bool set(JSContext* aCx, JS::Handle<JSObject*> aProxy,
|
|
|
|
JS::Handle<JS::PropertyKey> aId, JS::Handle<JS::Value> aV,
|
|
|
|
JS::Handle<JS::Value> aReceiver,
|
2022-03-11 01:44:27 +03:00
|
|
|
JS::ObjectOpResult& aResult) const override;
|
|
|
|
|
2022-05-18 11:43:09 +03:00
|
|
|
bool SetLength(JSContext* aCx, JS::Handle<JSObject*> aProxy,
|
2022-03-11 01:44:27 +03:00
|
|
|
uint32_t aLength) const;
|
|
|
|
|
|
|
|
static const char family;
|
|
|
|
|
|
|
|
protected:
|
2022-05-18 11:43:09 +03:00
|
|
|
bool GetBackingListObject(
|
|
|
|
JSContext* aCx, JS::Handle<JSObject*> aProxy,
|
|
|
|
JS::MutableHandle<JSObject*> aBackingListObject) const;
|
2022-03-11 01:44:27 +03:00
|
|
|
|
2022-05-18 11:43:09 +03:00
|
|
|
bool GetBackingListLength(JSContext* aCx, JS::Handle<JSObject*> aProxy,
|
2022-03-11 01:44:27 +03:00
|
|
|
uint32_t* aLength) const;
|
|
|
|
|
2022-05-18 11:43:09 +03:00
|
|
|
bool SetLength(JSContext* aCx, JS::Handle<JSObject*> aProxy,
|
|
|
|
JS::Handle<JSObject*> aBackingList, uint32_t aLength,
|
2022-03-11 01:44:27 +03:00
|
|
|
JS::ObjectOpResult& aResult) const;
|
|
|
|
|
2022-05-18 11:43:09 +03:00
|
|
|
bool SetLength(JSContext* aCx, JS::Handle<JSObject*> aProxy,
|
|
|
|
JS::Handle<JSObject*> aBackingList,
|
|
|
|
JS::Handle<JS::Value> aValue,
|
2022-03-11 01:44:27 +03:00
|
|
|
JS::ObjectOpResult& aResult) const;
|
|
|
|
|
|
|
|
// Hook for subclasses to invoke the setting the indexed value steps which
|
|
|
|
// would invoke DeleteAlgorithm/SetAlgorithm defined and implemented per
|
|
|
|
// interface. Returns false and throw exception on failure.
|
2022-05-18 11:43:09 +03:00
|
|
|
virtual bool SetIndexedValue(JSContext* aCx, JS::Handle<JSObject*> aProxy,
|
|
|
|
JS::Handle<JSObject*> aBackingList,
|
|
|
|
uint32_t aIndex, JS::Handle<JS::Value> aValue,
|
2022-03-11 01:44:27 +03:00
|
|
|
JS::ObjectOpResult& aResult) const = 0;
|
|
|
|
|
|
|
|
// Hook for subclasses to invoke the DeleteAlgorithm defined and implemented
|
|
|
|
// per interface. Returns false and throw exception on failure.
|
2022-05-18 11:43:09 +03:00
|
|
|
virtual bool OnDeleteItem(JSContext* aCx, JS::Handle<JSObject*> aProxy,
|
|
|
|
JS::Handle<JS::Value> aValue,
|
|
|
|
uint32_t aIndex) const = 0;
|
2022-03-11 01:44:27 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
inline bool IsObservableArrayProxy(JSObject* obj) {
|
|
|
|
return js::IsProxy(obj) && js::GetProxyHandler(obj)->family() ==
|
|
|
|
&ObservableArrayProxyHandler::family;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const ObservableArrayProxyHandler* GetObservableArrayProxyHandler(
|
|
|
|
JSObject* obj) {
|
|
|
|
MOZ_ASSERT(IsObservableArrayProxy(obj));
|
|
|
|
return static_cast<const ObservableArrayProxyHandler*>(
|
|
|
|
js::GetProxyHandler(obj));
|
|
|
|
}
|
|
|
|
|
2022-05-09 23:41:05 +03:00
|
|
|
} // namespace mozilla::dom
|
2022-03-11 01:44:27 +03:00
|
|
|
|
|
|
|
#endif /* mozilla_dom_ObservableArrayProxyHandler_h */
|