docs: public static double toNumber(Object val)
      {
          for (;;) {
              if (val instanceof Number)
                  return ((Number) val).doubleValue();
              if (val == null)
                  return +0.0;
              if (val == Undefined.instance)
                  return NaN;
              if (val instanceof String)
                  return toNumber((String) val);
              if (val instanceof CharSequence)
                  return toNumber(val.toString());
              if (val instanceof Boolean)
                  return ((Boolean) val).booleanValue() ? 1 : +0.0;
              if (val instanceof Symbol)
                  throw typeError0("msg.not.a.number");
              if (val instanceof Scriptable) {
                  val = ((Scriptable) val).getDefaultValue(NumberClass);
                  if ((val instanceof Scriptable) && !isSymbol(val))
                      throw errorWithClassName("msg.primitive.expected", val);
                  continue;
              }
              warnAboutNonJSObject(val);
              return NaN;
          }
      }