Exemple #1
0
        public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
        {
            if (!a.HasProperty(GLOBAL, "length"))
            {
                return(JSUndefined.Undefined);
            }
            int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL));

            if (alen < 1)
            {
                return(JSUndefined.Undefined);
            }

            object s = a.GetItem(GLOBAL, "0").GetValue(GLOBAL);

            if (!(s is string))
            {
                return(s);
            }
            //string str = (string)s;

            ExecutionContext x2 = new ExecutionContext(CodeType.EVAL_CODE);

            x2.thisOb             = x.thisOb;
            x2.caller             = x.caller;
            x2.callee             = x.callee;
            x2.scope              = x.scope;
            GLOBAL.currentContext = x2;
            try {
                jsexec JSExec = (jsexec)GLOBAL.jobject.GetItem(GLOBAL, "JSExec").GetValue(GLOBAL);
                JSExec.execute(jsparse.parse(GLOBAL, s.ToString(), null, 0), x2);
            } catch (ThrownException) {
                x.result = x2.result;
                throw;
            } finally {
                GLOBAL.currentContext = x;
            }
            return(x2.result);
        }
Exemple #2
0
        public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x)
        {
            ExecutionContext x2 = new ExecutionContext(CodeType.FUNCTION_CODE);

            x2.thisOb = (JSObjectBase)(JSObject.ToBool(GLOBAL, t) ? t : GLOBAL.jobject);
            x2.caller = x;
            x2.callee = this;
            a.SetItem(GLOBAL, "callee", new JSSimpleProperty("callee", this, false, false, true));
            Node f = this.node;

            x2.scope         = new ExecutionContext();
            x2.scope.parent  = this.scope;
            x2.scope.jobject = new Activation(GLOBAL, f, a);

            GLOBAL.currentContext = x2;

            try
            {
                jsexec JSExec = (jsexec)GLOBAL.jobject.GetItem(GLOBAL, "JSExec").GetValue(GLOBAL);
                JSExec.execute(f.body == null ? f : f.body, x2);
            }
            catch (ReturnException)
            {
                return(x2.result);
            }
            catch (ThrownException)
            {
                x.result = x2.result;
                throw;
            }
            finally
            {
                GLOBAL.currentContext = x;
            }

            return(JSUndefined.Undefined);
        }