Example #1
1
        /// <summary>
        /// Initializes a new instance of the <see cref="ActiveScriptEngine"/> class.
        /// </summary>
        /// <param name="scriptEngine"> The script engine. </param>
        /// <param name="language"> The scripting language. </param>
        private ActiveScriptEngine(object scriptEngine, ScriptLanguage language)
        {
            if (scriptEngine == null)
                throw new ArgumentNullException("scriptEngine");
            this.language = language;
            this.engine = (IActiveScript)scriptEngine;
            this.engine.SetScriptSite(this);
            this.parser = (IActiveScriptParse)this.engine;
            this.parser.InitNew();

            // Set properties.
            var activeScriptProperty = (IActiveScriptProperty)scriptEngine;

            // Indicate that we are not combining multiple script engines.
            object value = true;
            activeScriptProperty.SetProperty(SCRIPTPROP.ABBREVIATE_GLOBALNAME_RESOLUTION, IntPtr.Zero, ref value);

            // Upgrade the version of the script engine to 5.8 (IE 8).
            value = SCRIPTLANGUAGEVERSION.V5_8;
            activeScriptProperty.SetProperty(SCRIPTPROP.INVOKEVERSIONING, IntPtr.Zero, ref value);
        }
Example #2
0
        public static object CreateScriptObject(ScriptSiteBase scriptSite, string scriptText)
        {
            IActiveScript      engine = (IActiveScript)engineCache[scriptSite];
            IActiveScriptParse parser = (IActiveScriptParse)engine;

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

            EXCEPINFO ei;
            object    result;
            IScript   scriptObject;

            parser.ParseScriptText(scriptText, null, null, null, IntPtr.Zero, 1, ScriptText.None, out result, out ei);
            engine.GetScriptDispatch(null, out scriptObject);

            return(scriptObject);
        }
Example #3
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting
 /// unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     if (this.engine != null)
     {
         this.engine.Close();
     }
     if (this.parser != null)
     {
         Marshal.ReleaseComObject(this.parser);
     }
     this.parser = null;
     if (this.engine != null)
     {
         Marshal.ReleaseComObject(this.engine);
     }
     this.engine = null;
 }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ActiveScriptEngine"/> class.
        /// </summary>
        /// <param name="scriptEngine"> The script engine. </param>
        /// <param name="language"> The scripting language. </param>
        private ActiveScriptEngine(object scriptEngine, ScriptLanguage language)
        {
            if (scriptEngine == null)
            {
                throw new ArgumentNullException("scriptEngine");
            }
            this.language = language;
            this.engine   = (IActiveScript)scriptEngine;
            this.engine.SetScriptSite(this);
            this.parser = (IActiveScriptParse)this.engine;
            this.parser.InitNew();

            // Set properties.
            var activeScriptProperty = (IActiveScriptProperty)scriptEngine;

            // Indicate that we are not combining multiple script engines.
            object value = true;

            activeScriptProperty.SetProperty(SCRIPTPROP.ABBREVIATE_GLOBALNAME_RESOLUTION, IntPtr.Zero, ref value);

            // Upgrade the version of the script engine to 5.8 (IE 8).
            value = SCRIPTLANGUAGEVERSION.V5_8;
            activeScriptProperty.SetProperty(SCRIPTPROP.INVOKEVERSIONING, IntPtr.Zero, ref value);
        }
Example #5
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting
 /// unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     if (this.engine != null)
         this.engine.Close();
     if (this.parser != null)
         Marshal.ReleaseComObject(this.parser);
     this.parser = null;
     if (this.engine != null)
         Marshal.ReleaseComObject(this.engine);
     this.engine = null;
 }