generators-cachedscope.js 1.1 KB

1234567891011121314151617181920212223242526
  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. // This is a sketchy test because it relies on knowing that the following pattern
  6. // hits the heuristics that decide to cache the scopes within the generator function.
  7. // If those heuristics were to change this test could no longer be hitting the
  8. // desired code paths. If you suspect it is not hitting the cached scope code paths
  9. // dump the bytecode and check for InitCachedScope and LdHeapArgsCached opcodes.
  10. var o = {
  11. gf: function* () {
  12. var _a = 'pas';
  13. function a() { return _a; }
  14. return eval('a()') + arguments[0];
  15. }
  16. };
  17. function test() {
  18. for (var i = 0; i < 3; i += 1) {
  19. var g = o.gf('sed');
  20. WScript.Echo(g.next().value);
  21. }
  22. }
  23. test();