seal.js 1.1 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. function write(args)
  6. {
  7. WScript.Echo(args);
  8. }
  9. write("TestCase1");
  10. write(Object.seal.length);
  11. write(Object.isSealed({}));
  12. write("TestCase2 - seal & add a property");
  13. var a = {x:20, y:30};
  14. Object.seal(a);
  15. SafeCall(function() { a.x = 40; });
  16. SafeCall(function() { a.z = 50; });
  17. write(Object.getOwnPropertyNames(a));
  18. write(Object.isSealed(a));
  19. write(a.x);
  20. write("TestCase3 - seal & delete a property");
  21. var a = {x:20, y:30};
  22. Object.seal(a);
  23. SafeCall(function() { a.x = 40; });
  24. SafeCall(function() { delete a.x; });
  25. SafeCall(function() { a.z = 50; });
  26. write(Object.getOwnPropertyNames(a));
  27. write(Object.isSealed(a));
  28. write(a.x);
  29. function SafeCall(f)
  30. {
  31. try
  32. {
  33. f();
  34. }
  35. catch (e)
  36. {
  37. write("Exception: " + e.name);
  38. }
  39. }