GithubHelp home page GithubHelp logo

rjamesnw / v8dotnet Goto Github PK

View Code? Open in Web Editor NEW
155.0 12.0 41.0 301.28 MB

A fairly non-abstracted wrapper for Google's V8 JavaScript engine.

License: GNU Lesser General Public License v2.1

C++ 12.60% C# 82.81% CSS 0.04% ASP 0.01% JavaScript 0.93% HTML 2.84% Batchfile 0.67% C 0.10%
v8-engine c-sharp v8 v8-javascript-engine v8-net v8-wrapper

v8dotnet's People

Contributors

msvanvertloo avatar rjamesnw avatar wangjia184 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

v8dotnet's Issues

Dynamic module loading

Hi,

Is it possible to enable dynamic module loading?

In C++, you would call

void SetHostImportModuleDynamicallyCallback(HostImportModuleDynamicallyCallback callback)

on an isolate.

Thanks,
Mike

Run NodeJS

Hi,
i want to emulate a browser inside of v8.
After some research i found jsdom which implements the things needed to archive this.
My problem is that this script requires node.js.
Is there any way to make this script run on v8 via your wrapper?
I would be really glad to receive some tips for this. Thanks!

"Could not locate the required V8 native libraries" on macOS (.NET Core)

Hi James! Thank you for this library!

I created a dotnet new console project using the .NET Core 2 as the target, and used dotnet add package to install V8.NET. This is on macOS.

However, I'm getting the Could not locate the required V8 native libraries error, even though I've checked the paths for the DLL, and it is indeed there.

Any ideas?

params keyword not working

Using the params keyword throws the following exception:

V8ExecutionErrorException: Uncaught Error: Failed to invoke constructor: => Message: Types.ChangeType(): Cannot convert value "Hello" (type: 'System.String') to type 'System.String[]'. If you are developing the source type yourself, implement the 'IConvertible' interface.

Sample:

/// <summary>
/// The MFString field contains zero or more strings.
/// </summary>
[ScriptObject("MFString", ScriptMemberSecurity.NoAcccess)]
public class MFString
{
	private List<string> values = new List<string>();

	public MFString(params string[] values)
	{
		this.values.AddRange(values);
	}

	[ScriptMember("push", ScriptMemberSecurity.Locked)]
	private void Push(params string[] values)
	{
		this.values.AddRange(values);
	}

	[ScriptMember("toString", ScriptMemberSecurity.Locked)]
	public override string ToString()
	{
		return string.Join(", ", values);
	}
}
Engine.RegisterType<MFString>(null, null, ScriptMemberSecurity.Locked);
Engine.GlobalObject.SetProperty(typeof(MFString));

