Skip to content

Instantly share code, notes, and snippets.

@vvuk
Created June 16, 2017 18:22
Show Gist options
  • Save vvuk/3f5eefee56ee5a1cf22141e96d3df62d to your computer and use it in GitHub Desktop.
Save vvuk/3f5eefee56ee5a1cf22141e96d3df62d to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using V8.Net;
namespace Test1
{
class GlobalUtils
{
public static void WriteLine(string s)
{
Console.WriteLine(s);
}
}
public class TestClass
{
public TestClass()
{
}
public void Foo()
{
Console.WriteLine("base Foo called");
}
public void Bar()
{
Console.WriteLine("base Bar called");
}
}
class Program
{
public static void Main(string[] args)
{
var js = new V8Engine();
js.SetFlagsFromString("--use-strict");
js.RegisterType<GlobalUtils>("utils", false, ScriptMemberSecurity.Locked);
js.GlobalObject.SetProperty(typeof(GlobalUtils));
js.RegisterType<TestClass>();
js.GlobalObject.SetProperty(typeof(TestClass));
js.ConsoleExecute(jssrc);
}
private static string jssrc = @"
class Derived extends TestClass {
constructor() {
super();
utils.WriteLine('derived constructor');
}
Foo() {
utils.WriteLine('Derived foo');
}
Something() {
utils.WriteLine('Something');
}
}
// BUG 1 -- this crashes
//utils.WriteLine(Object.getPrototypeOf('Derived'));
var d = new Derived();
d.Foo();
d.Bar();
d.Something();
";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment