14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_OBJECT_FAST_OPERATOR_H
174514f5e3Sopenharmony_ci#define ECMASCRIPT_OBJECT_FAST_OPERATOR_H
184514f5e3Sopenharmony_ci
194514f5e3Sopenharmony_ci#include "ecmascript/js_handle.h"
204514f5e3Sopenharmony_ci#include "ecmascript/js_hclass.h"
214514f5e3Sopenharmony_ci#include "ecmascript/js_tagged_value.h"
224514f5e3Sopenharmony_ci#include "ecmascript/property_attributes.h"
234514f5e3Sopenharmony_ci
244514f5e3Sopenharmony_cinamespace panda::ecmascript {
254514f5e3Sopenharmony_ciusing SCheckMode = JSShared::SCheckMode;
264514f5e3Sopenharmony_ci
274514f5e3Sopenharmony_ciclass ObjectFastOperator final {
284514f5e3Sopenharmony_cipublic:
294514f5e3Sopenharmony_ci    enum class Status: uint8_t {
304514f5e3Sopenharmony_ci        None = 0x00UL,
314514f5e3Sopenharmony_ci        UseOwn = 0x01UL,
324514f5e3Sopenharmony_ci        GetInternal = 0x1UL << 1,
334514f5e3Sopenharmony_ci        DefineSemantics = 0x1UL << 2,
344514f5e3Sopenharmony_ci    };
354514f5e3Sopenharmony_ci
364514f5e3Sopenharmony_ci    static inline bool UseOwn(Status status)
374514f5e3Sopenharmony_ci    {
384514f5e3Sopenharmony_ci        return (static_cast<int32_t>(status) & static_cast<int32_t>(Status::UseOwn)) > 0;
394514f5e3Sopenharmony_ci    }
404514f5e3Sopenharmony_ci
414514f5e3Sopenharmony_ci    static inline bool GetInternal(Status status)
424514f5e3Sopenharmony_ci    {
434514f5e3Sopenharmony_ci        return (static_cast<int32_t>(status) & static_cast<int32_t>(Status::GetInternal)) > 0;
444514f5e3Sopenharmony_ci    }
454514f5e3Sopenharmony_ci
464514f5e3Sopenharmony_ci    static inline bool DefineSemantics(Status status)
474514f5e3Sopenharmony_ci    {
484514f5e3Sopenharmony_ci        return (static_cast<uint32_t>(status) & static_cast<int32_t>(Status::DefineSemantics)) > 0;
494514f5e3Sopenharmony_ci    }
504514f5e3Sopenharmony_ci
514514f5e3Sopenharmony_ci    static inline std::pair<JSTaggedValue, bool> HasOwnProperty(JSThread *thread,
524514f5e3Sopenharmony_ci                                                                JSTaggedValue receiver, JSTaggedValue key);
534514f5e3Sopenharmony_ci
544514f5e3Sopenharmony_ci    template<Status status = Status::None>
554514f5e3Sopenharmony_ci    static inline JSTaggedValue TryFastHasProperty(JSThread *thread, JSTaggedValue receiver,
564514f5e3Sopenharmony_ci                                                   JSMutableHandle<JSTaggedValue> keyHandle);
574514f5e3Sopenharmony_ci
584514f5e3Sopenharmony_ci    template<Status status = Status::None>
594514f5e3Sopenharmony_ci    static inline JSTaggedValue TryFastGetPropertyByValue(JSThread *thread, JSTaggedValue receiver,
604514f5e3Sopenharmony_ci                                                          JSMutableHandle<JSTaggedValue> keyHandle);
614514f5e3Sopenharmony_ci
624514f5e3Sopenharmony_ci    template<Status status = Status::None>
634514f5e3Sopenharmony_ci    static inline JSTaggedValue TryFastGetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index);
644514f5e3Sopenharmony_ci
654514f5e3Sopenharmony_ci    template<Status status = Status::None>
664514f5e3Sopenharmony_ci    static inline JSTaggedValue TryGetPropertyByNameThroughCacheAtLocal(JSThread *thread, JSTaggedValue receiver,
674514f5e3Sopenharmony_ci                                                                        JSTaggedValue key);
684514f5e3Sopenharmony_ci
694514f5e3Sopenharmony_ci    template<Status status = Status::None>
704514f5e3Sopenharmony_ci    static inline JSTaggedValue GetPropertyByName(JSThread *thread, JSTaggedValue receiver,
714514f5e3Sopenharmony_ci                                                  JSTaggedValue key, bool noAllocate = false,
724514f5e3Sopenharmony_ci                                                  bool *isCallGetter = nullptr);
734514f5e3Sopenharmony_ci
744514f5e3Sopenharmony_ci    template <Status status = Status::None>
754514f5e3Sopenharmony_ci    static inline JSTaggedValue TrySetPropertyByNameThroughCacheAtLocal(JSThread *thread, JSTaggedValue receiver,
764514f5e3Sopenharmony_ci                                                                        JSTaggedValue key, JSTaggedValue value);
774514f5e3Sopenharmony_ci
784514f5e3Sopenharmony_ci    template <Status status = Status::None>
794514f5e3Sopenharmony_ci    static inline JSTaggedValue SetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key,
804514f5e3Sopenharmony_ci                                                  JSTaggedValue value, SCheckMode sCheckMode = SCheckMode::CHECK);
814514f5e3Sopenharmony_ci
824514f5e3Sopenharmony_ci    template <Status status = Status::None>
834514f5e3Sopenharmony_ci    static inline JSTaggedValue GetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index);
844514f5e3Sopenharmony_ci
854514f5e3Sopenharmony_ci    template <Status status = Status::None>
864514f5e3Sopenharmony_ci    static inline JSTaggedValue SetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index,
874514f5e3Sopenharmony_ci                                                   JSTaggedValue value);
884514f5e3Sopenharmony_ci
894514f5e3Sopenharmony_ci    template <Status status = Status::None>
904514f5e3Sopenharmony_ci    static inline JSTaggedValue GetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key);
914514f5e3Sopenharmony_ci
924514f5e3Sopenharmony_ci    template <Status status = Status::None>
934514f5e3Sopenharmony_ci    static inline JSTaggedValue SetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key,
944514f5e3Sopenharmony_ci                                                   JSTaggedValue value, SCheckMode sCheckMode = SCheckMode::CHECK);
954514f5e3Sopenharmony_ci
964514f5e3Sopenharmony_ci    static inline bool FastSetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key,
974514f5e3Sopenharmony_ci                                              JSTaggedValue value, SCheckMode sCheckMode = SCheckMode::CHECK);
984514f5e3Sopenharmony_ci
994514f5e3Sopenharmony_ci    static inline bool FastSetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index,
1004514f5e3Sopenharmony_ci                                              JSTaggedValue value);
1014514f5e3Sopenharmony_ci
1024514f5e3Sopenharmony_ci    static inline JSTaggedValue FastGetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key);
1034514f5e3Sopenharmony_ci
1044514f5e3Sopenharmony_ci    static inline JSTaggedValue FastGetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key,
1054514f5e3Sopenharmony_ci                                                       SCheckMode sCheckMode = SCheckMode::CHECK);
1064514f5e3Sopenharmony_ci
1074514f5e3Sopenharmony_ci    static inline JSTaggedValue FastGetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index);
1084514f5e3Sopenharmony_ci
1094514f5e3Sopenharmony_ci    static inline JSTaggedValue FastParseDate(const EcmaString *str);
1104514f5e3Sopenharmony_ci
1114514f5e3Sopenharmony_ci    static inline PropertyAttributes AddPropertyByName(JSThread *thread, JSHandle<JSObject> objHandle,
1124514f5e3Sopenharmony_ci                                                       JSHandle<JSTaggedValue> keyHandle,
1134514f5e3Sopenharmony_ci                                                       JSHandle<JSTaggedValue> valueHandle,
1144514f5e3Sopenharmony_ci                                                       PropertyAttributes attr);
1154514f5e3Sopenharmony_ci
1164514f5e3Sopenharmony_ci    static inline JSTaggedValue CallGetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder,
1174514f5e3Sopenharmony_ci                                           JSTaggedValue value);
1184514f5e3Sopenharmony_ci    static inline JSTaggedValue FastGetPropertyByPorpsIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index);
1194514f5e3Sopenharmony_ci
1204514f5e3Sopenharmony_ci    static inline int64_t TryToElementsIndex(JSTaggedValue key);
1214514f5e3Sopenharmony_ciprivate:
1224514f5e3Sopenharmony_ci    static inline JSTaggedValue CallSetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue value,
1234514f5e3Sopenharmony_ci                                           JSTaggedValue accessorValue);
1244514f5e3Sopenharmony_ci
1254514f5e3Sopenharmony_ci    static inline bool ShouldCallSetter(JSTaggedValue receiver, JSTaggedValue holder, JSTaggedValue accessorValue,
1264514f5e3Sopenharmony_ci                                        PropertyAttributes attr);
1274514f5e3Sopenharmony_ci
1284514f5e3Sopenharmony_ci    static inline bool IsSpecialIndexedObj(JSType jsType);
1294514f5e3Sopenharmony_ci
1304514f5e3Sopenharmony_ci    static inline bool IsJSSharedArray(JSType jsType);
1314514f5e3Sopenharmony_ci
1324514f5e3Sopenharmony_ci    static inline bool IsFastTypeArray(JSType jsType);
1334514f5e3Sopenharmony_ci
1344514f5e3Sopenharmony_ci    static inline bool IsString(JSType jsType);
1354514f5e3Sopenharmony_ci
1364514f5e3Sopenharmony_ci    static inline bool IsJSPrimitiveRef(JSType jsType);
1374514f5e3Sopenharmony_ci
1384514f5e3Sopenharmony_ci    static inline bool TryStringOrSymbolToIndex(JSTaggedValue key, uint32_t *output);
1394514f5e3Sopenharmony_ci
1404514f5e3Sopenharmony_ci    static inline JSTaggedValue FastGetTypeArrayProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder,
1414514f5e3Sopenharmony_ci                                                         JSTaggedValue key, JSType jsType);
1424514f5e3Sopenharmony_ci
1434514f5e3Sopenharmony_ci    static inline JSTaggedValue FastSetTypeArrayProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder,
1444514f5e3Sopenharmony_ci                                                         JSTaggedValue key, JSTaggedValue value, JSType jsType);
1454514f5e3Sopenharmony_ci
1464514f5e3Sopenharmony_ci    // non ECMA standard jsapi container
1474514f5e3Sopenharmony_ci    static inline bool IsSpecialContainer(JSType jsType);
1484514f5e3Sopenharmony_ci
1494514f5e3Sopenharmony_ci    static inline JSTaggedValue GetContainerProperty(JSThread *thread, JSTaggedValue receiver, uint32_t index,
1504514f5e3Sopenharmony_ci                                                     JSType jsType);
1514514f5e3Sopenharmony_ci
1524514f5e3Sopenharmony_ci    static inline JSTaggedValue SetContainerProperty(JSThread *thread, JSTaggedValue receiver, uint32_t index,
1534514f5e3Sopenharmony_ci                                                     JSTaggedValue value, JSType jsType);
1544514f5e3Sopenharmony_ci
1554514f5e3Sopenharmony_ci    static inline JSTaggedValue AddPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index,
1564514f5e3Sopenharmony_ci                                                   JSTaggedValue value);
1574514f5e3Sopenharmony_ci
1584514f5e3Sopenharmony_ci    static inline bool GetNumFromString(const char *str, int len, int *index, int *num);
1594514f5e3Sopenharmony_ci
1604514f5e3Sopenharmony_ci    friend class FastRuntimeStub;
1614514f5e3Sopenharmony_ci};
1624514f5e3Sopenharmony_ci}  // namespace panda::ecmascript
1634514f5e3Sopenharmony_ci#endif  // ECMASCRIPT_OBJECT_FAST_OPERATOR_H
164