本文整理汇总了C#中JintEngine类的典型用法代码示例。如果您正苦于以下问题:C# JintEngine类的具体用法?C# JintEngine怎么用?C# JintEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JintEngine类属于命名空间,在下文中一共展示了JintEngine类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var assembly = Assembly.Load("Jint.Tests");
Stopwatch sw = new Stopwatch();
// string script = new StreamReader(assembly.GetManifestResourceStream("Jint.Tests.Parse.coffeescript-debug.js")).ReadToEnd();
JintEngine jint = new JintEngine()
// .SetDebugMode(true)
.DisableSecurity()
.SetFunction("print", new Action<string>(Console.WriteLine))
.SetFunction("write", new Action<string>(t => Console.WriteLine(t)))
.SetFunction("stop", new Action(delegate() { Console.WriteLine(); }));
sw.Reset();
sw.Start();
try
{
Console.WriteLine(jint.Run("2+3"));
Console.WriteLine("after0");
Console.WriteLine(jint.Run(")(---"));
Console.WriteLine("after1");
Console.WriteLine(jint.Run("FOOBAR"));
Console.WriteLine("after2");
}
catch (JintException e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("{0}ms", sw.ElapsedMilliseconds);
}
开发者ID:arelee,项目名称:ravendb,代码行数:33,代码来源:Program.cs
示例2: Main
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
// string script = new StreamReader(assembly.GetManifestResourceStream("Jint.Tests.Parse.coffeescript-debug.js")).ReadToEnd();
JintEngine jint = new JintEngine()
// .SetDebugMode(true)
.DisableSecurity()
.SetFunction("print", new Action<string>(Console.WriteLine))
.SetFunction("write", new Action<string>(t => Console.WriteLine(t)))
.SetFunction("stop", new Action(delegate() { Console.WriteLine(); }));
sw.Reset();
jint.SetMaxRecursions(50);
jint.SetMaxSteps(10*1000);
sw.Start();
try
{
Console.WriteLine(
jint.Run(File.ReadAllText(@"C:\Work\ravendb-1.2\SharedLibs\Sources\jint-22024d8a6e7a\Jint.Play\test.js")));
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
Console.WriteLine("{0}ms", sw.ElapsedMilliseconds);
}
}
开发者ID:karlgrz,项目名称:ravendb,代码行数:32,代码来源:Program.cs
示例3: TestPerformance
public void TestPerformance()
{
string[] tests = { "3d-cube", "3d-morph", "3d-raytrace", "access-binary-trees", "access-fannkuch", "access-nbody", "access-nsieve", "bitops-3bit-bits-in-byte", "bitops-bits-in-byte", "bitops-bitwise-and", "bitops-nsieve-bits", "controlflow-recursive", "crypto-aes", "crypto-md5", "crypto-sha1", "date-format-tofte", "date-format-xparb", "math-cordic", "math-partial-sums", "math-spectral-norm", "regexp-dna", "string-base64", "string-fasta", "string-tagcloud", "string-unpack-code", "string-validate-input" };
var assembly = Assembly.GetExecutingAssembly();
Stopwatch sw = new Stopwatch();
foreach (var test in tests) {
string script;
try {
script = new StreamReader(assembly.GetManifestResourceStream("Jint.Tests.SunSpider." + test + ".js")).ReadToEnd();
if (String.IsNullOrEmpty(script)) {
continue;
}
}
catch {
Console.WriteLine("{0}: ignored", test);
continue;
}
JintEngine jint = new JintEngine()
//.SetDebugMode(true)
.DisableSecurity();
sw.Reset();
sw.Start();
jint.Run(script);
Console.WriteLine("{0}: {1}ms", test, sw.ElapsedMilliseconds);
}
}
开发者ID:cosh,项目名称:Jint,代码行数:33,代码来源:SunSpider.cs
示例4: Main
static void Main(string[] args)
{
var assembly = Assembly.Load("Jint.Tests");
Stopwatch sw = new Stopwatch();
string script = new StreamReader(assembly.GetManifestResourceStream("Jint.Tests.Parse.coffeescript-format.js")).ReadToEnd();
JintEngine jint = new JintEngine()
// .SetDebugMode(true)
.DisableSecurity()
.SetFunction("print", new Action<string>(Console.WriteLine))
.SetFunction("stop", new Action( delegate() { Console.WriteLine(); }));
sw.Reset();
sw.Start();
jint.Run(script);
try
{
var result = jint.Run("CoffeeScript.compile('number = 42', {bare: true})");
}
catch (JintException e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("{0}ms", sw.ElapsedMilliseconds);
}
开发者ID:cosh,项目名称:Jint,代码行数:26,代码来源:Program.cs
示例5: RunFile
protected override object RunFile(JintEngine ctx, string fileName)
{
if (Debugger.IsAttached)
return base.RunFile(ctx, fileName);
else
return Timeout.Run(() => base.RunFile(ctx, fileName), ScriptTimeout);
}
开发者ID:pvginkel,项目名称:Jint2-Test262,代码行数:7,代码来源:Test262Fixture.cs
示例6: MainPage
// Constructor
public MainPage()
{
InitializeComponent();
engine = new JintEngine();
engine.SetFunction("alert", new Action<string>(t => MessageBox.Show(t)));
}
开发者ID:joelmartinez,项目名称:Jint.Phone,代码行数:8,代码来源:MainPage.xaml.cs
示例7: JintRuntime
public JintRuntime(JintEngine engine)
{
if (engine == null)
throw new ArgumentNullException("engine");
_engine = engine;
Global = new JsGlobal(this, engine);
GlobalScope = Global.GlobalScope;
}
开发者ID:pvginkel,项目名称:Jint2,代码行数:10,代码来源:JintRuntime.cs
示例8: ExecuteSunSpider
private static void ExecuteSunSpider()
{
const string fileName = @"..\..\..\Jint.Tests\SunSpider\Tests\access-fannkuch.js";
var jint = new JintEngine();
#if false
jint.ExecuteFile(fileName);
Console.WriteLine("Attach");
Console.ReadLine();
jint.ExecuteFile(fileName);
#else
jint.ExecuteFile(fileName);
var times = new TimeSpan[20];
int timeOffset = 0;
var lowest = new TimeSpan();
// Perform the iterations.
for (int i = 0; ; i++)
{
long memoryBefore = GC.GetTotalMemory(true);
var stopwatch = Stopwatch.StartNew();
jint.ExecuteFile(fileName);
var elapsed = stopwatch.Elapsed;
long memoryAfter = GC.GetTotalMemory(false);
times[timeOffset++] = elapsed;
if (timeOffset == times.Length)
timeOffset = 0;
if (times[times.Length - 1].Ticks != 0)
{
var average = new TimeSpan(times.Sum(p => p.Ticks) / times.Length);
if (lowest.Ticks == 0 || average.Ticks < lowest.Ticks)
lowest = average;
Console.WriteLine(
"This run: {0}, average: {1}, lowest: {2}, memory usage: {3}",
elapsed.ToString("s\\.fffff"),
average.ToString("s\\.fffff"),
lowest.ToString("s\\.fffff"),
NiceMemory(memoryAfter - memoryBefore)
);
}
}
#endif
}
开发者ID:pvginkel,项目名称:Jint2,代码行数:55,代码来源:Program.cs
示例9: RunFile
protected override object RunFile(JintEngine ctx, string fileName)
{
base.RunFile(ctx, fileName);
string suitePath = Path.Combine(
Path.GetDirectoryName(fileName),
"underscore-suite.js"
);
return ctx.ExecuteFile(suitePath);
}
开发者ID:pvginkel,项目名称:Jint2,代码行数:11,代码来源:Json2.cs
示例10: ShouldNotRunInRun
public void ShouldNotRunInRun()
{
var filename = Path.GetTempFileName();
File.WriteAllText(filename, "a='bar'");
var engine = new JintEngine().AddPermission(new FileIOPermission(PermissionState.None));
engine.AllowClr();
engine.SetFunction("load", new Action<string>(p => engine.ExecuteFile(p)));
engine.SetFunction("print", new Action<string>(Console.WriteLine));
engine.Execute("var a='foo'; load('" + EscapeStringLiteral(filename) + "'); print(a);");
}
开发者ID:pvginkel,项目名称:Jint2,代码行数:11,代码来源:EngineTests.cs
示例11: Main
static void Main(string[] args)
{
string line;
var jint = new JintEngine();
jint.SetFunction("print", new Action<object>(s => { Console.ForegroundColor = ConsoleColor.Blue; Console.Write(s); Console.ResetColor(); }));
#pragma warning disable 612,618
jint.SetFunction("import", new Action<string>(s => { Assembly.LoadWithPartialName(s); }));
#pragma warning restore 612,618
jint.DisableSecurity();
while (true) {
Console.Write("jint > ");
StringBuilder script = new StringBuilder();
while (String.Empty != (line = Console.ReadLine())) {
if (line.Trim() == "exit") {
return;
}
if (line.Trim() == "reset") {
jint = new JintEngine();
break;
}
if (line.Trim() == "help" || line.Trim() == "?") {
Console.WriteLine(@"Jint Shell");
Console.WriteLine(@"");
Console.WriteLine(@"exit - Quits the application");
Console.WriteLine(@"import(assembly) - assembly: String containing the partial name of a .NET assembly to load");
Console.WriteLine(@"reset - Initialize the current script");
Console.WriteLine(@"print(output) - Prints the specified output to the console");
Console.WriteLine(@"");
break;
}
script.AppendLine(line);
}
Console.SetError(new StringWriter(new StringBuilder()));
try {
jint.Execute(script.ToString());
}
catch (Exception e) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e.Message);
Console.ResetColor();
}
Console.WriteLine();
}
}
开发者ID:pvginkel,项目名称:Jint2,代码行数:54,代码来源:Program.cs
示例12: RunFile
protected override object RunFile(JintEngine ctx, string fileName)
{
string shellPath = Path.Combine(
Path.GetDirectoryName(fileName),
"shell.js"
);
if (File.Exists(shellPath))
ctx.ExecuteFile(shellPath);
return base.RunFile(ctx, fileName);
}
开发者ID:pvginkel,项目名称:Jint2,代码行数:12,代码来源:MozillaFixture.cs
示例13: Compile
private static BoundProgram Compile(string script)
{
var programSyntax = JintEngine.ParseProgram(script);
var engine = new JintEngine();
var visitor = new BindingVisitor(engine.TypeSystem.CreateScriptBuilder(null));
programSyntax.Accept(visitor);
var program = SquelchPhase.Perform(visitor.Program);
DefiniteAssignmentPhase.Perform(program);
return program;
}
开发者ID:pvginkel,项目名称:Jint2,代码行数:14,代码来源:DefiniteAssignmentFixture.Support.cs
示例14: RunInclude
protected override void RunInclude(JintEngine engine, string fileName)
{
string source;
if (!_includeCache.TryGetValue(fileName, out source))
{
source =
GetSpecialInclude(fileName) ??
File.ReadAllText(Path.Combine(_libPath, fileName));
_includeCache.Add(fileName, source);
}
engine.Execute(source, fileName);
}
开发者ID:pvginkel,项目名称:Jint2,代码行数:15,代码来源:FixturesFixture.cs
示例15: CreateContext
protected virtual JintEngine CreateContext(Action<string> errorAction)
{
var ctx = new JintEngine();
Action<string> failAction = Assert.Fail;
Action<string> printAction = message => Trace.WriteLine(message);
Action<string> includeAction = file => RunInclude(ctx, file);
ctx.SetFunction("$FAIL", failAction);
ctx.SetFunction("ERROR", errorAction);
ctx.SetFunction("$ERROR", errorAction);
ctx.SetFunction("$PRINT", printAction);
ctx.SetFunction("$INCLUDE", includeAction);
return ctx;
}
开发者ID:pvginkel,项目名称:Jint2,代码行数:16,代码来源:ScriptTestBase.cs
示例16: ExecuteSunSpiderScript
private static void ExecuteSunSpiderScript(string scriptName)
{
const string prefix = "Jint.Tests.SunSpider.";
var script = prefix + scriptName;
var assembly = Assembly.GetExecutingAssembly();
var program = new StreamReader(assembly.GetManifestResourceStream(script)).ReadToEnd();
var jint = new JintEngine(Options.Ecmascript5); // The SunSpider scripts doesn't work with strict mode
var sw = new Stopwatch();
sw.Start();
jint.Run(program);
Console.WriteLine(sw.Elapsed);
}
开发者ID:925coder,项目名称:ravendb,代码行数:16,代码来源:SunSpider.cs
示例17: ShouldRunInRun
public void ShouldRunInRun()
{
var filename = Path.GetTempFileName();
File.WriteAllText(filename, "a='bar'");
var engine = new JintEngine().AddPermission(new FileIOPermission(PermissionState.Unrestricted));
engine.AllowClr();
// The DLR compiler won't compile with permissions set
engine.DisableSecurity();
engine.SetFunction("load", new Action<string>(p => engine.ExecuteFile(p)));
engine.SetFunction("print", new Action<string>(Console.WriteLine));
engine.Execute("var a='foo'; load('" + EscapeStringLiteral(filename) + "'); print(a);");
File.Delete(filename);
}
开发者ID:pvginkel,项目名称:Jint2,代码行数:17,代码来源:EngineTests.cs
示例18: Main
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
// string script = new StreamReader(assembly.GetManifestResourceStream("Jint.Tests.Parse.coffeescript-debug.js")).ReadToEnd();
JintEngine jint = new JintEngine()
// .SetDebugMode(true)
.DisableSecurity()
.SetFunction("print", new Action<string>(Console.WriteLine))
.SetFunction("write", new Action<string>(t => Console.WriteLine(t)))
.SetFunction("stop", new Action(delegate() { Console.WriteLine(); }));
sw.Reset();
sw.Start();
Console.WriteLine(jint.Run("Math.floor(1.5)"));
Console.WriteLine("{0}ms", sw.ElapsedMilliseconds);
}
开发者ID:remcoros,项目名称:ravendb,代码行数:20,代码来源:Program.cs
示例19: ExecuteV8
private static void ExecuteV8()
{
const string fileName = @"..\..\..\Jint.Benchmarks\Suites\V8\raytrace.js";
var jint = new JintEngine();
jint.DisableSecurity();
jint.ExecuteFile(@"..\..\..\Jint.Benchmarks\Suites\V8\base.js");
jint.SetFunction(
"NotifyResult",
new Action<string, string>((name, result) => { })
);
jint.SetFunction(
"NotifyError",
new Action<string, object>((name, error) => { })
);
string score = null;
jint.SetFunction(
"NotifyScore",
new Action<string>(p => { score = p; })
);
jint.ExecuteFile(fileName);
Console.WriteLine("Attach");
Console.ReadLine();
jint.Execute(@"
BenchmarkSuite.RunSuites({
NotifyResult: NotifyResult,
NotifyError: NotifyError,
NotifyScore: NotifyScore,
Runs: 1
});");
Console.WriteLine("Score: " + score);
}
开发者ID:pvginkel,项目名称:Jint2,代码行数:41,代码来源:Program.cs
示例20: JsGlobal
public JsGlobal(JintRuntime runtime, JintEngine engine)
{
if (runtime == null)
throw new ArgumentNullException("runtime");
_runtime = runtime;
Id.SeedGlobal(this);
PrototypeSink = CreatePrototypeSink();
RootSchema = new JsSchema();
Engine = engine;
// The Random instance is used by Math to generate random numbers.
Random = new Random();
BuildEnvironment();
GlobalScope = CreateGlobalScope();
Marshaller = new Marshaller(runtime, this);
Marshaller.Initialize();
}
开发者ID:pvginkel,项目名称:Jint2,代码行数:23,代码来源:JsGlobal.cs
注:本文中的JintEngine类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论