FixedFieldsWithPropertyStringCache.js 972 B

123456789101112131415161718192021222324252627282930
  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. // Run with jc -maxinterpretcount:1
  6. // Create a path type with fixed method 'o.inspect'.
  7. var o = {};
  8. o.inspect = function () { WScript.Echo("original"); };
  9. // JIT a function that uses the fixed method
  10. function useMethod(obj) {
  11. obj.inspect();
  12. }
  13. useMethod(o);
  14. useMethod(o);
  15. // Use the property cache to overwrite the fixed method
  16. function test(obj, overwrite) {
  17. for (var prop in obj) {
  18. if (overwrite)
  19. obj[prop] = function () { WScript.Echo("new"); }
  20. }
  21. }
  22. test(o,false);
  23. test(o,true);
  24. // Verify that the new function is called.
  25. useMethod(o);