From 096e0abad97d72f402187eab5f0489cf5280de72 Mon Sep 17 00:00:00 2001 From: Dhruv/ <154677013+DhruvArvindSingh@users.noreply.github.com> Date: Sat, 18 Jan 2025 17:30:32 +0530 Subject: [PATCH] refactor: update `math/base/assert/is-finite` native addon from C++ to C PR-URL: https://github.com/stdlib-js/stdlib/pull/4617 Reviewed-by: Athan Reines Co-authored-by: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> --- .../math/base/assert/is-finite/include.gypi | 2 +- .../math/base/assert/is-finite/manifest.json | 108 ++++++++++++------ .../math/base/assert/is-finite/src/addon.c | 42 +++++++ .../math/base/assert/is-finite/src/addon.cpp | 80 ------------- .../base/assert/is-finite/test/test.native.js | 21 ---- 5 files changed, 113 insertions(+), 140 deletions(-) create mode 100644 lib/node_modules/@stdlib/math/base/assert/is-finite/src/addon.c delete mode 100644 lib/node_modules/@stdlib/math/base/assert/is-finite/src/addon.cpp diff --git a/lib/node_modules/@stdlib/math/base/assert/is-finite/include.gypi b/lib/node_modules/@stdlib/math/base/assert/is-finite/include.gypi index ffd7702dc420..de5f9994b817 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-finite/include.gypi +++ b/lib/node_modules/@stdlib/math/base/assert/is-finite/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 1 ); + STDLIB_NAPI_ARGV_DOUBLE( env, x, argv, 0 ); + STDLIB_NAPI_CREATE_INT32( env, (int32_t)stdlib_base_is_finite( x ), out ); + return out; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) + diff --git a/lib/node_modules/@stdlib/math/base/assert/is-finite/src/addon.cpp b/lib/node_modules/@stdlib/math/base/assert/is-finite/src/addon.cpp deleted file mode 100644 index 76b46f4ad6ea..000000000000 --- a/lib/node_modules/@stdlib/math/base/assert/is-finite/src/addon.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/math/base/assert/is_finite.h" -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_math_base_assert_is_finite { - - /** - * Tests if a double-precision floating-point numeric value is finite. - * - * ## Notes - * - * - When called from JavaScript, the function expects one argument: - * - * - `x`: a number - */ - napi_value node_is_finite( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 1; - napi_value argv[ 1 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 1 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide a number." ); - return nullptr; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - - napi_value v; - double x; - if ( vtype0 == napi_number ) { - status = napi_get_value_double( env, argv[ 0 ], &x ); - assert( status == napi_ok ); - - status = napi_create_int32( env, (int32_t)stdlib_base_is_finite( x ), &v ); - assert( status == napi_ok ); - } else { - status = napi_create_int32( env, 0, &v ); - assert( status == napi_ok ); - } - - return v; - } - - napi_value Init( napi_env env, napi_value exports ) { - napi_status status; - napi_value fcn; - status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_is_finite, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_math_base_assert_is_finite diff --git a/lib/node_modules/@stdlib/math/base/assert/is-finite/test/test.native.js b/lib/node_modules/@stdlib/math/base/assert/is-finite/test/test.native.js index d42e1f02d8f0..23d2fe6b7226 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-finite/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-finite/test/test.native.js @@ -74,24 +74,3 @@ tape( 'the function returns `false` if provided `-infinity`', opts, function tes t.equal( isfinite( NINF ), false, 'returns false' ); t.end(); }); - -tape( 'the function returns `false` if not provided a finite number', opts, function test( t ) { - var values; - var i; - - values = [ - '5', - NaN, - true, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( isfinite( values[i] ), false, 'returns false' ); - } - t.end(); -});