Last active
August 29, 2015 14:14
-
-
Save chrisber/bcf2d92d31cadc70f8e0 to your computer and use it in GitHub Desktop.
#v8dotnet Adding a fuction to global context setTimeout()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class setTimeout : V8Function | |
{ | |
public override ObjectHandle Initialize(bool isConstructCall, params InternalHandle[] args) | |
{ | |
Callback = setTimeoutConstructWrapper; | |
return base.Initialize(isConstructCall, args); | |
} | |
public InternalHandle setTimeoutConstructWrapper(V8Engine engine, bool isConstructCall, InternalHandle _this, params InternalHandle[] args) | |
{ | |
Thread.Sleep(args[1]); | |
return args[0].Call(null); | |
} | |
} | |
V8Engine v8Engine = new V8Engine(); | |
var funcTemplate = v8Engine.CreateFunctionTemplate(typeof(setTimeout).Name); | |
var testerFunc = funcTemplate.GetFunctionObject<setTimeout>(); | |
v8Engine.DynamicGlobalObject.setTimeout = testerFunc; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment