* WARNING: O(n) runtime, unless i == numChildren()
*/
public void put(int i, Scriptable start, Object value) {
- if (value == null) {
- if (i >= 0 && i < numChildren()) getChild(i).remove();
- return;
- }
- if (value instanceof RootProxy) {
- if (Log.on) Log.log(this, "attempt to reparent a box via its proxy object at " +
- Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
- return;
- } else if (!(value instanceof Box)) {
+
+ if (value != null && !(value instanceof Box)) {
if (Log.on) Log.log(this, "attempt to set a numerical property on a box to anything other than a box at " +
Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
- return;
- }
- Box newnode = (Box)value;
- for(Box cur = this; cur != null; cur = cur.getParent())
- if (cur == newnode) {
- if (Log.on) Log.log(this, "attempt to make a node a parent of its own ancestor at " +
- Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
- return;
+ } else if (redirect == null) {
+ if (Log.on) Log.log(this, "attempt to add/remove children to/from a node with a null redirect at " +
+ Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
+
+ } else if (redirect != this) {
+ Box b = value == null ? (Box)redirect.get(i, null) : (Box)value;
+ redirect.put(i, null, value);
+ put("0", null, b);
+
+ } else if (value == null) {
+ if (i >= 0 && i < numChildren()) {
+ Box b = getChild(i);
+ b.remove();
+ put("0", null, b);
}
- if (redirect == null) {
- if (Log.on) Log.log(this, "attempt to add a child to a node with a null redirect at " +
+ } else if (value instanceof RootProxy) {
+ if (Log.on) Log.log(this, "attempt to reparent a box via its proxy object at " +
Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
- return;
- } else if (redirect != this) redirect.put(i, null, newnode);
- else {
+
+ } else {
+ Box newnode = (Box)value;
+ for(Box cur = this; cur != null; cur = cur.getParent())
+ if (cur == newnode) {
+ if (Log.on) Log.log(this, "attempt to make a node a parent of its own ancestor at " +
+ Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
+ return;
+ }
+
if (numKids > 15 && children == null) convert_to_array();
if (newnode.parent != null) newnode.remove();
newnode.parent = this;
}
}
newnode.setSurface(surface);
-
+
// need both of these in case child was already uncalc'ed
newnode.mark_for_prerender();
mark_for_prerender();
-
+
newnode.dirty();
sync_cmin_to_children();
- }
- // note that JavaScript box[0] will invoke put(int i), not put(String s)
- put("0", null, newnode);
+ // note that JavaScript box[0] will invoke put(int i), not put(String s)
+ put("0", null, newnode);
+ }
}
public Object get(String name, Scriptable start) { return get(name, start, false); }