Exemplo n.º 1
0
 @Override
 public void defineOwnProperty(Context cx, Object key, ScriptableObject desc) {
   if (key instanceof String) {
     String name = (String) key;
     int info = findInstanceIdInfo(name);
     if (info != 0) {
       int id = (info & 0xFFFF);
       if (isAccessorDescriptor(desc)) {
         delete(id); // it will be replaced with a slot
       } else {
         int attr = (info >>> 16);
         Object value = getProperty(desc, "value");
         setInstanceIdValue(id, value == NOT_FOUND ? Undefined.instance : value);
         setAttributes(id, applyDescriptorToAttributeBitset(attr, desc));
         return;
       }
     }
     if (prototypeValues != null) {
       int id = prototypeValues.findId(name);
       if (id != 0) {
         if (isAccessorDescriptor(desc)) {
           prototypeValues.delete(id); // it will be replaced with a slot
         } else {
           int attr = prototypeValues.getAttributes(id);
           Object value = getProperty(desc, "value");
           prototypeValues.set(id, this, value == NOT_FOUND ? Undefined.instance : value);
           prototypeValues.setAttributes(id, applyDescriptorToAttributeBitset(attr, desc));
           return;
         }
       }
     }
   }
   super.defineOwnProperty(cx, key, desc);
 }
Exemplo n.º 2
0
  private ScriptableObject getBuiltInDescriptor(String name) {
    Object value = null;
    int attr = EMPTY;

    Scriptable scope = getParentScope();
    if (scope == null) {
      scope = this;
    }

    int info = findInstanceIdInfo(name);
    if (info != 0) {
      int id = (info & 0xFFFF);
      value = getInstanceIdValue(id);
      attr = (info >>> 16);
      return buildDataDescriptor(scope, value, attr);
    }
    if (prototypeValues != null) {
      int id = prototypeValues.findId(name);
      if (id != 0) {
        value = prototypeValues.get(id);
        attr = prototypeValues.getAttributes(id);
        return buildDataDescriptor(scope, value, attr);
      }
    }
    return null;
  }
Exemplo n.º 3
0
 @Override
 public void delete(String name) {
   int info = findInstanceIdInfo(name);
   if (info != 0) {
     // Let the super class to throw exceptions for sealed objects
     if (!isSealed()) {
       int attr = (info >>> 16);
       if ((attr & PERMANENT) == 0) {
         int id = (info & 0xFFFF);
         setInstanceIdValue(id, NOT_FOUND);
       }
       return;
     }
   }
   if (prototypeValues != null) {
     int id = prototypeValues.findId(name);
     if (id != 0) {
       if (!isSealed()) {
         prototypeValues.delete(id);
       }
       return;
     }
   }
   super.delete(name);
 }
Exemplo n.º 4
0
 @Override
 public void put(String name, Scriptable start, Object value) {
   int info = findInstanceIdInfo(name);
   if (info != 0) {
     if (start == this && isSealed()) {
       throw Context.reportRuntimeError1("msg.modify.sealed", name);
     }
     int attr = (info >>> 16);
     if ((attr & READONLY) == 0) {
       if (start == this) {
         int id = (info & 0xFFFF);
         setInstanceIdValue(id, value);
       } else {
         start.put(name, start, value);
       }
     }
     return;
   }
   if (prototypeValues != null) {
     int id = prototypeValues.findId(name);
     if (id != 0) {
       if (start == this && isSealed()) {
         throw Context.reportRuntimeError1("msg.modify.sealed", name);
       }
       prototypeValues.set(id, start, value);
       return;
     }
   }
   super.put(name, start, value);
 }
Exemplo n.º 5
0
 @Override
 public int getAttributes(String name) {
   int info = findInstanceIdInfo(name);
   if (info != 0) {
     int attr = (info >>> 16);
     return attr;
   }
   if (prototypeValues != null) {
     int id = prototypeValues.findId(name);
     if (id != 0) {
       return prototypeValues.getAttributes(id);
     }
   }
   return super.getAttributes(name);
 }
Exemplo n.º 6
0
 private void writeObject(ObjectOutputStream stream) throws IOException {
   stream.defaultWriteObject();
   int maxPrototypeId = 0;
   if (prototypeValues != null) {
     maxPrototypeId = prototypeValues.getMaxId();
   }
   stream.writeInt(maxPrototypeId);
 }
