예제 #1
0
        /// <summary>
        /// Creates the type reference.
        /// </summary>
        /// <param name="engine">The engine.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static EngineTypeReference CreateTypeReference(Engine engine, Type type)
        {
            var obj = new EngineTypeReference(engine, TypeReference.CreateTypeReference(engine, type))
            {
                Extensible = false,
                Type       = type,
                Prototype  = engine.Function.PrototypeObject
            };

            obj.FastAddProperty("length", 0, false, false, false);

            // The initial value of Boolean.prototype is the Boolean prototype object
            obj.FastAddProperty("prototype", engine.Object.PrototypeObject, false, false, false);

            return(obj);
        }
예제 #2
0
        /// <summary>
        /// Executes the specified script.
        /// </summary>
        /// <param name="script">The script.</param>
        public void Execute(string script)
        {
            var engine = new Engine();

            ExecuteStartedDateTime = DateTime.Now;

            //
            // Add in this object for specialized use by other methods that
            // need to access us.
            //
            engine.SetValue("__Bootstrap", this);

            //
            // Add in our global class types.
            //
            engine.SetValue("Template", EngineTypeReference.CreateTypeReference(engine, typeof(Template)));
            engine.SetValue("Instance", EngineTypeReference.CreateTypeReference(engine, typeof(Instance)));

            //
            // Add in global methods available to the scripts.
            //
            engine.SetValue("Log", new Action <object>(Log));
            engine.SetValue("LogProgress", new Action <object>(LogProgress));
            engine.SetValue("Abort", new Action <object>(Abort));
            engine.SetValue("Beep", new Action(Beep));

            try
            {
                engine.Execute(script);
            }
            catch (EngineAbortException)
            {
                /* Intentionally left blank */
            }
            catch (Exception ex)
            {
                var node = engine.GetLastSyntaxNode();

                if (node != null && node.Location != null)
                {
                    Log(string.Format("Exception occurred at line {0}.", node.Location.Start.Line));
                }
                throw ex;
            }
        }