Skip to content

Commit bf552fa

Browse files
jazellyaduh95
authored andcommitted
lib: prefer number to string in webidl type function
PR-URL: #55489 Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent aebf676 commit bf552fa

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

‎lib/internal/webidl.js‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ const { kEmptyObject } = require('internal/util');
2929

3030
constconverters={__proto__: null};
3131

32+
constUNDEFINED=1;
33+
constBOOLEAN=2;
34+
constSTRING=3;
35+
constSYMBOL=4;
36+
constNUMBER=5;
37+
constBIGINT=6;
38+
constNULL=7;
39+
constOBJECT=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

4150
converters.object=(V,opts=kEmptyObject)=>{
42-
if(type(V)!=='Object'){
51+
if(type(V)!==OBJECT){
4352
throwmakeException(
4453
'is not an object',
4554
kEmptyObject,
@@ -236,37 +245,37 @@ function createEnumConverter(name, values) {
236245

237246
// https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values
238247
functiontype(V){
239-
if(V===null)
240-
return'Null';
241-
242248
switch(typeofV){
243249
case'undefined':
244-
return'Undefined';
250+
returnUNDEFINED;
245251
case'boolean':
246-
return'Boolean';
252+
returnBOOLEAN;
247253
case'number':
248-
return'Number';
254+
returnNUMBER;
249255
case'string':
250-
return'String';
256+
returnSTRING;
251257
case'symbol':
252-
return'Symbol';
258+
returnSYMBOL;
253259
case'bigint':
254-
return'BigInt';
260+
returnBIGINT;
255261
case'object': // Fall through
256262
case'function': // Fall through
257263
default:
264+
if(V===null){
265+
returnNULL;
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+
returnOBJECT;
263272
}
264273
}
265274

266275
// https://webidl.spec.whatwg.org/#es-sequence
267276
functioncreateSequenceConverter(converter){
268277
returnfunction(V,opts=kEmptyObject){
269-
if(type(V)!=='Object'){
278+
if(type(V)!==OBJECT){
270279
throwmakeException(
271280
'can not be converted to sequence.',
272281
opts);

0 commit comments

Comments
 (0)