Exemple #1
0
        public virtual EcmaValue Call(EcmaHeadObject obj, EcmaValue[] arg)
        {
            EcmaHeadObject argument = new EcmaHeadObject();
            EcmaHeadObject var      = new EcmaHeadObject();
            int            i        = 0;

            for (; i < this.arg.Length; i++)
            {
                if (i < arg.Length)
                {
                    argument.Put(this.arg[i], arg[i]);
                    argument.Put(i.ToString(), arg[i]);
                    var.Put(this.arg[i], arg[i]);
                }
                else
                {
                    var.Put(this.arg[i], EcmaValue.Undefined());
                }
            }

            for (; i < arg.Length; i++)
            {
                argument.Put(i.ToString(), arg[i]);
            }

            argument.Prototype = State.Object;
            argument.Put("length", EcmaValue.Number(arg.Length));
            argument.Property["length"].DontEnum = true;

            var.Put("arguments", EcmaValue.Object(argument));
            var.Put("callee", EcmaValue.Object(this));
            var.Property["callee"].DontEnum = true;

            EcmaHeadObject[] scope = State.GetScope().Clone() as EcmaHeadObject[];
            System.Array.Resize <EcmaHeadObject>(ref scope, scope.Length + 1);
            scope[scope.Length - 1] = var;
            State.PushContext(obj, scope, var);

            EcmaComplication com = EcmaEvulator.Evulate(State, this.body);

            State.PopContext();
            if (com.Type == EcmaComplicationType.Return)
            {
                return(com.Value);
            }
            return(EcmaValue.Undefined());
        }
Exemple #2
0
        private EcmaValue LoadScriptFile(string path)
        {
            if (!File.Exists(path))
            {
                throw new EcmaRuntimeException("Unknown script path: " + path);
            }

            EcmaScript script = new EcmaScript();

            script.BuildStandartLibary();
            new DefaultScript(script);
            EcmaComplication com = script.RunCode(File.OpenText(path));

            if (com.Type != EcmaComplicationType.Return)
            {
                throw new EcmaRuntimeException("A included file must return a value!");
            }

            return(com.Value);
        }