当前位置: 首页>>代码示例>>C#>>正文


C# ScriptEngine.AddHostObject方法代码示例

本文整理汇总了C#中ScriptEngine.AddHostObject方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptEngine.AddHostObject方法的具体用法?C# ScriptEngine.AddHostObject怎么用?C# ScriptEngine.AddHostObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScriptEngine的用法示例。


在下文中一共展示了ScriptEngine.AddHostObject方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Install

        public void Install(IProjectSource source, ScriptEngine engine)
        {
            if (source is IScript == false)
            {
                return;
            }

            var console = new BrowserConsole((IScript) source);

            engine.AddHostObject(nameof(console), console);
        }
开发者ID:clbond,项目名称:continuous-runner,代码行数:11,代码来源:BrowserFramework.cs

示例2: Reflect

        public ITestCollection Reflect(IScript script, ScriptEngine engine)
        {
            var testCollection = _componentContext.Resolve<ITestCollection>(new TypedParameter(typeof(IScript), script));

            engine.AddHostObject(nameof(testCollection), testCollection);

            engine.Execute(
                @"function describe(description, callback) {
                        testCollection.AddSuite(description, callback.toString());
                        callback();
                      }");

            engine.Execute(
                @"function it(description, callback) {
                        testCollection.AddTest(description, callback.toString());
                      }");

            return testCollection;
        }
开发者ID:clbond,项目名称:continuous-runner,代码行数:19,代码来源:JasmineReflection.cs

示例3: TestInitialize

 public void TestInitialize()
 {
     engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging);
     engine.AddHostObject("host", new ExtendedHostFunctions());
     engine.AddHostObject("mscorlib", HostItemFlags.GlobalMembers, new HostTypeCollection("mscorlib"));
     engine.AddHostObject("ClearScriptTest", HostItemFlags.GlobalMembers, new HostTypeCollection("ClearScriptTest").GetNamespaceNode("Microsoft.ClearScript.Test"));
     engine.AddHostObject("testObject", testObject = new TestObject());
 }
开发者ID:sergueik,项目名称:swd-recorder-appium,代码行数:8,代码来源:BaseMemberAccessTest.cs

示例4: TestInitialize

 public void TestInitialize()
 {
     engine = new JScriptEngine(WindowsScriptEngineFlags.EnableDebugging);
     engine.AddHostObject("host", new ExtendedHostFunctions());
     engine.AddHostObject("mscorlib", HostItemFlags.GlobalMembers, new HostTypeCollection("mscorlib"));
     engine.AddHostObject("ClearScriptTest", HostItemFlags.GlobalMembers, new HostTypeCollection("ClearScriptTest").GetNamespaceNode("Microsoft.ClearScript.Test"));
     engine.AddHostObject("testObject", testInterface = testObject = new TestObject());
     engine.Execute("var testInterface = host.cast(IExplicitTestInterface, testObject)");
 }
开发者ID:julianhaslinger,项目名称:swd-recorder,代码行数:9,代码来源:ExplicitInterfaceMemberAccessTest.cs

示例5: Install

        public void Install(IProjectSource source, ScriptEngine engine)
        {
            if (source is IScript == false)
            {
                return;
            }

            var script = (IScript) source;

            var requireImpl = _componentContext.Resolve<RequireDefine>(
                new TypedParameter(typeof (ScriptEngine), engine),
                new TypedParameter(typeof (IScript), script));

            engine.AddHostObject(nameof(requireImpl), requireImpl);

            engine.Execute(
                @"var require = function (names, callback) {
                    var list = new mscorlib.System.Collections.ArrayList();

                    if (names && typeof names !== 'string') {
                        for (var i = 0; i < names.length; ++i) {
                          list.Add(names[i]);
                        }
                    }

                    var loaded = typeof name !== 'string'
                        ? requireImpl.RequireMultiple(list)
                        : requireImpl.RequireSingle(names);

                    if (typeof callback === 'function') {
                      return callback.apply(null, loaded);
                    }

                    return loaded;
                  };");

            engine.Execute(
              @"var define = function (name, deps, body) {
                  if (typeof name !== 'string') {
                      body = deps;
                      deps = name;
                      name = null;
                  }

                  if (deps instanceof Array === false) {
                    if (body == null && deps != null) {
                      body = deps;
                      deps = [];
                    }

                    body = deps;

                    deps = [];
                  }

                  var CallbackType = mscorlib.System.Func(mscorlib.System.Collections.ArrayList, mscorlib.System.Object);

                  var cb = new CallbackType(function(deps) {
                    if (typeof body === 'function') {
                      var transformed = [];

                      for (var i = 0; i < deps.Count; ++i) {
                        transformed.push(deps[i]);
                      }

                      return body.apply(null, deps);
                    }

                    return body;
                  });

                  var list = new mscorlib.System.Collections.ArrayList();

                  if (deps) {
                    for (var i = 0; i < deps.length; ++i) {
                      list.Add(deps[i]);
                    }
                  }

                  requireImpl.DefineModule(name, list, cb);

                  return require(name);
                };

                define['amd'] = true;");
        }
