• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "ecmascript/module/js_module_record.h"
17 #include "ecmascript/module/js_module_source_text.h"
18 #include "ecmascript/object_factory-inl.h"
19 
20 namespace panda::ecmascript {
Instantiate(JSThread * thread,const JSHandle<JSTaggedValue> & module)21 int32_t ModuleRecord::Instantiate(JSThread *thread, const JSHandle<JSTaggedValue> &module)
22 {
23     STACK_LIMIT_CHECK(thread, SourceTextModule::UNDEFINED_INDEX);
24     if (module->IsSourceTextModule()) {
25         return SourceTextModule::Instantiate(thread, module);
26     }
27     LOG_ECMA(FATAL) << "this branch is unreachable";
28     UNREACHABLE();
29 }
30 
Evaluate(JSThread * thread,const JSHandle<JSTaggedValue> & module)31 JSTaggedValue ModuleRecord::Evaluate(JSThread *thread, const JSHandle<JSTaggedValue> &module)
32 {
33     if (module->IsSourceTextModule()) {
34         JSHandle<SourceTextModule> moduleRecord = JSHandle<SourceTextModule>::Cast(module);
35         return SourceTextModule::Evaluate(thread, moduleRecord);
36     }
37     LOG_ECMA(FATAL) << "this branch is unreachable";
38     UNREACHABLE();
39 }
40 
GetNamespace(JSTaggedValue module)41 JSTaggedValue ModuleRecord::GetNamespace(JSTaggedValue module)
42 {
43     if (module.IsSourceTextModule()) {
44         return SourceTextModule::Cast(module.GetTaggedObject())->GetNamespace();
45     }
46     LOG_ECMA(FATAL) << "this branch is unreachable";
47     UNREACHABLE();
48 }
49 
SetNamespace(JSThread * thread,JSTaggedValue module,JSTaggedValue value)50 void ModuleRecord::SetNamespace(JSThread *thread, JSTaggedValue module, JSTaggedValue value)
51 {
52     if (module.IsSourceTextModule()) {
53         SourceTextModule::Cast(module.GetTaggedObject())->SetNamespace(thread, value);
54     } else {
55         LOG_ECMA(FATAL) << "this branch is unreachable";
56         UNREACHABLE();
57     }
58 }
59 }  // namespace panda::ecmascript