diff --git a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp index 43bae0a641fe559f119748a490977681cc3a716a..61ebb2f73b30d723e6847ee01b6396af7f1266d9 100644 --- a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp @@ -54,6 +54,12 @@ static DirEntity *GetDirEntity(napi_env env, napi_callback_info info) napi_value DirNExporter::CloseSync(napi_env env, napi_callback_info info) { + NFuncArg funcArg(env, info); + if (!funcArg.InitArgs(NARG_CNT::ZERO, NARG_CNT::ONE)) { + UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); + return nullptr; + } + DirEntity *dirEntity = GetDirEntity(env, info); if (!dirEntity || !dirEntity->dir_) { UniError(EBADF).ThrowErr(env, "Dir has been closed yet"); @@ -61,6 +67,10 @@ napi_value DirNExporter::CloseSync(napi_env env, napi_callback_info info) } dirEntity->dir_.reset(); + + void *pdata = nullptr; + NAPI_CALL(env, napi_remove_wrap(env, funcArg.GetThisVar(), &pdata)); + return nullptr; } @@ -103,11 +113,16 @@ napi_value DirNExporter::Close(napi_env env, napi_callback_info info) NVal thisVar(env, funcArg.GetThisVar()); static const string procedureName = "fileioDirClose"; if (funcArg.GetArgc() == NARG_CNT::ZERO) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbCompl).val_; + NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbCompl); } else { NVal cb(env, funcArg[NARG_POS::FIRST]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbCompl).val_; + NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbCompl); } + + void *pdata = nullptr; + NAPI_CALL(env, napi_remove_wrap(env, funcArg.GetThisVar(), &pdata)); + + return NVal::CreateUndefined(env).val_; } struct DirReadArgs { diff --git a/interfaces/kits/js/src/mod_fileio/class_randomaccessfile/randomaccessfile_n_exporter.cpp b/interfaces/kits/js/src/mod_fileio/class_randomaccessfile/randomaccessfile_n_exporter.cpp index f3f513c05eda5982855310a4ca753f9537e9cbb3..bfa6e098302623539e20f8d035db0e60e5e60506 100644 --- a/interfaces/kits/js/src/mod_fileio/class_randomaccessfile/randomaccessfile_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fileio/class_randomaccessfile/randomaccessfile_n_exporter.cpp @@ -353,6 +353,10 @@ napi_value RandomAccessFileNExporter::CloseSync(napi_env env, napi_callback_info return nullptr; } rafEntity->fd_.reset(); + + void *pdata = nullptr; + NAPI_CALL(env, napi_remove_wrap(env, funcArg.GetThisVar(), &pdata)); + return NVal::CreateUndefined(env).val_; } @@ -369,6 +373,7 @@ napi_value RandomAccessFileNExporter::Constructor(napi_env env, napi_callback_in UniError(EIO).ThrowErr(env, "INNER BUG. Failed to wrap entity for obj RandomAccessFile"); return nullptr; } + return funcArg.GetThisVar(); } diff --git a/interfaces/kits/js/src/mod_fileio/class_stream/stream_n_exporter.cpp b/interfaces/kits/js/src/mod_fileio/class_stream/stream_n_exporter.cpp index f9d6960b858f73d554ce6bfcd907950f535b1172..a61c81aa7472589ba1db840cfd55d3f9d40209ca 100644 --- a/interfaces/kits/js/src/mod_fileio/class_stream/stream_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fileio/class_stream/stream_n_exporter.cpp @@ -96,6 +96,10 @@ napi_value StreamNExporter::CloseSync(napi_env env, napi_callback_info info) return nullptr; } streamEntity->fp.reset(); + + void *pdata = nullptr; + NAPI_CALL(env, napi_remove_wrap(env, funcArg.GetThisVar(), &pdata)); + return NVal::CreateUndefined(env).val_; } @@ -330,12 +334,15 @@ napi_value StreamNExporter::Close(napi_env env, napi_callback_info info) string procedureName = "FileIOStreamClose"; NVal thisVar(env, funcArg.GetThisVar()); if (funcArg.GetArgc() == NARG_CNT::ZERO) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbCompl).val_; + NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbCompl); } else { NVal cb(env, funcArg[NARG_POS::FIRST]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbCompl).val_; + NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbCompl); } + void *pdata = nullptr; + NAPI_CALL(env, napi_remove_wrap(env, funcArg.GetThisVar(), &pdata)); + return NVal::CreateUndefined(env).val_; } diff --git a/interfaces/kits/js/src/mod_fileio/properties/close.cpp b/interfaces/kits/js/src/mod_fileio/properties/close.cpp index 202ad04bc0780ab1eda99d2bc6aa314667b7fe3f..54fb0e7c064a6231672c949007c1e6b85b72503a 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/close.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/close.cpp @@ -46,6 +46,9 @@ napi_value Close::Sync(napi_env env, napi_callback_info info) return nullptr; } + void *pdata = nullptr; + NAPI_CALL(env, napi_remove_wrap(env, funcArg.GetThisVar(), &pdata)); + return NVal::CreateUndefined(env).val_; } @@ -84,11 +87,16 @@ napi_value Close::Async(napi_env env, napi_callback_info info) size_t argc = funcArg.GetArgc(); NVal thisVar(env, funcArg.GetThisVar()); if (argc == NARG_CNT::ONE) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; + NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete); } else { NVal cb(env, funcArg[NARG_POS::SECOND]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; + NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete); } + + void *pdata = nullptr; + NAPI_CALL(env, napi_remove_wrap(env, funcArg.GetThisVar(), &pdata)); + + return NVal::CreateUndefined(env).val_; } } // namespace ModuleFileIO } // namespace DistributedFS