コード例 #1
0
ファイル: ScriptRuntime.cs プロジェクト: hazzik/Rhino.Net
		private static object DoScriptableIncrDecr(Scriptable target, string id, Scriptable protoChainStart, object value, int incrDecrMask)
		{
			bool post = ((incrDecrMask & Node.POST_FLAG) != 0);
			double number;
			if (value is Number)
			{
				number = System.Convert.ToDouble(((Number)value));
			}
			else
			{
				number = ToNumber(value);
				if (post)
				{
					// convert result to number
					value = WrapNumber(number);
				}
			}
			if ((incrDecrMask & Node.DECR_FLAG) == 0)
			{
				++number;
			}
			else
			{
				--number;
			}
			Number result = WrapNumber(number);
			target.Put(id, protoChainStart, result);
			if (post)
			{
				return value;
			}
			else
			{
				return result;
			}
		}
コード例 #2
0
ファイル: ScriptRuntime.cs プロジェクト: hazzik/Rhino.Net
		public static void InitFunction(Context cx, Scriptable scope, NativeFunction function, int type, bool fromEvalCode)
		{
			if (type == FunctionNode.FUNCTION_STATEMENT)
			{
				string name = function.GetFunctionName();
				if (name != null && name.Length != 0)
				{
					if (!fromEvalCode)
					{
						// ECMA specifies that functions defined in global and
						// function scope outside eval should have DONTDELETE set.
						ScriptableObject.DefineProperty(scope, name, function, ScriptableObject.PERMANENT);
					}
					else
					{
						scope.Put(name, scope, function);
					}
				}
			}
			else
			{
				if (type == FunctionNode.FUNCTION_EXPRESSION_STATEMENT)
				{
					string name = function.GetFunctionName();
					if (name != null && name.Length != 0)
					{
						// Always put function expression statements into initial
						// activation object ignoring the with statement to follow
						// SpiderMonkey
						while (scope is NativeWith)
						{
							scope = scope.GetParentScope();
						}
						scope.Put(name, scope, function);
					}
				}
				else
				{
					throw Kit.CodeBug();
				}
			}
		}
コード例 #3
0
ファイル: ScriptRuntime.cs プロジェクト: hazzik/Rhino.Net
		public static object SetName(Scriptable bound, object value, Context cx, Scriptable scope, string id)
		{
			if (bound != null)
			{
				// TODO: we used to special-case XMLObject here, but putProperty
				// seems to work for E4X and it's better to optimize  the common case
				ScriptableObject.PutProperty(bound, id, value);
			}
			else
			{
				// "newname = 7;", where 'newname' has not yet
				// been defined, creates a new property in the
				// top scope unless strict mode is specified.
				if (cx.HasFeature(Context.FEATURE_STRICT_MODE) || cx.HasFeature(Context.FEATURE_STRICT_VARS))
				{
					Context.ReportWarning(ScriptRuntime.GetMessage1("msg.assn.create.strict", id));
				}
				// Find the top scope by walking up the scope chain.
				bound = ScriptableObject.GetTopLevelScope(scope);
				if (cx.useDynamicScope)
				{
					bound = CheckDynamicScope(cx.topCallScope, bound);
				}
				bound.Put(id, bound, value);
			}
			return value;
		}
コード例 #4
0
ファイル: ScriptRuntime.cs プロジェクト: hazzik/Rhino.Net
		public static object SetConst(Scriptable bound, object value, Context cx, string id)
		{
			if (bound is XMLObject)
			{
				bound.Put(id, bound, value);
			}
			else
			{
				ScriptableObject.PutConstProperty(bound, id, value);
			}
			return value;
		}
コード例 #5
0
		public override void Put(string name, Scriptable start, object value)
		{
			int info = FindInstanceIdInfo(name);
			if (info != 0)
			{
				if (start == this && IsSealed())
				{
					throw Context.ReportRuntimeError1("msg.modify.sealed", name);
				}
				int attr = ((int)(((uint)info) >> 16));
				if ((attr & READONLY) == 0)
				{
					if (start == this)
					{
						int id = (info & unchecked((int)(0xFFFF)));
						SetInstanceIdValue(id, value);
					}
					else
					{
						start.Put(name, start, value);
					}
				}
				return;
			}
			if (prototypeValues != null)
			{
				int id = prototypeValues.FindId(name);
				if (id != 0)
				{
					if (start == this && IsSealed())
					{
						throw Context.ReportRuntimeError1("msg.modify.sealed", name);
					}
					prototypeValues.Set(id, start, value);
					return;
				}
			}
			base.Put(name, start, value);
		}