开发者ID:clbond,项目名称:continuous-runner,代码行数:86,代码来源:FrameworkImpl.cs

示例6: Init

 public void Init()
 {
     _eng = ScriptFactory.GetScriptEngine(this.ScriptingLanguage);
     for (int i = 0; i < _source.FieldCount; i++)
     {
         _fields.Add(_source.GetName(i));
     }
     _eng.AddHostObject("Record", _rec);
     _eng.AddHostType("Console", typeof(Console));
 }
开发者ID:raasiel,项目名称:Reflow,代码行数:10,代码来源:TransformedReader.cs

示例7: RunSuite

        public static void RunSuite(ScriptEngine engine)
        {
            // download raw test code if necessary
            if (!gotCode)
            {
                Console.Write("Downloading code... ");
                testPrefix = DownloadFileAsString("sunspider-test-prefix.js");
                testContents = DownloadFileAsString("sunspider-test-contents.js");
                Console.WriteLine("Done");
                gotCode = true;
            }

            // set up dummy HTML DOM
            var mockDOM = new MockDOM();
            engine.AccessContext = typeof(SunSpider);
            engine.AddHostObject("document", mockDOM);
            engine.AddHostObject("window", mockDOM);
            engine.AddHostObject("parent", mockDOM);

            // load raw test code
            engine.Execute(testPrefix);
            engine.Execute(testContents);
            engine.Execute(@"
                function ClearScriptCleanup() {
                    delete Array.prototype.toJSONString;
                    delete Boolean.prototype.toJSONString;
                    delete Date.prototype.toJSONString;
                    delete Number.prototype.toJSONString;
                    delete Object.prototype.toJSONString;
                }
            ");

            // initialize
            var testCount = (int)engine.Script.tests.length;
            var testIndices = Enumerable.Range(0, testCount).ToList();
            var repeatIndices = Enumerable.Range(0, repeatCount).ToList();

            // run warmup cycle
            Console.Write("Warming up... ");
            testIndices.ForEach(testIndex => RunTest(engine, mockDOM, testIndex));
            Console.WriteLine("Done");

            // run main test
            var results = repeatIndices.Select(index => new Dictionary<string, int>()).ToArray();
            repeatIndices.ForEach(repeatIndex =>
            {
                Console.Write("Running iteration {0}... ", repeatIndex + 1);
                testIndices.ForEach(testIndex =>
                {
                    var name = (string)engine.Script.tests[testIndex];
                    results[repeatIndex][name] = RunTest(engine, mockDOM, testIndex);
                });
                Console.WriteLine("Done");
            });

            // show results
            var resultString = new StringBuilder("{\"v\":\"" + version + "\",");
            results[0].Keys.ToList().ForEach(name =>
            {
                resultString.Append("\"" + name + "\":[");
                resultString.Append(string.Join(",", repeatIndices.Select(repeatIndex => results[repeatIndex][name])));
                resultString.Append("],");
            });
            resultString.Length -= 1;
            resultString.Append("}");
            Process.Start((new Uri(baseUrl + "results.html?" + resultString)).AbsoluteUri);
        }
开发者ID:dirkelfman,项目名称:ClearScript,代码行数:67,代码来源:SunSpider.cs

示例8: BugFix_AmbiguousIndexer_ADODB

        public void BugFix_AmbiguousIndexer_ADODB()
        {
            engine.Dispose();
            engine = new VBScriptEngine(WindowsScriptEngineFlags.EnableDebugging);

            var recordSet = new ADODB.Recordset();
            recordSet.Fields.Append("foo", ADODB.DataTypeEnum.adVarChar, 20);
            recordSet.Open(Missing.Value, Missing.Value, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic, 0);
            recordSet.AddNew(Missing.Value, Missing.Value);
            recordSet.Fields["foo"].Value = "bar";

            engine.AddHostObject("recordSet", recordSet);
            Assert.AreEqual("bar", engine.Evaluate("recordSet.Fields.Item(\"foo\").Value"));

            engine.Execute("recordSet.Fields.Item(\"foo\").Value = \"qux\"");
            Assert.AreEqual("qux", engine.Evaluate("recordSet.Fields.Item(\"foo\").Value"));

            TestUtil.AssertException<ScriptEngineException>(() => engine.Evaluate("recordSet.Fields.Item(\"baz\")"));
        }
开发者ID:dirkelfman,项目名称:ClearScript,代码行数:19,代码来源:BugFixTest.cs


注:本文中的ScriptEngine.AddHostObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。