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"
16 class PropertyResult
{
17 enum class Kind
: uint8_t {
25 // Set if kind is NativeProperty.
26 PropertyInfo propInfo_
;
27 // Set if kind is DenseElement.
29 // Set if kind is TypedArrayElement.
30 size_t typedArrayIndex_
;
32 Kind kind_
= Kind::NotFound
;
33 bool ignoreProtoChain_
= false;
36 // Note: because PropertyInfo does not have a default constructor, we can't
37 // use |= default| here.
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());
61 uint32_t denseElementIndex() const {
62 MOZ_ASSERT(isDenseElement());
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
;
78 void setWasmGcProperty() { kind_
= Kind::NonNativeProperty
; }
79 void setProxyProperty() { kind_
= Kind::NonNativeProperty
; }
81 void setDenseElement(uint32_t index
) {
82 kind_
= Kind::DenseElement
;
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;
103 #endif /* vm_PropertyResult_h */