diff options
author | Moonchild <moonchild@palemoon.org> | 2022-05-24 21:15:12 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2022-05-24 21:15:12 +0000 |
commit | a160e7772a0f3e142b5c50ac4cd9b4f353f9b92d (patch) | |
tree | a130ccf5597b7bb3a459c142cda1f22eec8ef3f7 /js | |
parent | dc5a60fb62a0f43fe77517bd0e46fe40358b44b0 (diff) | |
download | uxp-a160e7772a0f3e142b5c50ac4cd9b4f353f9b92d.tar.gz |
Issue #1742 - Part 2: Add a class to encapsulate the possible results of a property lookup
Diffstat (limited to 'js')
-rw-r--r-- | js/public/Class.h | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/js/public/Class.h b/js/public/Class.h index 6f1960a308..55da324e15 100644 --- a/js/public/Class.h +++ b/js/public/Class.h @@ -271,8 +271,119 @@ class ObjectOpResult } }; +class PropertyResult +{ + union { + js::Shape* shape_; + uintptr_t bits_; + }; + + static const uintptr_t NotFound = 0; + static const uintptr_t NonNativeProperty = 1; + static const uintptr_t DenseOrTypedArrayElement = 1; + + public: + PropertyResult() : bits_(NotFound) {} + + explicit PropertyResult(js::Shape* propertyShape) + : shape_(propertyShape) + { + MOZ_ASSERT(!isFound() || isNativeProperty()); + } + + explicit operator bool() const { + return isFound(); + } + + bool isFound() const { + return bits_ != NotFound; + } + + bool isNonNativeProperty() const { + return bits_ == NonNativeProperty; + } + + bool isDenseOrTypedArrayElement() const { + return bits_ == DenseOrTypedArrayElement; + } + + bool isNativeProperty() const { + return isFound() && !isNonNativeProperty(); + } + + js::Shape* maybeShape() const { + MOZ_ASSERT(!isNonNativeProperty()); + return isFound() ? shape_ : nullptr; + } + + js::Shape* shape() const { + MOZ_ASSERT(isNativeProperty()); + return shape_; + } + + void setNotFound() { + bits_ = NotFound; + } + + void setNativeProperty(js::Shape* propertyShape) { + shape_ = propertyShape; + MOZ_ASSERT(isNativeProperty()); + } + + void setNonNativeProperty() { + bits_ = NonNativeProperty; + } + + void setDenseOrTypedArrayElement() { + bits_ = DenseOrTypedArrayElement; + } + + void trace(JSTracer* trc); +}; + } // namespace JS +namespace js { + +template <class Wrapper> +class WrappedPtrOperations<JS::PropertyResult, Wrapper> +{ + const JS::PropertyResult& value() const { return static_cast<const Wrapper*>(this)->get(); } + + public: + bool isFound() const { return value().isFound(); } + explicit operator bool() const { return bool(value()); } + js::Shape* maybeShape() const { return value().maybeShape(); } + js::Shape* shape() const { return value().shape(); } + bool isNativeProperty() const { return value().isNativeProperty(); } + bool isNonNativeProperty() const { return value().isNonNativeProperty(); } + bool isDenseOrTypedArrayElement() const { return value().isDenseOrTypedArrayElement(); } + js::Shape* asTaggedShape() const { return value().asTaggedShape(); } +}; + +template <class Wrapper> +class MutableWrappedPtrOperations<JS::PropertyResult, Wrapper> + : public WrappedPtrOperations<JS::PropertyResult, Wrapper> +{ + JS::PropertyResult& value() { return static_cast<Wrapper*>(this)->get(); } + + public: + void setNotFound() { + value().setNotFound(); + } + void setNativeProperty(js::Shape* shape) { + value().setNativeProperty(shape); + } + void setNonNativeProperty() { + value().setNonNativeProperty(); + } + void setDenseOrTypedArrayElement() { + value().setDenseOrTypedArrayElement(); + } +}; + +} // namespace js + // JSClass operation signatures. /** |