コード例 #1
0
        public static JSObjectBase RegisterNamespace(ExecutionContext GLOBAL, JSObjectBase scope, string[] names, int idx)
        {
            JSObjectBase parent = idx == 0 ? scope : RegisterNamespace(GLOBAL, scope, names, idx - 1);

            if (!parent.HasProperty(GLOBAL, names[idx]))
            {
                JSObject wrapper = new JSObject();
                parent.GetItem(GLOBAL, names[idx]).SetValue(GLOBAL, wrapper);
                return(wrapper);
            }
            return((JSObjectBase)parent.GetItem(GLOBAL, names[idx]).GetValue(GLOBAL));
        }
コード例 #2
0
ファイル: jsexec.cs プロジェクト: mhoffesommer/pygmalion
        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);
        }
コード例 #3
0
ファイル: jsexec.cs プロジェクト: prozacchiwawa/pygmalion
        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;
        }