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


C# Scriptable.Get方法代码示例

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


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

示例1: NameIncrDecr

		public static object NameIncrDecr(Scriptable scopeChain, string id, Context cx, int incrDecrMask)
		{
			Scriptable target;
			object value;
			do
			{
				if (cx.useDynamicScope && scopeChain.GetParentScope() == null)
				{
					scopeChain = CheckDynamicScope(cx.topCallScope, scopeChain);
				}
				target = scopeChain;
				do
				{
					if (target is NativeWith && target.GetPrototype() is XMLObject)
					{
						break;
					}
					value = target.Get(id, scopeChain);
					if (value != ScriptableConstants.NOT_FOUND)
					{
						goto search_break;
					}
					target = target.GetPrototype();
				}
				while (target != null);
				scopeChain = scopeChain.GetParentScope();
			}
			while (scopeChain != null);
			throw NotFoundError(scopeChain, id);
search_break: ;
			return DoScriptableIncrDecr(target, id, scopeChain, value, incrDecrMask);
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:32,代码来源:ScriptRuntime.cs

示例2: NameOrFunction

		private static object NameOrFunction(Context cx, Scriptable scope, Scriptable parentScope, string name, bool asFunctionCall)
		{
			object result;
			Scriptable thisObj = scope;
			// It is used only if asFunctionCall==true.
			XMLObject firstXMLObject = null;
			for (; ; )
			{
				if (scope is NativeWith)
				{
					Scriptable withObj = scope.GetPrototype();
					if (withObj is XMLObject)
					{
						XMLObject xmlObj = (XMLObject)withObj;
						if (xmlObj.Has(name, xmlObj))
						{
							// function this should be the target object of with
							thisObj = xmlObj;
							result = xmlObj.Get(name, xmlObj);
							break;
						}
						if (firstXMLObject == null)
						{
							firstXMLObject = xmlObj;
						}
					}
					else
					{
						result = ScriptableObject.GetProperty(withObj, name);
						if (result != ScriptableConstants.NOT_FOUND)
						{
							// function this should be the target object of with
							thisObj = withObj;
							break;
						}
					}
				}
				else
				{
					if (scope is NativeCall)
					{
						// NativeCall does not prototype chain and Scriptable.get
						// can be called directly.
						result = scope.Get(name, scope);
						if (result != ScriptableConstants.NOT_FOUND)
						{
							if (asFunctionCall)
							{
								// ECMA 262 requires that this for nested funtions
								// should be top scope
								thisObj = ScriptableObject.GetTopLevelScope(parentScope);
							}
							break;
						}
					}
					else
					{
						// Can happen if Rhino embedding decided that nested
						// scopes are useful for what ever reasons.
						result = ScriptableObject.GetProperty(scope, name);
						if (result != ScriptableConstants.NOT_FOUND)
						{
							thisObj = scope;
							break;
						}
					}
				}
				scope = parentScope;
				parentScope = parentScope.GetParentScope();
				if (parentScope == null)
				{
					result = TopScopeName(cx, scope, name);
					if (result == ScriptableConstants.NOT_FOUND)
					{
						if (firstXMLObject == null || asFunctionCall)
						{
							throw NotFoundError(scope, name);
						}
						// The name was not found, but we did find an XML
						// object in the scope chain and we are looking for name,
						// not function. The result should be an empty XMLList
						// in name context.
						result = firstXMLObject.Get(name, firstXMLObject);
					}
					// For top scope thisObj for functions is always scope itself.
					thisObj = scope;
					break;
				}
			}
			if (asFunctionCall)
			{
				if (!(result is Callable))
				{
					throw NotFunctionError(result, name);
				}
				StoreScriptable(cx, thisObj);
			}
			return result;
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:99,代码来源:ScriptRuntime.cs

示例3: DefaultObjectToSource

		internal static string DefaultObjectToSource(Context cx, Scriptable scope, Scriptable thisObj, object[] args)
		{
			bool toplevel;
			bool iterating;
			if (cx.iterating == null)
			{
				toplevel = true;
				iterating = false;
				cx.iterating = new ObjToIntMap(31);
			}
			else
			{
				toplevel = false;
				iterating = cx.iterating.Has(thisObj);
			}
			StringBuilder result = new StringBuilder(128);
			if (toplevel)
			{
				result.Append("(");
			}
			result.Append('{');
			// Make sure cx.iterating is set to null when done
			// so we don't leak memory
			try
			{
				if (!iterating)
				{
					cx.iterating.Intern(thisObj);
					// stop recursion.
					object[] ids = thisObj.GetIds();
					for (int i = 0; i < ids.Length; i++)
					{
						object id = ids[i];
						object value;
						if (id is int)
						{
							int intId = System.Convert.ToInt32(((int)id));
							value = thisObj.Get(intId, thisObj);
							if (value == ScriptableConstants.NOT_FOUND)
							{
								continue;
							}
							// a property has been removed
							if (i > 0)
							{
								result.Append(", ");
							}
							result.Append(intId);
						}
						else
						{
							string strId = (string)id;
							value = thisObj.Get(strId, thisObj);
							if (value == ScriptableConstants.NOT_FOUND)
							{
								continue;
							}
							// a property has been removed
							if (i > 0)
							{
								result.Append(", ");
							}
							if (ScriptRuntime.IsValidIdentifierName(strId))
							{
								result.Append(strId);
							}
							else
							{
								result.Append('\'');
								result.Append(ScriptRuntime.EscapeString(strId, '\''));
								result.Append('\'');
							}
						}
						result.Append(':');
						result.Append(ScriptRuntime.Uneval(cx, scope, value));
					}
				}
			}
			finally
			{
				if (toplevel)
				{
					cx.iterating = null;
				}
			}
			result.Append('}');
			if (toplevel)
			{
				result.Append(')');
			}
			return result.ToString();
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:92,代码来源:ScriptRuntime.cs

示例4: Walk

		private static object Walk(Context cx, Scriptable scope, Callable reviver, Scriptable holder, object name)
		{
			object property;
			if (name is Number)
			{
				property = holder.Get(System.Convert.ToInt32(((Number)name)), holder);
			}
			else
			{
				property = holder.Get(((string)name), holder);
			}
			if (property is Scriptable)
			{
				Scriptable val = ((Scriptable)property);
				if (val is NativeArray)
				{
					long len = ((NativeArray)val).GetLength();
					for (long i = 0; i < len; i++)
					{
						// indices greater than MAX_INT are represented as strings
						if (i > int.MaxValue)
						{
							string id = System.Convert.ToString(i);
							object newElement = Walk(cx, scope, reviver, val, id);
							if (newElement == Undefined.instance)
							{
								val.Delete(id);
							}
							else
							{
								val.Put(id, val, newElement);
							}
						}
						else
						{
							int idx = (int)i;
							object newElement = Walk(cx, scope, reviver, val, idx);
							if (newElement == Undefined.instance)
							{
								val.Delete(idx);
							}
							else
							{
								val.Put(idx, val, newElement);
							}
						}
					}
				}
				else
				{
					object[] keys = val.GetIds();
					foreach (object p in keys)
					{
						object newElement = Walk(cx, scope, reviver, val, p);
						if (newElement == Undefined.instance)
						{
							if (p is Number)
							{
								val.Delete(System.Convert.ToInt32(((Number)p)));
							}
							else
							{
								val.Delete((string)p);
							}
						}
						else
						{
							if (p is Number)
							{
								val.Put(System.Convert.ToInt32(((Number)p)), val, newElement);
							}
							else
							{
								val.Put((string)p, val, newElement);
							}
						}
					}
				}
			}
			return reviver.Call(cx, scope, holder, new object[] { name, property });
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:81,代码来源:NativeJSON.cs

示例5: 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

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