1 /**
2 * Copyright (c) 2021-2025 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 #include "objectDescriptor.h"
17
18 #include "varbinder/variable.h"
19 #include "checker/types/ts/indexInfo.h"
20 #include "checker/types/signature.h"
21
22 namespace ark::es2panda::checker {
FindProperty(const util::StringView & name) const23 varbinder::LocalVariable *ObjectDescriptor::FindProperty(const util::StringView &name) const
24 {
25 for (auto *it : properties) {
26 if (it->Name() == name) {
27 return it;
28 }
29 }
30
31 return nullptr;
32 }
33
Copy(ArenaAllocator * allocator,ObjectDescriptor * copiedDesc,TypeRelation * relation,GlobalTypesHolder * globalTypes)34 void ObjectDescriptor::Copy(ArenaAllocator *allocator, ObjectDescriptor *copiedDesc, TypeRelation *relation,
35 GlobalTypesHolder *globalTypes)
36 {
37 ES2PANDA_ASSERT(copiedDesc != nullptr);
38 // copy by hand
39 for (auto *it : properties) {
40 auto *copiedProp = it->Copy(allocator, it->Declaration());
41 ES2PANDA_ASSERT(copiedProp != nullptr);
42 copiedProp->SetTsType(it->TsType()->Instantiate(allocator, relation, globalTypes));
43 copiedDesc->properties.push_back(copiedProp);
44 }
45
46 for (auto *it : callSignatures) {
47 copiedDesc->callSignatures.push_back(it->Copy(allocator, relation, globalTypes));
48 }
49
50 for (auto *it : constructSignatures) {
51 copiedDesc->constructSignatures.push_back(it->Copy(allocator, relation, globalTypes));
52 }
53
54 if (numberIndexInfo != nullptr) {
55 copiedDesc->numberIndexInfo = numberIndexInfo->Copy(allocator, relation, globalTypes);
56 }
57
58 if (stringIndexInfo != nullptr) {
59 copiedDesc->stringIndexInfo = stringIndexInfo->Copy(allocator, relation, globalTypes);
60 }
61 }
62 } // namespace ark::es2panda::checker
63