Engine.Execute
(@"
	function test() {
		var s = new MFString('Hello', 'World');
		Browser.println(s);
		s.push('!', 'Test', 'Test2');
		Browser.println(s);
	}

	test();
", "V8.NET", true, 0);

Unity/Android Build?

I’m interested in running ES6 Javascript modules within Unity (C#) in a way that lets me call C# functions / pass parameters back and forth. Specifically I’m targeting Android, not Windows. (That’s why something like Clearscript that uses mixed assemblies doesn’t work.) However, I can’t seem to find evidence that V8.NET supports platforms other than Windows. Is what I am looking for possible, and in that case, how would I build the project for my use case?
I’m currently looking around here, but am not really sure how to proceed: https://github.com/rjamesnw/v8dotnet/tree/master/Source/V8.NET-Proxy

Instantiation of classes which inherit from V8NativeObject in JS not working

The following sample throws a V8ExecutionErrorException in TypeBinder::_BindTypeMembers, because handle.Object in line 1561 of V8Engine_Binding.cs returns null:

[ScriptObject("Person", ScriptMemberSecurity.NoAcccess)]
public class Person : V8NativeObject
{
	[ScriptMember("name", ScriptMemberSecurity.ReadWrite)]
	public string Name { get; set; }

	public Person(string name)
	{
		Name = name;
	}

	[ScriptMember("toString", ScriptMemberSecurity.ReadWrite)]
	public override string ToString()
	{
		return Name;
	}
}
Engine.RegisterType<Person>();
Engine.GlobalObject.SetProperty(typeof(Person));

Engine.Execute
(@"
	function test() {
		var p = new Person('Bruce');
	}

	test();
", "V8.NET", true, 0);

As always, thank you. :-)

DllFileNotFound when in used in Xamarin.Forms

I get DllFileNotFound exeption when using v8.net in a net standard library from a Xamarin Forms project. It happens on both Android and iOS. It could be more of a Xamarin problem as I believe that neither the iOS nor the Android can directly use dll.

I have both dlls in my net standard library project set as Content, in Visual Studio.

Looking in the extensive docs it says it should be possible. It seems an iOS and Android project has to be added in addition to the netstandardlibrary.

Process with V8 dotnet crashes randomly

My scenario is I creae V8Engine evaluate some js, then disponse V8.
All is fine but periodically process crashes with:

Test host process crashed : #
Fatal error in C:\ProgramData\Google\V8\src\v8\src/api-inl.h, line 126
Debug check failed: allow_empty_handle || that != nullptr.####FailureMessage Object: 000000637837EBF0#
Fatal error in ../../src/base/platform/mutex.cc, line 207

Debug check failed: 0 == level_ (0 vs. 1).####FailureMessage Object: 000000637C1F90E0==== C stack trace =============================== (No symbol) [0x00007FF892A541EB] (No symbol) [0x00007FF89276F921] (No symbol) [0x00007FF89276090F] (No symbol) [0x00007FF89275F6B3] (No symbol) [0x00007FF892766574] (No symbol) [0x00007FF891EA8923] (No symbol) [0x00007FF891EAE4EE] (No symbol) [0x00007FF8918162DB] (No symbol) [0x00007FF8917F986A]==== C stack trace =============================== DestroyV8EngineProxy [0xDestroyV8EngineProxy [0x00007FF8917FC4CD+109]00007FF892A541EB+19220107] V8ExecuteCompiledScript [0x00007FF89276F921+16186817] (No symbol) [0xV8ExecuteCompiledScript [0x00007FF89276090F+16125359] V8ExecuteCompiledScript [0x00007FF89275F6B3+16120659] V8ExecuteCompiledScript [0x00007FF891835DD6+221814]00007FF8406EAFFE] (No symbol) [0x00007FF8917F9213] DisposeHandleProxy [0x00007FF8917FC5DC+236] (No symbol) [0x00007FF8406DDE3E]

I've tried to make minimal test, but no luck so far

InternalHandle <object: Array> conversion

How can i convert the InternalHandle from function args into an array type, IsArray = true but i cant convert it to an array type in managed code.

If i try args[0].As<char[]> or any alternative its throwing exceptions.

if (_req.Method == "POST" && args.Length == 1)
{
	if (args[0].IsString)
	{
		var pd = Encoding.UTF8.GetBytes(args[0].AsString);
		_req.GetRequestStream().Write(pd, 0, pd.Length);
	}
	else if (args[0].IsArray)
	{
		var pd = args[0].As<char[]>();
		_req.GetRequestStream().Write(pd, 0, pd.Length);
	}
}

crash with WriteLine(Object.getPrototypeOf('foo'))

(development branch)

This causes a native crash in v8, with the stack trace below.. not sure if this is a v8 bug or a v8.net bug. Can be reproduced by running the Console.exe tool and evaluating:

Console.WriteLine(Object.getPrototype('foo'))

(note the bogus quotes around 'foo')

v8 version is whatever the hash is in the download script

Named property setters not called due to recent changes

The commit f41cf81 broke named property setters. The engine does not call them anymore.

//EDIT:
Indexed properties seem to work, only named property setters are affected.

Reproduction sample:

[ScriptObject("Person", ScriptMemberSecurity.NoAcccess)]
public class Person
{
	[ScriptMember("name", ScriptMemberSecurity.ReadWrite)]
	public string Name { get; set; }

	private int age;

	public Person()
	{
		Name = "Michio";
		age = 72;
	}

	[ScriptMember("age", ScriptMemberSecurity.Permanent)]
	public int Age
	{
		get
		{
			return age;
		}
		set
		{
			// Will not get called
			age = value + 1;
		}
	}

	[ScriptMember("toString", ScriptMemberSecurity.Permanent)]
	public override string ToString()
	{
		return Name;
	}
}

private void StartEngine()
{
	Engine = new V8Engine();

	Engine.GlobalObject.SetProperty(typeof(Person));
}

public void ExecuteTest()
{
	Engine.Execute
	(@"
		function hello() {
			var p = new Person();
			p.name = 'Thomas'; // Won't call Name setter - does nothing
			p.age = 30; // Won't call Age setter - does nothing
			Browser.println(p.name); // Output: Michio
			Browser.println(p.age); // Output: 72
		}

		hello();
	", "V8.NET", true, 0);
}

Thanks in advance for fixing :-)

unresolved external symbol "char16_t * __cdecl Realloc<char16_t>

Hello,

I've been trying to compile v8.net proxy on Windows VS2019, however I got the following error and wanted to ask someone more experienced in this project:

Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "char16_t * __cdecl Realloc<char16_t>(char16_t *,unsigned __int64)" (??$Realloc@_S@@YAPEA_SPEA_S_K@Z) V8.Net-Proxy-x64 C:\work\v8dotnet\Source\V8.NET-Proxy\V8EngineProxy.obj 1
Error LNK2001 unresolved external symbol __imp___std_init_once_complete V8.Net-Proxy-x64 C:\work\v8dotnet\Source\V8.NET-Proxy\v8_monolith.lib(umutex.obj) 1
Error LNK2001 unresolved external symbol __imp___std_init_once_begin_initialize V8.Net-Proxy-x64 C:\work\v8dotnet\Source\V8.NET-Proxy\v8_monolith.lib(umutex.obj) 1

What could possibly be the cause of such an issue?
Can you please advise?

Callback problem. GC clear InternalHandle

I maked function with callback
Add(string event_name, string func_name, InternalHandle callback)
I call callback after execution but, GC clear InternalHandle.
It possible clone or other way to call callback?
Thanks!

Can't set value for list of objects

Hey. I'm trying to set value of list array, but

Uncaught Error: => Message: Types.ChangeType(): Cannot convert value "[object Layer]" (type: 'System.String') to type 'V8.NET.Console.ObjectExamples.Layer[]'. If you are developing the source type yourself, implement the 'IConvertible' interface.

Why does V8.Net think this is a string? Is there any way i can execute js correctly?

Here is my code

`public class Layer
{
public string name { get; set; }
}

public class Selection 
{
    public int length => layers.Count;
    public List<Layer> layers;
    public Selection()
    {
        layers = new List<Layer> { new Layer() { name = "ONE" }, new Layer() { name = "TWO" } };
    }
}
public class Console
{
    public void log(string t) { System.Console.WriteLine(t); }
}

class Program
{
    static void Main(string[] args)
    {
        V8Engine v8Engine = new V8Engine();
        v8Engine.GlobalObject.SetProperty("console", new Console(), recursive: true, memberSecurity: ScriptMemberSecurity.ReadWrite);

        v8Engine.RegisterType<Selection>("Selection", true, ScriptMemberSecurity.ReadWrite);
        v8Engine.GlobalObject.SetProperty(typeof(Selection));

        v8Engine.RegisterType<Layer>("Layer", true, ScriptMemberSecurity.ReadWrite); 
        v8Engine.GlobalObject.SetProperty(typeof(Layer));
        v8Engine.RegisterType<Layer[]>();

        v8Engine.RegisterType<System.Collections.Generic.List<Layer>>(null, true, ScriptMemberSecurity.ReadWrite); 
        v8Engine.GlobalObject.SetProperty(typeof(System.Collections.Generic.List<Layer>));
        v8Engine.RegisterType<System.Collections.ArrayList>(null, true, ScriptMemberSecurity.ReadWrite);
        v8Engine.GlobalObject.SetProperty(typeof(System.Collections.ArrayList));

        var gs2 = v8Engine.Execute(
            @"
                var selection = new Selection();
                var layer = new Layer();
                console.log(selection.layers[0].name);
                selection.layers = [layer];
                console.log(selection.layers.name);
               "
        );
        System.Console.WriteLine(gs2.AsString);
        System.Console.ReadKey(true);
    }
}`

I tried to change layers type to Layer[], but except for this error, engine also returns

Uncaught Error: The ObjectBinder is missing for property 'name' (name).

then i try to get array element property;

var selection = new Selection(); console.log(selection.layers[0].name);

[Inject] and [ScriptMember("toString", ...)] not working in base classes

[Inject] and [ScriptMember("toString", ...)] are ignored currently if used in a base class:

[ScriptObject("Person", ScriptMemberSecurity.NoAcccess)]
public class Person
{
	[Inject]
	private V8Engine Engine
	{
		set
		{
			_Engine = value;
			// Not called
			//UnityEngine.Debug.Log("SET _ENGINE");
		}
	}

	private V8Engine _Engine;

	[ScriptMember("name", ScriptMemberSecurity.ReadWrite)]
	public string Name { get; set; }

	public Person(string name)
	{
		Name = name;
	}

	[ScriptMember("age", ScriptMemberSecurity.Permanent)]
	private InternalHandle Age
	{
		get { return _Engine.CreateValue(30); }
	}

	[ScriptMember("toString", ScriptMemberSecurity.Permanent)]
	private InternalHandle _toString()
	{
		// Not called
		//UnityEngine.Debug.Log("toString()");
		return _Engine.CreateValue(ToString());
	}

	public override string ToString()
	{
		return Name;
	}
}

[ScriptObject("Employee", ScriptMemberSecurity.NoAcccess)]
public class Employee : Person
{
	public Employee(string name) :
		base(name)
	{
	}
}
Engine.RegisterType<Person>(null, null, ScriptMemberSecurity.Locked);
Engine.RegisterType<Employee>(null, null, ScriptMemberSecurity.Locked);
Engine.GlobalObject.SetProperty(typeof(Person));
Engine.GlobalObject.SetProperty(typeof(Employee));

Engine.Execute
(@"
	function test() {
		var emp = new Employee('Marie');
		Browser.println(emp); // Output: Marie - because Person::ToString was called instead of Person::_toString
		Browser.println(emp.age); // Crash, because _Engine is null
	}

	test();
", "V8.NET", true, 0);

Thanks :-)

Crash when trying function return InternalHandle with custom properties of class

public InternalHandle call(V8Engine engine, bool ConstructCall, InternalHandle _this, params InternalHandle[] args){
        V8Engine v8 = new V8Engine();
        v8.RegisterType<exports>(null,true,ScriptMemberSecurity.ReadWrite);
        v8.GlobalObject.SetProperty("exports",v8.CreateValue(new exports()));
        v8.Execute("exports.test = 12; var test = class{i =12;}");
        Debug.Log(v8.GlobalObject.GetProperty("exports"));
        
        return v8.GlobalObject.GetProperty("exports"); // crash there
    }

Log outputs:
Debug.Log(v8.GlobalObject.GetProperty("exports"));
"<Object Binder: Active; tracked handle (0), Test+exports, Engine ID: 1, Handle ID: 47, Object ID: 23, Locked: False>"
Debug.Log(v8.GlobalObject.GetProperty("test"));
"<object: Function, Active; tracked handle (0), Engine ID: 3, Handle ID: 51, Object ID: -101, Locked: False>"

ICU data files missing?

#
# Fatal error in ../../src/objects/js-number-format.cc, line 358
# Failed to create ICU number_format, are ICU data files missing?
#
#
#
#FailureMessage Object: 0000003C273FBE50
==== C stack trace ===============================

        V8ExecuteCompiledScript [0x00007FFDD4E841EB+19220107]
        V8ExecuteCompiledScript [0x00007FFDD4B9F921+16186817]
        V8ExecuteCompiledScript [0x00007FFDD4B9090F+16125359]
        V8ExecuteCompiledScript [0x00007FFDD44881AF+8750671]
        V8ExecuteCompiledScript [0x00007FFDD4455DDA+8544890]
        V8ExecuteCompiledScript [0x00007FFDD3DDB4D5+1751413]
        V8ExecuteCompiledScript [0x00007FFDD3DDCF9F+1758271]
        V8ExecuteCompiledScript [0x00007FFDD4933EED+13648781]

Encountering the above error when attempting to render a React component.

Any idea what this means?

Support for decimal type

Hi I have an issue,

I did some tests on calculation and formatting and came over the issue, where you register an object with decimal and double properties. For doubles everything works just fine, but decimal is not known. It always gets converted to object [object Decimal].

I know the calculation of decimal and double are different in C# as well, but there might be a solution as for example treating decimals as doubles inside the engine?

Attempting a Linux Build...

So I'm seriously out of my depth here, but I figured I'd take take a stab at getting the V8 proxy to compile under Linux (WSL 2 - Ubuntu to be exact).

The approach I'm taking is more or less to try and port the vcxproj to a CMakeLists.txt.

I'm able to get the build kicked off but it fails with...

/mnt/c/Projects/v8dotnet/Source/V8.NET-Proxy/ContextProxy.cpp:22:69: error: no viable conversion from 'v8::Isolate *' to 'Local<v8::Context>'
                        auto globalObject = _Context->Global()->GetPrototype()->ToObject(_EngineProxy->Isolate());
                                                                                         ^~~~~~~~~~~~~~~~~~~~~~~
/home/tom/v8/v8/include/v8.h:189:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'v8::Isolate *' to 'const v8::Local<v8::Context> &' for
      1st argument
class Local {
      ^
/home/tom/v8/v8/include/v8.h:189:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'v8::Isolate *' to 'v8::Local<v8::Context> &&' for 1st
      argument
/home/tom/v8/v8/include/v8.h:193:13: note: candidate template ignored: could not match 'Local<type-parameter-0-0>' against 'v8::Isolate *'
  V8_INLINE Local(Local<S> that)
            ^
/home/tom/v8/v8/include/v8.h:2775:22: note: passing argument to parameter 'context' here
      Local<Context> context) const;

I'm not exactly sure what I'm looking at here, any ideas?

Windows XP support

Hi I'm having an issue on Windows XP:

Unable to load DLL 'V8_Net_Proxy_x64': The specified procedure could not be found. (Exception from HRESULT: 0x8007007F) 
    at V8.Net.V8NetProxy.CreateHandleProxyTest64()

It may affect other platforms also. There don't appear to be any missing dependencies.
I'm using the NET40 binaries from the releases folder.

Thanks

System.AccessViolationException in V8_Net_Proxy_x64.DLL

My application crashed when i use V8.NET, but i can not catch this exception, help please..

Framework Version: v4.0.30319
System.AccessViolationException
at V8.Net.V8NetProxy.DoIdleNotification(V8.Net.NativeV8EngineProxy*, Int32)
at V8.Net.V8Engine._WorkerLoop()
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()

[ScriptMember("0", ...] not working with numbers

I would like to set the x member of a custom vector class in JavaScript by writing "v[0] = 5;", but using a number as script member name seems not to work properly. "v[0]" or "v['0']" always returns "undefined". Any ideas?

Btw.: Thank you for this awesome wrapper!

extending .NET type in JS doesn't seem to work

(development branch) Not quite sure what I'm doing wrong here -- also entirely possible that I'm just missing something and this isn't quite supposed to work :)

I would like to have a class defined in C#, and then give JS the ability to extend that, overriding native methods with JS methods as needed.

Here's my testcase:

using System;
using System.Collections.Generic;
using System.Linq;
using V8.Net;

namespace Test2 {
    class GlobalUtils {
        public static void WriteLine(string s) { Console.WriteLine(s); }
    }

    public class BaseClass {
        public BaseClass() { }
        public void Foo() { Console.WriteLine("BaseClass::Foo"); }
        public void Bar() { Console.WriteLine("BaseClass::Bar"); }
    }

    class Program {
        public static void MainFunc(string[] args) {
            var js = new V8Engine();
            
            js.RegisterType<GlobalUtils>("utils", false, ScriptMemberSecurity.Locked);
            js.GlobalObject.SetProperty(typeof(GlobalUtils));

            js.RegisterType<BaseClass>(null, false, ScriptMemberSecurity.Locked);
            js.GlobalObject.SetProperty(typeof(BaseClass));

            js.ConsoleExecute(jssrc);
        }

        private static string jssrc = @"
function Derived() {
}

Derived.prototype = Object.create(BaseClass.prototype);
Derived.prototype.constructor = Derived;
Derived.prototype.Foo = function() {
    utils.WriteLine('proper foo');
}
Derived.prototype.NewFunc = function() {
    utils.WriteLine('newfunc');
}

var x = new Derived();
x.Foo();
x.Bar();
x.NewFunc();
";
    }
}

This results in:

C:/proj/cs/ScriptBridge/bin/Debug/ScriptBridge.exe
proper foo
Uncaught TypeError: x.Bar is not a function
  Line: 16  Column: 2
  Stack:
    at V8.NET:16:3

as if it's not chaining up to BaseClass at all. If I create a new instance of BaseClass, I can call Foo and Bar just fine.

Note that if I switch the JS to es6 class syntax, the behaviour changes to the exact opposite: (replace the JS source with this)

class Derived extends BaseClass {
    constructor() { super(); utils.WriteLine('derived constructor'); }
    Foo() { utils.WriteLine('proper foo'); }
    NewFunc() { utils.WriteLine('newfunc'); }
}

var x = new Derived();
x.Foo();
x.Bar();
x.NewFunc();

output:

derived constructor
BaseClass::Foo
BaseClass::Bar
Uncaught TypeError: x.NewFunc is not a function
  Line: 11  Column: 2
  Stack:
    at V8.NET:11:3

In this case, it's as if the Derived class just isn't there, and a BaseClass was constructed instead -- but the derived constructor is clearly being called.

Also unexpected with the es6 syntax -- x instanceof Derived is false, as is x instanceof BaseClass. They're both properly true when using the original prototype-based code.

Ten general questions about making a Celeste mod with V8 integration

Hello,

So I'm making a Celeste mod using Everest that allows use of scripts, this makes it possible for people who have never coded before (the Everest mod loader allows for loading maps and not just code mods, so some modders don't code) to code some simple behaviours using the simple, easy and well-documented JavaScript language, rather than having to deal with how complex C# is for beginners.

I have a BUNCH of questions about using V8.NET for that purpose, since I couldn't understand much from the wiki, which are as follows:
(Please note that I have set up an "initialization" method that runs on a seperate thread and does some preparations while the game is loading to speed things up, so if any required process requires or can benefit from beforehand preparations please let me know in the answer, thank you)

First question:
TLDR: What is the fastest way to expose a CLR object or type "as is" from the game or from an other mod that I cannot edit or change?
Speed is the most important thing here, since its a game.
While writing this question I noticed that creating a binding and putting it as a property on the global object works nicely (I thought it doesn't), but its unpredictably unreliable. Some classes just don't work for seemingly no reason, like System.Diagnostics.Stopwatch, if I try doing this:
Stopwatch timer = new Stopwatch();
Then this:
Engine.GlobalObject.SetProperty("timer", timer);
I would get "undefined" whenever I try to access any method or property timer.xxxx from inside a script. The XML docs says stuff about sub-object members and boxed primitives, I don't understand what that means, I would assume its boxed value-types but not sure, am I missing something here?
I then tried writing an "ObjectExporter" class that takes an object, and using some Reflection it exposes the properties and methods of the original object. That worked very very well, except for the fact that its SO DAMN SLOW both on initialization and on execution, it horribly slows down the game's loop.
I saw the class ObjectBinder and thought of deriving from it but I couldn't figure out how, and I didn't know if it'll work for any class or it's specific.

Second question:
What is the fastest way to expose a CLR object or type that I have control over?
And by fastest, I mean which approach would give me the best performance on calling methods and retrieving properties.
I need to write some helper objects and classes for the scripts to use and I want those to work the FASTEST possible, since those are gonna be used very very frequently inside scripts, they're basically the main link between the scripts and the game.
The current method I'm using is the regular "binding -> property on global object" method, which works well but doesn't feel like the best approach, XML docs indicate that creating bindings is a slow process which is fine since again, speed doesn't matter since all the initialization work is done on a seperate thread, but I have no idea if it executes the fastest or not.

Third question:
Say, I did expose a CLR object to the script, what is the best way to also expose extensions methods alongside the object? (If that's possible at all, even if it means using slow means like Reflection-ing every single static type to look for the extensions, since as I mentioned earlier, initialization doesn't have to be fast)
Extensions would make it much easier for me and other mods to provide extra functionality for scripts on top of the game's original classes that's used in a very simple fashion, avoiding having to write either a messy mass of methods on a single class, or expose the mass of static classes containing extensions.

Fourth question:
How does one use a generic method or a generic type from inside a script? (If its possible ofc)

Fifth question:
Having exposed a type, is it possible to use static methods and fields/properties? If so, should I be exposing a TypeBinder or a regular plain Type? And if extension methods are possible to expose, what can I do (on a method that extends System.Type) to expose a new object instance given a Type object?

Sixth question:
What's with the context? What's its use? What I know about V8 is that the context represents quite literally the context for the scripts, but it feels a little bit "ambigous" -would you say- to use.
Edit: While writing this question I realized that contexts can be used to provide a custom object template for the GlobalObject property, is that really the only use to it?

Seventh question:
In the context of contexts, because I feel this is related to contexts, does a globally-scoped script-defined function or variable persist across multiple script executions (including the case where executed scripts are different)? If so, does that mean I have to "new" a V8Engine for each mod to not cause global conflictions? If that's the case, is it possible to do some sort of "clean-up" to remove all global variables and functions? That would be useful for scripters.

It might seem like I don't like that but I actually do, it means I can initialize a seperate engine for each mod and execute a mod-defined "Initialize.js" script that imports the types and classes (if there is a good answer to question 1) and puts them on global variables, and defined some global functions for use in the other scripts, that's a huge speed boost to executing the scripts.

Eighth question:
Is there a good way to use generator functions? I built an Iterator class that takes the InternalHandle returned from a generator function and iterates through it, but its a bit slow since it has to call next() on the iterator on each iteration and it also has to retrieve "current" and "done" properties from the returned object of next() which is quite a bit of work, even when I changed from using Handle to using InternalHandle (since its a class I can dispose of the handles in the deconstructor) which sped things up quite a bit but still not enough to support a descent amount of code inside the actual game.

Ninth question:
What is the fastest way to retrieve a V8NativeObject out of an InternalHandle representing a JavaScript object? I tried InternalHandle.Object but that is null all the time, and the only approach I found to be working is using InternalHandle.Engine.CreateObject as I did it on an extension method, which seems slow and since it's used inside the Iterator class I built (which I really need to speed up) a speed boost on this could help.

Tenth question: (and possibly the most important question)
Debugging, debugging, DEBUGGING. Looking at the source code I found a line that calls some method on the proxy with parameters:
bool enableDebugging, void* debugMessageDispatcher, int debuggerPort
I tried changing those (well, I couldn't change the code and build since I was offline and didn't have some required stuff on Visual Studio so I had to do a little bit of runtime IL manipulation which I'm pretty sure works just as well, and its a temporary solution anyways) and it doesn't work, or at least it doesn't with Chrome's Node.JS dedicated-debugger (which works nicely with ClearScript, so my big brain told me it should work with anything V8). The only theory I have in mind is that the two use different debugging protocol, I remember reading a document about a legacy debugging protocol and a new one. If that's the case, is it planned to implement the new one? I would've done it myself if I wasn't braindead. Debugging would be a very major plus to the library and would make scripting much easier.

Those are all my questions, and I'm ready to write a small FAQ page based on the answers, that is if there's gonna be any answers at all and if it's gonna be useful.
Sorry if there are too many questions, or they're a little bit too long. I didn't want to post TEN issues seperately for each question repeating how I'm making a Celeste mod and everything, and I wanted to make my questions as specific as possible to avoid confusion.

And finally, here are some puns as my way of showing gratitude for the effort that's gonna be needed to put an answer altogether for the questions, or to read them at all :)

  1. What does the gardener do when he finishes his work? He leafs and goes home.
  2. I was asked to put the cat out, I didn't know it had caugh fire.
  3. I have a builder friend, I asked him to give me a pun but he said he's "working" on one.
  4. What do you say about a very visually-appealing hand-drawn painting? It "draws" attention.
  5. I once heard a pun about paper, it was "tearable".
  6. My friend was offered a job as a stand-up comedian, but he prefered "sitting".
  7. Mettaton: Have you met any other robots like me, human?
    Human: Yup, I've met-a-ton.
  8. How does one describe long hands? "Catchy".

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.