1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ECMASCRIPT_OBJECT_FAST_OPERATOR_H 17 #define ECMASCRIPT_OBJECT_FAST_OPERATOR_H 18 19 #include "ecmascript/js_tagged_value.h" 20 21 namespace panda::ecmascript { 22 class ObjectFastOperator final { 23 public: 24 template<bool UseOwn = false> 25 static inline JSTaggedValue GetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key); 26 27 template<bool UseOwn = false> 28 static inline JSTaggedValue SetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, 29 JSTaggedValue value); 30 31 template<bool UseOwn = false> 32 static inline JSTaggedValue GetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index); 33 34 template<bool UseOwn = false> 35 static inline JSTaggedValue SetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index, 36 JSTaggedValue value); 37 38 template<bool UseOwn = false> 39 static inline JSTaggedValue GetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key); 40 41 template<bool UseOwn = false> 42 static inline JSTaggedValue SetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, 43 JSTaggedValue value); 44 45 static inline bool FastSetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, 46 JSTaggedValue value); 47 48 static inline bool FastSetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index, 49 JSTaggedValue value); 50 51 static inline JSTaggedValue FastGetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key); 52 53 static inline JSTaggedValue FastGetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key); 54 55 template<bool UseHole = false> 56 static inline JSTaggedValue FastGetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index); 57 58 static inline JSTaggedValue FastParseDate(const EcmaString *str); 59 60 static inline PropertyAttributes AddPropertyByName(JSThread *thread, JSHandle<JSObject> objHandle, 61 JSHandle<JSTaggedValue> keyHandle, 62 JSHandle<JSTaggedValue> valueHandle, 63 PropertyAttributes attr); 64 65 static inline JSTaggedValue CallGetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder, 66 JSTaggedValue value); 67 private: 68 static inline JSTaggedValue CallSetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue value, 69 JSTaggedValue accessorValue); 70 71 static inline bool ShouldCallSetter(JSTaggedValue receiver, JSTaggedValue holder, JSTaggedValue accessorValue, 72 PropertyAttributes attr); 73 74 static inline bool IsSpecialIndexedObj(JSType jsType); 75 76 static inline bool IsFastTypeArray(JSType jsType); 77 78 static inline bool TryStringOrSymbolToIndex(JSTaggedValue key, uint32_t *output); 79 80 static inline JSTaggedValue FastGetTypeArrayProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder, 81 JSTaggedValue key, JSType jsType); 82 83 static inline JSTaggedValue FastSetTypeArrayProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder, 84 JSTaggedValue key, JSTaggedValue value, JSType jsType); 85 86 // non ECMA standard jsapi container 87 static inline bool IsSpecialContainer(JSType jsType); 88 89 static inline JSTaggedValue GetContainerProperty(JSThread *thread, JSTaggedValue receiver, uint32_t index, 90 JSType jsType); 91 92 static inline JSTaggedValue SetContainerProperty(JSThread *thread, JSTaggedValue receiver, uint32_t index, 93 JSTaggedValue value, JSType jsType); 94 95 static inline JSTaggedValue AddPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index, 96 JSTaggedValue value); 97 98 static inline int64_t TryToElementsIndex(JSTaggedValue key); 99 100 static inline bool GetNumFromString(const char *str, int len, int *index, int *num); 101 102 friend class FastRuntimeStub; 103 }; 104 } // namespace panda::ecmascript 105 #endif // ECMASCRIPT_OBJECT_FAST_OPERATOR_H