コード例 #1
0
        private object EvalJScript(string src)
        {
            var engine = Engine;

            try
            {
                With.JScriptWith(this, Engine);
                return(Eval.JScriptEvaluate(src, "unsafe", engine));
            }
            finally
            {
                engine.PopScriptObject(/* with */);
            }
        }
コード例 #2
0
        /// <summary> Создание экземпляра класса </summary>
        /// <param name="reff">Список ссылок на дополнительные сборки</param>
        public JS(params string[] reff)
        {
            //VsaEngine.CreateEngineAndGetGlobalScope(false, new[] { "System.dll"});
            var v = new List <string>()
            {
                "mscorlib.dll", "System.dll", "System.Xml.dll", "System.Data.dll", "System.Drawing.dll", "System.Windows.Forms.dll"                         /*, AppContext.AppFullFileName */
            };

            if (reff != null)
            {
                v.AddRange(reff);
            }
            var gs = (GlobalScope)JSContext._type("Microsoft.JScript.Vsa.VsaEngine").InvokeMember("CreateEngineAndGetGlobalScope", BindingFlags.InvokeMethod, Type.DefaultBinder, null, new object[] { false, v.ToArray() }); //fast=false иначе with(this){x=0} throw stackowerflowexception

            Import.JScriptImport("System", gs.engine);                                                                                                                                                                        //для имён с '.' ("System.Collections" и т.п.) - не работает
            _scope = new GlobalScope(gs, gs.engine);
            gs.engine.PushScriptObject(_scope);
            With.JScriptWith(new JSContext(), _scope.engine);//по умолчанию используется стандартный контекст
        }
コード例 #3
0
            public override bool Eval(object context)
            {
                VsaEngine engine = Engine;

                //
                // Following is equivalent to calling eval in JScript,
                // with the value of the context variable established at the
                // global scope in order for it to be available to the
                // expression source.
                //

                _contextField.SetValue(_scope, context);

                try
                {
                    With.JScriptWith(context, engine);
                    return(Convert.ToBoolean(Microsoft.JScript.Eval.JScriptEvaluate(_expression, engine)));
                }
                finally
                {
                    engine.PopScriptObject(/* with */);
                }
            }
コード例 #4
0
 public JS SetContext(object ext = null)
 {
     _scope.engine.PopScriptObject();//удаляем старый контекст
     With.JScriptWith(ext ?? new JSContext(), _scope.engine);
     return(this);
 }