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


C# Scriptable.GetParentScope方法代码示例

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


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

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

示例2: CallSpecial

		public static object CallSpecial(Context cx, Callable fun, Scriptable thisObj, object[] args, Scriptable scope, Scriptable callerThis, int callType, string filename, int lineNumber)
		{
			if (callType == Node.SPECIALCALL_EVAL)
			{
				if (thisObj.GetParentScope() == null && NativeGlobal.IsEvalFunction(fun))
				{
					return EvalSpecial(cx, scope, callerThis, args, filename, lineNumber);
				}
			}
			else
			{
				if (callType == Node.SPECIALCALL_WITH)
				{
					if (NativeWith.IsWithFunction(fun))
					{
						throw Context.ReportRuntimeError1("msg.only.from.new", "With");
					}
				}
				else
				{
					throw Kit.CodeBug();
				}
			}
			return fun.Call(cx, scope, thisObj, args);
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:25,代码来源:ScriptRuntime.cs

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

示例4: Bind

		/// <summary>Returns the object in the scope chain that has a given property.</summary>
		/// <remarks>
		/// Returns the object in the scope chain that has a given property.
		/// The order of evaluation of an assignment expression involves
		/// evaluating the lhs to a reference, evaluating the rhs, and then
		/// modifying the reference with the rhs value. This method is used
		/// to 'bind' the given name to an object containing that property
		/// so that the side effects of evaluating the rhs do not affect
		/// which property is modified.
		/// Typically used in conjunction with setName.
		/// See ECMA 10.1.4
		/// </remarks>
		public static Scriptable Bind(Context cx, Scriptable scope, string id)
		{
			Scriptable firstXMLObject = null;
			Scriptable parent = scope.GetParentScope();
			if (parent != null)
			{
				// Check for possibly nested "with" scopes first
				while (scope is NativeWith)
				{
					Scriptable withObj = scope.GetPrototype();
					if (withObj is XMLObject)
					{
						XMLObject xmlObject = (XMLObject)withObj;
						if (xmlObject.Has(cx, id))
						{
							return xmlObject;
						}
						if (firstXMLObject == null)
						{
							firstXMLObject = xmlObject;
						}
					}
					else
					{
						if (ScriptableObject.HasProperty(withObj, id))
						{
							return withObj;
						}
					}
					scope = parent;
					parent = parent.GetParentScope();
					if (parent == null)
					{
						goto childScopesChecks_break;
					}
				}
				for (; ; )
				{
					if (ScriptableObject.HasProperty(scope, id))
					{
						return scope;
					}
					scope = parent;
					parent = parent.GetParentScope();
					if (parent == null)
					{
						goto childScopesChecks_break;
					}
				}
			}
childScopesChecks_break: ;
			// scope here is top scope
			if (cx.useDynamicScope)
			{
				scope = CheckDynamicScope(cx.topCallScope, scope);
			}
			if (ScriptableObject.HasProperty(scope, id))
			{
				return scope;
			}
			// Nothing was found, but since XML objects always bind
			// return one if found
			return firstXMLObject;
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:76,代码来源:ScriptRuntime.cs

示例5: GetNameFunctionAndThis

		/// <summary>
		/// Prepare for calling name(...): return function corresponding to
		/// name and make current top scope available
		/// as ScriptRuntime.lastStoredScriptable() for consumption as thisObj.
		/// </summary>
		/// <remarks>
		/// Prepare for calling name(...): return function corresponding to
		/// name and make current top scope available
		/// as ScriptRuntime.lastStoredScriptable() for consumption as thisObj.
		/// The caller must call ScriptRuntime.lastStoredScriptable() immediately
		/// after calling this method.
		/// </remarks>
		public static Callable GetNameFunctionAndThis(string name, Context cx, Scriptable scope)
		{
			Scriptable parent = scope.GetParentScope();
			if (parent == null)
			{
				object result = TopScopeName(cx, scope, name);
				if (!(result is Callable))
				{
					if (result == ScriptableConstants.NOT_FOUND)
					{
						throw NotFoundError(scope, name);
					}
					else
					{
						throw NotFunctionError(result, name);
					}
				}
				// Top scope is not NativeWith or NativeCall => thisObj == scope
				Scriptable thisObj = scope;
				StoreScriptable(cx, thisObj);
				return (Callable)result;
			}
			// name will call storeScriptable(cx, thisObj);
			return (Callable)NameOrFunction(cx, scope, parent, name, true);
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:37,代码来源:ScriptRuntime.cs

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

示例7: Name

		/// <summary>Looks up a name in the scope chain and returns its value.</summary>
		/// <remarks>Looks up a name in the scope chain and returns its value.</remarks>
		public static object Name(Context cx, Scriptable scope, string name)
		{
			Scriptable parent = scope.GetParentScope();
			if (parent == null)
			{
				object result = TopScopeName(cx, scope, name);
				if (result == ScriptableConstants.NOT_FOUND)
				{
					throw NotFoundError(scope, name);
				}
				return result;
			}
			return NameOrFunction(cx, scope, parent, name, false);
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:16,代码来源:ScriptRuntime.cs

示例8: GetBuiltinPrototype

		/// <summary>
		/// Static helper method to get a built-in object prototype with the given
		/// <code>type</code> from the given <code>scope</code>.
		/// </summary>
		/// <remarks>
		/// Static helper method to get a built-in object prototype with the given
		/// <code>type</code> from the given <code>scope</code>. If the scope is not
		/// an instance of this class or does have a cache of built-ins,
		/// the prototype is looked up via normal property lookup.
		/// </remarks>
		/// <param name="scope">the top-level scope</param>
		/// <param name="type">the built-in type</param>
		/// <returns>the built-in prototype</returns>
		public static Scriptable GetBuiltinPrototype(Scriptable scope, TopLevel.Builtins type)
		{
			// must be called with top level scope
			System.Diagnostics.Debug.Assert(scope.GetParentScope() == null);
			if (scope is TopLevel)
			{
				Scriptable result = ((TopLevel)scope).GetBuiltinPrototype(type);
				if (result != null)
				{
					return result;
				}
			}
			// fall back to normal prototype lookup
			return ScriptableObject.GetClassPrototype(scope, type.ToString());
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:28,代码来源:TopLevel.cs

示例9: GetBuiltinCtor

		/// <summary>
		/// Static helper method to get a built-in object constructor with the given
		/// <code>type</code> from the given <code>scope</code>.
		/// </summary>
		/// <remarks>
		/// Static helper method to get a built-in object constructor with the given
		/// <code>type</code> from the given <code>scope</code>. If the scope is not
		/// an instance of this class or does have a cache of built-ins,
		/// the constructor is looked up via normal property lookup.
		/// </remarks>
		/// <param name="cx">the current Context</param>
		/// <param name="scope">the top-level scope</param>
		/// <param name="type">the built-in type</param>
		/// <returns>the built-in constructor</returns>
		public static Function GetBuiltinCtor(Context cx, Scriptable scope, TopLevel.Builtins type)
		{
			// must be called with top level scope
			System.Diagnostics.Debug.Assert(scope.GetParentScope() == null);
			if (scope is TopLevel)
			{
				Function result = ((TopLevel)scope).GetBuiltinCtor(type);
				if (result != null)
				{
					return result;
				}
			}
			// fall back to normal constructor lookup
			return ScriptRuntime.GetExistingCtor(cx, scope, type.ToString());
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:29,代码来源:TopLevel.cs

示例10: XmlPrimaryReference

		private Ref XmlPrimaryReference(Context cx, XMLName xmlName, Scriptable scope)
		{
			XMLObjectImpl xmlObj;
			XMLObjectImpl firstXml = null;
			for (; ; )
			{
				// XML object can only present on scope chain as a wrapper
				// of XMLWithScope
				if (scope is XMLWithScope)
				{
					xmlObj = (XMLObjectImpl)scope.GetPrototype();
					if (xmlObj.HasXMLProperty(xmlName))
					{
						break;
					}
					if (firstXml == null)
					{
						firstXml = xmlObj;
					}
				}
				scope = scope.GetParentScope();
				if (scope == null)
				{
					xmlObj = firstXml;
					break;
				}
			}
			// xmlObj == null corresponds to undefined as the target of
			// the reference
			if (xmlObj != null)
			{
				xmlName.InitXMLObject(xmlObj);
			}
			return xmlName;
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:35,代码来源:XMLLibImpl.cs


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