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