/// <summary>
    /// Initializes a new instance of the <see cref="ScriptEngine"/> class.
    /// </summary>
    /// <param name="language">The scripting language. Standard Windows Script engines names are 'jscript' or 'vbscript'.</param>
    public ScriptEngine(string language)
    {
        if (language == null)
        {
            throw new ArgumentNullException("language");
        }

        Type engine = Type.GetTypeFromProgID(language, true);

        _engine = Activator.CreateInstance(engine) as IActiveScript;
        if (_engine == null)
        {
            throw new ArgumentException(language + " is not an Windows Script Engine", "language");
        }

        _site = new ScriptSite();
        _engine.SetScriptSite(_site);

        // support 32-bit & 64-bit process
        if (IntPtr.Size == 4)
        {
            _parse32 = _engine as IActiveScriptParse32;
            _parse32.InitNew();
        }
        else
        {
            _parse64 = _engine as IActiveScriptParse64;
            _parse64.InitNew();
        }
    }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScriptEngine"/> class.
        /// </summary>
        public ScriptEngine()
        {
            try
            {
                _engine = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("{16d51579-a30b-4c8b-a276-0ff4dc41e755}"), true)) as IActiveScript;
            }
            catch
            {
                _engine = Activator.CreateInstance(Type.GetTypeFromProgID("javascript", true)) as IActiveScript;
            }

            Site = new ScriptSite();
            _engine.SetScriptSite(Site);

            // support 32-bit & 64-bit process
            if (IntPtr.Size == 4)
            {
                _parse32 = (IActiveScriptParse32)_engine;
                _parse32.InitNew();
            }
            else
            {
                _parse64 = (IActiveScriptParse64)_engine;
                _parse64.InitNew();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScriptEngine"/> class.
        /// </summary>
        /// <param name="language">The scripting language. Standard Windows Script engines names are 'jscript' or 'vbscript'.</param>
        public ScriptEngine()
        {
            var  guid = new System.Guid("{16d51579-a30b-4c8b-a276-0ff4dc41e755}");            // Chakra IE9/IE10 JS Engine
            Type t    = Type.GetTypeFromCLSID(guid, true);

            _engine = Activator.CreateInstance(t) as IActiveScript;

            if (_engine == null)
            {
                throw new Exception("Unable to initialize the Chakra engine.");
            }

            _site = new ScriptSite();
            _engine.SetScriptSite(_site);

            if (IntPtr.Size == 4)
            {
                _parse32 = _engine as IActiveScriptParse32;
                _parse32.InitNew();
            }
            else
            {
                _parse64 = _engine as IActiveScriptParse64;
                _parse64.InitNew();
            }
        }
Beispiel #4
0
 /// <summary>
 /// Initializes the scripting engine
 /// </summary>
 public void InitNew()
 {
     if (_is64Bit)
     {
         _activeScriptParse64.InitNew();
     }
     else
     {
         _activeScriptParse32.InitNew();
     }
 }
 internal void InitNew()
 {
     if (asp32 != null)
     {
         asp32.InitNew();
     }
     else
     {
         asp64.InitNew();
     }
 }
Beispiel #6
0
        public static object CreateScriptObject(ScriptSiteBase scriptSite, string scriptText)
        {
            IActiveScript        engine   = (IActiveScript)engineCache[scriptSite];
            IActiveScriptParse32 parser32 = null;
            IActiveScriptParse64 parser64 = null;

            if (IntPtr.Size == 4)
            {
                parser32 = (IActiveScriptParse32)engine;
            }
            else
            {
                parser64 = (IActiveScriptParse64)engine;
            }

            if (engine == null)
            {
                engine = (IActiveScript) new JScriptEngine();
                engine.SetScriptSite(scriptSite);
                foreach (string name in scriptSite.GetNamedItems())
                {
                    engine.AddNamedItem(name, ScriptItem.IsVisible);
                }

                if (IntPtr.Size == 4)
                {
                    parser32 = (IActiveScriptParse32)engine;
                    parser32.InitNew();
                }
                else
                {
                    parser64 = (IActiveScriptParse64)engine;
                    parser64.InitNew();
                }
                engineCache.Add(scriptSite, engine);
            }

            EXCEPINFO ei;
            object    result;
            IScript   scriptObject;

            if (IntPtr.Size == 4)
            {
                parser32.ParseScriptText(scriptText, null, null, null, IntPtr.Zero, 1, ScriptText.None, out result, out ei);
            }
            else
            {
                parser64.ParseScriptText(scriptText, null, null, null, IntPtr.Zero, 1, ScriptText.None, out result, out ei);
            }
            engine.GetScriptDispatch(null, out scriptObject);

            return(scriptObject);
        }
 /// <summary>
 /// Initializes the scripting engine.
 /// </summary>
 public void InitNew()
 {
     if (_parse32 != null)
     {
         _parse32.InitNew();
     }
     else if (_parse64 != null)
     {
         _parse64.InitNew();
     }
     else
     {
         throw new NotImplementedException(NeitherValidMessage);
     }
 }
Beispiel #8
0
        private static object JSonToObject(string json)
        {
            JScriptEngine engine = new JScriptEngine();
            IActiveScript script = (IActiveScript)engine;
            MySite        site   = new MySite();

            engine.SetScriptSite(site);

            IActiveScriptParse32 scriptParser = (IActiveScriptParse32)engine;

            scriptParser.InitNew();
            engine.SetScriptState(ScriptState.SCRIPTSTATE_CONNECTED);

            // SCRIPTTEXT_ISEXPRESSION
            // If the distinction between a computational expression and a
            // statement is important but syntactically ambiguous in the
            // script language, this flag specifies that the scriptlet is
            // to be interpreted as an expression, rather than as a
            // statement or list of statements. By default, statements are
            // assumed unless the correct choice can be determined from
            // the syntax of the scriptlet text.
            const int SCRIPTTEXT_ISEXPRESSION = 0x00000020;
            // Tricky: http://msdn2.microsoft.com/en-us/library/system.runtime.interopservices.variantwrapper.aspx.
            object result = null;

            System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo;

            Trace.WriteLine("Parsing JSON:");
            if (json.Length < 256)
            {
                Trace.WriteLine(json);
            }
            else
            {
                Trace.WriteLine(json.Substring(0, 128) + "..." + json.Substring(json.Length - 128, 128));
            }

            scriptParser.ParseScriptText(json, null, null, null, 0, 0,
                                         SCRIPTTEXT_ISEXPRESSION, ref result, out exceptionInfo);

            if (exceptionInfo.scode != 0)
            {
                throw new Exception(exceptionInfo.bstrDescription);
            }

            //engine.Close();
            return(result);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ScriptEngine"/> class.
        /// </summary>
        /// <param name="language">The scripting language. Standard Windows Script engines names are 'jscript' or 'vbscript'.</param>
        public ScriptEngine(string language)
        {
            if (language == null)
            {
                throw new ArgumentNullException(nameof(language));
            }

            Type engine;
            Guid clsid;

            if (Guid.TryParse(language, out clsid))
            {
                engine = Type.GetTypeFromCLSID(clsid, true);
            }
            else
            {
                engine = Type.GetTypeFromProgID(language, true);
            }

            _engine = Activator.CreateInstance(engine) as IActiveScript;
            if (_engine == null)
            {
                throw new ArgumentException(language + " is not an Windows Script Engine", nameof(language));
            }

            Site = new ScriptSite();
            _engine.SetScriptSite(Site);

            // support 32-bit & 64-bit process
            if (IntPtr.Size == 4)
            {
                _parse32 = (IActiveScriptParse32)_engine;
                _parse32.InitNew();
            }
            else
            {
                _parse64 = (IActiveScriptParse64)_engine;
                _parse64.InitNew();
            }
        }
    /// <summary>
    /// Initializes a new instance of the <see cref="ScriptEngine"/> class.
    /// </summary>
    /// <param name="language">The scripting language. Standard Windows Script engines names are 'jscript' or 'vbscript'.</param>
    public ScriptEngine(string language)
    {
        if (language == null)
        {
            throw new ArgumentNullException("language");
        }

        // support CLSID format (for chakra support that doesn't have a name on its own)
        Type engine;
        Guid clsid;

        if (Guid.TryParse(language, out clsid))
        {
            engine = Type.GetTypeFromCLSID(clsid, true);
        }
        else
        {
            engine = Type.GetTypeFromProgID(language, true);
        }
        _engine = Activator.CreateInstance(engine) as IActiveScript;
        if (_engine == null)
        {
            throw new ArgumentException(language + " is not an Windows Script Engine", "language");
        }

        _site = new ScriptSite();
        _engine.SetScriptSite(_site);

        // support 32-bit & 64-bit process
        if (IntPtr.Size == 4)
        {
            _parse32 = _engine as IActiveScriptParse32;
            _parse32.InitNew();
        }
        else
        {
            _parse64 = _engine as IActiveScriptParse64;
            _parse64.InitNew();
        }
    }
Beispiel #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScriptEngine"/> class.
        /// </summary>
        /// <param name="language">The scripting language. Standard Windows Script engines names are 'jscript' or 'vbscript'.</param>
        public ScriptEngine()
        {
            var guid = new System.Guid("{16d51579-a30b-4c8b-a276-0ff4dc41e755}"); // Chakra IE9/IE10 JS Engine
            Type t = Type.GetTypeFromCLSID(guid, true);

            _engine = Activator.CreateInstance(t) as IActiveScript;

            if (_engine == null) {
                throw new Exception("Unable to initialize the Chakra engine.");
            }

            _site = new ScriptSite();
            _engine.SetScriptSite(_site);

            if (IntPtr.Size == 4) {
                _parse32 = _engine as IActiveScriptParse32;
                _parse32.InitNew();
            }
            else {
                _parse64 = _engine as IActiveScriptParse64;
                _parse64.InitNew();
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ScriptEngine"/> class.
        /// </summary>
        /// <param name="language">The scripting language. Standard Windows Script engines names are 'jscript' or 'vbscript'.</param>
        public ScriptEngine(string language)
        {
            if (language == null)
                throw new ArgumentNullException("language");

            Type engine = Type.GetTypeFromProgID(language, true);
            this.engine = Activator.CreateInstance(engine) as IActiveScript;
            if (this.engine == null)
                throw new ArgumentException(language + " is not an Windows Script Engine", "language");

            Site = new ScriptSite();
            this.engine.SetScriptSite(Site);

            // support 32-bit & 64-bit process
            if (IntPtr.Size == 4)
            {
                parse32 = this.engine as IActiveScriptParse32;
                parse32.InitNew();
            }
            else
            {
                parse64 = this.engine as IActiveScriptParse64;
                parse64.InitNew();
            }
        }
Beispiel #13
0
 public override void InitNew()
 {
     activeScriptParse.InitNew();
 }
Beispiel #14
0
        /// <summary> 
        /// Initializes a new instance of the <see cref="ScriptEngine"/> class. 
        /// </summary>
        public ScriptEngine()
        {
            try
            {
                _engine = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("{16d51579-a30b-4c8b-a276-0ff4dc41e755}"), true)) as IActiveScript;
            }
            catch
            {
            	_engine = Activator.CreateInstance(Type.GetTypeFromProgID("javascript", true)) as IActiveScript;
            }

            Site = new ScriptSite();
            _engine.SetScriptSite(Site);

            // support 32-bit & 64-bit process 
            if (IntPtr.Size == 4)
            {
                _parse32 = (IActiveScriptParse32)_engine;
                _parse32.InitNew();
            }
            else
            {
                _parse64 = (IActiveScriptParse64)_engine;
                _parse64.InitNew();
            }
        }