From 014d19c765512c22c36e3090be297ce709ae13d5 Mon Sep 17 00:00:00 2001 From: adismort14 <104080429+adismort14@users.noreply.github.com> Date: Wed, 17 Apr 2024 17:41:46 +0530 Subject: [PATCH] Added argument check and corresponding node runner test for the get_shape method (#23637) This Fixes #23441 issue. Details: 1. Modified get_shape() method to report error in case any argument is passed. 2. Added Required Tests for the above in `tensor.test.js`. --------- Co-authored-by: Vishniakov Nikolai Co-authored-by: Alicja Miloszewska --- src/bindings/js/node/src/tensor.cpp | 4 ++++ src/bindings/js/node/tests/tensor.test.js | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/bindings/js/node/src/tensor.cpp b/src/bindings/js/node/src/tensor.cpp index 9324e6abe3b90a..084ec4e77bafcd 100644 --- a/src/bindings/js/node/src/tensor.cpp +++ b/src/bindings/js/node/src/tensor.cpp @@ -133,6 +133,10 @@ Napi::Value TensorWrap::get_data(const Napi::CallbackInfo& info) { } Napi::Value TensorWrap::get_shape(const Napi::CallbackInfo& info) { + if (info.Length() > 0) { + reportError(info.Env(), "No parameters are allowed for the getShape() method."); + return info.Env().Undefined(); + } return cpp_to_js(info, _tensor.get_shape()); } diff --git a/src/bindings/js/node/tests/tensor.test.js b/src/bindings/js/node/tests/tensor.test.js index b54d164f8c3604..3a26c86cdc7305 100644 --- a/src/bindings/js/node/tests/tensor.test.js +++ b/src/bindings/js/node/tests/tensor.test.js @@ -120,6 +120,14 @@ describe('Tensor shape', () => { /Cannot convert argument./ ); }); + + it('getShape() method does not accept parameters', () => { + const tensor = new ov.Tensor(ov.element.f32, [1, 3, 224, 224], data); + assert.throws( + () => tensor.getShape(1, 2, 3), + { message: 'No parameters are allowed for the getShape() method.'} + ); + }); }); describe('Tensor element type', () => {