Repository: denoland/deno
File: ext/node/polyfills/_util/std_asserts.ts (TypeScript)

Code before:
    // unless it's mistreated as object
    if (
      a &&
      b &&
      ((ObjectPrototypeIsPrototypeOf(RegExpPrototype, a) &&
        ObjectPrototypeIsPrototypeOf(RegExpPrototype, b)) ||
        (ObjectPrototypeIsPrototypeOf(URLPrototype, a) &&
          ObjectPrototypeIsPrototypeOf(URLPrototype, b)))
    ) {
      return String(a) === String(b);
    }
    if (
      ObjectPrototypeIsPrototypeOf(DatePrototype, a) &&
      ObjectPrototypeIsPrototypeOf(DatePrototype, b)
    ) {
      const aTime = DatePrototypeGetTime(a);
      const bTime = DatePrototypeGetTime(b);
      // Check for NaN equality manually since NaN is not
      // equal to itself.
      if (NumberIsNaN(aTime) && NumberIsNaN(bTime)) {
        return true;
      }
      return aTime === bTime;
    }
    if (typeof a === "number" && typeof b === "number") {
      return NumberIsNaN(a) && NumberIsNaN(b) || ObjectIs(a, b);
    }
    if (ObjectIs(a, b)) {
      return true;
    }
    if (a && typeof a === "object" && b && typeof b === "object") {
      if (a && b && !constructorsEqual(a, b)) {
        return false;
      }
      if (
        ObjectPrototypeIsPrototypeOf(WeakMapPrototype, a) ||
        ObjectPrototypeIsPrototypeOf(WeakMapPrototype, b)
      ) {
        if (
          !(ObjectPrototypeIsPrototypeOf(WeakMapPrototype, a) &&
            ObjectPrototypeIsPrototypeOf(WeakMapPrototype, b))
        ) return false;
        throw new TypeError("cannot compare WeakMap instances");
      }
      if (
        ObjectPrototypeIsPrototypeOf(WeakSetPrototype, a) ||
        ObjectPrototypeIsPrototypeOf(WeakSetPrototype, b)
      ) {
        if (
          !(ObjectPrototypeIsPrototypeOf(WeakSetPrototype, a) &&
            ObjectPrototypeIsPrototypeOf(WeakSetPrototype, b))

Review comment (suggestion):
`Object.is(NaN, NaN)` is `true`.

```suggestion
      return ObjectIs(a, b);
```


Code after:
    // unless it's mistreated as object
    if (
      a &&
      b &&
      ((ObjectPrototypeIsPrototypeOf(RegExpPrototype, a) &&
        ObjectPrototypeIsPrototypeOf(RegExpPrototype, b)) ||
        (ObjectPrototypeIsPrototypeOf(URLPrototype, a) &&
          ObjectPrototypeIsPrototypeOf(URLPrototype, b)))
    ) {
      return String(a) === String(b);
    }
    if (
      ObjectPrototypeIsPrototypeOf(DatePrototype, a) &&
      ObjectPrototypeIsPrototypeOf(DatePrototype, b)
    ) {
      const aTime = DatePrototypeGetTime(a);
      const bTime = DatePrototypeGetTime(b);
      // Check for NaN equality manually since NaN is not
      // equal to itself.
      if (NumberIsNaN(aTime) && NumberIsNaN(bTime)) {
        return true;
      }
      return aTime === bTime;
    }
    if (typeof a === "number" && typeof b === "number") {
      return ObjectIs(a, b);
    }
    if (ObjectIs(a, b)) {
      return true;
    }
    if (a && typeof a === "object" && b && typeof b === "object") {
      if (a && b && !constructorsEqual(a, b)) {
        return false;
      }
      if (
        ObjectPrototypeIsPrototypeOf(WeakMapPrototype, a) ||
        ObjectPrototypeIsPrototypeOf(WeakMapPrototype, b)
      ) {
        if (
          !(ObjectPrototypeIsPrototypeOf(WeakMapPrototype, a) &&
            ObjectPrototypeIsPrototypeOf(WeakMapPrototype, b))
        ) return false;
        throw new TypeError("cannot compare WeakMap instances");
      }
      if (
        ObjectPrototypeIsPrototypeOf(WeakSetPrototype, a) ||
        ObjectPrototypeIsPrototypeOf(WeakSetPrototype, b)
      ) {
        if (
          !(ObjectPrototypeIsPrototypeOf(WeakSetPrototype, a) &&
            ObjectPrototypeIsPrototypeOf(WeakSetPrototype, b))