From dfc61cf8989f0c7a3e94ed632690caacacb82560 Mon Sep 17 00:00:00 2001 From: Nashez Zubair Date: Tue, 30 Jul 2024 23:56:20 +0530 Subject: [PATCH] [OV JS] Use type_validation for model.clone Make use of the allowed_signatures pattern provided in the type_validation.hpp file to validate the model.clone API arguments Resolves: #25402 Signed-off-by: Nashez Zubair --- src/bindings/js/node/src/model_wrap.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/bindings/js/node/src/model_wrap.cpp b/src/bindings/js/node/src/model_wrap.cpp index f3d020b0f7a525..ce6efde9d64901 100644 --- a/src/bindings/js/node/src/model_wrap.cpp +++ b/src/bindings/js/node/src/model_wrap.cpp @@ -7,6 +7,7 @@ #include "node/include/errors.hpp" #include "node/include/helper.hpp" #include "node/include/node_output.hpp" +#include "node/include/type_validation.hpp" ModelWrap::ModelWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info), @@ -174,11 +175,18 @@ Napi::Value ModelWrap::get_output_shape(const Napi::CallbackInfo& info) { } Napi::Value ModelWrap::clone(const Napi::CallbackInfo& info) { - Napi::Env env = info.Env(); - if (info.Length() > 0) { - reportError(env, "clone() does not accept any arguments."); - return env.Undefined(); + std::vector allowed_signatures; + try { + if (ov::js::validate(info, allowed_signatures)) { + return cpp_to_js(info.Env(), _model->clone()); + } + else { + OPENVINO_THROW("'clone'", ov::js::get_parameters_error_msg(info, allowed_signatures)); + } + } + catch(const std::exception& e) { + reportError(info.Env(), e.what()); + return info.Env().Undefined(); } - return cpp_to_js(env, _model->clone()); }