1/*
2 * Copyright (c) 2024 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_JS_NAPI_SENDABLE_H
17#define ECMASCRIPT_JS_NAPI_SENDABLE_H
18
19#include "ecmascript/layout_info.h"
20#include "ecmascript/property_attributes.h"
21
22namespace panda::ecmascript {
23
24class JSNapiSendable {
25public:
26    JSNapiSendable(JSThread *thread, FunctionRef::SendablePropertiesInfos &infos, Local<StringRef> &name);
27    void SetSConstructor(JSHandle<JSFunction> constructor);
28    const std::vector<PropertyDescriptor> GetStaticDescs() const
29    {
30        return staticDescs_;
31    }
32    const std::vector<PropertyDescriptor> GetNonStaticDescs() const
33    {
34        return nonStaticDescs_;
35    }
36    const std::vector<PropertyDescriptor> GetInstanceDescs() const
37    {
38        return instanceDescs_;
39    }
40    static void InitWithPropertiesInfo(JSThread *thread,
41                                       FunctionRef::SendablePropertiesInfo &info,
42                                       std::vector<PropertyDescriptor> &descs);
43
44private:
45    std::vector<PropertyDescriptor> staticDescs_;
46    std::vector<PropertyDescriptor> nonStaticDescs_;
47    std::vector<PropertyDescriptor> instanceDescs_;
48
49    static void InitStaticDescription(JSThread *thread, std::vector<PropertyDescriptor> &descs, Local<StringRef> &name);
50    static void InitNonStaticDescription(JSThread *thread, std::vector<PropertyDescriptor> &descs);
51    static void InitInstanceDescription(JSThread *thread, std::vector<PropertyDescriptor> &descs);
52    static SharedFieldType GetSharedFieldType(JSThread *thread,
53                                              FunctionRef::SendableType type,
54                                              Local<JSValueRef> value);
55};
56
57}  // namespace panda::ecmascript
58
59#endif
60