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
19 namespace panda::ecmascript {
Instantiate(JSThread * thread,const JSHandle<JSTaggedValue> & module)20 int32_t ModuleRecord::Instantiate(JSThread *thread, const JSHandle<JSTaggedValue> &module)
21 {
22 if (module->IsSourceTextModule()) {
23 return SourceTextModule::Instantiate(thread, module);
24 }
25 LOG_ECMA(FATAL) << "this branch is unreachable";
26 UNREACHABLE();
27 }
28
Evaluate(JSThread * thread,const JSHandle<JSTaggedValue> & module)29 int32_t ModuleRecord::Evaluate(JSThread *thread, const JSHandle<JSTaggedValue> &module)
30 {
31 if (module->IsSourceTextModule()) {
32 JSHandle<SourceTextModule> moduleRecord = JSHandle<SourceTextModule>::Cast(module);
33 return SourceTextModule::Evaluate(thread, moduleRecord);
34 }
35 LOG_ECMA(FATAL) << "this branch is unreachable";
36 UNREACHABLE();
37 }
38
GetNamespace(JSTaggedValue module)39 JSTaggedValue ModuleRecord::GetNamespace(JSTaggedValue module)
40 {
41 if (module.IsSourceTextModule()) {
42 return SourceTextModule::Cast(module.GetTaggedObject())->GetNamespace();
43 }
44 LOG_ECMA(FATAL) << "this branch is unreachable";
45 UNREACHABLE();
46 }
47
SetNamespace(JSThread * thread,JSTaggedValue module,JSTaggedValue value)48 void ModuleRecord::SetNamespace(JSThread *thread, JSTaggedValue module, JSTaggedValue value)
49 {
50 if (module.IsSourceTextModule()) {
51 SourceTextModule::Cast(module.GetTaggedObject())->SetNamespace(thread, value);
52 } else {
53 LOG_ECMA(FATAL) << "this branch is unreachable";
54 UNREACHABLE();
55 }
56 }
57 } // namespace panda::ecmascript