ObjectSpread_JIT.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. // Object Spread JIT unit tests
  6. if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch
  7. this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  8. }
  9. var tests = [
  10. {
  11. name: "Test JIT basic behavior",
  12. body: function() {
  13. function f() {
  14. return {...{a: 1}};
  15. }
  16. f();
  17. let obj = f();
  18. assert.areEqual(1, obj.a);
  19. }
  20. },
  21. {
  22. name: "Test JIT bailout",
  23. body: function() {
  24. const obj = { a: 2 };
  25. function f(x) {
  26. const a = obj.a;
  27. const unused = {...x};
  28. return a + obj.a;
  29. }
  30. // Train it that ...x is not reentrant, so it emits code that assumes the second obj.a matches the first
  31. const result = f({});
  32. assert.areEqual(4, result);
  33. // Now call with a getter and verify that it bails out when the previous assumption is invalidated
  34. const reentrantResult = f({ get b() { obj.a = 3; } });
  35. assert.areEqual(5, reentrantResult);
  36. }
  37. },
  38. ];
  39. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });