示例#1
0
        /// <summary>
        /// Parses the given code scriptlet, adding declarations into the namespace and
        /// evaluating code as appropriate
        /// </summary>
        /// <param name="code">The scriptlet text to evaluate. The interpretation of this
        /// string depends on the scripting language</param>
        /// <param name="itemName">The item name that gives the context in which the
        /// scriptlet is to be evaluated. If this parameter is null, the code is evaluated
        /// in the scripting engine's global context</param>
        /// <param name="context">The context object. This object is reserved for use in a
        /// debugging environment, where such a context may be provided by the debugger to
        /// represent an active run-time context. If this parameter is null, the engine
        /// uses <paramref name="itemName"/> to identify the context.</param>
        /// <param name="delimiter">The end-of-scriptlet delimiter. When <paramref name="code"/>
        /// is parsed from a stream of text, the host typically uses a delimiter, such as two
        /// single quotation marks (''), to detect the end of the scriptlet. This parameter
        /// specifies the delimiter that the host used, allowing the scripting engine to provide
        /// some conditional primitive preprocessing (for example, replacing a single quotation
        /// mark ['] with two single quotation marks for use as a delimiter). Exactly how
        /// (and if) the scripting engine makes use of this information depends on the
        /// scripting engine. Set this parameter to null if the host did not use a delimiter
        /// to mark the end of the scriptlet.</param>
        /// <param name="sourceContextCookie">Application-defined value that is used for
        /// debugging purposes</param>
        /// <param name="startingLineNumber">Zero-based value that specifies which line the
        /// parsing will begin at</param>
        /// <param name="flags">Flags associated with the scriptlet</param>
        /// <returns>The results of scriptlet processing, or null if the caller expects no
        /// result (that is, the <see cref="ScriptTextFlags.IsExpression"/> value is not set)</returns>
        public object ParseScriptText(string code, string itemName, object context, string delimiter,
                                      UIntPtr sourceContextCookie, uint startingLineNumber, ScriptTextFlags flags)
        {
            object result;

            if (_is64Bit)
            {
                _activeScriptParse64.ParseScriptText(
                    code,
                    itemName,
                    context,
                    delimiter,
                    sourceContextCookie,
                    startingLineNumber,
                    flags,
                    out result,
                    out _lastException);
            }
            else
            {
                _activeScriptParse32.ParseScriptText(
                    code,
                    itemName,
                    context,
                    delimiter,
                    sourceContextCookie,
                    startingLineNumber,
                    flags,
                    out result,
                    out _lastException);
            }

            return(result);
        }
示例#2
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>
        /// Parses the given code scriptlet, adding declarations into the namespace and
        /// evaluating code as appropriate.
        /// </summary>
        /// <param name="code">The scriptlet text to evaluate. The interpretation of this
        /// string depends on the scripting language.</param>
        /// <param name="itemName">The item name that gives the context in which the
        /// scriptlet is to be evaluated. If this parameter is NULL, the code is evaluated
        /// in the scripting engine's global context.</param>
        /// <param name="context">The context object. This object is reserved for use in a
        /// debugging environment, where such a context may be provided by the debugger to
        /// represent an active run-time context. If this parameter is NULL, the engine
        /// uses pstrItemName to identify the context.</param>
        /// <param name="delimiter">The end-of-scriptlet delimiter. When pstrCode is parsed
        /// from a stream of text, the host typically uses a delimiter, such as two single
        /// quotation marks (''), to detect the end of the scriptlet. This parameter specifies
        /// the delimiter that the host used, allowing the scripting engine to provide some
        /// conditional primitive preprocessing (for example, replacing a single quotation
        /// mark ['] with two single quotation marks for use as a delimiter). Exactly how
        /// (and if) the scripting engine makes use of this information depends on the
        /// scripting engine. Set this parameter to NULL if the host did not use a delimiter
        /// to mark the end of the scriptlet.</param>
        /// <param name="sourceContextCookie">Application-defined value that is used for
        /// debugging purposes.</param>
        /// <param name="startingLineNumber">Zero-based value that specifies which line the
        /// parsing will begin at.</param>
        /// <param name="flags">Flags associated with the scriptlet.</param>
        /// <returns>
        /// The results of scriptlet processing, or NULL if the caller
        /// expects no result (that is, the SCRIPTTEXT_ISEXPRESSION value is not set).
        /// </returns>
        public object ParseScriptText(
            string code,
            string itemName,
            object context,
            string delimiter,
            IntPtr sourceContextCookie,
            uint startingLineNumber,
            ScriptTextFlags flags)
        {
            object result;

            if (_parse32 != null)
            {
                _parse32.ParseScriptText(
                    code,
                    itemName,
                    context,
                    delimiter,
                    sourceContextCookie,
                    startingLineNumber,
                    flags,
                    out result,
                    out _exceptionInfo);
            }
            else if (_parse64 != null)
            {
                _parse64.ParseScriptText(
                    code,
                    itemName,
                    context,
                    delimiter,
                    sourceContextCookie,
                    startingLineNumber,
                    flags,
                    out result,
                    out _exceptionInfo);
            }
            else
            {
                throw new NotImplementedException(NeitherValidMessage);
            }

            return(result);
        }
示例#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);
        }
 internal void ParseScriptText(
     string code,
     string itemName,
     [MarshalAs(UnmanagedType.IUnknown)] object context,
     string delimiter,
     IntPtr sourceContextCookie,
     uint startingLineNumber,
     ScriptText flags,
     [MarshalAs(UnmanagedType.Struct)] out object result,
     out EXCEPINFO exceptionInfo)
 {
     if (asp32 != null)
     {
         asp32.ParseScriptText(code, itemName, context, delimiter, sourceContextCookie,
                               startingLineNumber, flags, out result, out exceptionInfo);
     }
     else
     {
         asp64.ParseScriptText(code, itemName, context, delimiter, sourceContextCookie,
                               startingLineNumber, flags, out result, out exceptionInfo);
     }
 }
示例#6
0
 public void ParseScriptText(
     string code,
     string itemName,
     object context,
     string delimiter,
     ulong sourceContext,
     uint startingLineNumber,
     ScriptTextFlags flags,
     IntPtr pVarResult,
     out EXCEPINFO excepInfo)
 {
     if (is64Bit)
     {
         activeScriptParse64.ParseScriptText(
             code,
             itemName,
             context,
             delimiter,
             sourceContext,
             startingLineNumber,
             flags,
             pVarResult,
             out excepInfo);
     }
     else
     {
         activeScriptParse32.ParseScriptText(
             code,
             itemName,
             context,
             delimiter,
             (uint)sourceContext,
             startingLineNumber,
             flags,
             pVarResult,
             out excepInfo);
     }
 }
示例#7
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);
        }
示例#8
0
 public override void ParseScriptText(string code, string itemName, object context, string delimiter, UIntPtr sourceContext, uint startingLineNumber, ScriptTextFlags flags, IntPtr pVarResult, out EXCEPINFO excepInfo)
 {
     activeScriptParse.ParseScriptText(code, itemName, context, delimiter, sourceContext.ToUInt64(), startingLineNumber, flags, pVarResult, out excepInfo);
 }
示例#9
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);
        }