Mercurial > pub > Jint1
diff Jint.Runtime/VM/Box.cs @ 5:cb13da6e3349
simple loop test
author | cin |
---|---|
date | Mon, 28 Oct 2013 00:49:15 +0400 |
parents | 1ae5b10f7a10 |
children | a6329b092499 |
line wrap: on
line diff
--- a/Jint.Runtime/VM/Box.cs Sun Oct 27 21:20:59 2013 +0400 +++ b/Jint.Runtime/VM/Box.cs Mon Oct 28 00:49:15 2013 +0400 @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using Jint.Runtime.VM.OpCodes; +using System.ComponentModel; namespace Jint.Runtime.VM { class Box<T>: AbstractBox, IGettter<T>, ISetter<T> { @@ -10,6 +11,7 @@ public T holdingValue; object[] m_impl; RuntimeContext m_runtime; + TypeConverter m_converter; public Box(T value, RuntimeContext runtime): base(typeof(T)) { if (runtime == null) @@ -27,6 +29,14 @@ } } + TypeConverter TypeConverter { + get { + if (m_converter == null) + m_converter = TypeDescriptor.GetConverter(typeof(T)); + return m_converter; + } + } + public T Get() { return holdingValue; } @@ -45,14 +55,18 @@ frame.SetValue(dest, op(holdingValue)); } - public override void InvokeCompareOperation(int arg2, int dest, Frame frame) { + public override int InvokeCompareOperation(int arg2, Frame frame) { var op = (CompareOperation<T>)Impl[(int)Codes.Cmp]; - frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2))); + return op(holdingValue, frame.GetValue<T>(arg2)); } - public override void InvokeEqualityOperation(int arg2, int dest, Frame frame) { + public override bool InvokeEqualityOperation(int arg2, Frame frame) { var op = (EqualityOperation<T>)Impl[(int)Codes.Cmp]; - frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2))); + return op(holdingValue, frame.GetValue<T>(arg2)); + } + + public override T2 Convert<T2>() { + return (T2)TypeConverter.ConvertTo(holdingValue, typeof(T2)); } } }