Example #1
0
        /// <summary>
        /// Executes script code as a command.
        /// </summary>
        /// <param name="command">The script command to execute.</param>
        /// <returns>The command output.</returns>
        /// <remarks>
        /// <para>
        /// This method is similar to <see cref="ScriptEngine.Evaluate(string)"/> but optimized for
        /// command consoles. The specified command must be limited to a single expression or
        /// statement. Script engines can override this method to customize command execution as
        /// well as the process of converting the result to a string for console output.
        /// </para>
        /// <para>
        /// The <see cref="VBScriptEngine"/> version of this method supports both expressions and
        /// statements. If the specified command begins with "eval " (not case-sensitive), the
        /// engine executes the remainder as an expression and attempts to use
        /// <see href="https://docs.microsoft.com/en-us/previous-versions//0zk841e9(v=vs.85)">CStr</see>
        /// to convert the result value. Otherwise, it executes the command as a statement and does
        /// not return a value.
        /// </para>
        /// </remarks>
        public override string ExecuteCommand(string command)
        {
            var trimmedCommand = command.Trim();

            if (trimmedCommand.StartsWith("eval ", StringComparison.OrdinalIgnoreCase))
            {
                var expression   = MiscHelpers.FormatInvariant("EngineInternal.getCommandResult({0})", trimmedCommand.Substring(5));
                var documentInfo = new DocumentInfo("Expression")
                {
                    Flags = DocumentFlags.IsTransient
                };
                return(GetCommandResultString(Evaluate(documentInfo.MakeUnique(this), expression, false)));
            }

            Execute("Command", true, trimmedCommand);
            return(null);
        }
Example #2
0
 /// <summary>
 /// Creates a compiled script with the specified document meta-information, consuming previously generated cache data.
 /// </summary>
 /// <param name="documentInfo">A structure containing meta-information for the script document.</param>
 /// <param name="code">The script code to compile.</param>
 /// <param name="cacheKind">The kind of cache data to be consumed.</param>
 /// <param name="cacheBytes">Cache data for accelerated compilation.</param>
 /// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
 /// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
 /// <remarks>
 /// To be accepted, the cache data must have been generated for identical script code by
 /// the same V8 build.
 /// </remarks>
 /// <seealso cref="Compile(DocumentInfo, string, V8CacheKind, out byte[])"/>
 public V8Script Compile(DocumentInfo documentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
 {
     VerifyNotDisposed();
     return(CompileInternal(documentInfo.MakeUnique(documentNameManager), code, cacheKind, cacheBytes, out cacheAccepted));
 }
Example #3
0
 /// <summary>
 /// Creates a compiled script with the specified document meta-information.
 /// </summary>
 /// <param name="documentInfo">A structure containing meta-information for the script document.</param>
 /// <param name="code">The script code to compile.</param>
 /// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
 public V8Script Compile(DocumentInfo documentInfo, string code)
 {
     VerifyNotDisposed();
     return(CompileInternal(documentInfo.MakeUnique(documentNameManager), code));
 }