Exemplo n.º 7
0
 @Override
 public Object get(String name, Scriptable start) {
   int info = findInstanceIdInfo(name);
   if (info != 0) {
     int id = (info & 0xFFFF);
     Object value = getInstanceIdValue(id);
     if (value != NOT_FOUND) return value;
   }
   if (prototypeValues != null) {
     int id = prototypeValues.findId(name);
     if (id != 0) {
       Object value = prototypeValues.get(id);
       if (value != NOT_FOUND) return value;
     }
   }
   return super.get(name, start);
 }
Exemplo n.º 8
0
 public final void initPrototypeConstructor(IdFunctionObject f) {
   int id = prototypeValues.constructorId;
   if (id == 0) throw new IllegalStateException();
   if (f.methodId() != id) throw new IllegalArgumentException();
   if (isSealed()) {
     f.sealObject();
   }
   prototypeValues.initValue(id, "constructor", f, DONTENUM);
 }
Exemplo n.º 9
0
 @Override
 public boolean has(String name, Scriptable start) {
   int info = findInstanceIdInfo(name);
   if (info != 0) {
     int attr = (info >>> 16);
     if ((attr & PERMANENT) != 0) {
       return true;
     }
     int id = (info & 0xFFFF);
     return NOT_FOUND != getInstanceIdValue(id);
   }
   if (prototypeValues != null) {
     int id = prototypeValues.findId(name);
     if (id != 0) {
       return prototypeValues.has(id);
     }
   }
   return super.has(name, start);
 }
Exemplo n.º 10
0
 @Override
 public void setAttributes(String name, int attributes) {
   ScriptableObject.checkValidAttributes(attributes);
   int info = findInstanceIdInfo(name);
   if (info != 0) {
     int currentAttributes = (info >>> 16);
     if (attributes != currentAttributes) {
       throw new RuntimeException("Change of attributes for this id is not supported");
     }
     return;
   }
   if (prototypeValues != null) {
     int id = prototypeValues.findId(name);
     if (id != 0) {
       prototypeValues.setAttributes(id, attributes);
       return;
     }
   }
   super.setAttributes(name, attributes);
 }
Exemplo n.º 11
0
  @Override
  Object[] getIds(boolean getAll) {
    Object[] result = super.getIds(getAll);

    if (prototypeValues != null) {
      result = prototypeValues.getNames(getAll, result);
    }

    int maxInstanceId = getMaxInstanceId();
    if (maxInstanceId != 0) {
      Object[] ids = null;
      int count = 0;

      for (int id = maxInstanceId; id != 0; --id) {
        String name = getInstanceIdName(id);
        int info = findInstanceIdInfo(name);
        if (info != 0) {
          int attr = (info >>> 16);
          if ((attr & PERMANENT) == 0) {
            if (NOT_FOUND == getInstanceIdValue(id)) {
              continue;
            }
          }
          if (getAll || (attr & DONTENUM) == 0) {
            if (count == 0) {
              // Need extra room for no more then [1..id] names
              ids = new Object[id];
            }
            ids[count++] = name;
          }
        }
      }
      if (count != 0) {
        if (result.length == 0 && ids.length == count) {
          result = ids;
        } else {
          Object[] tmp = new Object[result.length + count];
          System.arraycopy(result, 0, tmp, 0, result.length);
          System.arraycopy(ids, 0, tmp, result.length, count);
          result = tmp;
        }
      }
    }
    return result;
  }
Exemplo n.º 12
0
  public final IdFunctionObject exportAsJSClass(
      int maxPrototypeId, Scriptable scope, boolean sealed) {
    // Set scope and prototype unless this is top level scope itself
    if (scope != this && scope != null) {
      setParentScope(scope);
      setPrototype(getObjectPrototype(scope));
    }

    activatePrototypeMap(maxPrototypeId);
    IdFunctionObject ctor = prototypeValues.createPrecachedConstructor();
    if (sealed) {
      sealObject();
    }
    fillConstructorProperties(ctor);
    if (sealed) {
      ctor.sealObject();
    }
    ctor.exportAsScopeProperty();
    return ctor;
  }
Exemplo n.º 13
0
 public final void initPrototypeValue(int id, String name, Object value, int attributes) {
   prototypeValues.initValue(id, name, value, attributes);
 }
Exemplo n.º 14
0
 public final void initPrototypeMethod(Object tag, int id, String name, int arity) {
   Scriptable scope = ScriptableObject.getTopLevelScope(this);
   IdFunctionObject f = newIdFunction(tag, id, name, arity, scope);
   prototypeValues.initValue(id, name, f, DONTENUM);
 }