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