Skip to content

Instantly share code, notes, and snippets.

@vvuk
Created June 16, 2017 18:22
Show Gist options
  • Select an option

  • Save vvuk/3f5eefee56ee5a1cf22141e96d3df62d to your computer and use it in GitHub Desktop.

Select an option

Save vvuk/3f5eefee56ee5a1cf22141e96d3df62d to your computer and use it in GitHub Desktop.

Revisions

  1. vvuk created this gist Jun 16, 2017.
    75 changes: 75 additions & 0 deletions Test1.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,75 @@
    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();
    ";
    }
    }