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; }
@Override public void delete(int index) { if (0 <= index && index < args.length) { synchronized (this) { if (args[index] != NOT_FOUND) { if (args == activation.originalArgs) { args = args.clone(); } args[index] = NOT_FOUND; return; } } } super.delete(index); }
@Override public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { if (!f.hasTag(FTAG)) { return super.execIdCall(f, cx, scope, thisObj, args); } int id = f.methodId(); switch (id) { case Id_constructor: throw Context.reportRuntimeError("Direct call is not supported"); } throw new IllegalArgumentException(String.valueOf(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; }
@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); }
int maxInstanceId = getMaxInstanceId(); if (maxInstanceId != 0) { Object[] ids = null; 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;
@Override public Object get(String name, Scriptable start) { int info = findInstanceIdInfo(name); if (info != 0) { int id = (info & 0xFFFF); return getInstanceIdValue(id); } if (prototypeValues != null) { int id = prototypeValues.findId(name); if (id != 0) { return prototypeValues.get(id); } } return super.get(name, start); }
@Override protected int findInstanceIdInfo(String s) { if (s.equals("length")) { return instanceIdInfo(DONTENUM | READONLY | PERMANENT, Id_length); } return super.findInstanceIdInfo(s); }
@Override protected void fillConstructorProperties(IdFunctionObject ctor) { // Fix up bootstrapping problem: getPrototype of the IdFunctionObject // can not return Function.prototype because Function object is not // yet defined. ctor.setPrototype(this); super.fillConstructorProperties(ctor); }
@Override public Object get(int index, Scriptable start) { if (0 <= index && index < string.length()) { return string.substring(index, index + 1); } return super.get(index, start); }
@Override public Object getDefaultValue(Class<?> typeHint) { if (typeHint == null) typeHint = ScriptRuntime.StringClass; return super.getDefaultValue(typeHint); }
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; }
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); int maxPrototypeId = stream.readInt(); if (maxPrototypeId != 0) { activatePrototypeMap(maxPrototypeId); } }
@Override public Object[] getAllIds() { Set<Object> allIds = new LinkedHashSet<Object>( Arrays.asList(this.getIds())); allIds.addAll(Arrays.asList(super.getAllIds())); return allIds.toArray(); }
@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); if (start == this) { int id = (info & 0xFFFF); setInstanceIdValue(id, value); int id = prototypeValues.findId(name); if (id != 0) { if (start == this && isSealed()) { throw Context.reportRuntimeError1("msg.modify.sealed", name);
@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); }
@Override protected int findInstanceIdInfo(String s) { if (s.equals("length")) { return instanceIdInfo(DONTENUM | PERMANENT, Id_length); } return super.findInstanceIdInfo(s); }
@Override protected void fillConstructorProperties(IdFunctionObject ctor) { addIdFunctionProperty(ctor, DATE_TAG, ConstructorId_now, "now", 0); addIdFunctionProperty(ctor, DATE_TAG, ConstructorId_parse, "parse", 1); addIdFunctionProperty(ctor, DATE_TAG, ConstructorId_UTC, "UTC", 1); super.fillConstructorProperties(ctor); }
@Override public Object getDefaultValue(Class<?> typeHint) { // This is actually non-ECMA, but will be proposed // as a change in round 2. if (typeHint == ScriptRuntime.BooleanClass) return ScriptRuntime.wrapBoolean(booleanValue); return super.getDefaultValue(typeHint); }