Bug 1885337 - Part 1: Implement to/from hex methods. r=dminor
[gecko.git] / js / src / vm / PropertyResult.h
blobe9e9b4c1cc58c669cc424486998e26c50e433409
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 vm_PropertyResult_h
8 #define vm_PropertyResult_h
10 #include "mozilla/Assertions.h"
12 #include "vm/PropertyInfo.h"
14 namespace js {
16 class PropertyResult {
17 enum class Kind : uint8_t {
18 NotFound,
19 NativeProperty,
20 NonNativeProperty,
21 DenseElement,
22 TypedArrayElement,
24 union {
25 // Set if kind is NativeProperty.
26 PropertyInfo propInfo_;
27 // Set if kind is DenseElement.
28 uint32_t denseIndex_;
29 // Set if kind is TypedArrayElement.
30 size_t typedArrayIndex_;
32 Kind kind_ = Kind::NotFound;
33 bool ignoreProtoChain_ = false;
35 public:
36 // Note: because PropertyInfo does not have a default constructor, we can't
37 // use |= default| here.
38 PropertyResult() {}
40 // When a property is not found, we may additionally indicate that the
41 // prototype chain should be ignored. This occurs for:
42 // - An out-of-range numeric property on a TypedArrayObject.
43 // - A resolve hook recursively calling itself as it sets the property.
44 bool isNotFound() const { return kind_ == Kind::NotFound; }
45 bool shouldIgnoreProtoChain() const {
46 MOZ_ASSERT(isNotFound());
47 return ignoreProtoChain_;
50 bool isFound() const { return kind_ != Kind::NotFound; }
51 bool isNonNativeProperty() const { return kind_ == Kind::NonNativeProperty; }
52 bool isDenseElement() const { return kind_ == Kind::DenseElement; }
53 bool isTypedArrayElement() const { return kind_ == Kind::TypedArrayElement; }
54 bool isNativeProperty() const { return kind_ == Kind::NativeProperty; }
56 PropertyInfo propertyInfo() const {
57 MOZ_ASSERT(isNativeProperty());
58 return propInfo_;
61 uint32_t denseElementIndex() const {
62 MOZ_ASSERT(isDenseElement());
63 return denseIndex_;
66 size_t typedArrayElementIndex() const {
67 MOZ_ASSERT(isTypedArrayElement());
68 return typedArrayIndex_;
71 void setNotFound() { kind_ = Kind::NotFound; }
73 void setNativeProperty(PropertyInfo prop) {
74 kind_ = Kind::NativeProperty;
75 propInfo_ = prop;
78 void setWasmGcProperty() { kind_ = Kind::NonNativeProperty; }
79 void setProxyProperty() { kind_ = Kind::NonNativeProperty; }
81 void setDenseElement(uint32_t index) {
82 kind_ = Kind::DenseElement;
83 denseIndex_ = index;
86 void setTypedArrayElement(size_t index) {
87 kind_ = Kind::TypedArrayElement;
88 typedArrayIndex_ = index;
91 void setTypedArrayOutOfRange() {
92 kind_ = Kind::NotFound;
93 ignoreProtoChain_ = true;
95 void setRecursiveResolve() {
96 kind_ = Kind::NotFound;
97 ignoreProtoChain_ = true;
101 } // namespace js
103 #endif /* vm_PropertyResult_h */