当前位置: 首页>>代码示例>>C#>>正文


C# Scriptable.Put方法代码示例

本文整理汇总了C#中Scriptable.Put方法的典型用法代码示例。如果您正苦于以下问题:C# Scriptable.Put方法的具体用法?C# Scriptable.Put怎么用?C# Scriptable.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scriptable的用法示例。


在下文中一共展示了Scriptable.Put方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoScriptableIncrDecr

		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;
			}
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:36,代码来源:ScriptRuntime.cs

示例2: InitFunction

		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();
				}
			}
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:42,代码来源:ScriptRuntime.cs

示例3: SetName

		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;
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:27,代码来源:ScriptRuntime.cs

示例4: SetConst

		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;
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:12,代码来源:ScriptRuntime.cs

示例5: Put

		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);
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:39,代码来源:IdScriptableObject.cs

示例6: Set

			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);
					}
				}
			}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:30,代码来源:IdScriptableObject.cs

示例7: SetUp

		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();
			}
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:15,代码来源:ContinuationsApiTest.cs

示例8: TestContinuationsInlineFunctionsSerialization

		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();
			}
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:51,代码来源:ContinuationsApiTest.cs

示例9: TestContinuationsPrototypesAndSerialization

		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();
				}
			}
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:65,代码来源:ContinuationsApiTest.cs


注:本文中的Scriptable.Put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。