Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bf552fa

Browse filesBrowse 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
Copy full SHA for bf552fa

File tree

Expand file treeCollapse file tree

1 file changed

+21
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-12
lines changed
Open diff view settings
Collapse file

‎lib/internal/webidl.js‎

Copy file name to clipboardExpand all lines: lib/internal/webidl.js
+21-12Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ const { kEmptyObject } = require('internal/util');
2929

3030
const 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

4150
converters.object = (V, opts = kEmptyObject) => {
42-
if (type(V) !== 'Object') {
51+
if (type(V) !== OBJECT) {
4352
throw makeException(
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
function type(V) {
239-
if (V === null)
240-
return 'Null';
241-
242248
switch (typeof V) {
243249
case 'undefined':
244-
return 'Undefined';
250+
return UNDEFINED;
245251
case 'boolean':
246-
return 'Boolean';
252+
return BOOLEAN;
247253
case 'number':
248-
return 'Number';
254+
return NUMBER;
249255
case 'string':
250-
return 'String';
256+
return STRING;
251257
case 'symbol':
252-
return 'Symbol';
258+
return SYMBOL;
253259
case 'bigint':
254-
return 'BigInt';
260+
return BIGINT;
255261
case 'object': // Fall through
256262
case 'function': // Fall through
257263
default:
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
267276
function createSequenceConverter(converter) {
268277
return function(V, opts = kEmptyObject) {
269-
if (type(V) !== 'Object') {
278+
if (type(V) !== OBJECT) {
270279
throw makeException(
271280
'can not be converted to sequence.',
272281
opts);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.