Skip to content

Instantly share code, notes, and snippets.

@chrisber
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisber/bcf2d92d31cadc70f8e0 to your computer and use it in GitHub Desktop.
Save chrisber/bcf2d92d31cadc70f8e0 to your computer and use it in GitHub Desktop.
#v8dotnet Adding a fuction to global context setTimeout()
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