writable1.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. //
  6. // Test changing [writable] attribute should trigger Type transition.
  7. //
  8. var echo = this.WScript ? WScript.Echo : function () { console.log([].join.apply(arguments, [", "])); };
  9. function assert(value, msg) { if (!value) { throw new Error("Failed: " + msg); } }
  10. function endTest() { echo("pass"); }
  11. //
  12. // Win8: 713428
  13. //
  14. // When CLEAR writable on a SHARED SimpleTypeHandler, we fail to ChangeType, thus fail to invalidate cache.
  15. // This test exploits the bug with inline cache.
  16. //
  17. function changePrototype(f, expectedSucceed, msg) {
  18. var tmp = new Object();
  19. // This exploits inline cache
  20. f.prototype = tmp;
  21. var succeeded = (f.prototype === tmp);
  22. assert(succeeded === expectedSucceed, msg);
  23. }
  24. // Initially we use a shared SimpleTypeHandler with "prototype" property for a function.
  25. function f() { }
  26. changePrototype(f, true, "Should be able to change f.prototype initially");
  27. Object.defineProperty(f, "prototype", { writable: false });
  28. changePrototype(f, false, "f.prototype is now not writable, shouldn't be changed");
  29. endTest();