Rhino.ScriptRuntime.InitScript C# (CSharp) Method

InitScript() public static method

public static InitScript ( NativeFunction funObj, Scriptable thisObj, Context cx, Scriptable scope, bool evalScript ) : void
funObj NativeFunction
thisObj Scriptable
cx Context
scope Scriptable
evalScript bool
return void
		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);
					}
				}
			}
		}
ScriptRuntime