MCPcopy Create free account
hub / github.com/dynjs/dynjs / compareRelational

Method compareRelational

src/main/java/org/dynjs/runtime/Types.java:490–549  ·  view source on GitHub ↗
(ExecutionContext context, Object x,
            Object y, boolean leftFirst)

Source from the content-addressed store, hash-verified

488 }
489
490 public static Object compareRelational(ExecutionContext context, Object x,
491 Object y, boolean leftFirst) {
492 // 11.8.5
493
494 Object px = null;
495 Object py = null;
496
497 if (leftFirst) {
498 px = toPrimitive(context, x, "Number");
499 py = toPrimitive(context, y, "Number");
500 } else {
501 py = toPrimitive(context, y, "Number");
502 px = toPrimitive(context, x, "Number");
503 }
504
505 if (px instanceof String && py instanceof String) {
506 String sx = (String) px;
507 String sy = (String) py;
508
509 if (sx.compareTo(sy) < 0) {
510 return true;
511 }
512
513 return false;
514 } else {
515 Number nx = toNumber(context, px);
516 Number ny = toNumber(context, py);
517
518 if (Double.isNaN(nx.doubleValue()) || Double.isNaN(ny.doubleValue())) {
519 return Types.UNDEFINED;
520 }
521
522 if (nx.equals(ny)) {
523 return false;
524 }
525
526 if (nx.doubleValue() == Double.POSITIVE_INFINITY) {
527 return false;
528 }
529
530 if (ny.doubleValue() == Double.POSITIVE_INFINITY) {
531 return true;
532 }
533
534 if (ny.doubleValue() == Double.NEGATIVE_INFINITY) {
535 return false;
536 }
537
538 if (nx.doubleValue() == Double.NEGATIVE_INFINITY) {
539 return true;
540 }
541
542 if (nx.doubleValue() < ny.doubleValue()) {
543 return true;
544 }
545
546 return false;
547 }

Callers 3

executeMethod · 0.95
interpretMethod · 0.95
visitMethod · 0.95

Calls 4

toPrimitiveMethod · 0.95
toNumberMethod · 0.95
compareToMethod · 0.80
isNaNMethod · 0.45

Tested by

no test coverage detected