new-expression.js 811 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. load("test-common.js");
  2. try {
  3. function Foo() { this.x = 1; }
  4. let foo = new Foo();
  5. assert(foo.x === 1);
  6. foo = new Foo
  7. assert(foo.x === 1);
  8. foo = new
  9. Foo
  10. ()
  11. assert(foo.x === 1);
  12. foo = new Foo + 2
  13. assert(foo === "[object Object]2");
  14. let a = {
  15. b: function() {
  16. this.x = 2;
  17. },
  18. };
  19. foo = new a.b();
  20. assert(foo.x === 2);
  21. foo = new a.b;
  22. assert(foo.x === 2);
  23. foo = new
  24. a.b();
  25. assert(foo.x === 2);
  26. function funcGetter() {
  27. return function(a, b) {
  28. this.x = a + b;
  29. };
  30. };
  31. foo = new funcGetter()(1, 5);
  32. assert(foo === undefined);
  33. foo = new (funcGetter())(1, 5);
  34. assert(foo.x === 6);
  35. console.log("PASS");
  36. } catch (e) {
  37. console.log("FAIL: " + e);
  38. }