with.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. // 0
  6. {
  7. with({x:0}) {
  8. WScript.Echo(x)
  9. }
  10. let x = 1
  11. }
  12. // 0
  13. {
  14. eval('with({x:0}) { WScript.Echo(x) }')
  15. let x = 1
  16. }
  17. // 0
  18. {
  19. let f = function() {
  20. with({x:0}) {
  21. WScript.Echo(x)
  22. }
  23. }
  24. let x = 1
  25. f()
  26. }
  27. // Reference error.
  28. {
  29. try {
  30. with({}) {
  31. WScript.Echo(x)
  32. }
  33. let x = 1
  34. } catch(e) {
  35. WScript.Echo(e)
  36. }
  37. }
  38. // Reference error.
  39. {
  40. try {
  41. eval('with({}) { WScript.Echo(x) }')
  42. let x = 1
  43. } catch(e) {
  44. WScript.Echo(e)
  45. }
  46. }
  47. // 1
  48. {
  49. with({x:0}) {
  50. let x = 1
  51. WScript.Echo(x)
  52. }
  53. }
  54. // Reference error.
  55. {
  56. try {
  57. with({x:0}) {
  58. WScript.Echo(x)
  59. let x = 1
  60. }
  61. } catch(e) {
  62. WScript.Echo(e)
  63. }
  64. }
  65. // string
  66. with({x: 'x'})
  67. {
  68. WScript.Echo(typeof x)
  69. }
  70. let x = 5