You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The fast path did not anticipate different ways to express a loose
equal string value (e.g., 1n == '+0001'). This is now fixed with the
downside that all primitives that could theoretically have equal
entries must go through a full comparison.
Only some strings, symbols, undefined, null and NaN can be detected
in a fast path as those entries have a strictly limited set of
possible equal entries.
PR-URL: #22495
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: John-David Dalton <[email protected]>
@@ -374,23 +374,52 @@ function setHasEqualElement(set, val1, strict, memo) {
374
374
returnfalse;
375
375
}
376
376
377
-
// Note: we currently run this multiple times for each loose key!
378
-
// This is done to prevent slowing down the average case.
379
-
functionsetHasLoosePrim(a,b,val){
380
-
constaltValues=findLooseMatchingPrimitives(val);
381
-
if(altValues===undefined)
382
-
returnfalse;
377
+
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness#Loose_equality_using
378
+
// Sadly it is not possible to detect corresponding values properly in case the
379
+
// type is a string, number, bigint or boolean. The reason is that those values
380
+
// can match lots of different string values (e.g., 1n == '+00001').
381
+
functionfindLooseMatchingPrimitives(prim){
382
+
switch(typeofprim){
383
+
case'undefined':
384
+
returnnull;
385
+
case'object': // Only pass in null as object!
386
+
returnundefined;
387
+
case'symbol':
388
+
returnfalse;
389
+
case'string':
390
+
prim=+prim;
391
+
// Loose equal entries exist only if the string is possible to convert to
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness#Loose_equality_using
435
-
functionfindLooseMatchingPrimitives(prim){
436
-
switch(typeofprim){
437
-
case'number':
438
-
if(prim===0){
439
-
return['','0',false];
440
-
}
441
-
if(prim===1){
442
-
return['1',true];
443
-
}
444
-
return[''+prim];
445
-
case'string':
446
-
if(prim===''||prim==='0'){
447
-
return[0,false];
448
-
}
449
-
if(prim==='1'){
450
-
return[1,true];
451
-
}
452
-
constnumber=+prim;
453
-
if(''+number===prim){
454
-
return[number];
455
-
}
456
-
return;
457
-
case'undefined':
458
-
return[null];
459
-
case'object': // Only pass in null as object!
460
-
return[undefined];
461
-
case'boolean':
462
-
if(prim===false){
463
-
return['','0',0];
464
-
}
465
-
return['1',1];
466
-
}
467
-
}
468
-
469
-
// This is a ugly but relatively fast way to determine if a loose equal entry
470
-
// currently has a correspondent matching entry. Otherwise checking for such
471
-
// values would be way more expensive (O(n^2)).
472
-
// Note: we currently run this multiple times for each loose key!
473
-
// This is done to prevent slowing down the average case.
0 commit comments