view Jint.Runtime/VM/Box.cs @ 2:4aed85a1f558

implemented simple vm2
author cin
date Fri, 25 Oct 2013 15:52:16 +0400
parents e113095f1de0
children aced2ae9957f
line wrap: on
line source

using System;

namespace Jint.Runtime.VM
{
	public class Box<T>: BoxBase, IGetter<T>, ISetter<T>
	{
		T m_value;
		IBinder<T> m_binder;

		public Box(T value,IBinder<T> binder) {
			m_value = value;
			m_binder = binder;
		}

		public override bool IsReference {
			get {
				return true;
			}
		}

        public override Type HoldingType
        {
            get { return typeof(T); }
        }

		#region IGetter implementation

		public T Get ()
		{
			return m_value;
		}

		#endregion

		#region ISetter implementation

		public void Set (T value)
		{
			m_value = value;
		}

		#endregion

		public override T2 Convert<T2> ()
		{
			if (m_binder == null)
				throw new ArgumentNullException ();
			return m_binder.Convert<T2> (m_value);
		}

		public override void Invoke(IBinaryOperation op, BoxBase arg2,Frame frame) {
			op.Invoke (m_value, ((IGetter<T>)arg2).Get (), m_binder, frame);
		}
	}
}