示例#1
0
 internal CompiledEval(GlobalOrEvalMethodGenerator methodGen)
 {
     if (methodGen == null)
     {
         throw new ArgumentNullException(nameof(methodGen));
     }
     this.methodGen = methodGen;
 }
示例#2
0
        /// <summary>
        /// Compiles source code into a quickly executed form, using the given compiler options.
        /// </summary>
        /// <param name="source"> The javascript source code to execute. </param>
        /// <param name="options"> Compiler options, or <c>null</c> to use the default options. </param>
        /// <returns> A CompiledScript instance, which can be executed as many times as needed. </returns>
        /// <exception cref="ArgumentNullException"> <paramref name="source"/> is a <c>null</c> reference. </exception>
        public static CompiledEval Compile(ScriptSource source, CompilerOptions options = null)
        {
            var methodGen = new GlobalOrEvalMethodGenerator(
                source,                             // The source code.
                options ?? new CompilerOptions(),   // The compiler options.
                GlobalOrEvalMethodGenerator.GeneratorContext.GlobalEval);

            // Parse
            methodGen.Parse();

            // Optimize
            methodGen.Optimize();

            // Generate code
            methodGen.GenerateCode();

            return(new CompiledEval(methodGen));
        }