substring.js 1.0 KB

123456789101112131415161718192021222324252627282930313233
  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. // Testing our implementation of the substring, making sure that we keep the correct reference
  6. // of the original string so that it doesn't get collected
  7. var s = new String();
  8. s = s + 'a';
  9. s = s + 'b';
  10. s = s + 'c';
  11. s = s + 'd';
  12. s = s + 'e';
  13. var s1 = s.substr(1,3);
  14. var s2 = s1.substr(1,2);
  15. s = undefined;
  16. s1 = undefined;
  17. //implicit calls
  18. function foo()
  19. {
  20. var a = 1;
  21. var b = 2;
  22. var obj = {toString: function(){ a=3; return "Hello World";}};
  23. a = b;
  24. Object.prototype.substring = String.prototype.substring;
  25. var f = obj.substring(2,7);
  26. WScript.Echo (a);
  27. }
  28. foo();
  29. CollectGarbage();
  30. WScript.Echo(s2);