closure-funcexpr-eval.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function write(x) { WScript.Echo(x + ""); }
  6. (function f(x) {
  7. write(f);
  8. write(x);
  9. (function () {
  10. write(f);
  11. write(x);
  12. eval('f = "inner f";');
  13. eval('x = "inner x";');
  14. write(f);
  15. write(x);
  16. eval('var f = "inner f 2";');
  17. eval('var x = "inner x 2";');
  18. write(f);
  19. write(x);
  20. })();
  21. write(f);
  22. write(x);
  23. })('outer x');
  24. var functest;
  25. var vartest = 0;
  26. var value = (function functest(arg) {
  27. eval('');
  28. if (arg) return 1;
  29. vartest = 1;
  30. functest = function(arg) {
  31. return 2;
  32. }; // this line does nothing as 'functest' is ReadOnly here
  33. return functest(true); // this is therefore tail recursion and returns 1
  34. })(false);
  35. WScript.Echo('vartest = ' + vartest);
  36. WScript.Echo('value = ' + value);
  37. (function (){
  38. try {
  39. throw 'hello';
  40. }
  41. catch(e) {
  42. var f = function(){ eval('WScript.Echo(e)') };
  43. }
  44. f();
  45. })();
  46. var moobah = function moobah() {
  47. this.innerfb = function() {
  48. moobah.x = 'whatever';
  49. }
  50. this.innerfb();
  51. write(moobah.x);
  52. }
  53. moobah();