strictdefaultsetter.js 867 B

12345678910111213141516171819202122232425262728293031
  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. 'use strict';
  6. function f(o) {
  7. o.x = 'me';
  8. }
  9. var o1 = { set x(v) { val = v; } };
  10. var o2 = { get x() { WScript.Echo('get') } };
  11. var val = 'you';
  12. f(o1);
  13. if (val !== 'me') WScript.Echo('fail 1');
  14. val = 'you';
  15. f(o1);
  16. if (val !== 'me') WScript.Echo('fail 2');
  17. try {
  18. f(o2);
  19. }
  20. catch(e) {
  21. val = e;
  22. }
  23. if (val.toString() === 'TypeError: Assignment to read-only properties is not allowed in strict mode')
  24. WScript.Echo('pass');
  25. else
  26. WScript.Echo('fail 3');