private Object ensureId(int id) {
   Object[] array = valueArray;
   if (array == null) {
     synchronized (this) {
       array = valueArray;
       if (array == null) {
         array = new Object[maxId * SLOT_SPAN];
         valueArray = array;
         attributeArray = new short[maxId];
       }
     }
   }
   int valueSlot = (id - 1) * SLOT_SPAN + VALUE_SLOT;
   Object value = array[valueSlot];
   if (value == null) {
     if (id == constructorId) {
       initSlot(constructorId, "constructor", constructor, constructorAttrs);
       constructor = null; // no need to refer it any longer
     } else {
       obj.initPrototypeId(id);
     }
     value = array[valueSlot];
     if (value == null) {
       throw new IllegalStateException(
           obj.getClass().getName()
               + ".initPrototypeId(int id) "
               + "did not initialize id="
               + id);
     }
   }
   return value;
 }
 final int findId(String name) {
   Object[] array = valueArray;
   if (array == null) {
     return obj.findPrototypeId(name);
   }
   int id = lastFoundId;
   if (name == array[(id - 1) * SLOT_SPAN + NAME_SLOT]) {
     return id;
   }
   id = obj.findPrototypeId(name);
   if (id != 0) {
     int nameSlot = (id - 1) * SLOT_SPAN + NAME_SLOT;
     // Make cache to work!
     array[nameSlot] = name;
     lastFoundId = id;
   }
   return id;
 }
 final IdFunctionObject createPrecachedConstructor() {
   if (constructorId != 0) throw new IllegalStateException();
   constructorId = obj.findPrototypeId("constructor");
   if (constructorId == 0) {
     throw new IllegalStateException("No id for constructor property");
   }
   obj.initPrototypeId(constructorId);
   if (constructor == null) {
     throw new IllegalStateException(
         obj.getClass().getName()
             + ".initPrototypeId() did not "
             + "initialize id="
             + constructorId);
   }
   constructor.initFunction(obj.getClassName(), ScriptableObject.getTopLevelScope(obj));
   constructor.markAsConstructor(obj);
   return constructor;
 }
    final void initValue(int id, String name, Object value, int attributes) {
      if (!(1 <= id && id <= maxId)) throw new IllegalArgumentException();
      if (name == null) throw new IllegalArgumentException();
      if (value == NOT_FOUND) throw new IllegalArgumentException();
      ScriptableObject.checkValidAttributes(attributes);
      if (obj.findPrototypeId(name) != id) throw new IllegalArgumentException(name);

      if (id == constructorId) {
        if (!(value instanceof IdFunctionObject)) {
          throw new IllegalArgumentException(
              "consructor should be initialized with IdFunctionObject");
        }
        constructor = (IdFunctionObject) value;
        constructorAttrs = (short) attributes;
        return;
      }

      initSlot(id, name, value, attributes);
    }