deferredGetterSetter.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // /forcedeferparse test to make sure we can handle getters and setters at global scope,
  6. // at function scope, and with nested functions.
  7. var x = {
  8. _y : 'x.y',
  9. get y() { WScript.Echo('getting x.y'); return this._y; },
  10. set y(val) { WScript.Echo('setting x.y'); this._y = val; }
  11. };
  12. WScript.Echo(x.y);
  13. x.y = 'new x.y';
  14. function f() {
  15. var x = {
  16. _y : 'local x.y',
  17. get y() { WScript.Echo('getting local x.y'); return this._y; },
  18. set y(val) { WScript.Echo('setting local x.y'); this._y = val; }
  19. };
  20. WScript.Echo(x.y);
  21. x.y = 'new local x.y';
  22. var nested_x = {
  23. _y : 'nested x.y',
  24. get y() { function fget(o) { WScript.Echo('getting nested x.y'); return o._y; } return fget(this); },
  25. set y(val) { function fset(o, val) { WScript.Echo('setting nested x.y'); o._y = val; } fset(this, val); }
  26. };
  27. WScript.Echo(nested_x.y);
  28. nested_x.y = 'new nested x.y';
  29. WScript.Echo(nested_x.y);
  30. WScript.Echo(x.y);
  31. }
  32. f();
  33. WScript.Echo(x.y);