コード例 #6
0
			internal void Set(int id, Scriptable start, object value)
			{
				if (value == ScriptableConstants.NOT_FOUND)
				{
					throw new ArgumentException();
				}
				EnsureId(id);
				int attr = attributeArray[id - 1];
				if ((attr & READONLY) == 0)
				{
					if (start == obj)
					{
						if (value == null)
						{
							value = UniqueTag.NULL_VALUE;
						}
						int valueSlot = (id - 1) * SLOT_SPAN;
						lock (this)
						{
							valueArray[valueSlot] = value;
						}
					}
					else
					{
						int nameSlot = (id - 1) * SLOT_SPAN + NAME_SLOT;
						string name = (string)valueArray[nameSlot];
						start.Put(name, start, value);
					}
				}
			}
コード例 #7
0
		protected virtual void SetUp()
		{
			Context cx = Context.Enter();
			try
			{
				globalScope = cx.InitStandardObjects();
				cx.SetOptimizationLevel(-1);
				// must use interpreter mode
				globalScope.Put("myObject", globalScope, Context.JavaToJS(new ContinuationsApiTest.MyClass(), globalScope));
			}
			finally
			{
				Context.Exit();
			}
		}
コード例 #8
0
		public virtual void TestContinuationsInlineFunctionsSerialization()
		{
			Scriptable globalScope;
			Context cx = Context.Enter();
			try
			{
				globalScope = cx.InitStandardObjects();
				cx.SetOptimizationLevel(-1);
				// must use interpreter mode
				globalScope.Put("myObject", globalScope, Context.JavaToJS(new ContinuationsApiTest.MyClass(), globalScope));
			}
			finally
			{
				Context.Exit();
			}
			cx = Context.Enter();
			try
			{
				cx.SetOptimizationLevel(-1);
				// must use interpreter mode
				cx.EvaluateString(globalScope, "function f(a) { var k = eval(myObject.h()); var t = []; return k; }", "function test source", 1, null);
				Function f = (Function)globalScope.Get("f", globalScope);
				object[] args = new object[] { 7 };
				cx.CallFunctionWithContinuations(f, globalScope, args);
				NUnit.Framework.Assert.Fail("Should throw ContinuationPending");
			}
			catch (ContinuationPending pending)
			{
				// serialize
				MemoryStream baos = new MemoryStream();
				ScriptableOutputStream sos = new ScriptableOutputStream(baos, globalScope);
				sos.WriteObject(globalScope);
				sos.WriteObject(pending.GetContinuation());
				sos.Close();
				baos.Close();
				byte[] serializedData = baos.ToArray();
				// deserialize
				MemoryStream bais = new MemoryStream(serializedData);
				ScriptableInputStream sis = new ScriptableInputStream(bais, globalScope);
				globalScope = (Scriptable)sis.ReadObject();
				object continuation = sis.ReadObject();
				sis.Close();
				bais.Close();
				object result = cx.ResumeContinuation(continuation, globalScope, "2+3");
				NUnit.Framework.Assert.AreEqual(5, System.Convert.ToInt32(((Number)result)));
			}
			finally
			{
				Context.Exit();
			}
		}
コード例 #9
0
		public virtual void TestContinuationsPrototypesAndSerialization()
		{
			byte[] serializedData = null;
			{
				Scriptable globalScope;
				Context cx = Context.Enter();
				try
				{
					globalScope = cx.InitStandardObjects();
					cx.SetOptimizationLevel(-1);
					// must use interpreter mode
					globalScope.Put("myObject", globalScope, Context.JavaToJS(new ContinuationsApiTest.MyClass(), globalScope));
				}
				finally
				{
					Context.Exit();
				}
				cx = Context.Enter();
				try
				{
					cx.SetOptimizationLevel(-1);
					// must use interpreter mode
					cx.EvaluateString(globalScope, "function f(a) { Number.prototype.blargh = function() {return 'foo';}; var k = myObject.f(a); var t = []; return new Number(8).blargh(); }", "function test source", 1, null);
					Function f = (Function)globalScope.Get("f", globalScope);
					object[] args = new object[] { 7 };
					cx.CallFunctionWithContinuations(f, globalScope, args);
					NUnit.Framework.Assert.Fail("Should throw ContinuationPending");
				}
				catch (ContinuationPending pending)
				{
					// serialize
					MemoryStream baos = new MemoryStream();
					ObjectOutputStream sos = new ObjectOutputStream(baos);
					sos.WriteObject(globalScope);
					sos.WriteObject(pending.GetContinuation());
					sos.Close();
					baos.Close();
					serializedData = baos.ToArray();
				}
				finally
				{
					Context.Exit();
				}
			}
			{
				try
				{
					Context cx = Context.Enter();
					Scriptable globalScope;
					// deserialize
					MemoryStream bais = new MemoryStream(serializedData);
					ObjectInputStream sis = new ObjectInputStream(bais);
					globalScope = (Scriptable)sis.ReadObject();
					object continuation = sis.ReadObject();
					sis.Close();
					bais.Close();
					object result = cx.ResumeContinuation(continuation, globalScope, 8);
					NUnit.Framework.Assert.AreEqual("foo", result);
				}
				finally
				{
					Context.Exit();
				}
			}
		}