proto_addprop.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. /// <reference path="../UnitTestFramework/UnitTestFramework.js" />
  6. if (this.WScript && this.WScript.LoadScriptFile) {
  7. WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  8. }
  9. var p = { pp: 123 };
  10. function F() { this.dummy = 12; /*reserve slots, make jit code simpler to read*/ }
  11. F.prototype = p;
  12. function make_object() {
  13. /// Create new objects of the same Type, and with __proto__ "p"
  14. return new F();
  15. }
  16. function foo(o) {
  17. o.x = 1;
  18. o.y = 2;
  19. }
  20. // Need to run this twice. Test with maxinterpretcount 1 and 2
  21. foo(make_object());
  22. foo(make_object());
  23. var o3 = make_object();
  24. assert.isTrue(Object.getPrototypeOf(o3) === p);
  25. p.__proto__ = { get x() { return "x"; } };
  26. foo(o3);
  27. assert.areEqual("x", o3.x, "Shouldn't add field x");
  28. WScript.Echo("pass");