private static void DoAdd(object[] stack, double[] sDbl, int stackTop, Context cx) { object rhs = stack[stackTop + 1]; object lhs = stack[stackTop]; double d; bool leftRightOrder; if (rhs == UniqueTag.DOUBLE_MARK) { d = sDbl[stackTop + 1]; if (lhs == UniqueTag.DOUBLE_MARK) { sDbl[stackTop] += d; return; } leftRightOrder = true; } else { // fallthrough to object + number code if (lhs == UniqueTag.DOUBLE_MARK) { d = sDbl[stackTop]; lhs = rhs; leftRightOrder = false; } else { // fallthrough to object + number code if (lhs is Scriptable || rhs is Scriptable) { stack[stackTop] = ScriptRuntime.Add(lhs, rhs, cx); } else { if (lhs is CharSequence || rhs is CharSequence) { CharSequence lstr = ScriptRuntime.ToCharSequence(lhs); CharSequence rstr = ScriptRuntime.ToCharSequence(rhs); stack[stackTop] = new ConsString(lstr, rstr); } else { double lDbl = (lhs is Number) ? System.Convert.ToDouble(((Number)lhs)) : ScriptRuntime.ToNumber(lhs); double rDbl = (rhs is Number) ? System.Convert.ToDouble(((Number)rhs)) : ScriptRuntime.ToNumber(rhs); stack[stackTop] = UniqueTag.DOUBLE_MARK; sDbl[stackTop] = lDbl + rDbl; } } return; } } // handle object(lhs) + number(d) code if (lhs is Scriptable) { rhs = ScriptRuntime.WrapNumber(d); if (!leftRightOrder) { object tmp = lhs; lhs = rhs; rhs = tmp; } stack[stackTop] = ScriptRuntime.Add(lhs, rhs, cx); } else { if (lhs is CharSequence) { CharSequence lstr = (CharSequence)lhs; CharSequence rstr = ScriptRuntime.ToCharSequence(d); if (leftRightOrder) { stack[stackTop] = new ConsString(lstr, rstr); } else { stack[stackTop] = new ConsString(rstr, lstr); } } else { double lDbl = (lhs is Number) ? System.Convert.ToDouble(((Number)lhs)) : ScriptRuntime.ToNumber(lhs); stack[stackTop] = UniqueTag.DOUBLE_MARK; sDbl[stackTop] = lDbl + d; } } }
public virtual void TestConsStringSerialization() { ConsString r1 = new ConsString("foo", "bar"); MemoryStream baos = new MemoryStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.WriteObject(r1); oos.Flush(); MemoryStream bais = new MemoryStream(baos.ToArray()); ObjectInputStream ois = new ObjectInputStream(bais); CharSequence r2 = (CharSequence)ois.ReadObject(); NUnit.Framework.Assert.AreEqual("still the same at the other end", r1.ToString(), r2.ToString()); }