- 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 (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;
- if (redirect == null) {
- if (Log.on) Log.log(this, "attempt to add a child to a node with a null redirect at " +
- Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
- return;
- } else if (redirect != this) redirect.put(i, null, newnode);
- else {
+ public void put(int i, Object value) {
+ if (i < 0) return;
+
+ if (value != null && !(value instanceof Box)) {
+ if (Log.on) Log.logJS(this, "attempt to set a numerical property on a box to anything other than a box");
+ } else if (redirect == null) {
+ if (Log.on) Log.logJS(this, "attempt to add/remove children to/from a node with a null redirect");
+ } else if (redirect != this) {
+ Box b = value == null ? (Box)redirect.get(i) : (Box)value;
+ redirect.put(i, value);
+ put("0", b);
+
+ } else if (value == null) {
+ if (i >= 0 && i < numChildren()) {
+ Box b = getChild(i);
+ b.remove();
+ put("0", b);
+ }
+
+ } else if (value instanceof RootProxy) {
+ if (Log.on) Log.logJS(this, "attempt to reparent a box via its proxy object");
+
+ } else {
+ Box newnode = (Box)value;
+
+ // check if box being moved is currently target of a redirect
+ for(Box cur = newnode.getParent(); cur != null; cur = cur.getParent())
+ if (cur.redirect == newnode) {
+ if (Log.on) Log.logJS(this, "attempt to move a box that is the target of a redirect");
+ return;
+ }
+
+ // check for recursive ancestor violation
+ for(Box cur = this; cur != null; cur = cur.getParent())
+ if (cur == newnode) {
+ if (Log.on) Log.logJS(this, "attempt to make a node a parent of its own ancestor");
+ if (Log.on) Log.log(this, "box == " + this + " ancestor == " + newnode);
+ return;
+ }
+