Skip to content

Commit

Permalink
Fix#27796 Added condition and test case for the getData parameter inp…
Browse files Browse the repository at this point in the history
…ut functionality (openvinotoolkit#27843)

This fixes openvinotoolkit#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
  • Loading branch information
Manideep-Kanna authored and 11happy committed Dec 23, 2024
1 parent caff123 commit 7c22a38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/bindings/js/node/src/tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/bindings/js/node/tests/unit/tensor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 7c22a38

Please sign in to comment.