docs: static long getLengthProperty(Context cx, Scriptable obj, boolean throwIfTooLarge) {
          // These will both give numeric lengths within Uint32 range.
          if (obj instanceof NativeString) {
              return ((NativeString)obj).getLength();
          }
          if (obj instanceof NativeArray) {
              return ((NativeArray)obj).getLength();
          }
  
          Object len = ScriptableObject.getProperty(obj, "length");
          if (len == Scriptable.NOT_FOUND) {
              // toUint32(undefined) == 0
              return 0;
          }
  
          double doubleLen = ScriptRuntime.toNumber(len);
          if (doubleLen > NativeNumber.MAX_SAFE_INTEGER) {
              if (throwIfTooLarge) {
                  String msg = ScriptRuntime.getMessage0("msg.arraylength.bad");
                  throw ScriptRuntime.constructError("RangeError", msg);
              }
              return (int) NativeNumber.MAX_SAFE_INTEGER;
          }
          if (doubleLen < 0) {
              return 0;
          }
          return ScriptRuntime.toUint32(len);
      }