proxy.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. var handler1 = {
  6. get: function(target, key)
  7. {
  8. return key in target ? target[key] : 'Not Found';
  9. }
  10. };
  11. var handler2 = {
  12. get: function(target, key)
  13. {
  14. return "[[" + key + "]]";;
  15. }
  16. };
  17. var p = new Proxy({}, handler1);
  18. p.a = 1;
  19. var revocable = Proxy.revocable({}, handler2);
  20. var proxy = revocable.proxy;
  21. var revocableDone = Proxy.revocable({}, handler2);
  22. var proxyDone = revocableDone.proxy;
  23. revocableDone.revoke();
  24. WScript.SetTimeout(testFunction, 50);
  25. /////////////////
  26. function testFunction()
  27. {
  28. var threw = false;
  29. telemetryLog(`p.a: ${p.a}`, true); //1);
  30. telemetryLog(`p.b: ${p.b}`, true); //Not Found
  31. try
  32. {
  33. proxyDone.foo;
  34. }
  35. catch(e)
  36. {
  37. threw = true;
  38. }
  39. telemetryLog(`proxyDone.foo: ${threw}`, true); //true
  40. telemetryLog(`proxy.foo: ${proxy.foo}`, true); //[[foo]]
  41. revocable.revoke();
  42. try
  43. {
  44. proxy.foo;
  45. }
  46. catch(e)
  47. {
  48. threw = true;
  49. }
  50. telemetryLog(`proxy.foo (after revoke): ${threw}`, true); //true
  51. }