@@ -27,6 +27,15 @@ const { kEmptyObject } = require('internal/util');
2727
2828const converters = { __proto__ : null } ;
2929
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+
3039/**
3140 * @see https://webidl.spec.whatwg.org/#es-any
3241 * @param {any } V
@@ -37,7 +46,7 @@ converters.any = (V) => {
3746} ;
3847
3948converters . object = ( V , opts = kEmptyObject ) => {
40- if ( type ( V ) !== 'Object' ) {
49+ if ( type ( V ) !== OBJECT ) {
4150 throw makeException (
4251 'is not an object' ,
4352 kEmptyObject ,
@@ -234,37 +243,37 @@ function createEnumConverter(name, values) {
234243
235244// https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values
236245function type ( V ) {
237- if ( V === null )
238- return 'Null' ;
239-
240246 switch ( typeof V ) {
241247 case 'undefined' :
242- return 'Undefined' ;
248+ return UNDEFINED ;
243249 case 'boolean' :
244- return 'Boolean' ;
250+ return BOOLEAN ;
245251 case 'number' :
246- return 'Number' ;
252+ return NUMBER ;
247253 case 'string' :
248- return 'String' ;
254+ return STRING ;
249255 case 'symbol' :
250- return 'Symbol' ;
256+ return SYMBOL ;
251257 case 'bigint' :
252- return 'BigInt' ;
258+ return BIGINT ;
253259 case 'object' : // Fall through
254260 case 'function' : // Fall through
255261 default :
262+ if ( V === null ) {
263+ return NULL ;
264+ }
256265 // Per ES spec, typeof returns an implementation-defined value that is not
257266 // any of the existing ones for uncallable non-standard exotic objects.
258267 // Yet Type() which the Web IDL spec depends on returns Object for such
259268 // cases. So treat the default case as an object.
260- return 'Object' ;
269+ return OBJECT ;
261270 }
262271}
263272
264273// https://webidl.spec.whatwg.org/#es-sequence
265274function createSequenceConverter ( converter ) {
266275 return function ( V , opts = kEmptyObject ) {
267- if ( type ( V ) !== 'Object' ) {
276+ if ( type ( V ) !== OBJECT ) {
268277 throw makeException (
269278 'can not be converted to sequence.' ,
270279 opts ) ;
0 commit comments