File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,6 +29,15 @@ const { kEmptyObject } = require('internal/util');
2929
3030const converters = { __proto__ : null } ;
3131
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+
3241/**
3342 * @see https://webidl.spec.whatwg.org/#es-any
3443 * @param {any } V
@@ -39,7 +48,7 @@ converters.any = (V) => {
3948} ;
4049
4150converters . object = ( V , opts = kEmptyObject ) => {
42- if ( type ( V ) !== 'Object' ) {
51+ if ( type ( V ) !== OBJECT ) {
4352throw makeException (
4453'is not an object' ,
4554kEmptyObject ,
@@ -236,37 +245,37 @@ function createEnumConverter(name, values) {
236245
237246// https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values
238247function type ( V ) {
239- if ( V === null )
240- return 'Null' ;
241-
242248switch ( typeof V ) {
243249case 'undefined' :
244- return 'Undefined' ;
250+ return UNDEFINED ;
245251case 'boolean' :
246- return 'Boolean' ;
252+ return BOOLEAN ;
247253case 'number' :
248- return 'Number' ;
254+ return NUMBER ;
249255case 'string' :
250- return 'String' ;
256+ return STRING ;
251257case 'symbol' :
252- return 'Symbol' ;
258+ return SYMBOL ;
253259case 'bigint' :
254- return 'BigInt' ;
260+ return BIGINT ;
255261case 'object' : // Fall through
256262case 'function' : // Fall through
257263default :
264+ if ( V === null ) {
265+ return NULL ;
266+ }
258267// Per ES spec, typeof returns an implementation-defined value that is not
259268// any of the existing ones for uncallable non-standard exotic objects.
260269// Yet Type() which the Web IDL spec depends on returns Object for such
261270// cases. So treat the default case as an object.
262- return 'Object' ;
271+ return OBJECT ;
263272}
264273}
265274
266275// https://webidl.spec.whatwg.org/#es-sequence
267276function createSequenceConverter ( converter ) {
268277return function ( V , opts = kEmptyObject ) {
269- if ( type ( V ) !== 'Object' ) {
278+ if ( type ( V ) !== OBJECT ) {
270279throw makeException (
271280'can not be converted to sequence.' ,
272281opts ) ;
You can’t perform that action at this time.
0 commit comments