@@ -7,20 +7,36 @@ function uncurryThis(f) {
7
7
return f . call . bind ( f ) ;
8
8
}
9
9
10
- var TypedArrayPrototype = Object . getPrototypeOf ( Uint8Array . prototype ) ;
10
+ var supported = {
11
+ BigInt : typeof BigInt !== 'undefined' ,
12
+ Symbol : typeof Symbol !== 'undefined' ,
13
+ Uint8Array : typeof Uint8Array !== 'undefined' ,
14
+ ArrayBuffer : typeof ArrayBuffer !== 'undefined'
15
+ } ;
11
16
12
- var TypedArrayProto_toStringTag =
13
- uncurryThis (
14
- Object . getOwnPropertyDescriptor ( TypedArrayPrototype ,
15
- Symbol . toStringTag ) . get ) ;
17
+ if ( supported . Uint8Array ) {
18
+ var TypedArrayPrototype = Object . getPrototypeOf ( Uint8Array . prototype ) ;
19
+
20
+ var TypedArrayProto_toStringTag =
21
+ uncurryThis (
22
+ Object . getOwnPropertyDescriptor ( TypedArrayPrototype ,
23
+ Symbol . toStringTag ) . get ) ;
24
+
25
+ }
16
26
17
27
var ObjectToString = uncurryThis ( Object . prototype . toString ) ;
18
28
19
29
var numberValue = uncurryThis ( Number . prototype . valueOf ) ;
20
30
var stringValue = uncurryThis ( String . prototype . valueOf ) ;
21
31
var booleanValue = uncurryThis ( Boolean . prototype . valueOf ) ;
22
- var bigIntValue = uncurryThis ( BigInt . prototype . valueOf ) ;
23
- var symbolValue = uncurryThis ( Symbol . prototype . valueOf ) ;
32
+
33
+ if ( supported . BigInt ) {
34
+ var bigIntValue = uncurryThis ( BigInt . prototype . valueOf ) ;
35
+ }
36
+
37
+ if ( supported . Symbol ) {
38
+ var symbolValue = uncurryThis ( Symbol . prototype . valueOf ) ;
39
+ }
24
40
25
41
function checkBoxedPrimitive ( value , prototypeValueOf ) {
26
42
if ( typeof value !== 'object' ) {
@@ -35,78 +51,95 @@ function checkBoxedPrimitive(value, prototypeValueOf) {
35
51
}
36
52
37
53
var methods = [
54
+ {
55
+ name : 'isArgumentsObject' ,
56
+ function : require ( 'is-arguments' ) ,
57
+ } ,
38
58
{
39
59
name : 'isArrayBufferView' ,
60
+ supported : supported . ArrayBuffer ,
40
61
function : ArrayBuffer . isView ,
41
62
} ,
42
63
{
43
64
name : 'isTypedArray' ,
65
+ supported : supported . Uint8Array ,
44
66
function : function ( value ) {
45
67
return TypedArrayProto_toStringTag ( value ) !== undefined ;
46
68
}
47
69
} ,
48
70
{
49
71
name : 'isUint8Array' ,
72
+ supported : supported . Uint8Array ,
50
73
function : function ( value ) {
51
74
return TypedArrayProto_toStringTag ( value ) === 'Uint8Array' ;
52
75
}
53
76
} ,
54
77
{
55
78
name : 'isUint8ClampedArray' ,
79
+ supported : supported . Uint8Array ,
56
80
function : function ( value ) {
57
81
return TypedArrayProto_toStringTag ( value ) === 'Uint8ClampedArray' ;
58
82
}
59
83
} ,
60
84
{
61
85
name : 'isUint16Array' ,
86
+ supported : supported . Uint8Array ,
62
87
function : function ( value ) {
63
88
return TypedArrayProto_toStringTag ( value ) === 'Uint16Array' ;
64
89
}
65
90
} ,
66
91
{
67
92
name : 'isUint32Array' ,
93
+ supported : supported . Uint8Array ,
68
94
function : function ( value ) {
69
95
return TypedArrayProto_toStringTag ( value ) === 'Uint32Array' ;
70
96
}
71
97
} ,
72
98
{
73
99
name : 'isInt8Array' ,
100
+ supported : supported . Uint8Array ,
74
101
function : function ( value ) {
75
102
return TypedArrayProto_toStringTag ( value ) === 'Int8Array' ;
76
103
}
77
104
} ,
78
105
{
79
106
name : 'isInt16Array' ,
107
+ supported : supported . Uint8Array ,
80
108
function : function ( value ) {
81
109
return TypedArrayProto_toStringTag ( value ) === 'Int16Array' ;
82
110
}
83
111
} ,
84
112
{
85
113
name : 'isInt32Array' ,
114
+ supported : supported . Uint8Array ,
86
115
function : function ( value ) {
87
116
return TypedArrayProto_toStringTag ( value ) === 'Int32Array' ;
88
117
}
89
118
} ,
90
119
{
91
120
name : 'isFloat32Array' ,
121
+ supported : supported . Uint8Array ,
92
122
function : function ( value ) {
93
123
return TypedArrayProto_toStringTag ( value ) === 'Float32Array' ;
94
124
}
95
125
} ,
96
126
{
97
127
name : 'isFloat64Array' ,
128
+ supported : supported . Uint8Array ,
98
129
function : function ( value ) {
99
130
return TypedArrayProto_toStringTag ( value ) === 'Float64Array' ;
100
131
}
101
132
} ,
102
133
{
103
134
name : 'isBigInt64Array' ,
135
+ supported : supported . Uint8Array ,
104
136
function : function ( value ) {
105
137
return TypedArrayProto_toStringTag ( value ) === 'BigInt64Array' ;
106
138
}
107
139
} ,
108
140
{
109
141
name : 'isBigUint64Array' ,
142
+ supported : supported . Uint8Array ,
110
143
function : function ( value ) {
111
144
return TypedArrayProto_toStringTag ( value ) === 'BigUint64Array' ;
112
145
}
@@ -153,12 +186,6 @@ var methods = [
153
186
return ObjectToString ( value ) === '[object DataView]' ;
154
187
}
155
188
} ,
156
- {
157
- name : 'isArrayBuffer' ,
158
- function : function ( value ) {
159
- return ObjectToString ( value ) === '[object ArrayBuffer]' ;
160
- }
161
- } ,
162
189
{
163
190
name : 'isSharedArrayBuffer' ,
164
191
function : function ( value ) {
@@ -221,12 +248,14 @@ var methods = [
221
248
} ,
222
249
{
223
250
name : 'isBigIntObject' ,
251
+ supported : supported . BigInt ,
224
252
function : function ( value ) {
225
253
return checkBoxedPrimitive ( value , bigIntValue ) ;
226
254
}
227
255
} ,
228
256
{
229
257
name : 'isSymbolObject' ,
258
+ supported : supported . Symbol ,
230
259
function : function ( value ) {
231
260
return checkBoxedPrimitive ( value , symbolValue ) ;
232
261
}
@@ -238,45 +267,41 @@ var methods = [
238
267
exports . isNumberObject ( value ) ||
239
268
exports . isStringObject ( value ) ||
240
269
exports . isBooleanObject ( value ) ||
241
- exports . isBigIntObject ( value ) ||
242
- exports . isSymbolObject ( value )
270
+ ( supported . BigInt && exports . isBigIntObject ( value ) ) ||
271
+ ( supported . Symbol && exports . isSymbolObject ( value ) )
243
272
) ;
244
273
}
245
274
} ,
246
275
{
247
276
name : 'isAnyArrayBuffer' ,
277
+ supported : supported . Uint8Array ,
248
278
function : function ( value ) {
249
279
return (
250
280
exports . isArrayBuffer ( value ) ||
251
281
exports . isSharedArrayBuffer ( value )
252
282
) ;
253
283
}
254
- }
255
- ] ;
256
-
257
- methods . forEach ( function ( method ) {
258
- exports [ method . name ] = method . function ;
259
- } ) ;
260
-
261
- Object . defineProperty ( exports , 'isProxy' , {
262
- enumerable : false ,
263
- value : function ( ) {
264
- throw new Error ( 'Proxies can not be detected in userland' ) ;
265
284
} ,
266
- } ) ;
267
-
268
- Object . defineProperty ( exports , 'isExternal' , {
269
- enumerable : false ,
270
- value : function ( ) {
271
- throw new Error ( 'External values can not be detected in userland' ) ;
285
+ {
286
+ name : 'isProxy' ,
287
+ supported : false
272
288
} ,
273
- } ) ;
274
-
275
- Object . defineProperty ( exports , 'isModuleNamespaceObject' , {
276
- enumerable : false ,
277
- value : function ( ) {
278
- throw new Error ( 'Module namespace objects are not supported' ) ;
289
+ {
290
+ name : 'isExternal' ,
291
+ supported : false
279
292
} ,
280
- } ) ;
293
+ {
294
+ name : 'isModuleNamespaceObject' ,
295
+ supported : false
296
+ } ,
297
+ ] ;
281
298
282
- exports . isArgumentsObject = require ( 'is-arguments' ) ;
299
+ methods . forEach ( function ( method ) {
300
+ const supported = method . supported !== false ;
301
+ Object . defineProperty ( exports , method . name , {
302
+ enumerable : supported ,
303
+ value : supported ? method . function : function ( ) {
304
+ throw new Error ( method . name + ' is not supported' ) ;
305
+ }
306
+ } ) ;
307
+ } ) ;
0 commit comments