示例#1
0
        public object InstallBundle(Jurassic.ScriptEngine engine)
        {
            var baristaInstance = engine.GetGlobalValue("barista") as BaristaGlobal;

            if (baristaInstance == null)
            {
                throw new InvalidOperationException("Barista Global bundle could not be obtained.");
            }

            var dependencyResultObj = engine.Object.Construct();

            //Require all dependencies..
            foreach (var dependency in m_dependencies)
            {
                var result = baristaInstance.Common.Require(dependency.Key, null);
                dependencyResultObj.SetPropertyValue(dependency.Value, result, false);
            }

            //If it's a function dependency, execute that.
            if (this.ScriptFunction != null)
            {
                var args = new List <object>();
                if (this.ScriptFunction is UserDefinedFunction)
                {
                    var udf = this.ScriptFunction as UserDefinedFunction;

                    args.AddRange(udf.ArgumentNames.Select(argumentName => dependencyResultObj.HasProperty(argumentName) ? dependencyResultObj.GetPropertyValue(argumentName) : Null.Value));
                }

                return(this.ScriptFunction.Call(engine.Global, args.ToArray()));
            }

            //Use the implemented "include" function to include the scripts.
            //this promotes loose coupling between the script bundle and the include.
            var variableNames = dependencyResultObj.Properties.Select(pn => pn.Name).ToArray();
            var resultArray   = engine.Array.Construct();

            foreach (var scriptReference in m_scriptReferences)
            {
                //Create a new scope, and eval the script within the new scope.
                var scope = DeclarativeScope.CreateRuntimeScope(engine.CreateGlobalScope(), variableNames);
                foreach (var property in dependencyResultObj.Properties)
                {
                    if (property.Value == Undefined.Value || property.Value == Null.Value || property.Value == null)
                    {
                        continue;
                    }

                    scope.SetValue(property.Name, property.Value);
                }

                var result = baristaInstance.Include(scriptReference, scope, engine.Global, engine.ForceStrictMode);

                ArrayInstance.Push(resultArray, result);
            }

            return(resultArray.Length == 1
        ? resultArray[0]
        : resultArray);
        }
示例#2
0
文件: ImpactGame.cs 项目: Kevnz/JS360
        protected override void Initialize()
        {
            timers = new TimerManager();

            js = new Jurassic.ScriptEngine();
            js.SetGlobalFunction("setTimeout", new Action <Jurassic.Library.FunctionInstance, int>(setTimeout));
            js.SetGlobalFunction("setInterval", new Action <Jurassic.Library.FunctionInstance, int>(setInterval));
            js.SetGlobalFunction("clearTimeout", new Action <int>(clearTimeout));
            js.SetGlobalFunction("clearInterval", new Action <int>(clearInterval));

            js.SetGlobalValue("window", js.Global);
            js.SetGlobalValue("console", new JSConsole(js));
            js.SetGlobalValue("Canvas", new JSCanvasConstructor(js));
            js.SetGlobalValue("Image", new JSImageConstructor(js));

#if !XBOX
            if (GenerateAndExit != null)
            {
                GenerateAssemblyAndExit(GenerateAndExit);
                return;
            }
#endif

#if XBOX || RELEASE
            // On the XBOX or RELEASE config, run the compiled JavaScript from the Assembly
            js.LoadFromAssembly("ImpactGame");
            Generated.Main(js, js.CreateGlobalScope(), js.Global);
#else
            // In Windows/DEBUG, run JavaScript directly from source
            js.EnableDebugging = true;
            js.Evaluate(new Jurassic.FileScriptSource("Game/index.js"));
#endif
            base.Initialize();
        }
示例#3
0
        protected override void Initialize()
        {
            timers = new TimerManager();

            js = new Jurassic.ScriptEngine();
            js.SetGlobalFunction("setTimeout", new Action<Jurassic.Library.FunctionInstance, int>(setTimeout));
            js.SetGlobalFunction("setInterval", new Action<Jurassic.Library.FunctionInstance, int>(setInterval));
            js.SetGlobalFunction("clearTimeout", new Action<int>(clearTimeout));
            js.SetGlobalFunction("clearInterval", new Action<int>(clearInterval));

            js.SetGlobalValue("window", js.Global);
            js.SetGlobalValue("console", new JSConsole(js));
            js.SetGlobalValue("Canvas", new JSCanvasConstructor(js));
            js.SetGlobalValue("Image", new JSImageConstructor(js));

            #if !XBOX
            if (GenerateAndExit != null)
            {
                GenerateAssemblyAndExit(GenerateAndExit);
                return;
            }

            #endif

            #if XBOX || RELEASE
            // On the XBOX or RELEASE config, run the compiled JavaScript from the Assembly
            js.LoadFromAssembly("ImpactGame");
            Generated.Main(js, js.CreateGlobalScope(), js.Global);
            #else
            // In Windows/DEBUG, run JavaScript directly from source
            js.EnableDebugging = true;
            js.Evaluate(new Jurassic.FileScriptSource("Game/index.js"));
            #endif
            base.Initialize();
        }