1 /**
2 * Copyright (c) 2021-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 #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 // copy by hand
38 for (auto *it : properties) {
39 auto *copiedProp = it->Copy(allocator, it->Declaration());
40 copiedProp->SetTsType(it->TsType()->Instantiate(allocator, relation, globalTypes));
41 copiedDesc->properties.push_back(copiedProp);
42 }
43
44 for (auto *it : callSignatures) {
45 copiedDesc->callSignatures.push_back(it->Copy(allocator, relation, globalTypes));
46 }
47
48 for (auto *it : constructSignatures) {
49 copiedDesc->constructSignatures.push_back(it->Copy(allocator, relation, globalTypes));
50 }
51
52 if (numberIndexInfo != nullptr) {
53 copiedDesc->numberIndexInfo = numberIndexInfo->Copy(allocator, relation, globalTypes);
54 }
55
56 if (stringIndexInfo != nullptr) {
57 copiedDesc->stringIndexInfo = stringIndexInfo->Copy(allocator, relation, globalTypes);
58 }
59 }
60 } // namespace ark::es2panda::checker
61