@@ -27,6 +27,15 @@ const { kEmptyObject } = require('internal/util');
27
27
28
28
const converters = { __proto__ : null } ;
29
29
30
+ const UNDEFINED = 1 ;
31
+ const BOOLEAN = 2 ;
32
+ const STRING = 3 ;
33
+ const SYMBOL = 4 ;
34
+ const NUMBER = 5 ;
35
+ const BIGINT = 6 ;
36
+ const NULL = 7 ;
37
+ const OBJECT = 8 ;
38
+
30
39
/**
31
40
* @see https://webidl.spec.whatwg.org/#es-any
32
41
* @param {any } V
@@ -37,7 +46,7 @@ converters.any = (V) => {
37
46
} ;
38
47
39
48
converters . object = ( V , opts = kEmptyObject ) => {
40
- if ( type ( V ) !== 'Object' ) {
49
+ if ( type ( V ) !== OBJECT ) {
41
50
throw makeException (
42
51
'is not an object' ,
43
52
kEmptyObject ,
@@ -234,37 +243,37 @@ function createEnumConverter(name, values) {
234
243
235
244
// https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values
236
245
function type ( V ) {
237
- if ( V === null )
238
- return 'Null' ;
239
-
240
246
switch ( typeof V ) {
241
247
case 'undefined' :
242
- return 'Undefined' ;
248
+ return UNDEFINED ;
243
249
case 'boolean' :
244
- return 'Boolean' ;
250
+ return BOOLEAN ;
245
251
case 'number' :
246
- return 'Number' ;
252
+ return NUMBER ;
247
253
case 'string' :
248
- return 'String' ;
254
+ return STRING ;
249
255
case 'symbol' :
250
- return 'Symbol' ;
256
+ return SYMBOL ;
251
257
case 'bigint' :
252
- return 'BigInt' ;
258
+ return BIGINT ;
253
259
case 'object' : // Fall through
254
260
case 'function' : // Fall through
255
261
default :
262
+ if ( V === null ) {
263
+ return NULL ;
264
+ }
256
265
// Per ES spec, typeof returns an implementation-defined value that is not
257
266
// any of the existing ones for uncallable non-standard exotic objects.
258
267
// Yet Type() which the Web IDL spec depends on returns Object for such
259
268
// cases. So treat the default case as an object.
260
- return 'Object' ;
269
+ return OBJECT ;
261
270
}
262
271
}
263
272
264
273
// https://webidl.spec.whatwg.org/#es-sequence
265
274
function createSequenceConverter ( converter ) {
266
275
return function ( V , opts = kEmptyObject ) {
267
- if ( type ( V ) !== 'Object' ) {
276
+ if ( type ( V ) !== OBJECT ) {
268
277
throw makeException (
269
278
'can not be converted to sequence.' ,
270
279
opts ) ;
0 commit comments