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 #ifndef ECMASCRIPT_REQUIRE_JS_REQUIRE_MANAGER_H 17 #define ECMASCRIPT_REQUIRE_JS_REQUIRE_MANAGER_H 18 19 #include "ecmascript/js_tagged_value-inl.h" 20 #include "ecmascript/jspandafile/js_pandafile.h" 21 #include "ecmascript/require/js_cjs_module_cache.h" 22 #include "ecmascript/require/js_cjs_module.h" 23 #include "ecmascript/require/js_cjs_require.h" 24 #include "ecmascript/require/js_cjs_exports.h" 25 26 namespace panda::ecmascript { 27 struct CJSInfo { 28 JSHandle<CjsModule> moduleHdl; 29 JSHandle<JSTaggedValue> requireHdl; 30 JSHandle<CjsExports> exportsHdl; 31 JSHandle<JSTaggedValue> filenameHdl; 32 JSHandle<JSTaggedValue> dirnameHdl; CJSInfoCJSInfo33 CJSInfo(JSHandle<CjsModule> &module, 34 JSHandle<JSTaggedValue> &require, 35 JSHandle<CjsExports> &exports, 36 JSHandle<JSTaggedValue> &filename, 37 JSHandle<JSTaggedValue> &dirname) : moduleHdl(module), requireHdl(require), exportsHdl(exports), 38 filenameHdl(filename), dirnameHdl(dirname) {} 39 }; 40 class RequireManager { 41 public: 42 static void InitializeCommonJS(JSThread *thread, CJSInfo cjsInfo); 43 44 static void CollectExecutedExp(JSThread *thread, CJSInfo cjsInfo); 45 }; 46 } // namespace panda::ecmascript 47 #endif // ECMASCRIPT_REQUIRE_JS_REQUIRE_MANAGER_H