Skip to content

Commit

Permalink
[OV JS] Use type_validation for model.clone
Browse files Browse the repository at this point in the history
Make use of the allowed_signatures pattern
provided in the type_validation.hpp file to
validate the model.clone API arguments

Resolves: openvinotoolkit#25402

Signed-off-by: Nashez Zubair <[email protected]>
  • Loading branch information
nashez committed Aug 1, 2024
1 parent d0cb977 commit db32891
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/bindings/js/node/src/model_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModelWrap>(info),
Expand Down Expand Up @@ -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<std::string> 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());
}

0 comments on commit db32891

Please sign in to comment.