diff --git a/lib/node_modules/@stdlib/assert/is-enumerable-property/lib/has_builtin.js b/lib/node_modules/@stdlib/assert/is-enumerable-property/lib/has_builtin.js new file mode 100644 index 000000000000..b2637bb5c0fb --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-enumerable-property/lib/has_builtin.js @@ -0,0 +1,28 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +'use strict'; + +// MAIN // + +var bool = ( typeof Object.prototype.propertyIsEnumerable === 'function' ); + + +// EXPORTS // + +module.exports = bool; diff --git a/lib/node_modules/@stdlib/assert/is-enumerable-property/lib/has_string_enumerability_bug.js b/lib/node_modules/@stdlib/assert/is-enumerable-property/lib/has_string_enumerability_bug.js index 3dffeb602791..d998143616cc 100644 --- a/lib/node_modules/@stdlib/assert/is-enumerable-property/lib/has_string_enumerability_bug.js +++ b/lib/node_modules/@stdlib/assert/is-enumerable-property/lib/has_string_enumerability_bug.js @@ -37,6 +37,9 @@ var bool; * @returns {boolean} boolean indicating whether an environment has the bug */ function detect() { + if ( typeof isEnum !== 'function' ) { + return false; + } return !isEnum.call( 'beep', '0' ); } diff --git a/lib/node_modules/@stdlib/assert/is-enumerable-property/lib/index.js b/lib/node_modules/@stdlib/assert/is-enumerable-property/lib/index.js index fdcf913a4b04..b95a7e73fe36 100644 --- a/lib/node_modules/@stdlib/assert/is-enumerable-property/lib/index.js +++ b/lib/node_modules/@stdlib/assert/is-enumerable-property/lib/index.js @@ -39,9 +39,21 @@ // MODULES // +var HAS_BUILTIN = require( './has_builtin.js' ); +var polyfill = require( './polyfill.js' ); var main = require( './main.js' ); +// MAIN // + +var isEnumerableProperty; +if ( HAS_BUILTIN ) { + isEnumerableProperty = main; +} else { + isEnumerableProperty = polyfill; +} + + // EXPORTS // -module.exports = main; +module.exports = isEnumerableProperty; diff --git a/lib/node_modules/@stdlib/assert/is-enumerable-property/lib/polyfill.js b/lib/node_modules/@stdlib/assert/is-enumerable-property/lib/polyfill.js new file mode 100644 index 000000000000..554f027fa927 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-enumerable-property/lib/polyfill.js @@ -0,0 +1,90 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +'use strict'; + +// MODULES // + +var Object = require( '@stdlib/object/ctor' ); + + +// VARIABLES // + +// NOTE: we explicitly avoid using `@stdlib/utils/keys` in order to avoid circular dependencies, as that package depends on this one. +var objectKeys = Object.keys; + + +// MAIN // + +/** +* Tests if an object's own property is enumerable. +* +* ## Notes +* +* - Enumerable own symbol properties are not detected (`Object.keys` cannot +* see symbols). +* +* @private +* @param {*} value - value to test +* @param {*} property - property to test +* @returns {boolean} boolean indicating if an object property is enumerable +* +* @example +* var beep = { +* 'boop': true +* }; +* +* var bool = isEnumerableProperty( beep, 'boop' ); +* // returns true +* +* @example +* var beep = { +* 'boop': true +* }; +* +* var bool = isEnumerableProperty( beep, 'hasOwnProperty' ); +* // returns false +*/ +function isEnumerableProperty( value, property ) { + var keys; + var prop; + var i; + + if ( + value === void 0 || + value === null + ) { + return false; + } + if ( typeof property === 'symbol' ) { + return false; + } + keys = objectKeys( Object( value ) ); + prop = String( property ); + for ( i = 0; i < keys.length; i++ ) { + if ( keys[ i ] === prop ) { + return true; + } + } + return false; +} + + +// EXPORTS // + +module.exports = isEnumerableProperty; diff --git a/lib/node_modules/@stdlib/assert/is-enumerable-property/test/test.js b/lib/node_modules/@stdlib/assert/is-enumerable-property/test/test.js index 2433d2b298e7..b165731d6c2d 100644 --- a/lib/node_modules/@stdlib/assert/is-enumerable-property/test/test.js +++ b/lib/node_modules/@stdlib/assert/is-enumerable-property/test/test.js @@ -22,6 +22,8 @@ var tape = require( 'tape' ); var proxyquire = require( 'proxyquire' ); +var polyfill = require( './../lib/polyfill.js' ); +var main = require( './../lib/main.js' ); var isEnumerableProperty = require( './../lib' ); @@ -155,3 +157,50 @@ tape( 'property values are coerced to strings', function test( t ) { t.end(); }); + +tape( 'the main export is a polyfill if an environment does not support native `propertyIsEnumerable`', function test( t ) { + var isEnumerableProperty = proxyquire( './../lib', { + './has_builtin.js': false + }); + t.strictEqual( isEnumerableProperty, polyfill, 'returns expected value' ); + t.end(); +}); + +tape( 'the main export is a wrapper around a builtin if an environment supports native `propertyIsEnumerable`', function test( t ) { + var isEnumerableProperty = proxyquire( './../lib', { + './has_builtin.js': true + }); + t.strictEqual( isEnumerableProperty, main, 'returns expected value' ); + t.end(); +}); + +tape( 'the function works when native `propertyIsEnumerable` is not supported (polyfill fallback)', function test( t ) { + var isEnumerableProperty = proxyquire( './../lib', { + './has_builtin.js': false + }); + var bool; + + bool = isEnumerableProperty({ + 'a': 'b' + }, 'a' ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = isEnumerableProperty({ + 'a': 'b' + }, 'c' ); + t.strictEqual( bool, false, 'returns expected value' ); + + bool = isEnumerableProperty( [ 1, 2, 3 ], '1' ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = isEnumerableProperty( {}, 'hasOwnProperty' ); + t.strictEqual( bool, false, 'returns expected value' ); + + bool = isEnumerableProperty( null, 'beep' ); + t.strictEqual( bool, false, 'returns expected value' ); + + bool = isEnumerableProperty( void 0, 'beep' ); + t.strictEqual( bool, false, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/assert/is-enumerable-property/test/test.polyfill.js b/lib/node_modules/@stdlib/assert/is-enumerable-property/test/test.polyfill.js new file mode 100644 index 000000000000..9c4c5d84b94c --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-enumerable-property/test/test.polyfill.js @@ -0,0 +1,167 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasSymbolSupport = require( '@stdlib/assert/has-symbol-support' ); +var Symbol = require( '@stdlib/symbol/ctor' ); +var polyfill = require( './../lib/polyfill.js' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasSymbolSupport() +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof polyfill, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `false` if provided `null` or `undefined`', function test( t ) { + var bool; + + bool = polyfill( null, 'a' ); + t.strictEqual( bool, false, 'returns false when null' ); + + bool = polyfill( void 0, 'a' ); + t.strictEqual( bool, false, 'returns false when undefined' ); + + t.end(); +}); + +tape( 'the function returns `true` if an object property is enumerable', function test( t ) { + var bool; + var obj; + + obj = { + 'a': 'b', + 'c': 1 + }; + bool = polyfill( obj, 'a' ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = polyfill( obj, 'c' ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = polyfill( [ 1, 2, 3 ], '1' ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = polyfill( [ 1, 2, 3 ], 1 ); + t.strictEqual( bool, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `false` if an object property is not enumerable', function test( t ) { + var bool; + var obj; + + obj = { + 'a': 'b' + }; + bool = polyfill( obj, 'c' ); + t.strictEqual( bool, false, 'returns expected value' ); + + bool = polyfill( [ 'a' ], 'length' ); + t.strictEqual( bool, false, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `false` if provided an inherited property', function test( t ) { + var bool; + + bool = polyfill( {}, 'hasOwnProperty' ); + t.strictEqual( bool, false, 'returns expected value' ); + + bool = polyfill( {}, 'toString' ); + t.strictEqual( bool, false, 'returns expected value' ); + + bool = polyfill( {}, 'constructor' ); + t.strictEqual( bool, false, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `true` for enumerable string indices', function test( t ) { + var bool; + + bool = polyfill( 'beep', '1' ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = polyfill( 'beep', 1 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = polyfill( 'beep', 'length' ); + t.strictEqual( bool, false, 'returns expected value' ); + + bool = polyfill( 'beep', '10' ); + t.strictEqual( bool, false, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function coerces property values to strings', function test( t ) { + var bool; + var prop; + var obj; + + obj = { + 'null': true, + '[object Object]': true + }; + bool = polyfill( obj, null ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = polyfill( obj, {} ); + t.strictEqual( bool, true, 'returns expected value' ); + + prop = { + 'toString': function toString() { + return 'foo'; + }, + 'valueOf': function valueOf() { + return 'bar'; + } + }; + obj = { + 'foo': true, + 'bar': false + }; + bool = polyfill( obj, prop ); + t.strictEqual( bool, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `false` when provided a symbol', opts, function test( t ) { + var bool; + + bool = polyfill( {}, Symbol( 'a' ) ); + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/assert/is-plain-object/lib/main.js b/lib/node_modules/@stdlib/assert/is-plain-object/lib/main.js index 2f4ec883044c..0eae568511ab 100644 --- a/lib/node_modules/@stdlib/assert/is-plain-object/lib/main.js +++ b/lib/node_modules/@stdlib/assert/is-plain-object/lib/main.js @@ -92,16 +92,17 @@ function isPlainObject( value ) { isFunction( proto.constructor ) && nativeClass( proto.constructor ) === '[object Function]' && - // Test for object-specific method: - hasOwnProp( proto, 'isPrototypeOf' ) && - isFunction( proto.isPrototypeOf ) && - ( // Test if the prototype matches the global `Object` prototype (same realm): proto === objectPrototype || - // Test that all properties are own properties (cross-realm; *most* likely a plain object): - ownProps( value ) + ( + // Test that all properties are own properties (cross-realm). + // Prototype must have object methods: + hasOwnProp( proto, 'isPrototypeOf' ) && + isFunction( proto.isPrototypeOf ) && + ownProps( value ) + ) ) ); } diff --git a/lib/node_modules/@stdlib/assert/is-plain-object/test/test.js b/lib/node_modules/@stdlib/assert/is-plain-object/test/test.js index 16a602c134c8..28c6e64e11de 100644 --- a/lib/node_modules/@stdlib/assert/is-plain-object/test/test.js +++ b/lib/node_modules/@stdlib/assert/is-plain-object/test/test.js @@ -193,3 +193,39 @@ tape( 'the function returns `true` if provided a value whose prototype does not t.strictEqual( isPlainObject( new Foo() ), true, 'returns expected value' ); t.end(); }); + +tape( 'the function returns `true` if provided a plain object in the same realm even when `isPrototypeOf` is missing', function test( t ) { + var isPlainObject = proxyquire( './../lib/main.js', { + '@stdlib/assert/has-own-property': hasOwnProp + }); + + t.strictEqual( isPlainObject( {} ), true, 'returns expected value' ); + t.strictEqual( isPlainObject({ + 'a': 'b' + }), true, 'returns expected value' ); + t.end(); + + function hasOwnProp( obj, prop ) { + if ( prop === 'isPrototypeOf' ) { + return false; + } + return Object.prototype.hasOwnProperty.call( obj, prop ); + } +}); + +tape( 'the function returns `false` if provided a value whose prototype does not equal the global `Object` prototype and lacks `isPrototypeOf` (cross-realm)', function test( t ) { + function Foo() { + this.foo = 'bar'; + return this; + } + Foo.prototype = Object.create( Object.prototype ); + + defineProperty( Foo.prototype, 'constructor', { + 'configurable': true, + 'enumerable': false, + 'value': Foo + }); + + t.strictEqual( isPlainObject( new Foo() ), false, 'returns expected value' ); + t.end(); +});