Created
April 18, 2017 09:03
-
-
Save sjmulder/e103746f9b2a9e3fe3997f22d899975d to your computer and use it in GitHub Desktop.
Sample of how referencing setTimeout in a VroomJs context causes an error
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
/* 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