Skip to content

Instantly share code, notes, and snippets.

@sjmulder
Created April 18, 2017 09:03
Show Gist options
  • Save sjmulder/e103746f9b2a9e3fe3997f22d899975d to your computer and use it in GitHub Desktop.
Save sjmulder/e103746f9b2a9e3fe3997f22d899975d to your computer and use it in GitHub Desktop.
Sample of how referencing setTimeout in a VroomJs context causes an error
/* Sample of how referencing setTimeout in a VroomJs context causes an
error.
Tested with NuGet package VroomJs 1.2.3 */
using VroomJs;
class Program
{
static void Main(string[] args)
{
AssemblyLoader.EnsureLoaded();
using (var js = new JsEngine())
using (var context = js.CreateContext())
{
/* f1() will work because setTimeout, which is not availablve
within the VroomJs context, is only referenced by the inner
function which is not executed.
f2() will fail because the 'var x = setTimeout' line yields a
reference error when executed. */
context.Execute(@"
function f1() {
return function() {
setTimeout(function() {}, 1);
}
}
function f2() {
var x = setTimeout;
return function() {
x(function() {}, 1);
}
}");
context.Execute("f1();");
context.Execute("f2();");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment