From c4daa2545b78ae68fd96c1a1858804a4e79413f2 Mon Sep 17 00:00:00 2001 From: Manideep-Kanna <72699920+Manideep-Kanna@users.noreply.github.com> Date: Wed, 11 Dec 2024 17:31:04 +0530 Subject: [PATCH] Fix#27796 Added condition and test case for the getData parameter input functionality (#27843) This fixes #27796 Implemented the exception for the passing parameter scenario for getData function - Added condition to check if parameters are passed or not - Added tests in Tensor.test.js --- src/bindings/js/node/src/tensor.cpp | 6 ++++++ src/bindings/js/node/tests/unit/tensor.test.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/bindings/js/node/src/tensor.cpp b/src/bindings/js/node/src/tensor.cpp index 78785a10b2275b..14a68286e5372c 100644 --- a/src/bindings/js/node/src/tensor.cpp +++ b/src/bindings/js/node/src/tensor.cpp @@ -66,6 +66,12 @@ Napi::Object TensorWrap::wrap(Napi::Env env, ov::Tensor tensor) { } Napi::Value TensorWrap::get_data(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + if (info.Length() > 0) { + reportError(env, "getData() does not accept any arguments."); + return env.Undefined(); + } + auto type = _tensor.get_element_type(); switch (type) { diff --git a/src/bindings/js/node/tests/unit/tensor.test.js b/src/bindings/js/node/tests/unit/tensor.test.js index 656bdf9b122e58..2cd5115b5af2a8 100644 --- a/src/bindings/js/node/tests/unit/tensor.test.js +++ b/src/bindings/js/node/tests/unit/tensor.test.js @@ -121,6 +121,12 @@ describe('ov.Tensor tests', () => { assert.deepStrictEqual(tensor.getData(), data); }); + it('getData should throw an error if arguments are provided', () => { + const tensor = new ov.Tensor(ov.element.f32, shape, data); + assert.throws(() => tensor.getData(1), { + message: 'getData() does not accept any arguments.', + }); + }); it('test tensor.data setter - different element type throws', () => { const float64Data = Float64Array.from([1, 2, 3]); const tensor = new ov.Tensor(ov.element.f32, [1, 3]);