FunctionTests.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using Xunit;
  3. namespace Jint.Tests.Runtime
  4. {
  5. public class FunctionTests
  6. {
  7. [Fact]
  8. public void BindCombinesBoundArgumentsToCallArgumentsCorrectly()
  9. {
  10. var e = new Engine();
  11. e.Execute("var testFunc = function (a, b, c) { return a + ', ' + b + ', ' + c + ', ' + JSON.stringify(arguments); }");
  12. Assert.Equal("a, 1, a, {\"0\":\"a\",\"1\":1,\"2\":\"a\"}", e.Execute("testFunc('a', 1, 'a');").GetCompletionValue().AsString());
  13. Assert.Equal("a, 1, a, {\"0\":\"a\",\"1\":1,\"2\":\"a\"}", e.Execute("testFunc.bind('anything')('a', 1, 'a');").GetCompletionValue().AsString());
  14. }
  15. [Fact]
  16. public void ProxyCanBeRevokedWithoutContext()
  17. {
  18. new Engine()
  19. .Execute(@"
  20. var revocable = Proxy.revocable({}, {});
  21. var revoke = revocable.revoke;
  22. revoke.call(null);
  23. ");
  24. }
  25. [Fact]
  26. public void ArrowFunctionShouldBeExtensible()
  27. {
  28. new Engine()
  29. .SetValue("assert", new Action<bool>(Assert.True))
  30. .Execute(@"
  31. var a = () => null
  32. Object.defineProperty(a, 'hello', { enumerable: true, get: () => 'world' })
  33. assert(a.hello === 'world')
  34. a.foo = 'bar';
  35. assert(a.foo === 'bar');
  36. ");
  37. }
  38. }
  39. }