Example #1
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);
        }
        public void LoadLibrary(string code)
        {
            try
            {
                parser.ParseScriptText(code, null, null, null, IntPtr.Zero, 0, ScriptTextFlags.IsVisible);
            }
            catch
            {
                ThrowAndResetIfScriptException();
                throw;
            }

            ComRelease(ref dispatch);
            engine.GetScriptDispatch(null, out dispatch);
            dispatchType = dispatch.GetType();
        }
Example #3
0
        /// <summary>
        /// Initializes a script dispatch
        /// </summary>
        private void InitScriptDispatch()
        {
            IExpando dispatch = null;
            object   obj;

            _activeScript.GetScriptDispatch(null, out obj);

            if (obj != null && obj.GetType().IsCOMObject)
            {
                dispatch = obj as IExpando;
            }

            if (dispatch == null)
            {
                throw new InvalidOperationException(NetFrameworkStrings.Runtime_ActiveScriptDispatcherNotInitialized);
            }

            _dispatch = dispatch;
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public Script Parse(string code)
        {
            _engine.SetScriptState(ScriptState.Connected);

            try
            {
                object result;
                System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo;
                if (_parse32 != null)
                {
                    _parse32.ParseScriptText(code, null, IntPtr.Zero, null, 0, 0, ScriptText.None, out result, out exceptionInfo);
                }
                else
                {
                    _parse64.ParseScriptText(code, null, IntPtr.Zero, null, 0, 0, ScriptText.None, out result, out exceptionInfo);
                }
            }
            catch
            {
                if (Site.LastException != null)
                {
                    throw Site.LastException;
                }

                throw;
            }

            if (Site.LastException != null)
            {
                throw Site.LastException;
            }

            IntPtr dispatch;

            _engine.GetScriptDispatch(null, out dispatch);
            Script script = new Script(this, dispatch);

            return(script);
        }
Example #5
0
        public IEJavaScriptEngine()
        {
            try
            {
                engine = new ChakraJavaScriptEngine() as IActiveScript;
            }
            catch
            {
                engine = new JavaScriptEngine() as IActiveScript;
            }

            if (engine == null)
            {
                throw new Exception("Could not create IE JavaScript engine.");
            }

            parser = new ActiveScriptParseWrapper(engine);

            parser.InitNew();
            engine.SetScriptSite(this);

            engine.GetScriptDispatch(null, out dispatch);
            dispatchType = dispatch.GetType();
        }
Example #6
0
        private object Parse(string text, bool expression)
        {
            const string varName = "x___";
            object       result;

            _engine.SetScriptState(ScriptState.Connected);

            ScriptText flags = ScriptText.None;

            if (expression)
            {
                flags |= ScriptText.IsExpression;
            }

            try
            {
                // immediate expression computation seems to work only for 64-bit
                // so hack something for 32-bit...
                System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo;
                if (_parse32 != null)
                {
                    if (expression)
                    {
                        // should work for jscript & vbscript at least...
                        text = varName + "=" + text;
                    }
                    _parse32.ParseScriptText(text, null, IntPtr.Zero, null, 0, 0, flags, out result, out exceptionInfo);
                }
                else
                {
                    _parse64.ParseScriptText(text, null, IntPtr.Zero, null, 0, 0, flags, out result, out exceptionInfo);
                }
            }
            catch
            {
                if (Site.LastException != null)
                {
                    throw Site.LastException;
                }

                throw;
            }

            IntPtr dispatch;

            if (expression)
            {
                // continue  our 32-bit hack...
                if (_parse32 != null)
                {
                    _engine.GetScriptDispatch(null, out dispatch);
                    object dp = Marshal.GetObjectForIUnknown(dispatch);
                    try
                    {
                        return(dp.GetType().InvokeMember(varName, BindingFlags.GetProperty, null, dp, null));
                    }
                    catch
                    {
                        if (Site.LastException != null)
                        {
                            throw Site.LastException;
                        }

                        throw;
                    }
                }
                return(result);
            }

            _engine.GetScriptDispatch(null, out dispatch);
            ParsedScript parsed = new ParsedScript(this, dispatch);

            return(parsed);
        }
Example #7
0
 public override void GetScriptDispatch(string itemName, out object dispatch)
 {
     activeScript.GetScriptDispatch(itemName, out dispatch);
 }
 private void UpdateDispatch()
 {
     ComRelease(ref JsDispatch);
     ScriptEngine.GetScriptDispatch(null, out JsDispatch);
     JsDispatchType = JsDispatch.GetType();
 }
Example #9
0
 private void UpdateDispatch()
 {
     ComRelease(ref _jsDispatcher);
     _jsEngine.GetScriptDispatch(null, out _jsDispatcher);
     _jsDispatcherType = _jsDispatcher.GetType();
 }
Example #10
0
 /// <summary>
 /// Retrieves the IDispatch interface for the methods and properties associated
 /// with the currently running script
 /// </summary>
 /// <param name="itemName">The name of the item for which the caller needs the associated
 /// dispatch object. If this parameter is null, the dispatch object contains as its members
 /// all of the global methods and properties defined by the script. Through the
 /// IDispatch interface and the associated <see cref="ITypeInfo"/> interface, the host can
 /// invoke script methods or view and modify script variables.</param>
 /// <param name="dispatch">The object associated with the script's global methods and
 /// properties. If the scripting engine does not support such an object, null is returned.</param>
 public void GetScriptDispatch(string itemName, out object dispatch)
 {
     _activeScript.GetScriptDispatch(itemName, out dispatch);
 }
 private void UpdateDispatch()
 {
     ComRelease(ref jsDispatch);
     jsEngine.GetScriptDispatch(null, out jsDispatch);
     jsDispatchType = jsDispatch.GetType();
 }
Example #12
0
 /// <summary>
 /// Gets the IDispatch handle for the specified namespace.
 /// </summary>
 /// <param name="namespaceName">The namespace of the IDispatch handle to get, or null
 /// to get the root namespace.</param>
 /// <returns>An IDispatch handle.</returns>
 public object GetScriptHandle(string namespaceName)
 {
     return(activeScript.GetScriptDispatch(namespaceName));
 }
Example #13
0
        private object Parse(string text, bool expression)
        {
            const string varName = "x___";

            System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo;
            object result;

            _engine.SetScriptState(ScriptState.Connected);

            ScriptText flags = ScriptText.None;

            if (expression)
            {
                flags |= ScriptText.IsExpression;
            }

            try
            {
                if (_parse32 != null)
                {
                    if (expression)
                    {
                        text = varName + "=" + text;
                    }
                    _parse32.ParseScriptText(text, null, null, null, IntPtr.Zero, 0, flags, out result, out exceptionInfo);
                }
                else
                {
                    _parse64.ParseScriptText(text, null, null, null, IntPtr.Zero, 0, flags, out result, out exceptionInfo);
                }
            }
            catch
            {
                if (_site._lastException != null)
                {
                    throw _site._lastException;
                }

                throw;
            }

            IntPtr dispatch;

            if (expression)
            {
                if (_parse32 != null)
                {
                    _engine.GetScriptDispatch(null, out dispatch);
                    object dp = Marshal.GetObjectForIUnknown(dispatch);
                    try
                    {
                        return(dp.GetType().InvokeMember(varName, BindingFlags.GetProperty, null, dp, null));
                    }
                    catch
                    {
                        if (_site._lastException != null)
                        {
                            throw _site._lastException;
                        }

                        throw;
                    }
                }
                return(result);
            }

            _engine.GetScriptDispatch(null, out dispatch);
            ParsedScript parsed = new ParsedScript(this, dispatch);

            return(parsed);
        }