Esempio n. 1
0
        internal BuiltinCall(BuiltinFunction function, IScriptable scope, object [] args)
        {
            this.function = function;

            ParentScope = scope;
            // leave prototype null

            this.originalArgs = (args == null) ? ScriptRuntime.EmptyArgs : args;

            // initialize values of arguments
            int paramAndVarCount = function.ParamAndVarCount;
            int paramCount = function.ParamCount;
            if (paramAndVarCount != 0) {
                for (int i = 0; i != paramCount; ++i) {
                    string name = function.getParamOrVarName (i);
                    object val = i < args.Length ? args [i] : Undefined.Value;
                    DefineProperty (name, val, PERMANENT);
                }
            }

            // initialize "arguments" property but only if it was not overriden 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)) {
                        DefineProperty (name, Undefined.Value, PERMANENT);
                    }
                }
            }
        }
Esempio n. 2
0
        internal BuiltinCall(BuiltinFunction function, IScriptable scope, object [] args)
        {
            this.function = function;

            ParentScope = scope;
            // leave prototype null

            this.originalArgs = (args == null) ? ScriptRuntime.EmptyArgs : args;

            // initialize values of arguments
            int paramAndVarCount = function.ParamAndVarCount;
            int paramCount       = function.ParamCount;

            if (paramAndVarCount != 0)
            {
                for (int i = 0; i != paramCount; ++i)
                {
                    string name = function.getParamOrVarName(i);
                    object val  = i < args.Length ? args [i] : Undefined.Value;
                    DefineProperty(name, val, PERMANENT);
                }
            }

            // initialize "arguments" property but only if it was not overriden 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))
                    {
                        DefineProperty(name, Undefined.Value, PERMANENT);
                    }
                }
            }
        }
 public static IScriptable createFunctionActivation(BuiltinFunction funObj, IScriptable scope, object [] args)
 {
     return new BuiltinCall (funObj, scope, args);
 }
        public static void initScript(BuiltinFunction funObj, IScriptable thisObj, Context cx, IScriptable scope, bool evalScript)
        {
            if (cx.topCallScope == null)
                throw new ApplicationException ();

            int varCount = funObj.ParamAndVarCount;
            if (varCount != 0) {

                IScriptable varScope = scope;
                // Never define any variables from var statements inside with
                // object. See bug 38590.
                while (varScope is BuiltinWith) {
                    varScope = varScope.ParentScope;
                }

                for (int i = varCount; i-- != 0; ) {
                    string name = funObj.getParamOrVarName (i);
                    // Don't overwrite existing def if already defined in object
                    // or prototypes of object.
                    if (!ScriptableObject.HasProperty (scope, name)) {
                        if (!evalScript) {
                            // Global var definitions are supposed to be DONTDELETE
                            ScriptableObject.DefineProperty (varScope, name, Undefined.Value, ScriptableObject.PERMANENT);
                        }
                        else {
                            varScope.Put (name, varScope, Undefined.Value);
                        }
                    }
                }
            }
        }
 public static void initFunction(Context cx, IScriptable scope, BuiltinFunction function, int type, bool fromEvalCode)
 {
     if (type == FunctionNode.FUNCTION_STATEMENT) {
         string name = function.FunctionName;
         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.FunctionName;
         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 BuiltinWith) {
                 scope = scope.ParentScope;
             }
             scope.Put (name, scope, function);
         }
     }
     else {
         throw Context.CodeBug ();
     }
 }