• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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/builtins/builtins_cjs_module.h"
17 
18 #include "ecmascript/base/builtins_base.h"
19 #include "ecmascript/interpreter/interpreter-inl.h"
20 #include "ecmascript/module/module_path_helper.h"
21 #include "ecmascript/platform/file.h"
22 #include "ecmascript/require/js_cjs_module.h"
23 #include "ecmascript/require/js_require_manager.h"
24 
25 namespace panda::ecmascript::builtins {
26 
CjsModuleConstructor(EcmaRuntimeCallInfo * argv)27 JSTaggedValue BuiltinsCjsModule::CjsModuleConstructor(EcmaRuntimeCallInfo *argv)
28 {
29     JSThread *thread = argv->GetThread();
30     BUILTINS_API_TRACE(thread, CjsModule, CjsModuleConstructor);
31     [[maybe_unused]] EcmaHandleScope scope(thread);
32 
33     LOG_ECMA(ERROR) << "BuiltinsCjsModule::CjsModuleConstructor : can not be call";
34     return JSTaggedValue::Undefined();
35 }
36 
Compiler(EcmaRuntimeCallInfo * msg)37 JSTaggedValue BuiltinsCjsModule::Compiler(EcmaRuntimeCallInfo *msg)
38 {
39     ASSERT(msg);
40     JSThread *thread = msg->GetThread();
41     BUILTINS_API_TRACE(thread, CjsModule, Compiler);
42     [[maybe_unused]] EcmaHandleScope handleScope(thread);
43     return JSTaggedValue::Hole();
44 }
45 
Load(EcmaRuntimeCallInfo * msg)46 JSTaggedValue BuiltinsCjsModule::Load(EcmaRuntimeCallInfo *msg)
47 {
48     ASSERT(msg);
49     JSThread *thread = msg->GetThread();
50     BUILTINS_API_TRACE(thread, CjsModule, Load);
51     [[maybe_unused]] EcmaHandleScope handleScope(thread);
52     return JSTaggedValue::Hole();
53 }
54 
ResolveFilename(EcmaRuntimeCallInfo * argv)55 JSTaggedValue BuiltinsCjsModule::ResolveFilename(EcmaRuntimeCallInfo *argv)
56 {
57     ASSERT(argv);
58     JSThread *thread = argv->GetThread();
59     BUILTINS_API_TRACE(thread, CjsModule, ResolveFilename);
60     [[maybe_unused]] EcmaHandleScope handleScope(thread);
61 
62     uint32_t length = argv->GetArgsNumber();
63     JSMutableHandle<JSTaggedValue> parent(thread, JSTaggedValue::Undefined());
64     JSMutableHandle<JSTaggedValue> dirname(thread, JSTaggedValue::Undefined());
65     const JSPandaFile *jsPandaFile = EcmaInterpreter::GetNativeCallPandafile(thread);
66     ModulePathHelper::ResolveCurrentPath(thread, parent, dirname, jsPandaFile);
67 
68     if (length != 1) {  // strange arg's number
69         LOG_ECMA(FATAL) << "BuiltinsCjsModule::Load : can only accept one argument";
70         UNREACHABLE();
71     }
72     JSHandle<EcmaString> requestName = JSHandle<EcmaString>::Cast(GetCallArg(argv, 0));
73     JSHandle<EcmaString> filename = ResolveFilenameFromNative(thread, dirname.GetTaggedValue(),
74                                                               requestName.GetTaggedValue());
75 
76     return filename.GetTaggedValue();
77 }
78 
Require(EcmaRuntimeCallInfo * msg)79 JSTaggedValue BuiltinsCjsModule::Require(EcmaRuntimeCallInfo *msg)
80 {
81     ASSERT(msg);
82     JSThread *thread = msg->GetThread();
83     BUILTINS_API_TRACE(thread, CjsModule, Require);
84     [[maybe_unused]] EcmaHandleScope handleScope(thread);
85     return JSTaggedValue::Hole();
86 }
87 
GetExportsForCircularRequire(EcmaRuntimeCallInfo * msg)88 JSTaggedValue BuiltinsCjsModule::GetExportsForCircularRequire(EcmaRuntimeCallInfo *msg)
89 {
90     ASSERT(msg);
91     JSThread *thread = msg->GetThread();
92     BUILTINS_API_TRACE(thread, CjsModule, GetExportsForCircularRequire);
93     [[maybe_unused]] EcmaHandleScope handleScope(thread);
94     return JSTaggedValue::Hole();
95 }
96 
UpdateChildren(EcmaRuntimeCallInfo * msg)97 JSTaggedValue BuiltinsCjsModule::UpdateChildren(EcmaRuntimeCallInfo *msg)
98 {
99     ASSERT(msg);
100     JSThread *thread = msg->GetThread();
101     BUILTINS_API_TRACE(thread, CjsModule, UpdateChildren);
102     [[maybe_unused]] EcmaHandleScope handleScope(thread);
103     return JSTaggedValue::Hole();
104 }
105 }  // namespace panda::ecmascript::builtins
106 
107