예제 #1
0
            private BuilderJsObject(IronJS.Environment env, Builder builder)
                : base(env, env.NewPrototype())
            {
                Put("run",
                    IronJS.Native.Utils.CreateFunction<Action<CommonObject>>(env, 1, obj => builder.Run(new JavaScriptApp(obj))));

                Put("use",
                    IronJS.Native.Utils.CreateFunction<Action<CommonObject>>(env, 1,
                        obj => builder.Use(typeof(JavaScriptApp), obj)));

                Put("map",
                    IronJS.Native.Utils.CreateFunction<Action<string, FunctionObject>>(env, 2,
                        (str, func) => builder.Map(str, MapBuilder(func))));
            }
            public JsStream(IronJS.Environment env, Stream stream) 
                : base(env, env.NewPrototype())
            {
                Put("read",
                    IronJS.Native.Utils.CreateFunction<Func<CommonObject>>(env, 0,
                        () =>
                        {
                            if (stream == null)
                            {
                                return null;
                            }

                            string input;
                            using (var strm = stream)
                            {
                                strm.Position = 0;
                                var reader = new StreamReader(strm);
                                input = reader.ReadToEnd();
                                strm.Close();
                            }

                            return env.NewString(input);
                        }));
            }