File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed
lib/node_modules/@stdlib/assert/instance-of Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 2020
2121// MODULES //
2222
23+ var hasHasInstanceSymbolSupport = require ( '@stdlib/assert/has-has-instance-symbol-support' ) ; // eslint-disable-line id-length
24+ var HasInstanceSymbol = require ( '@stdlib/symbol/has-instance' ) ;
2325var format = require ( '@stdlib/string/format' ) ;
2426
2527
28+ // VARIABLES //
29+
30+ var hasSupport = hasHasInstanceSymbolSupport ( ) ;
31+
32+
2633// MAIN //
2734
2835/**
@@ -55,7 +62,14 @@ var format = require( '@stdlib/string/format' );
5562*/
5663function instanceOf ( value , constructor ) {
5764 // TODO: replace with `isCallable` check
58- if ( typeof constructor !== 'function' ) {
65+ if (
66+ typeof constructor !== 'function' &&
67+ ! (
68+ hasSupport &&
69+ typeof constructor === 'object' &&
70+ typeof constructor [ HasInstanceSymbol ] === 'function'
71+ )
72+ ) {
5973 throw new TypeError ( format ( 'invalid argument. Second argument must be callable. Value: `%s`.' , constructor ) ) ;
6074 }
6175 return ( value instanceof constructor ) ;
Original file line number Diff line number Diff line change 2121// MODULES //
2222
2323var tape = require ( 'tape' ) ;
24+ var isArray = require ( '@stdlib/assert/is-array' ) ;
25+ var hasHasInstanceSymbolSupport = require ( '@stdlib/assert/has-has-instance-symbol-support' ) ; // eslint-disable-line id-length
26+ var HasInstanceSymbol = require ( '@stdlib/symbol/has-instance' ) ;
2427var inherit = require ( '@stdlib/utils/inherit' ) ;
2528var Boolean = require ( '@stdlib/boolean/ctor' ) ;
2629var Function = require ( '@stdlib/function/ctor' ) ;
@@ -29,6 +32,13 @@ var Object = require( '@stdlib/object/ctor' );
2932var instanceOf = require ( './../lib' ) ;
3033
3134
35+ // VARIABLES //
36+
37+ var opts = {
38+ 'skip' : ! hasHasInstanceSymbolSupport ( )
39+ } ;
40+
41+
3242// TESTS //
3343
3444tape ( 'main export is a function' , function test ( t ) {
@@ -176,3 +186,19 @@ tape( 'the function returns `false` if provided primitives and their correspondi
176186
177187 t . end ( ) ;
178188} ) ;
189+
190+ tape ( 'the function supports ES2015+ environments supporting `Symbol.hasInstance`' , opts , function test ( t ) {
191+ var bool ;
192+ var obj ;
193+ var x ;
194+
195+ x = [ 1 , 2 , 3 ] ;
196+
197+ obj = { } ;
198+ obj [ HasInstanceSymbol ] = isArray ;
199+
200+ bool = instanceOf ( x , obj ) ;
201+ t . strictEqual ( bool , true , 'returns expected value' ) ;
202+
203+ t . end ( ) ;
204+ } ) ;
You can’t perform that action at this time.
0 commit comments