OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/base/utils/random-number-generator.h" | 5 #include "src/base/utils/random-number-generator.h" |
6 #include "src/code-factory.h" | 6 #include "src/code-factory.h" |
7 #include "src/code-stub-assembler.h" | 7 #include "src/code-stub-assembler.h" |
8 #include "src/compiler/node.h" | 8 #include "src/compiler/node.h" |
9 #include "src/ic/stub-cache.h" | 9 #include "src/ic/stub-cache.h" |
10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
(...skipping 1711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1722 ft.Call(handle(Smi::FromInt(i), isolate)).ToHandleChecked(); | 1722 ft.Call(handle(Smi::FromInt(i), isolate)).ToHandleChecked(); |
1723 Handle<NameDictionary> dict = NameDictionary::New(isolate, i); | 1723 Handle<NameDictionary> dict = NameDictionary::New(isolate, i); |
1724 // Both dictionaries should be memory equal. | 1724 // Both dictionaries should be memory equal. |
1725 int size = | 1725 int size = |
1726 FixedArrayBase::kHeaderSize + (dict->length() - 1) * kPointerSize; | 1726 FixedArrayBase::kHeaderSize + (dict->length() - 1) * kPointerSize; |
1727 CHECK_EQ(0, memcmp(*dict, *result, size)); | 1727 CHECK_EQ(0, memcmp(*dict, *result, size)); |
1728 } | 1728 } |
1729 } | 1729 } |
1730 } | 1730 } |
1731 | 1731 |
1732 TEST(PopAndReturnConstant) { | |
1733 Isolate* isolate(CcTest::InitIsolateOnce()); | |
1734 | |
1735 const int kNumParams = 4; | |
1736 const int kNumProgramaticParams = 2; | |
1737 CodeStubAssemblerTester m(isolate, kNumParams - kNumProgramaticParams); | |
1738 | |
1739 // Call a function that return |kNumProgramaticParams| parameters in addition | |
1740 // to those specified by the static descriptor. |kNumProgramaticParams| is | |
1741 // specified as a constant. | |
1742 m.PopAndReturn(m.Int32Constant(kNumProgramaticParams), | |
1743 m.SmiConstant(Smi::FromInt(1234))); | |
1744 | |
1745 Handle<Code> code = m.GenerateCode(); | |
1746 CHECK(!code.is_null()); | |
1747 | |
1748 FunctionTester ft(code, kNumParams); | |
1749 Handle<Object> result; | |
1750 for (int test_count = 0; test_count < 100; ++test_count) { | |
1751 result = ft.Call(isolate->factory()->undefined_value(), | |
1752 Handle<Smi>(Smi::FromInt(1234), isolate), | |
1753 isolate->factory()->undefined_value(), | |
1754 isolate->factory()->undefined_value()) | |
1755 .ToHandleChecked(); | |
1756 CHECK_EQ(1234, Handle<Smi>::cast(result)->value()); | |
1757 } | |
1758 } | |
1759 | |
1760 TEST(PopAndReturnVariable) { | |
1761 Isolate* isolate(CcTest::InitIsolateOnce()); | |
1762 | |
1763 const int kNumParams = 4; | |
1764 const int kNumProgramaticParams = 2; | |
1765 CodeStubAssemblerTester m(isolate, kNumParams - kNumProgramaticParams); | |
1766 | |
1767 // Call a function that return |kNumProgramaticParams| parameters in addition | |
1768 // to those specified by the static descriptor. |kNumProgramaticParams| is | |
1769 // passed in as a parameter to the function so that it can't be recongized as | |
1770 // a constant. | |
1771 m.PopAndReturn(m.SmiUntag(m.Parameter(1)), m.SmiConstant(Smi::FromInt(1234))); | |
1772 | |
1773 Handle<Code> code = m.GenerateCode(); | |
1774 CHECK(!code.is_null()); | |
1775 | |
1776 FunctionTester ft(code, kNumParams); | |
1777 Handle<Object> result; | |
1778 for (int test_count = 0; test_count < 100; ++test_count) { | |
1779 result = | |
1780 ft.Call(isolate->factory()->undefined_value(), | |
1781 Handle<Smi>(Smi::FromInt(1234), isolate), | |
1782 isolate->factory()->undefined_value(), | |
1783 Handle<Smi>(Smi::FromInt(kNumProgramaticParams * kPointerSize), | |
1784 isolate)) | |
1785 .ToHandleChecked(); | |
1786 CHECK_EQ(1234, Handle<Smi>::cast(result)->value()); | |
1787 } | |
1788 } | |
1789 | |
1790 } // namespace internal | 1732 } // namespace internal |
1791 } // namespace v8 | 1733 } // namespace v8 |
OLD | NEW |