• 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 
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     UNREACHABLE();
26 }
27 
Evaluate(JSThread * thread,const JSHandle<JSTaggedValue> & module)28 int32_t ModuleRecord::Evaluate(JSThread *thread, const JSHandle<JSTaggedValue> &module)
29 {
30     if (module->IsSourceTextModule()) {
31         JSHandle<SourceTextModule> moduleRecord = JSHandle<SourceTextModule>::Cast(module);
32         return SourceTextModule::Evaluate(thread, moduleRecord);
33     }
34     UNREACHABLE();
35 }
36 
GetNamespace(JSTaggedValue module)37 JSTaggedValue ModuleRecord::GetNamespace(JSTaggedValue module)
38 {
39     if (module.IsSourceTextModule()) {
40         return SourceTextModule::Cast(module.GetTaggedObject())->GetNamespace();
41     }
42     UNREACHABLE();
43 }
44 
SetNamespace(JSThread * thread,JSTaggedValue module,JSTaggedValue value)45 void ModuleRecord::SetNamespace(JSThread *thread, JSTaggedValue module, JSTaggedValue value)
46 {
47     if (module.IsSourceTextModule()) {
48         SourceTextModule::Cast(module.GetTaggedObject())->SetNamespace(thread, value);
49     } else {
50         UNREACHABLE();
51     }
52 }
53 }  // namespace panda::ecmascript