GetParamAndVarCount() protected abstract method

Get number of declared parameters and variables defined through var statements.
Get number of declared parameters and variables defined through var statements.
protected abstract GetParamAndVarCount ( ) : int
return int
示例#1
0
		internal NativeCall(NativeFunction function, Scriptable scope, object[] args)
		{
			this.function = function;
			SetParentScope(scope);
			// leave prototype null
			this.originalArgs = (args == null) ? ScriptRuntime.emptyArgs : args;
			// initialize values of arguments
			int paramAndVarCount = function.GetParamAndVarCount();
			int paramCount = function.GetParamCount();
			if (paramAndVarCount != 0)
			{
				for (int i = 0; i < paramCount; ++i)
				{
					string name = function.GetParamOrVarName(i);
					object val = i < args.Length ? args[i] : Undefined.instance;
					DefineProperty(name, val, PERMANENT);
				}
			}
			// initialize "arguments" property but only if it was not overridden by
			// the parameter with the same name
			if (!base.Has("arguments", this))
			{
				DefineProperty("arguments", new Arguments(this), PERMANENT);
			}
			if (paramAndVarCount != 0)
			{
				for (int i = paramCount; i < paramAndVarCount; ++i)
				{
					string name = function.GetParamOrVarName(i);
					if (!base.Has(name, this))
					{
						if (function.GetParamOrVarConst(i))
						{
							DefineProperty(name, Undefined.instance, CONST);
						}
						else
						{
							DefineProperty(name, Undefined.instance, PERMANENT);
						}
					}
				}
			}
		}
示例#2
0
		public static void InitScript(NativeFunction funObj, Scriptable thisObj, Context cx, Scriptable scope, bool evalScript)
		{
			if (cx.topCallScope == null)
			{
				throw new InvalidOperationException();
			}
			int varCount = funObj.GetParamAndVarCount();
			if (varCount != 0)
			{
				Scriptable varScope = scope;
				// Never define any variables from var statements inside with
				// object. See bug 38590.
				while (varScope is NativeWith)
				{
					varScope = varScope.GetParentScope();
				}
				for (int i = varCount; i-- != 0; )
				{
					string name = funObj.GetParamOrVarName(i);
					bool isConst = funObj.GetParamOrVarConst(i);
					// Don't overwrite existing def if already defined in object
					// or prototypes of object.
					if (!ScriptableObject.HasProperty(scope, name))
					{
						if (isConst)
						{
							ScriptableObject.DefineConstProperty(varScope, name);
						}
						else
						{
							if (!evalScript)
							{
								// Global var definitions are supposed to be DONTDELETE
								ScriptableObject.DefineProperty(varScope, name, Undefined.instance, ScriptableObject.PERMANENT);
							}
							else
							{
								varScope.Put(name, varScope, Undefined.instance);
							}
						}
					}
					else
					{
						ScriptableObject.RedefineProperty(scope, name, isConst);
					}
				}
			}
		}