/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ecmascript/builtins/builtins_cjs_module.h" #include "ecmascript/base/builtins_base.h" #include "ecmascript/base/path_helper.h" #include "ecmascript/interpreter/interpreter-inl.h" #include "ecmascript/platform/file.h" #include "ecmascript/require/js_cjs_module.h" #include "ecmascript/require/js_require_manager.h" namespace panda::ecmascript::builtins { using PathHelper = base::PathHelper; JSTaggedValue BuiltinsCjsModule::CjsModuleConstructor(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); LOG_ECMA(ERROR) << "BuiltinsCjsModule::CjsModuleConstructor : can not be call"; return JSTaggedValue::Undefined(); } JSTaggedValue BuiltinsCjsModule::Compiler(EcmaRuntimeCallInfo *msg) { ASSERT(msg); JSThread *thread = msg->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); return JSTaggedValue::Hole(); } JSTaggedValue BuiltinsCjsModule::Load(EcmaRuntimeCallInfo *msg) { ASSERT(msg); JSThread *thread = msg->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); return JSTaggedValue::Hole(); } JSTaggedValue BuiltinsCjsModule::ResolveFilename(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); uint32_t length = argv->GetArgsNumber(); JSMutableHandle parent(thread, JSTaggedValue::Undefined()); JSMutableHandle dirname(thread, JSTaggedValue::Undefined()); const JSPandaFile *jsPandaFile = EcmaInterpreter::GetNativeCallPandafile(thread); PathHelper::ResolveCurrentPath(thread, parent, dirname, jsPandaFile); if (length != 1) { // strange arg's number LOG_ECMA(ERROR) << "BuiltinsCjsModule::Load : can only accept one argument"; UNREACHABLE(); } JSHandle requestName = JSHandle::Cast(GetCallArg(argv, 0)); JSHandle filename = ResolveFilenameFromNative(thread, dirname.GetTaggedValue(), requestName.GetTaggedValue()); return filename.GetTaggedValue(); } JSTaggedValue BuiltinsCjsModule::Require(EcmaRuntimeCallInfo *msg) { ASSERT(msg); JSThread *thread = msg->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); return JSTaggedValue::Hole(); } JSTaggedValue BuiltinsCjsModule::GetExportsForCircularRequire(EcmaRuntimeCallInfo *msg) { ASSERT(msg); JSThread *thread = msg->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); return JSTaggedValue::Hole(); } JSTaggedValue BuiltinsCjsModule::UpdateChildren(EcmaRuntimeCallInfo *msg) { ASSERT(msg); JSThread *thread = msg->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); return JSTaggedValue::Hole(); } } // namespace panda::ecmascript::builtins